[Neo-report] r2614 gregory - in /trunk/neo: ./ storage/ tests/storage/
nobody at svn.erp5.org
nobody at svn.erp5.org
Tue Jan 11 17:37:40 CET 2011
Author: gregory
Date: Tue Jan 11 17:37:40 2011
New Revision: 2614
Log:
Move getOudatedPartitionList logic to partition table.
Modified:
trunk/neo/pt.py
trunk/neo/storage/replicator.py
trunk/neo/tests/storage/testReplicator.py
Modified: trunk/neo/pt.py
==============================================================================
--- trunk/neo/pt.py [iso-8859-1] (original)
+++ trunk/neo/pt.py [iso-8859-1] Tue Jan 11 17:37:40 2011
@@ -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]:
Modified: trunk/neo/storage/replicator.py
==============================================================================
--- trunk/neo/storage/replicator.py [iso-8859-1] (original)
+++ trunk/neo/storage/replicator.py [iso-8859-1] Tue Jan 11 17:37:40 2011
@@ -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)
Modified: trunk/neo/tests/storage/testReplicator.py
==============================================================================
--- trunk/neo/tests/storage/testReplicator.py [iso-8859-1] (original)
+++ trunk/neo/tests/storage/testReplicator.py [iso-8859-1] Tue Jan 11 17:37:40 2011
@@ -36,12 +36,7 @@ class StorageReplicatorTests(NeoUnitTest
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(NeoUnitTest
'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,
More information about the Neo-report
mailing list