From ee089614ac1bd77dda31f6a40d9d44114aa51d75 Mon Sep 17 00:00:00 2001 From: Pavel Kalinnikov Date: Thu, 25 Jan 2024 16:42:54 +0000 Subject: [PATCH] tracker: make UpdateOnEntrieSend errorless 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 --- raft.go | 5 +---- tracker/progress.go | 7 ++++--- 2 files changed, 5 insertions(+), 7 deletions(-) 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