Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Breaking change consistant hashing #16

Closed
dennis-tra opened this issue May 15, 2019 · 2 comments
Closed

Breaking change consistant hashing #16

dennis-tra opened this issue May 15, 2019 · 2 comments

Comments

@dennis-tra
Copy link

dennis-tra commented May 15, 2019

Hi everyone,

the last commit broke our assumption that a randomly ordered slice of nodes will consistently return the same node for the same hash. The following test code fails on the current HEAD of master and works fine with the previous commit:

func TestStableHashring(t *testing.T) {
	nodes := []string{"NODE_1", "NODE_2", "NODE_3", "NODE_4", "NODE_5"}

	hash := "HASH"
	var constantNode string
	for i := 0; i < 100; i++ {

		rand.Shuffle(len(nodes), func(i, j int) { nodes[i], nodes[j] = nodes[j], nodes[i] })

		hr := New(nodes)
		n, ok := hr.GetNode(hash)
		if !ok {
			t.Error("error getting node")
		}

		if constantNode == "" {
			constantNode = n
		}

		if n != constantNode {
			t.Errorf("nodes are not equalt %s != %s", n, constantNode)
		}
	}
}

Is this a falsey assumption or did the latest changes introduce an unintended behaviour?

Cheers,
Dennis

@EmpireJones
Copy link

I'm curious of the intention here too; I had to fork with a revert commit, as this broke a desired behavior; I was using this for consensus among multiple servers, but that doesn't work well if they don't agree on anything.

@serialx
Copy link
Owner

serialx commented Jul 16, 2020

Fixed by #23

@serialx serialx closed this as completed Jul 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants