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):
def getPartition(self, oid_or_tid):
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):
""" Check if the oid is assigned to the given node """
for cell in self.partition_list[u64(oid) % self.np]:
......
......@@ -19,7 +19,7 @@ import neo
from random import choice
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.util import dump
......@@ -174,7 +174,9 @@ class Replicator(object):
table is the one accepted by primary master.
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.reset()
......@@ -187,15 +189,6 @@ class Replicator(object):
self.unfinished_tid_list = None
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):
"""Return whether there is any pending partition."""
return len(self.partition_dict) or len(self.new_partition_dict)
......
......@@ -36,12 +36,7 @@ class StorageReplicatorTests(NeoUnitTestBase):
app.uuid = my_uuid
app.pt = Mock({
'getPartitions': 2,
'getRow': ReturnValues(
((my_uuid, CellStates.OUT_OF_DATE),
(other_uuid, CellStates.UP_TO_DATE), ),
((my_uuid, CellStates.UP_TO_DATE),
(other_uuid, CellStates.OUT_OF_DATE), ),
),
'getOutdatedOffsetListFor': [0],
})
replicator = Replicator(app)
self.assertEqual(replicator.new_partition_dict, {})
......@@ -118,11 +113,8 @@ class StorageReplicatorTests(NeoUnitTestBase):
'getNodeState': NodeStates.UNKNOWN,
})
app.pt = Mock({
'getPartitions': 1,
'getRow': ReturnValues(
((uuid, CellStates.OUT_OF_DATE), ),
),
'getCellList': [running_cell, unknown_cell],
'getOutdatedOffsetListFor': [0],
})
node_conn_handler = Mock({
'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