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

Factorize duplicate code that send informations about all nodes.

Fix a bug where an empty packet could be sent.


git-svn-id: https://svn.erp5.org/repos/neo/branches/prototype3@496 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent 64fd593b
......@@ -333,6 +333,23 @@ class Application(object):
if row_list:
conn.notify(protocol.sendPartitionTable(self.lptid, row_list))
def sendNodesInformations(self, conn):
""" Send informations on all nodes through the given connection """
node_list = []
for n in self.nm.getNodeList():
try:
ip_address, port = n.getServer()
except TypeError:
ip_address, port = '0.0.0.0', 0
node_list.append((n.getNodeType(), ip_address, port,
n.getUUID() or INVALID_UUID, n.getState()))
# Split the packet if too huge.
if len(node_list) == 10000:
conn.notify(protocol.notifyNodeInformation(node_list))
del node_list[:]
if node_list:
conn.notify(protocol.notifyNodeInformation(node_list))
def recoverStatus(self):
"""Recover the status about the cluster. Obtain the last OID, the last TID,
and the last Partition Table ID from storage nodes, then get back the latest
......
......@@ -197,19 +197,7 @@ class RecoveryEventHandler(MasterEventHandler):
conn.answer(p, packet)
# Send the information.
node_list = []
for n in app.nm.getNodeList():
try:
ip_address, port = n.getServer()
except TypeError:
ip_address, port = '0.0.0.0', 0
node_list.append((n.getNodeType(), ip_address, port,
n.getUUID() or INVALID_UUID, n.getState()))
if len(node_list) == 10000:
# Ugly, but it is necessary to split a packet, if it is too big.
conn.notify(protocol.notifyNodeInformation(node_list))
del node_list[:]
conn.notify(protocol.notifyNodeInformation(node_list))
app.sendNodesInformations(conn)
# If this is a storage node, ask the last IDs.
node = app.nm.getNodeByUUID(uuid)
......
......@@ -309,27 +309,13 @@ class ServiceEventHandler(MasterEventHandler):
conn.answer(protocol.answerPrimaryMaster(app.uuid, []), packet)
# Send the information.
logging.info('sending notify node information to %s:%d',
*(conn.getAddress()))
node_list = []
for n in app.nm.getNodeList():
try:
ip_address, port = n.getServer()
except TypeError:
ip_address, port = '0.0.0.0', 0
node_list.append((n.getNodeType(), ip_address, port,
n.getUUID() or INVALID_UUID, n.getState()))
if len(node_list) == 10000:
# Ugly, but it is necessary to split a packet, if it is too big.
conn.notify(protocol.notifyNodeInformation(node_list))
del node_list[:]
conn.notify(protocol.notifyNodeInformation(node_list))
logging.info('sending notify node information to %s:%d', *(conn.getAddress()))
app.sendNodesInformations(conn)
# If this is a storage node or a client node or an admin node, send the partition table.
node = app.nm.getNodeByUUID(uuid)
if node.getNodeType() in (STORAGE_NODE_TYPE, CLIENT_NODE_TYPE, ADMIN_NODE_TYPE):
logging.info('sending partition table to %s:%d',
*(conn.getAddress()))
logging.info('sending partition table to %s:%d', *(conn.getAddress()))
app.sendPartitionTable(conn)
# If this is a storage node, ask it to start.
......
......@@ -220,19 +220,7 @@ class VerificationEventHandler(MasterEventHandler):
conn.answer(protocol.answerPrimaryMaster(app.uuid, []), packet)
# Send the information.
node_list = []
for n in app.nm.getNodeList():
try:
ip_address, port = n.getServer()
except TypeError:
ip_address, port = '0.0.0.0', 0
node_list.append((n.getNodeType(), ip_address, port,
n.getUUID() or INVALID_UUID, n.getState()))
if len(node_list) == 10000:
# Ugly, but it is necessary to split a packet, if it is too big.
conn.notify(protocol.notifyNodeInformation(node_list))
del node_list[:]
conn.notify(protocol.notifyNodeInformation(node_list))
app.sendNodesInformations(conn)
# If this is a storage node or an admin node, send the partition table.
node = app.nm.getNodeByUUID(uuid)
......
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