Commit 2dcc079b authored by Julien Muchembled's avatar Julien Muchembled

client: do never reconnect to master if already connected

parent d85b471d
...@@ -107,11 +107,9 @@ class Application(object): ...@@ -107,11 +107,9 @@ class Application(object):
# _cache_lock is used for the client cache # _cache_lock is used for the client cache
self._cache_lock_acquire = lock.acquire self._cache_lock_acquire = lock.acquire
self._cache_lock_release = lock.release self._cache_lock_release = lock.release
lock = Lock()
# _connecting_to_master_node is used to prevent simultaneous master # _connecting_to_master_node is used to prevent simultaneous master
# node connection attemps # node connection attemps
self._connecting_to_master_node_acquire = lock.acquire self._connecting_to_master_node = Lock()
self._connecting_to_master_node_release = lock.release
# _nm ensure exclusive access to the node manager # _nm ensure exclusive access to the node manager
lock = Lock() lock = Lock()
self._nm_acquire = lock.acquire self._nm_acquire = lock.acquire
...@@ -231,15 +229,16 @@ class Application(object): ...@@ -231,15 +229,16 @@ class Application(object):
def _getMasterConnection(self): def _getMasterConnection(self):
""" Connect to the primary master node on demand """ """ Connect to the primary master node on demand """
# acquire the lock to allow only one thread to connect to the primary # For performance reasons, get 'master_conn' without locking.
result = self.master_conn result = self.master_conn
if result is None: if result is None:
self._connecting_to_master_node_acquire() # If not connected, 'master_conn' must be tested again while we have
try: # the lock, to avoid concurrent threads reconnecting.
self.new_oid_list = [] with self._connecting_to_master_node:
result = self._connectToPrimaryNode() result = self.master_conn
finally: if result is None:
self._connecting_to_master_node_release() self.new_oid_list = []
result = self.master_conn = self._connectToPrimaryNode()
return result return result
def getPartitionTable(self): def getPartitionTable(self):
......
...@@ -80,7 +80,6 @@ class PrimaryBootstrapHandler(AnswerBaseHandler): ...@@ -80,7 +80,6 @@ class PrimaryBootstrapHandler(AnswerBaseHandler):
# Always create partition table # Always create partition table
app.pt = PartitionTable(num_partitions, num_replicas) app.pt = PartitionTable(num_partitions, num_replicas)
app.master_conn = conn
def answerPartitionTable(self, conn, ptid, row_list): def answerPartitionTable(self, conn, ptid, row_list):
assert row_list assert row_list
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment