Commit 96827f57 authored by Vincent Pelletier's avatar Vincent Pelletier

Merge called-once methods into their caller.

parent caeac356
...@@ -150,6 +150,7 @@ class Application(object): ...@@ -150,6 +150,7 @@ class Application(object):
to self as well as master nodes.""" to self as well as master nodes."""
neo.lib.logging.info('begin the election of a primary master') neo.lib.logging.info('begin the election of a primary master')
client_handler = election.ClientElectionHandler(self)
self.unconnected_master_node_set.clear() self.unconnected_master_node_set.clear()
self.negotiating_master_node_set.clear() self.negotiating_master_node_set.clear()
self.listening_conn.setHandler(election.ServerElectionHandler(self)) self.listening_conn.setHandler(election.ServerElectionHandler(self))
...@@ -165,25 +166,6 @@ class Application(object): ...@@ -165,25 +166,6 @@ class Application(object):
self.primary = None self.primary = None
self.primary_master_node = None self.primary_master_node = None
try: try:
self._doElection(bootstrap)
except ElectionFailure, m:
# something goes wrong, clean then restart
self._electionFailed(m)
bootstrap = False
else:
# election succeed, stop the process
self.primary = self.primary is None
break
def _doElection(self, bootstrap):
"""
Start the election process:
- Try to connect to any known master node
- Wait at most for the timeout defined by bootstrap parameter
When done, the current process is defined either as primary or
secondary master node
"""
# Wait at most 20 seconds at bootstrap. Otherwise, wait at most # Wait at most 20 seconds at bootstrap. Otherwise, wait at most
# 10 seconds to avoid stopping the whole cluster for a long time. # 10 seconds to avoid stopping the whole cluster for a long time.
# Note that even if not all master are up in the first 20 seconds # Note that even if not all master are up in the first 20 seconds
...@@ -193,7 +175,6 @@ class Application(object): ...@@ -193,7 +175,6 @@ class Application(object):
expiration = 20 expiration = 20
else: else:
expiration = 10 expiration = 10
client_handler = election.ClientElectionHandler(self)
t = 0 t = 0
while True: while True:
current_time = time() current_time = time()
...@@ -217,29 +198,8 @@ class Application(object): ...@@ -217,29 +198,8 @@ class Application(object):
if not (self.unconnected_master_node_set or if not (self.unconnected_master_node_set or
self.negotiating_master_node_set): self.negotiating_master_node_set):
break break
except ElectionFailure, m:
def _announcePrimary(self): # something goes wrong, clean then restart
"""
Broadcast the announce that I'm the primary
"""
# I am the primary.
neo.lib.logging.debug('I am the primary, sending an announcement')
for conn in self.em.getClientList():
conn.notify(Packets.AnnouncePrimary())
conn.abort()
t = time()
while self.em.getClientList():
self.em.poll(1)
if t + 10 < time():
for conn in self.em.getClientList():
conn.close()
break
def _electionFailed(self, m):
"""
Ask other masters to reelect a primary after an election failure.
"""
neo.lib.logging.error('election failed: %s', (m, )) neo.lib.logging.error('election failed: %s', (m, ))
# Ask all connected nodes to reelect a single primary master. # Ask all connected nodes to reelect a single primary master.
...@@ -260,6 +220,29 @@ class Application(object): ...@@ -260,6 +220,29 @@ class Application(object):
# Close all connections. # Close all connections.
for conn in self.em.getClientList() + self.em.getServerList(): for conn in self.em.getClientList() + self.em.getServerList():
conn.close() conn.close()
bootstrap = False
else:
# election succeed, stop the process
self.primary = self.primary is None
break
def _announcePrimary(self):
"""
Broadcast the announce that I'm the primary
"""
# I am the primary.
neo.lib.logging.debug('I am the primary, sending an announcement')
for conn in self.em.getClientList():
conn.notify(Packets.AnnouncePrimary())
conn.abort()
t = time()
while self.em.getClientList():
self.em.poll(1)
if t + 10 < time():
for conn in self.em.getClientList():
conn.close()
break
def broadcastNodesInformation(self, node_list): def broadcastNodesInformation(self, node_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