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

change math/rand to crypto/rand to break tie in elections #50

Merged
merged 1 commit into from
May 25, 2023

Conversation

CaojiamingAlan
Copy link
Contributor

@CaojiamingAlan CaojiamingAlan commented May 10, 2023

This is to solve #48
Change math/rand to crypto/rand so that even in emulations the random numbers are different for each server.
Result verified by the sample given in etcd-io/etcd#15784:

[ec2-user@ip-172-31-38-170 ~]$ cat shadow.data/hosts/server3/etcd.1000.stdout | grep leader
2000-01-01T00:00:02.65Z	info	raft	v3@v3.0.0-20221201111702-eaa6808e1f7a/node.go:344	raft.node: d88930ebb1eeba8b elected leader 4ec99d67dc5f5788 at term 2
[ec2-user@ip-172-31-38-170 ~]$ cat shadow.data/hosts/server1/etcd.1000.stdout | grep leader
2000-01-01T00:00:02.65Z	info	raft	v3@v3.0.0-20221201111702-eaa6808e1f7a/node.go:344	raft.node: 4f7b593e8bbade70 elected leader 4ec99d67dc5f5788 at term 2
[ec2-user@ip-172-31-38-170 ~]$ cat shadow.data/hosts/server2/etcd.1000.stdout | grep leader
2000-01-01T00:00:02.6Z	info	raft	v3@v3.0.0-20221201111702-eaa6808e1f7a/raft.go:903	4ec99d67dc5f5788 became leader at term 2
2000-01-01T00:00:02.6Z	info	raft	v3@v3.0.0-20221201111702-eaa6808e1f7a/node.go:344	raft.node: 4ec99d67dc5f5788 elected leader 4ec99d67dc5f5788 at term 2

Signed-off-by: caojiamingalan <alan.c.19971111@gmail.com>
Copy link
Member

@ahrtr ahrtr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

cc @tbg @pavelkalinnikov

@tbg tbg merged commit 7f872e8 into etcd-io:main May 25, 2023
@tbg
Copy link
Collaborator

tbg commented May 25, 2023

(I verified that globalRand is used only for the election timeout, i.e. it's not on any hot path).

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

Successfully merging this pull request may close these issues.

None yet

3 participants