Commit 186ec9ae authored by Grégory Wisniewski's avatar Grégory Wisniewski

Add a load() on PartitionTable() to remove some logic from handlers, add

docstring and comments.


git-svn-id: https://svn.erp5.org/repos/neo/branches/prototype3@1070 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent 15d368f0
...@@ -162,9 +162,31 @@ class PartitionTable(object): ...@@ -162,9 +162,31 @@ class PartitionTable(object):
self.count_dict[node] = self.count_dict.get(node, 0) - 1 self.count_dict[node] = self.count_dict.get(node, 0) - 1
break break
# XXX: node manager is given here just to verify that any node in the def load(self, ptid, row_list, nm):
# partition table is known, this will be removed when checked. """
Load the partition table with the specified PTID, discard all previous
content and can be done in multiple calls
"""
if ptid != self.id:
self.id = ptid
self.clear()
for offset, row in row_list:
for uuid, state in row:
node = nm.getNodeByUUID(uuid)
# XXX: the node should be known before we receive the partition
# table, so remove this assert when this is checked.
assert node is not None
self.setCell(offset, node, state)
def update(self, ptid, cell_list, nm): def update(self, ptid, cell_list, nm):
"""
Update the partition with the cell list supplied. Ignore those changes
if the partition table ID is not greater than the current one. If a node
is not known, it is created in the node manager and set as unavailable
"""
if ptid <= self.id:
logging.warning('ignoring older partition changes')
return
self.id = ptid self.id = ptid
for offset, uuid, state in cell_list: for offset, uuid, state in cell_list:
node = nm.getNodeByUUID(uuid) node = nm.getNodeByUUID(uuid)
......
...@@ -66,6 +66,7 @@ class HiddenHandler(BaseMasterHandler): ...@@ -66,6 +66,7 @@ class HiddenHandler(BaseMasterHandler):
def handleNotifyPartitionChanges(self, conn, packet, ptid, cell_list): def handleNotifyPartitionChanges(self, conn, packet, ptid, cell_list):
"""This is very similar to Send Partition Table, except that """This is very similar to Send Partition Table, except that
the information is only about changes from the previous.""" the information is only about changes from the previous."""
# XXX: this is a copy/paste from handlers/master.py
app = self.app app = self.app
if app.ptid >= ptid: if app.ptid >= ptid:
# Ignore this packet. # Ignore this packet.
......
...@@ -36,23 +36,7 @@ class InitializationHandler(BaseMasterHandler): ...@@ -36,23 +36,7 @@ class InitializationHandler(BaseMasterHandler):
def handleSendPartitionTable(self, conn, packet, ptid, row_list): def handleSendPartitionTable(self, conn, packet, ptid, row_list):
"""A primary master node sends this packet to synchronize a partition """A primary master node sends this packet to synchronize a partition
table. Note that the message can be split into multiple packets.""" table. Note that the message can be split into multiple packets."""
app = self.app self.app.pt.load(ptid, row_list, self.app.nm)
nm = app.nm
pt = app.pt
if app.ptid != ptid:
app.ptid = ptid
pt.clear()
for offset, row in row_list:
for uuid, state in row:
node = nm.getNodeByUUID(uuid)
if node is None:
node = StorageNode(uuid = uuid)
if uuid != app.uuid:
node.setState(TEMPORARILY_DOWN_STATE)
nm.add(node)
pt.setCell(offset, node, state)
def handleAnswerPartitionTable(self, conn, packet, ptid, row_list): def handleAnswerPartitionTable(self, conn, packet, ptid, row_list):
app = self.app app = self.app
......
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