consistent
consistent copied to clipboard
[Question/Bug] Use hashring instead of calculating the hash again using node
Hi,
Thanks for writing this module, helped me learn a thing or two about consistent hashing. When I was going through the package, I noticed that in the updateSortHashKeys you are recreating the hash again using the node keys present in the dataSet object.
https://github.com/kkdai/consistent/blob/master/consistent.go#L113
This seem like a bug to me, for the following reason
- When searching the for the node to retrieve the keys, we are not even considering the virtual nodes that are added. This information is present in
circleRingbut when you update the sort hash key, this information is not present in the sortedhashkey. - Performance impact of recreating the keys again. Minimal, still adding this point.
Instead of using dataSet in updateSortHashKeys, one needs to use the circleRing since it already has the virtual nodes and has the hash already created.