From 9a036320434a8e9ec97b052d8c99d13dca34dfd9 Mon Sep 17 00:00:00 2001 From: Nathan VanBenschoten Date: Thu, 29 Sep 2022 12:32:10 -0400 Subject: [PATCH] raft: update prevHardSt on Ready accept, not advance This commit updates the `RawNode`'s `prevHardSt` to the new HardState in `acceptReady` instead of on `Advance`. This aligns the handling of `prevHardSt` with that of `prevSoftSt` (and other fields like `msgs`) and simplifies the logic in `Advance`. Signed-off-by: Nathan VanBenschoten --- raft/rawnode.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/raft/rawnode.go b/raft/rawnode.go index 4111d029d..abe1f9634 100644 --- a/raft/rawnode.go +++ b/raft/rawnode.go @@ -141,6 +141,9 @@ func (rn *RawNode) acceptReady(rd Ready) { if rd.SoftState != nil { rn.prevSoftSt = rd.SoftState } + if !IsEmptyHardState(rd.HardState) { + rn.prevHardSt = rd.HardState + } if len(rd.ReadStates) != 0 { rn.raft.readStates = nil } @@ -172,9 +175,6 @@ func (rn *RawNode) HasReady() bool { // Advance notifies the RawNode that the application has applied and saved progress in the // last Ready results. func (rn *RawNode) Advance(rd Ready) { - if !IsEmptyHardState(rd.HardState) { - rn.prevHardSt = rd.HardState - } rn.raft.advance(rd) }