Commit dab39147 authored by Grégory Wisniewski's avatar Grégory Wisniewski

Some changes in election:

- Nodes start in UNKNOWN state.
- Running and Unknown nodes are candidates during election.
- Set temporarily down if an established connection is lost.
- Keep in unknown state if a connection fails.

git-svn-id: https://svn.erp5.org/repos/neo/trunk@1541 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent 8fc436a8
...@@ -137,16 +137,11 @@ class Application(object): ...@@ -137,16 +137,11 @@ class Application(object):
self.negotiating_master_node_set = set() self.negotiating_master_node_set = set()
self.listening_conn.setHandler(election.ServerElectionHandler(self)) self.listening_conn.setHandler(election.ServerElectionHandler(self))
for node in self.nm.getMasterList():
# For now, believe that every node should be available,
# since down or broken nodes may be already repaired.
node.setRunning()
while True: while True:
# handle new connected masters # handle new connected masters
for node in self.nm.getMasterList(): for node in self.nm.getMasterList():
if node.isRunning(): if node.isRunning() or node.isUnknown():
self.unconnected_master_node_set.add(node.getAddress()) self.unconnected_master_node_set.add(node.getAddress())
# start the election process # start the election process
......
...@@ -71,42 +71,47 @@ class ClientElectionHandler(ElectionHandler): ...@@ -71,42 +71,47 @@ class ClientElectionHandler(ElectionHandler):
MasterHandler.packetReceived(self, conn, packet) MasterHandler.packetReceived(self, conn, packet)
def connectionStarted(self, conn): def connectionStarted(self, conn):
app = self.app
addr = conn.getAddress() addr = conn.getAddress()
app.unconnected_master_node_set.remove(addr) # connection in progress
app.negotiating_master_node_set.add(addr) self.app.unconnected_master_node_set.remove(addr)
self.app.negotiating_master_node_set.add(addr)
MasterHandler.connectionStarted(self, conn) MasterHandler.connectionStarted(self, conn)
def connectionFailed(self, conn):
addr = conn.getAddress()
node = self.app.nm.getByAddress(addr)
# connection never success, node is still in unknown state
self.app.negotiating_master_node_set.discard(addr)
self.app.unconnected_master_node_set.add(addr)
MasterHandler.connectionFailed(self, conn)
def connectionCompleted(self, conn): def connectionCompleted(self, conn):
addr = conn.getAddress()
node = self.app.nm.getByAddress(addr)
# connection successfull, set it as running
node.setRunning()
conn.ask(Packets.AskPrimary()) conn.ask(Packets.AskPrimary())
MasterHandler.connectionCompleted(self, conn)
def connectionClosed(self, conn): def connectionClosed(self, conn):
addr = conn.getAddress()
node = self.app.nm.getByAddress(addr)
node.setTemporarilyDown()
self.app.negotiating_master_node_set.discard(addr)
self.connectionFailed(conn) self.connectionFailed(conn)
MasterHandler.connectionClosed(self, conn)
def timeoutExpired(self, conn): def timeoutExpired(self, conn):
self.connectionFailed(conn)
MasterHandler.timeoutExpired(self, conn)
def connectionFailed(self, conn):
app = self.app
addr = conn.getAddress() addr = conn.getAddress()
app.negotiating_master_node_set.discard(addr) node = self.app.nm.getByAddress(addr)
node = app.nm.getByAddress(addr) node.setTemporarilyDown()
if node.isRunning(): self.app.negotiating_master_node_set.discard(addr)
node.setTemporarilyDown() MasterHandler.timeoutExpired(self, conn)
if node.isTemporarilyDown():
app.unconnected_master_node_set.add(addr)
MasterHandler.connectionFailed(self, conn)
def peerBroken(self, conn): def peerBroken(self, conn):
app = self.app
addr = conn.getAddress() addr = conn.getAddress()
node = app.nm.getByAddress(addr) node = self.app.nm.getByAddress(addr)
if node is not None: if node is not None:
node.setDown() node.setDown()
app.negotiating_master_node_set.discard(addr) self.app.negotiating_master_node_set.discard(addr)
MasterHandler.peerBroken(self, conn) MasterHandler.peerBroken(self, conn)
def acceptIdentification(self, conn, packet, node_type, def acceptIdentification(self, conn, packet, node_type,
......
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