Skip to content

Commit

Permalink
return the actually committed index if it's greater than the official…
Browse files Browse the repository at this point in the history
… committed index for ReadIndex

Signed-off-by: Benjamin Wang <[email protected]>
  • Loading branch information
ahrtr committed Sep 30, 2023
1 parent 645ea12 commit ef55987
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion raft.go
Original file line number Diff line number Diff line change
Expand Up @@ -1303,7 +1303,10 @@ func stepLeader(r *raft, m pb.Message) error {
case pb.MsgReadIndex:
// only one voting member (the leader) in the cluster
if r.prs.IsSingleton() {
if resp := r.responseToReadIndexReq(m, r.raftLog.committed); resp.To != None {
// It's possible that the "officially committed index" < "actually committed index",
// raft may return an out of date readindex in such case.
readIndex := max(r.raftLog.committed, r.prs.Committed())
if resp := r.responseToReadIndexReq(m, readIndex); resp.To != None {
r.send(resp)
}
return nil
Expand Down

0 comments on commit ef55987

Please sign in to comment.