Commit fae27fbf authored by Julien Muchembled's avatar Julien Muchembled

pt: Remove useless 'writable' parameter PartitionTable.getCellList

Cells must never be in DISCARDED state so 'getCellList' can be simplified
and all 'isUpToDate or isFeeding' can be replaced by 'not isOutOfDate'.
parent 0e5c59e9
......@@ -540,7 +540,7 @@ class Application(object):
add_involved_nodes = involved_nodes.add
packet = Packets.AskStoreObject(oid, serial, compression,
checksum, compressed_data, data_serial, ttid, unlock)
for node, conn in self.cp.iterateForObject(oid, writable=True):
for node, conn in self.cp.iterateForObject(oid):
try:
conn.ask(packet, on_timeout=on_timeout, queue=queue)
add_involved_nodes(node)
......@@ -715,7 +715,7 @@ class Application(object):
str(transaction.description), dumps(transaction._extension),
txn_context['cache_dict'])
add_involved_nodes = txn_context['involved_nodes'].add
for node, conn in self.cp.iterateForObject(ttid, writable=True):
for node, conn in self.cp.iterateForObject(ttid):
neo.lib.logging.debug("voting object %s on %s", dump(ttid),
dump(conn.getUUID()))
try:
......@@ -1096,7 +1096,7 @@ class Application(object):
assert oid not in txn_context['cache_dict'], (oid, txn_context)
txn_context['data_dict'].setdefault(oid, CHECKED_SERIAL)
packet = Packets.AskCheckCurrentSerial(ttid, serial, oid)
for node, conn in self.cp.iterateForObject(oid, writable=True):
for node, conn in self.cp.iterateForObject(oid):
try:
conn.ask(packet, queue=queue)
except ConnectionClosed:
......
......@@ -121,12 +121,12 @@ class ConnectionPool(object):
def getConnForCell(self, cell):
return self.getConnForNode(cell.getNode())
def iterateForObject(self, object_id, readable=False, writable=False):
def iterateForObject(self, object_id, readable=False):
""" Iterate over nodes managing an object """
pt = self.app.getPartitionTable()
if type(object_id) is str:
object_id = pt.getPartition(object_id)
cell_list = pt.getCellList(object_id, readable, writable)
cell_list = pt.getCellList(object_id, readable)
if not cell_list:
raise NEOStorageError('no storage available')
getConnForNode = self.getConnForNode
......
......@@ -33,7 +33,7 @@ class Cell(object):
def __init__(self, node, state = CellStates.UP_TO_DATE):
self.node = node
self.state = state
self.setState(state)
def __repr__(self):
return "<Cell(uuid=%s, address=%s, state=%s)>" % (
......@@ -46,6 +46,7 @@ class Cell(object):
return self.state
def setState(self, state):
assert state != CellStates.DISCARDED
self.state = state
def isUpToDate(self):
......@@ -125,20 +126,11 @@ class PartitionTable(object):
return [node for node, count in self.count_dict.iteritems() \
if count > 0]
def getCellList(self, offset, readable=False, writable=False):
# allow all cell states
state_set = set(CellStates.values())
if readable or writable:
# except non readables
state_set.remove(CellStates.DISCARDED)
def getCellList(self, offset, readable=False):
if readable:
# except non writables
state_set.remove(CellStates.OUT_OF_DATE)
try:
return [cell for cell in self.partition_list[offset] \
if cell is not None and cell.getState() in state_set]
except (TypeError, KeyError):
return []
return [cell for cell in self.partition_list[offset]
if not cell.isOutOfDate()]
return list(self.partition_list[offset])
def getPartition(self, oid_or_tid):
return u64(oid_or_tid) % self.getPartitions()
......@@ -189,7 +181,6 @@ class PartitionTable(object):
def removeCell(self, offset, node):
row = self.partition_list[offset]
assert row is not None
for cell in row:
if cell.getNode() == node:
row.remove(cell)
......@@ -303,8 +294,7 @@ class PartitionTable(object):
return False
for row in self.partition_list:
for cell in row:
if (cell.isUpToDate() or cell.isFeeding()) and \
cell.getNode().isRunning():
if not cell.isOutOfDate() and cell.getNode().isRunning():
break
else:
return False
......
......@@ -302,7 +302,7 @@ class PartitionTable(PartitionTable):
lost = lost_node
cell_list = []
for cell in row:
if cell.isUpToDate() or cell.isFeeding():
if not cell.isOutOfDate():
if cell.getNode().isRunning():
lost = None
else :
......@@ -322,8 +322,7 @@ class PartitionTable(PartitionTable):
return set(cell.getNode()
for row in self.partition_list
for cell in row
if cell.isUpToDate() or cell.isFeeding()
)
if not cell.isOutOfDate())
def getOutOfDateCellNodeSet(self):
"""
......@@ -332,6 +331,6 @@ class PartitionTable(PartitionTable):
"""
return set(cell.getNode()
for row in self.partition_list
for cell in row if cell.isOutOfDate()
)
for cell in row
if cell.isOutOfDate())
......@@ -198,14 +198,6 @@ class PartitionTableTests(NeoUnitTestBase):
self.assertTrue(sn2 in all_nodes)
self.assertTrue(sn3 in all_nodes)
self.assertTrue(sn4 not in all_nodes)
# writable nodes
all_cell = pt.getCellList(0, writable=True)
all_nodes = [x.getNode() for x in all_cell]
self.assertEqual(len(all_cell), 3)
self.assertTrue(sn1 in all_nodes)
self.assertTrue(sn2 in all_nodes)
self.assertTrue(sn3 in all_nodes)
self.assertTrue(sn4 not in all_nodes)
# readable nodes
all_cell = pt.getCellList(0, readable=True)
all_nodes = [x.getNode() for x in all_cell]
......@@ -214,14 +206,6 @@ class PartitionTableTests(NeoUnitTestBase):
self.assertTrue(sn2 not in all_nodes)
self.assertTrue(sn3 in all_nodes)
self.assertTrue(sn4 not in all_nodes)
# writable & readable nodes
all_cell = pt.getCellList(0, readable=True, writable=True)
all_nodes = [x.getNode() for x in all_cell]
self.assertEqual(len(all_cell), 2)
self.assertTrue(sn1 in all_nodes)
self.assertTrue(sn2 not in all_nodes)
self.assertTrue(sn3 in all_nodes)
self.assertTrue(sn4 not in all_nodes)
else:
self.assertEqual(len(pt.getCellList(1, False)), 0)
self.assertEqual(len(pt.getCellList(1, True)), 0)
......
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