3rd-Eden / node-hashring

hashring is a consistent hashing algorithm for Node.js that is compatible with libketama and python's hash_ring package
MIT License
350 stars 61 forks source link

Solve inconsistent hashing behavior #45

Open tcf909 opened 7 years ago

tcf909 commented 7 years ago

In a dynamic cluster (adding and removing nodes), there is a chance when dividing we receive an infinite repeating result which floors to a value that would be less than it needs to be to maintain a consistent hash with a prior state (in which the dividing result is a full integer, or not repeating).

Using round here seems to resolve the issue.

Test case: create a cluster of 6, distribute keys, add a new pnode (total 7), redistribute keys, add a new pnode (total 8), redistribute keys and then run through all keys and check that they exist in the correct location (failure).

solves issue #43