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

Nodes use update() method of partition table to reduce duplicate code.


git-svn-id: https://svn.erp5.org/repos/neo/branches/prototype3@944 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent f106a20c
...@@ -209,25 +209,12 @@ class MasterMonitoringEventHandler(MasterBaseEventHandler): ...@@ -209,25 +209,12 @@ class MasterMonitoringEventHandler(MasterBaseEventHandler):
def handleNotifyPartitionChanges(self, conn, packet, ptid, cell_list): def handleNotifyPartitionChanges(self, conn, packet, ptid, cell_list):
app = self.app app = self.app
nm = app.nm
pt = app.pt
node = nm.getNodeByUUID(conn.getUUID())
if ptid < app.ptid: if ptid < app.ptid:
# Ignore this packet. # Ignore this packet.
# XXX: is it safe ? # XXX: is it safe ?
return return
app.ptid = ptid app.ptid = ptid
for offset, uuid, state in cell_list: app.pt.update(cell_list, app.nm)
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)
pt.log()
def handleSendPartitionTable(self, conn, packet, ptid, row_list): def handleSendPartitionTable(self, conn, packet, ptid, row_list):
uuid = conn.getUUID() uuid = conn.getUUID()
...@@ -235,10 +222,6 @@ class MasterMonitoringEventHandler(MasterBaseEventHandler): ...@@ -235,10 +222,6 @@ class MasterMonitoringEventHandler(MasterBaseEventHandler):
nm = app.nm nm = app.nm
pt = app.pt pt = app.pt
node = app.nm.getNodeByUUID(uuid) node = app.nm.getNodeByUUID(uuid)
# This must be sent only by primary master node
if node.getNodeType() != MASTER_NODE_TYPE:
return
if app.ptid != ptid: if app.ptid != ptid:
app.ptid = ptid app.ptid = ptid
pt.clear() pt.clear()
...@@ -250,6 +233,5 @@ class MasterMonitoringEventHandler(MasterBaseEventHandler): ...@@ -250,6 +233,5 @@ class MasterMonitoringEventHandler(MasterBaseEventHandler):
node.setState(TEMPORARILY_DOWN_STATE) node.setState(TEMPORARILY_DOWN_STATE)
nm.add(node) nm.add(node)
pt.setCell(offset, node, state) pt.setCell(offset, node, state)
pt.log() pt.log()
...@@ -174,21 +174,11 @@ class PrimaryNotificationsHandler(BaseHandler): ...@@ -174,21 +174,11 @@ class PrimaryNotificationsHandler(BaseHandler):
def handleNotifyPartitionChanges(self, conn, packet, ptid, cell_list): def handleNotifyPartitionChanges(self, conn, packet, ptid, cell_list):
app = self.app app = self.app
nm = app.nm
pt = app.pt
if app.ptid >= ptid: if app.ptid >= ptid:
# Ignore this packet. # Ignore this packet.
return return
app.ptid = ptid app.ptid = ptid
for offset, uuid, state in cell_list: app.pt.update(cell_list, app.nm)
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)
@decorators.identification_required @decorators.identification_required
def handleSendPartitionTable(self, conn, packet, ptid, row_list): def handleSendPartitionTable(self, conn, packet, ptid, row_list):
......
...@@ -74,8 +74,6 @@ class HiddenHandler(BaseMasterHandler): ...@@ -74,8 +74,6 @@ class HiddenHandler(BaseMasterHandler):
"""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."""
app = self.app app = self.app
nm = app.nm
pt = app.pt
if app.ptid >= ptid: if app.ptid >= ptid:
# Ignore this packet. # Ignore this packet.
logging.debug('ignoring older partition changes') logging.debug('ignoring older partition changes')
...@@ -84,14 +82,6 @@ class HiddenHandler(BaseMasterHandler): ...@@ -84,14 +82,6 @@ class HiddenHandler(BaseMasterHandler):
# First, change the table on memory. # First, change the table on memory.
app.ptid = ptid app.ptid = ptid
for offset, uuid, state in cell_list: for offset, uuid, state in cell_list:
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)
if uuid == app.uuid and app.replicator is not None: if uuid == app.uuid and app.replicator is not None:
# If this is for myself, this can affect replications. # If this is for myself, this can affect replications.
if state == DISCARDED_STATE: if state == DISCARDED_STATE:
...@@ -99,9 +89,9 @@ class HiddenHandler(BaseMasterHandler): ...@@ -99,9 +89,9 @@ class HiddenHandler(BaseMasterHandler):
elif state == OUT_OF_DATE_STATE: elif state == OUT_OF_DATE_STATE:
app.replicator.addPartition(offset) app.replicator.addPartition(offset)
# Then, the database. # update partition table in memory and the database
app.pt.update(cell_list, app.nm)
app.dm.changePartitionTable(ptid, cell_list) app.dm.changePartitionTable(ptid, cell_list)
app.pt.log()
@decorators.client_connection_required @decorators.client_connection_required
def handleStartOperation(self, conn, packet): def handleStartOperation(self, conn, packet):
......
...@@ -38,10 +38,8 @@ class MasterOperationHandler(BaseMasterHandler): ...@@ -38,10 +38,8 @@ class MasterOperationHandler(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."""
app = self.app app = self.app
nm = app.nm
pt = app.pt
if app.ptid >= ptid: if app.ptid >= ptid:
# Ignore this packet. # Ignore this packet.
logging.debug('ignoring older partition changes') logging.debug('ignoring older partition changes')
...@@ -50,25 +48,16 @@ class MasterOperationHandler(BaseMasterHandler): ...@@ -50,25 +48,16 @@ class MasterOperationHandler(BaseMasterHandler):
# First, change the table on memory. # First, change the table on memory.
app.ptid = ptid app.ptid = ptid
for offset, uuid, state in cell_list: for offset, uuid, state in cell_list:
node = nm.getNodeByUUID(uuid) if uuid == app.uuid and app.replicator is not None:
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)
if uuid == app.uuid:
# If this is for myself, this can affect replications. # If this is for myself, this can affect replications.
if state == DISCARDED_STATE: if state == DISCARDED_STATE:
app.replicator.removePartition(offset) app.replicator.removePartition(offset)
elif state == OUT_OF_DATE_STATE: elif state == OUT_OF_DATE_STATE:
app.replicator.addPartition(offset) app.replicator.addPartition(offset)
# Then, the database. # update partition table in memory and the database
app.pt.update(cell_list, app.nm)
app.dm.changePartitionTable(ptid, cell_list) app.dm.changePartitionTable(ptid, cell_list)
logging.debug('Partition table updated:')
self.app.pt.log()
def handleLockInformation(self, conn, packet, tid): def handleLockInformation(self, conn, packet, tid):
app = self.app app = self.app
......
...@@ -61,26 +61,13 @@ class VerificationHandler(BaseMasterHandler): ...@@ -61,26 +61,13 @@ class VerificationHandler(BaseMasterHandler):
"""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."""
app = self.app app = self.app
nm = app.nm
pt = app.pt
if app.ptid >= ptid: if app.ptid >= ptid:
# Ignore this packet. # Ignore this packet.
logging.debug('ignoring older partition changes') logging.debug('ignoring older partition changes')
return return
# First, change the table on memory.
app.ptid = ptid app.ptid = ptid
for offset, uuid, state in cell_list: # update partition table in memory and the database
node = nm.getNodeByUUID(uuid) app.pt.update(cell_list, app.nm)
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)
# Then, the database.
app.dm.changePartitionTable(ptid, cell_list) app.dm.changePartitionTable(ptid, cell_list)
def handleStartOperation(self, conn, packet): def handleStartOperation(self, conn, packet):
......
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