From fd4a9b16af68eeda9479bb6f7956e18179aa66a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9gory=20Wisniewski?= <gregory@nexedi.com> Date: Fri, 22 Jan 2010 10:45:21 +0000 Subject: [PATCH] Add notifyReplicationDone packet. This packet replace notifyPartitionChange when used by storage's replicator at the end of a single partition replication. In those case, only one partition was involved and the node concerned must match with the sender identify, causing many useless on the master side. This packet contains only the partition number that is replicated and implies that the node's cell is now up to date. It should be sent only by the storage node from replicator and received by master node. git-svn-id: https://svn.erp5.org/repos/neo/trunk@1467 71dcc9de-d417-0410-9af5-da40c76e7ee4 --- neo/handler.py | 4 ++++ neo/logger.py | 3 +++ neo/protocol.py | 15 +++++++++++++++ neo/tests/testProtocol.py | 6 ++++++ 4 files changed, 28 insertions(+) diff --git a/neo/handler.py b/neo/handler.py index c782d22d..f386a2c4 100644 --- a/neo/handler.py +++ b/neo/handler.py @@ -331,6 +331,9 @@ class EventHandler(object): def notifyLastOID(self, conn, packet, oid): raise UnexpectedPacketError + def notifyReplicationDone(self, conn, packet, offset): + raise UnexpectedPacketError + # Error packet handlers. @@ -433,6 +436,7 @@ class EventHandler(object): d[Packets.AnswerClusterState] = self.answerClusterState d[Packets.NotifyClusterInformation] = self.notifyClusterInformation d[Packets.NotifyLastOID] = self.notifyLastOID + d[Packets.NotifyReplicationDone] = self.notifyReplicationDone return d diff --git a/neo/logger.py b/neo/logger.py index 73a83f36..ae2036cc 100644 --- a/neo/logger.py +++ b/neo/logger.py @@ -249,5 +249,8 @@ class PacketLogger(EventHandler): def notifyLastOID(self, conn, packet, oid): pass + def notifyReplicationDone(self, conn, packet, offset): + pass + PACKET_LOGGER = PacketLogger() diff --git a/neo/protocol.py b/neo/protocol.py index 059c79a8..a850244b 100644 --- a/neo/protocol.py +++ b/neo/protocol.py @@ -518,6 +518,20 @@ class NotifyPartitionChanges(Packet): cell_list.append((offset, uuid, state)) return (ptid, cell_list) +class NotifyReplicationDone(Packet): + """ + Notify the master node that a partition has been successully replicated from + a storage to another. + S -> M + """ + + def _encode(self, offset): + return pack('!L', offset) + + def _decode(self, body): + (offset, ) = unpack('!L', body) + return (offset, ) + class StartOperation(Packet): """ Tell a storage nodes to start an operation. Until a storage node receives @@ -1317,6 +1331,7 @@ class PacketRegistry(dict): AskClusterState = register(0x0028, AskClusterState) AnswerClusterState = register(0x8028, AnswerClusterState) NotifyLastOID = register(0x0030, NotifyLastOID) + NotifyReplicationDone = register(0x0031, NotifyReplicationDone) # build a "singleton" Packets = PacketRegistry() diff --git a/neo/tests/testProtocol.py b/neo/tests/testProtocol.py index bb9dac97..adcd8492 100644 --- a/neo/tests/testProtocol.py +++ b/neo/tests/testProtocol.py @@ -470,6 +470,12 @@ class ProtocolTests(NeoTestBase): p_oid_list = p.decode()[0] self.assertEqual(p_oid_list, oid_list) + def test_57_notifyReplicationDone(self): + offset = 10 + p = Packets.NotifyReplicationDone(offset) + p_offset = p.decode()[0] + self.assertEqual(p_offset, offset) + if __name__ == '__main__': unittest.main() -- 2.30.9