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