Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
neoppod
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
1
Issues
1
List
Boards
Labels
Milestones
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
neoppod
Commits
e438f864
Commit
e438f864
authored
Aug 10, 2015
by
Julien Muchembled
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
client: a simple lock is enough for the connection pool
parent
c319b065
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
4 additions
and
9 deletions
+4
-9
neo/client/pool.py
neo/client/pool.py
+4
-9
No files found.
neo/client/pool.py
View file @
e438f864
...
@@ -18,7 +18,7 @@ import time
...
@@ -18,7 +18,7 @@ import time
from
random
import
shuffle
from
random
import
shuffle
from
neo.lib
import
logging
from
neo.lib
import
logging
from
neo.lib.locking
import
R
Lock
from
neo.lib.locking
import
Lock
from
neo.lib.protocol
import
NodeTypes
,
Packets
from
neo.lib.protocol
import
NodeTypes
,
Packets
from
neo.lib.connection
import
MTClientConnection
,
ConnectionClosed
from
neo.lib.connection
import
MTClientConnection
,
ConnectionClosed
from
neo.lib.exception
import
NodeNotReady
from
neo.lib.exception
import
NodeNotReady
...
@@ -46,9 +46,7 @@ class ConnectionPool(object):
...
@@ -46,9 +46,7 @@ class ConnectionPool(object):
# Define a lock in order to create one connection to
# Define a lock in order to create one connection to
# a storage node at a time to avoid multiple connections
# a storage node at a time to avoid multiple connections
# to the same node.
# to the same node.
l
=
RLock
()
self
.
_lock
=
Lock
()
self
.
connection_lock_acquire
=
l
.
acquire
self
.
connection_lock_release
=
l
.
release
self
.
node_failure_dict
=
{}
self
.
node_failure_dict
=
{}
def
_initNodeConnection
(
self
,
node
):
def
_initNodeConnection
(
self
,
node
):
...
@@ -142,8 +140,7 @@ class ConnectionPool(object):
...
@@ -142,8 +140,7 @@ class ConnectionPool(object):
# Already connected to node
# Already connected to node
return
self
.
connection_dict
[
uuid
]
return
self
.
connection_dict
[
uuid
]
except
KeyError
:
except
KeyError
:
self
.
connection_lock_acquire
()
with
self
.
_lock
:
try
:
# Second lookup, if another thread initiated connection
# Second lookup, if another thread initiated connection
# while we were waiting for connection lock.
# while we were waiting for connection lock.
try
:
try
:
...
@@ -157,8 +154,6 @@ class ConnectionPool(object):
...
@@ -157,8 +154,6 @@ class ConnectionPool(object):
if
conn
is
not
None
:
if
conn
is
not
None
:
self
.
connection_dict
[
uuid
]
=
conn
self
.
connection_dict
[
uuid
]
=
conn
return
conn
return
conn
finally
:
self
.
connection_lock_release
()
def
removeConnection
(
self
,
node
):
def
removeConnection
(
self
,
node
):
"""Explicitly remove connection when a node is broken."""
"""Explicitly remove connection when a node is broken."""
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment