Commit f0adc66c authored by Julien Muchembled's avatar Julien Muchembled

master: simplify pt.addNode() a little

parent 005cb829
...@@ -173,16 +173,13 @@ class PartitionTable(neo.lib.pt.PartitionTable): ...@@ -173,16 +173,13 @@ class PartitionTable(neo.lib.pt.PartitionTable):
cell_list = [] cell_list = []
node_count = self.count_dict.get(node, 0) node_count = self.count_dict.get(node, 0)
for offset, row in enumerate(self.partition_list): for offset, row in enumerate(self.partition_list):
feeding_cell = None
max_count = 0 max_count = 0
max_cell = None max_cell = None
num_cells = 0 num_cells = 0
for cell in row: for cell in row:
if cell.getNode() is node: if cell.getNode() is node:
break break
if cell.isFeeding(): if not cell.isFeeding():
feeding_cell = cell
else:
num_cells += 1 num_cells += 1
count = self.count_dict[cell.getNode()] count = self.count_dict[cell.getNode()]
if count > max_count: if count > max_count:
...@@ -190,25 +187,17 @@ class PartitionTable(neo.lib.pt.PartitionTable): ...@@ -190,25 +187,17 @@ class PartitionTable(neo.lib.pt.PartitionTable):
max_cell = cell max_cell = cell
else: else:
if num_cells <= self.nr: if self.nr < num_cells:
row.append(Cell(node, CellStates.OUT_OF_DATE)) if node_count + 1 >= max_count:
cell_list.append((offset, node.getUUID(), continue
CellStates.OUT_OF_DATE)) if max_cell.isReadable():
node_count += 1
elif node_count + 1 < max_count:
if feeding_cell is not None or not max_cell.isReadable():
# If there is a feeding cell already or it is
# out-of-date, just drop the node.
row.remove(max_cell)
cell_list.append((offset, max_cell.getUUID(),
CellStates.DISCARDED))
self.count_dict[max_cell.getNode()] -= 1
else:
# Otherwise, use it as a feeding cell for safety.
max_cell.setState(CellStates.FEEDING) max_cell.setState(CellStates.FEEDING)
cell_list.append((offset, max_cell.getUUID(), cell_list.append((offset, max_cell.getUUID(),
CellStates.FEEDING)) CellStates.FEEDING))
# Don't count a feeding cell. else:
row.remove(max_cell)
cell_list.append((offset, max_cell.getUUID(),
CellStates.DISCARDED))
self.count_dict[max_cell.getNode()] -= 1 self.count_dict[max_cell.getNode()] -= 1
row.append(Cell(node, CellStates.OUT_OF_DATE)) row.append(Cell(node, CellStates.OUT_OF_DATE))
cell_list.append((offset, node.getUUID(), cell_list.append((offset, node.getUUID(),
......
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