Skip to content

Commit

Permalink
raft: don't assume MsgSnap comes from leader
Browse files Browse the repository at this point in the history
We can't consider MsgSnap to be from the leader of Message.Term until we
address #127348 and #127349.

Epic: None
Release note: None
  • Loading branch information
nvanbenschoten committed Oct 22, 2024
1 parent 5333c56 commit a3a2b5b
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
5 changes: 5 additions & 0 deletions pkg/raft/raft.go
Original file line number Diff line number Diff line change
Expand Up @@ -2043,6 +2043,11 @@ func stepCandidate(r *raft, m pb.Message) error {
case pb.MsgProp:
r.logger.Infof("%x no leader at term %d; dropping proposal", r.id, r.Term)
return ErrProposalDropped
case pb.MsgSnap:
// TODO(nvanbenschoten): we can't consider MsgSnap to be from the leader of
// Message.Term until we address #127348 and #127349.
r.becomeFollower(m.Term, None)
r.handleSnapshot(m)
case myVoteRespType:
gr, rj, res := r.poll(m.From, m.Type, !m.Reject)
r.logger.Infof("%x has received %d %s votes and %d vote rejections", r.id, gr, m.Type, rj)
Expand Down
2 changes: 1 addition & 1 deletion pkg/raft/raft_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2615,7 +2615,7 @@ func TestRestoreFromSnapMsg(t *testing.T) {
sm := newTestRaft(2, 10, 1, newTestMemoryStorage(withPeers(1, 2)))
sm.Step(m)

assert.Equal(t, pb.PeerID(1), sm.lead)
assert.Equal(t, None, sm.lead)
// TODO(bdarnell): what should this test?
}

Expand Down
6 changes: 4 additions & 2 deletions pkg/raft/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@ var isResponseMsg = [...]bool{
}

var isMsgFromLeader = [...]bool{
pb.MsgApp: true,
pb.MsgSnap: true,
pb.MsgApp: true,
// TODO(nvanbenschoten): we can't consider MsgSnap to be from the leader of
// Message.Term until we address #127348 and #127349.
// pb.MsgSnap: true,
pb.MsgHeartbeat: true,
pb.MsgTimeoutNow: true,
pb.MsgFortifyLeader: true,
Expand Down
2 changes: 1 addition & 1 deletion pkg/raft/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ func TestMsgFromLeader(t *testing.T) {
{pb.MsgAppResp, false},
{pb.MsgVote, false},
{pb.MsgVoteResp, false},
{pb.MsgSnap, true},
{pb.MsgSnap, false},
{pb.MsgHeartbeat, true},
{pb.MsgHeartbeatResp, false},
{pb.MsgTimeoutNow, true},
Expand Down

0 comments on commit a3a2b5b

Please sign in to comment.