diff --git a/raft.go b/raft.go index 558c5e23..7994877b 100644 --- a/raft.go +++ b/raft.go @@ -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, @@ -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 } diff --git a/tracker/progress.go b/tracker/progress.go index b1acd8a7..8c618765 100644 --- a/tracker/progress.go +++ b/tracker/progress.go @@ -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 { @@ -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