Skip to content

Commit

Permalink
raft: clean up getBasicStatus hack
Browse files Browse the repository at this point in the history
Layers above raft expect that raft state == StateLeader iff
leader ID == replica ID. This state is no longer possible inside
of raft, so we can get rid of the hack in getBasicStatus that
handled this.

Epic: none

Release note: None
  • Loading branch information
arulajmani committed Dec 11, 2024
1 parent e1673ec commit b88c571
Showing 1 changed file with 4 additions and 17 deletions.
21 changes: 4 additions & 17 deletions pkg/raft/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,23 +101,10 @@ func getBasicStatus(r *raft) BasicStatus {
s.HardState = r.hardState()
s.SoftState = r.softState()
s.Applied = r.raftLog.applied
if s.RaftState == pb.StateFollower && s.Lead == r.id {
// A raft leader's term ends when it is shut down. It'll rejoin its peers as
// a follower when it comes back up, but its Lead and Term field may still
// correspond to its pre-restart leadership term. We expect this to quickly
// be updated when it hears from the new leader, if one was elected in its
// absence, or when it campaigns.
//
// The layers above raft (in particular kvserver) do not handle the case
// where a raft node's state is StateFollower but its lead field points to
// itself. They expect the Lead field to correspond to the current leader,
// which we know we are not. For their benefit, we overwrite the Lead field
// to None.
//
// TODO(arul): the layers above should not conflate Lead with current
// leader. Fix that and get rid of this overwrite.
s.HardState.Lead = None
}
assertTrue((s.RaftState == pb.StateLeader && s.Lead == r.id) ||
(s.RaftState != pb.StateLeader && s.Lead != r.id),
"inconsistent lead / raft state",
)
return s
}

Expand Down

0 comments on commit b88c571

Please sign in to comment.