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): ...@@ -333,6 +333,23 @@ class Application(object):
if row_list: if row_list:
conn.notify(protocol.sendPartitionTable(self.lptid, 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): def recoverStatus(self):
"""Recover the status about the cluster. Obtain the last OID, the last TID, """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 and the last Partition Table ID from storage nodes, then get back the latest
......
...@@ -197,19 +197,7 @@ class RecoveryEventHandler(MasterEventHandler): ...@@ -197,19 +197,7 @@ class RecoveryEventHandler(MasterEventHandler):
conn.answer(p, packet) conn.answer(p, packet)
# Send the information. # Send the information.
node_list = [] app.sendNodesInformations(conn)
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))
# If this is a storage node, ask the last IDs. # If this is a storage node, ask the last IDs.
node = app.nm.getNodeByUUID(uuid) node = app.nm.getNodeByUUID(uuid)
......
...@@ -309,27 +309,13 @@ class ServiceEventHandler(MasterEventHandler): ...@@ -309,27 +309,13 @@ class ServiceEventHandler(MasterEventHandler):
conn.answer(protocol.answerPrimaryMaster(app.uuid, []), packet) conn.answer(protocol.answerPrimaryMaster(app.uuid, []), packet)
# Send the information. # Send the information.
logging.info('sending notify node information to %s:%d', logging.info('sending notify node information to %s:%d', *(conn.getAddress()))
*(conn.getAddress())) app.sendNodesInformations(conn)
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))
# If this is a storage node or a client node or an admin node, send the partition table. # If this is a storage node or a client node or an admin node, send the partition table.
node = app.nm.getNodeByUUID(uuid) node = app.nm.getNodeByUUID(uuid)
if node.getNodeType() in (STORAGE_NODE_TYPE, CLIENT_NODE_TYPE, ADMIN_NODE_TYPE): if node.getNodeType() in (STORAGE_NODE_TYPE, CLIENT_NODE_TYPE, ADMIN_NODE_TYPE):
logging.info('sending partition table to %s:%d', logging.info('sending partition table to %s:%d', *(conn.getAddress()))
*(conn.getAddress()))
app.sendPartitionTable(conn) app.sendPartitionTable(conn)
# If this is a storage node, ask it to start. # If this is a storage node, ask it to start.
......
...@@ -220,19 +220,7 @@ class VerificationEventHandler(MasterEventHandler): ...@@ -220,19 +220,7 @@ class VerificationEventHandler(MasterEventHandler):
conn.answer(protocol.answerPrimaryMaster(app.uuid, []), packet) conn.answer(protocol.answerPrimaryMaster(app.uuid, []), packet)
# Send the information. # Send the information.
node_list = [] app.sendNodesInformations(conn)
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))
# If this is a storage node or an admin node, send the partition table. # If this is a storage node or an admin node, send the partition table.
node = app.nm.getNodeByUUID(uuid) 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