Commit 8f1fa695 authored by Grégory Wisniewski's avatar Grégory Wisniewski

Factorize gathering of assigned partitions.

git-svn-id: https://svn.erp5.org/repos/neo/trunk@1533 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent 2dc227f8
...@@ -99,6 +99,16 @@ class PartitionTable(object): ...@@ -99,6 +99,16 @@ class PartitionTable(object):
self.partition_list = [[] for x in xrange(self.np)] self.partition_list = [[] for x in xrange(self.np)]
self.count_dict.clear() self.count_dict.clear()
def getAssignedPartitionList(self, uuid):
""" Return the partition assigned to the specified UUID """
assigned_partitions = []
for offset in xrange(self.np):
for cell in self.getCellList(offset, readable=True):
if cell.getUUID() == uuid:
assigned_partitions.add(offset)
break
return assigned_partitions
def hasOffset(self, offset): def hasOffset(self, offset):
try: try:
return len(self.partition_list[offset]) > 0 return len(self.partition_list[offset]) > 0
......
...@@ -71,16 +71,8 @@ class BaseClientAndStorageOperationHandler(BaseStorageHandler): ...@@ -71,16 +71,8 @@ class BaseClientAndStorageOperationHandler(BaseStorageHandler):
raise protocol.ProtocolError('invalid offsets') raise protocol.ProtocolError('invalid offsets')
app = self.app app = self.app
if partition == protocol.INVALID_PARTITION: if partition == protocol.INVALID_PARTITION:
# Collect all usable partitions for me. partition_list = app.pt.getAssignedPartitionList(app.uuid)
getCellList = app.pt.getCellList
partition_list = []
for offset in xrange(app.pt.getPartitions()):
for cell in getCellList(offset, readable=True):
if cell.getUUID() == app.uuid:
partition_list.append(offset)
break
else: else:
partition_list = [partition] partition_list = [partition]
......
...@@ -37,16 +37,10 @@ class StorageOperationHandler(BaseClientAndStorageOperationHandler): ...@@ -37,16 +37,10 @@ class StorageOperationHandler(BaseClientAndStorageOperationHandler):
app = self.app app = self.app
if partition == protocol.INVALID_PARTITION: if partition == protocol.INVALID_PARTITION:
# Collect all usable partitions for me. partition_list = app.pt.getAssignedPartitionList(app.uuid)
getCellList = app.pt.getCellList
partition_list = []
for offset in xrange(app.pt.getPartitions()):
for cell in getCellList(offset, readable=True):
if cell.getUUID() == app.uuid:
partition_list.append(offset)
break
else: else:
partition_list = [partition] partition_list = [partition]
oid_list = app.dm.getOIDList(first, last - first, oid_list = app.dm.getOIDList(first, last - first,
app.pt.getPartitions(), partition_list) app.pt.getPartitions(), partition_list)
conn.answer(Packets.AnswerOIDs(oid_list), packet.getId()) conn.answer(Packets.AnswerOIDs(oid_list), packet.getId())
......
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