Commit ae37c472 authored by Vincent Pelletier's avatar Vincent Pelletier

Use a (non-blocking) lock to prevent two simultaneous reconnection attemps to...

Use a (non-blocking) lock to prevent two simultaneous reconnection attemps to master instead of a simple variable.


git-svn-id: https://svn.erp5.org/repos/neo/branches/prototype3@266 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent 31481811
......@@ -15,7 +15,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
from threading import Thread
from threading import Thread, Lock
from Queue import Empty, Queue
from neo.protocol import PING, Packet, CLIENT_NODE_TYPE, FINISH_TRANSACTION
......@@ -36,7 +36,7 @@ class Dispatcher(Thread):
# and thus redispatch answer to the original thread
self.message_table = {}
# Indicate if we are in process of connection to master node
self.connecting_to_master_node = 0
self.connecting_to_master_node = Lock()
def run(self):
while 1:
......@@ -66,7 +66,9 @@ class Dispatcher(Thread):
This can be called either at bootstrap or when
client got disconnected during process"""
# Indicate we are trying to connect to avoid multiple try a time
self.connecting_to_master_node = 1
acquired = self.connecting_to_master_node.acquire(blocking=0)
if acquired:
try:
from neo.client.handler import ClientEventHandler
if app.pt is not None:
app.pt.clear()
......@@ -139,4 +141,5 @@ class Dispatcher(Thread):
logging.info("connected to primary master node %s:%d" %app.primary_master_node.getServer())
app.master_conn = conn
self.connecting_to_master_node = 0
finally:
self.connecting_to_master_node.release()
......@@ -101,8 +101,6 @@ class ClientEventHandler(EventHandler):
elif self.app.primary_master_node is not None and uuid == \
self.app.primary_master_node.getUUID():
logging.critical("connection to primary master node failed")
if self.dispatcher.connecting_to_master_node == 0:
logging.critical("trying reconnection to master node...")
self.dispatcher.connectToPrimaryMasterNode(app, conn)
else:
# Connection to a storage node failed
......@@ -124,8 +122,6 @@ class ClientEventHandler(EventHandler):
app.master_conn.close()
app.master_conn = None
app.primary_master_node = None
if self.dispatcher.connecting_to_master_node == 0:
logging.critical("trying reconnection to master node...")
self.dispatcher.connectToPrimaryMasterNode(app, conn)
else:
node = app.nm.getNodeByServer(conn.getAddress())
......@@ -145,8 +141,6 @@ class ClientEventHandler(EventHandler):
app.primary_master_node = -1
if app.master_conn is not None and uuid == app.primary_master_node.getUUID():
logging.critical("connection timeout to primary master node expired")
if self.dispatcher.connecting_to_master_node == 0:
logging.critical("trying reconnection to master node...")
self.dispatcher.connectToPrimaryMasterNode(app, conn)
else:
node = app.nm.getNodeByServer(conn.getAddress())
......@@ -165,8 +159,6 @@ class ClientEventHandler(EventHandler):
app.primary_master_node = -1
if app.master_conn is not None and uuid == app.primary_master_node.getUUID():
logging.critical("primary master node is broken")
if self.dispatcher.connecting_to_master_node == 0:
logging.critical("trying reconnection to master node...")
self.dispatcher.connectToPrimaryMasterNode(app, conn)
else:
node = app.nm.getNodeByServer(conn.getAddress())
......
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