Bug fix in NodeHeap

When running with a large number of nodes it fails to send the store request
to the k closest nodes and instead ends up sending multiple store requests to
the same 4 or 5 nodes.

It appears the cause is a bug in NodeHeap which allows the same node to be
pushed onto the heap multiple times bumping out other legimate nodes.

This pull request just adds some logic to make sure the node isn't already
in the heap before pushing.
This commit is contained in:
cpacia 2015-06-03 18:05:20 -04:00
parent d222050025
commit 088699bfbb
1 changed files with 3 additions and 2 deletions

View File

@ -94,8 +94,9 @@ class NodeHeap(object):
nodes = [nodes]
for node in nodes:
distance = self.node.distanceTo(node)
heapq.heappush(self.heap, (distance, node))
if node.id not in [n.id for n in self]:
distance = self.node.distanceTo(node)
heapq.heappush(self.heap, (distance, node))
def __len__(self):
return min(len(self.heap), self.maxsize)