Commit 49a524f1 authored by Grégory Wisniewski's avatar Grégory Wisniewski

Move getOudatedPartitionList logic to partition table.

git-svn-id: https://svn.erp5.org/repos/neo/trunk@2614 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent 2c3bea29
...@@ -148,6 +148,13 @@ class PartitionTable(object): ...@@ -148,6 +148,13 @@ class PartitionTable(object):
def getPartition(self, oid_or_tid): def getPartition(self, oid_or_tid):
return u64(oid_or_tid) % self.getPartitions() return u64(oid_or_tid) % self.getPartitions()
def getOutdatedOffsetListFor(self, uuid):
return [
offset for offset in xrange(self.np)
for c in self.partition_list[offset]
if c.getUUID() == uuid and c.getState() == CellStates.OUT_OF_DATE
]
def isAssigned(self, oid, uuid): def isAssigned(self, oid, uuid):
""" Check if the oid is assigned to the given node """ """ Check if the oid is assigned to the given node """
for cell in self.partition_list[u64(oid) % self.np]: for cell in self.partition_list[u64(oid) % self.np]:
......
...@@ -19,7 +19,7 @@ import neo ...@@ -19,7 +19,7 @@ import neo
from random import choice from random import choice
from neo.storage.handlers import replication from neo.storage.handlers import replication
from neo.protocol import NodeTypes, NodeStates, CellStates, Packets, ZERO_TID from neo.protocol import NodeTypes, NodeStates, Packets
from neo.connection import ClientConnection from neo.connection import ClientConnection
from neo.util import dump from neo.util import dump
...@@ -174,7 +174,9 @@ class Replicator(object): ...@@ -174,7 +174,9 @@ class Replicator(object):
table is the one accepted by primary master. table is the one accepted by primary master.
Implies a reset. Implies a reset.
""" """
self.new_partition_dict = self._getOutdatedPartitionList() self.new_partition_dict = {}
for offset in self.app.pt.getOutdatedOffsetListFor(self.app.uuid):
self.new_partition_dict[offset] = Partition(offset)
self.partition_dict = {} self.partition_dict = {}
self.reset() self.reset()
...@@ -187,15 +189,6 @@ class Replicator(object): ...@@ -187,15 +189,6 @@ class Replicator(object):
self.unfinished_tid_list = None self.unfinished_tid_list = None
self.replication_done = True self.replication_done = True
def _getOutdatedPartitionList(self):
app = self.app
partition_dict = {}
for offset in xrange(app.pt.getPartitions()):
for uuid, state in app.pt.getRow(offset):
if uuid == app.uuid and state == CellStates.OUT_OF_DATE:
partition_dict[offset] = Partition(offset)
return partition_dict
def pending(self): def pending(self):
"""Return whether there is any pending partition.""" """Return whether there is any pending partition."""
return len(self.partition_dict) or len(self.new_partition_dict) return len(self.partition_dict) or len(self.new_partition_dict)
......
...@@ -36,12 +36,7 @@ class StorageReplicatorTests(NeoUnitTestBase): ...@@ -36,12 +36,7 @@ class StorageReplicatorTests(NeoUnitTestBase):
app.uuid = my_uuid app.uuid = my_uuid
app.pt = Mock({ app.pt = Mock({
'getPartitions': 2, 'getPartitions': 2,
'getRow': ReturnValues( 'getOutdatedOffsetListFor': [0],
((my_uuid, CellStates.OUT_OF_DATE),
(other_uuid, CellStates.UP_TO_DATE), ),
((my_uuid, CellStates.UP_TO_DATE),
(other_uuid, CellStates.OUT_OF_DATE), ),
),
}) })
replicator = Replicator(app) replicator = Replicator(app)
self.assertEqual(replicator.new_partition_dict, {}) self.assertEqual(replicator.new_partition_dict, {})
...@@ -118,11 +113,8 @@ class StorageReplicatorTests(NeoUnitTestBase): ...@@ -118,11 +113,8 @@ class StorageReplicatorTests(NeoUnitTestBase):
'getNodeState': NodeStates.UNKNOWN, 'getNodeState': NodeStates.UNKNOWN,
}) })
app.pt = Mock({ app.pt = Mock({
'getPartitions': 1,
'getRow': ReturnValues(
((uuid, CellStates.OUT_OF_DATE), ),
),
'getCellList': [running_cell, unknown_cell], 'getCellList': [running_cell, unknown_cell],
'getOutdatedOffsetListFor': [0],
}) })
node_conn_handler = Mock({ node_conn_handler = Mock({
'startReplication': None, 'startReplication': None,
......
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