From 4cb197e0faaed1551601cec9f225a44cf54358f5 Mon Sep 17 00:00:00 2001 From: Wei Fu Date: Wed, 24 Apr 2024 11:15:26 +0800 Subject: [PATCH] mvcc: should update currentRev in revMu Signed-off-by: Wei Fu --- mvcc/kvstore.go | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/mvcc/kvstore.go b/mvcc/kvstore.go index ba114273d..098e684f6 100644 --- a/mvcc/kvstore.go +++ b/mvcc/kvstore.go @@ -450,6 +450,17 @@ func (s *store) restore() error { s.currentRev = s.compactMainRev } + // If the latest revision was a tombstone revision and etcd just compacted + // it, but crashed right before persisting the FinishedCompactRevision, + // then it would lead to revision decreasing in bbolt db file. In such + // a scenario, we should adjust the current revision using the scheduled + // compact revision on bootstrap when etcd gets started again. + // + // See https://github.com/etcd-io/etcd/issues/17780#issuecomment-2061900231 + if s.currentRev < scheduledCompact { + s.currentRev = scheduledCompact + } + if scheduledCompact <= s.compactMainRev { scheduledCompact = 0 } @@ -474,17 +485,6 @@ func (s *store) restore() error { } } - // If the latest revision was a tombstone revision and etcd just compacted - // it, but crashed right before persisting the FinishedCompactRevision, - // then it would lead to revision decreasing in bbolt db file. In such - // a scenario, we should adjust the current revision using the scheduled - // compact revision on bootstrap when etcd gets started again. - // - // See https://github.com/etcd-io/etcd/issues/17780#issuecomment-2061900231 - if s.currentRev < scheduledCompact { - s.currentRev = scheduledCompact - } - tx.Unlock() if scheduledCompact != 0 {