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):
to self as well as master nodes."""
neo.lib.logging.info('begin the election of a primary master')
client_handler = election.ClientElectionHandler(self)
self.unconnected_master_node_set.clear()
self.negotiating_master_node_set.clear()
self.listening_conn.setHandler(election.ServerElectionHandler(self))
......@@ -165,25 +166,6 @@ class Application(object):
self.primary = None
self.primary_master_node = None
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
# 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
......@@ -193,7 +175,6 @@ class Application(object):
expiration = 20
else:
expiration = 10
client_handler = election.ClientElectionHandler(self)
t = 0
while True:
current_time = time()
......@@ -217,29 +198,8 @@ class Application(object):
if not (self.unconnected_master_node_set or
self.negotiating_master_node_set):
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 _electionFailed(self, m):
"""
Ask other masters to reelect a primary after an election failure.
"""
except ElectionFailure, m:
# something goes wrong, clean then restart
neo.lib.logging.error('election failed: %s', (m, ))
# Ask all connected nodes to reelect a single primary master.
......@@ -260,6 +220,29 @@ class Application(object):
# Close all connections.
for conn in self.em.getClientList() + self.em.getServerList():
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):
......
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