mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
Merge pull request #1432 from unihorn/187
raft: use raft-specific rand.Rand instead of global one
This commit is contained in:
commit
60cb18b6c2
@ -115,6 +115,7 @@ type raft struct {
|
||||
elapsed int // number of ticks since the last msg
|
||||
heartbeatTimeout int
|
||||
electionTimeout int
|
||||
rand *rand.Rand
|
||||
tick func()
|
||||
step stepFunc
|
||||
}
|
||||
@ -123,7 +124,6 @@ func newRaft(id uint64, peers []uint64, election, heartbeat int) *raft {
|
||||
if id == None {
|
||||
panic("cannot use none id")
|
||||
}
|
||||
rand.Seed(int64(id))
|
||||
r := &raft{
|
||||
id: id,
|
||||
lead: None,
|
||||
@ -132,6 +132,7 @@ func newRaft(id uint64, peers []uint64, election, heartbeat int) *raft {
|
||||
electionTimeout: election,
|
||||
heartbeatTimeout: heartbeat,
|
||||
}
|
||||
r.rand = rand.New(rand.NewSource(int64(id)))
|
||||
for _, p := range peers {
|
||||
r.prs[p] = &progress{}
|
||||
}
|
||||
@ -575,5 +576,5 @@ func (r *raft) isElectionTimeout() bool {
|
||||
if d < 0 {
|
||||
return false
|
||||
}
|
||||
return d > rand.Int()%r.electionTimeout
|
||||
return d > r.rand.Int()%r.electionTimeout
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user