mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
raft: avoid another call to quorum()
This particular caller just wanted to know whether it was in a single-voter cluster configuration, which is now a question prs can answer.
This commit is contained in:
parent
bc828e939a
commit
57a1b39fcd
@ -310,6 +310,12 @@ func makePRS(maxInflight int) prs {
|
||||
return p
|
||||
}
|
||||
|
||||
// isSingleton returns true if (and only if) there is only one voting member
|
||||
// (i.e. the leader) in the current configuration.
|
||||
func (p *prs) isSingleton() bool {
|
||||
return len(p.nodes) == 1
|
||||
}
|
||||
|
||||
func (p *prs) quorum() int {
|
||||
return len(p.nodes)/2 + 1
|
||||
}
|
||||
|
@ -988,7 +988,7 @@ func stepLeader(r *raft, m pb.Message) error {
|
||||
r.bcastAppend()
|
||||
return nil
|
||||
case pb.MsgReadIndex:
|
||||
if r.prs.quorum() > 1 {
|
||||
if !r.prs.isSingleton() { // more than one voting member in cluster
|
||||
if r.raftLog.zeroTermOnErrCompacted(r.raftLog.term(r.raftLog.committed)) != r.Term {
|
||||
// Reject read only request when this leader has not committed any log entry at its term.
|
||||
return nil
|
||||
@ -1009,7 +1009,7 @@ func stepLeader(r *raft, m pb.Message) error {
|
||||
r.send(pb.Message{To: m.From, Type: pb.MsgReadIndexResp, Index: ri, Entries: m.Entries})
|
||||
}
|
||||
}
|
||||
} else { // there is only one voting member (the leader) in the cluster
|
||||
} else { // only one voting member (the leader) in the cluster
|
||||
if m.From == None || m.From == r.id { // from leader itself
|
||||
r.readStates = append(r.readStates, ReadState{Index: r.raftLog.committed, RequestCtx: m.Entries[0].Data})
|
||||
} else { // from learner member
|
||||
|
Loading…
x
Reference in New Issue
Block a user