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
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Vincent Pelletier
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
Hide 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
from
random
import
shuffle
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.connection
import
MTClientConnection
,
ConnectionClosed
from
neo.lib.exception
import
NodeNotReady
...
...
@@ -46,9 +46,7 @@ class ConnectionPool(object):
# Define a lock in order to create one connection to
# a storage node at a time to avoid multiple connections
# to the same node.
l
=
RLock
()
self
.
connection_lock_acquire
=
l
.
acquire
self
.
connection_lock_release
=
l
.
release
self
.
_lock
=
Lock
()
self
.
node_failure_dict
=
{}
def
_initNodeConnection
(
self
,
node
):
...
...
@@ -142,8 +140,7 @@ class ConnectionPool(object):
# Already connected to node
return
self
.
connection_dict
[
uuid
]
except
KeyError
:
self
.
connection_lock_acquire
()
try
:
with
self
.
_lock
:
# Second lookup, if another thread initiated connection
# while we were waiting for connection lock.
try
:
...
...
@@ -156,9 +153,7 @@ class ConnectionPool(object):
conn
=
self
.
_initNodeConnection
(
node
)
if
conn
is
not
None
:
self
.
connection_dict
[
uuid
]
=
conn
return
conn
finally
:
self
.
connection_lock_release
()
return
conn
def
removeConnection
(
self
,
node
):
"""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