Commit 7ce47a3d authored by Vincent Pelletier's avatar Vincent Pelletier

Merge _waitForPrimaryAnnouncement with its only caller.

git-svn-id: https://svn.erp5.org/repos/neo/trunk@1584 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent 81ee387a
...@@ -219,41 +219,6 @@ class Application(object): ...@@ -219,41 +219,6 @@ class Application(object):
break break
def _waitForPrimaryAnnouncement(self):
"""
For for the primary announcement as i'm not the primary.
If this is too long, raise ElectionFailure to restart the whole
election process.
"""
# Wait for an announcement. If this is too long, probably
# the primary master is down.
t = time()
while self.primary_master_node is None:
self.em.poll(1)
if t + 10 < time():
# election timeout
raise ElectionFailure("Election timeout")
# Now I need only a connection to the primary master node.
addr = self.primary_master_node.getAddress()
for conn in self.em.getServerList():
conn.close()
connected_to_master = False
primary_handler = secondary.PrimaryHandler(self)
for conn in self.em.getClientList():
if conn.getAddress() == addr:
connected_to_master = True
conn.setHandler(primary_handler)
else:
conn.close()
if not connected_to_master:
ClientConnection(self.em, primary_handler, addr=addr,
connector_handler=self.connector_handler)
def _electionFailed(self, m): def _electionFailed(self, m):
""" """
Ask other masters to reelect a primary after an election failure. Ask other masters to reelect a primary after an election failure.
...@@ -627,8 +592,33 @@ class Application(object): ...@@ -627,8 +592,33 @@ class Application(object):
logging.info('play the secondary role with %s (%s:%d)', logging.info('play the secondary role with %s (%s:%d)',
dump(self.uuid), *(self.server)) dump(self.uuid), *(self.server))
# otherwise, wait for the primary announcement # Wait for an announcement. If this is too long, probably
self._waitForPrimaryAnnouncement() # the primary master is down.
t = time()
while self.primary_master_node is None:
self.em.poll(1)
if t + 10 < time():
# election timeout
raise ElectionFailure("Election timeout")
# Now I need only a connection to the primary master node.
addr = self.primary_master_node.getAddress()
for conn in self.em.getServerList():
conn.close()
connected_to_master = False
primary_handler = secondary.PrimaryHandler(self)
for conn in self.em.getClientList():
if conn.getAddress() == addr:
connected_to_master = True
conn.setHandler(primary_handler)
else:
conn.close()
if not connected_to_master:
ClientConnection(self.em, primary_handler, addr=addr,
connector_handler=self.connector_handler)
# and another for the future incoming connections # and another for the future incoming connections
handler = identification.IdentificationHandler(self) handler = identification.IdentificationHandler(self)
......
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