Skip to content

Commit

Permalink
tracker: make UpdateOnEntrieSend errorless
Browse files Browse the repository at this point in the history
The method will not be used in states other than StateProbe or
StateReplicate, so there is little sense in having the error path in it.

Signed-off-by: Pavel Kalinnikov <[email protected]>
  • Loading branch information
pav-kv committed Jan 30, 2024
1 parent 50b6d04 commit ee08961
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
5 changes: 1 addition & 4 deletions raft.go
Original file line number Diff line number Diff line change
Expand Up @@ -627,10 +627,6 @@ func (r *raft) maybeSendAppend(to uint64, sendIfEmpty bool) bool {
}

// Send the actual MsgApp otherwise, and update the progress accordingly.
if err := pr.UpdateOnEntriesSend(len(ents), uint64(payloadsSize(ents))); err != nil {
r.logger.Panicf("%x: %v", r.id, err)
}
// NB: pr has been updated, but we make sure to only use its old values below.
r.send(pb.Message{
To: to,
Type: pb.MsgApp,
Expand All @@ -639,6 +635,7 @@ func (r *raft) maybeSendAppend(to uint64, sendIfEmpty bool) bool {
Entries: ents,
Commit: r.raftLog.committed,
})
pr.UpdateOnEntriesSend(len(ents), uint64(payloadsSize(ents)))
return true
}

Expand Down
7 changes: 4 additions & 3 deletions tracker/progress.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,9 @@ func (pr *Progress) BecomeSnapshot(snapshoti uint64) {
// UpdateOnEntriesSend updates the progress on the given number of consecutive
// entries being sent in a MsgApp, with the given total bytes size, appended at
// log indices >= pr.Next.
func (pr *Progress) UpdateOnEntriesSend(entries int, bytes uint64) error {
//
// Must be used with StateProbe or StateReplicate.
func (pr *Progress) UpdateOnEntriesSend(entries int, bytes uint64) {
switch pr.State {
case StateReplicate:
if entries > 0 {
Expand All @@ -170,9 +172,8 @@ func (pr *Progress) UpdateOnEntriesSend(entries int, bytes uint64) error {
pr.MsgAppFlowPaused = true
}
default:
return fmt.Errorf("sending append in unhandled state %s", pr.State)
panic(fmt.Sprintf("sending append in unhandled state %s", pr.State))
}
return nil
}

// MaybeUpdate is called when an MsgAppResp arrives from the follower, with the
Expand Down

0 comments on commit ee08961

Please sign in to comment.