From 94c83a962b1f8149042bfb19b9022b1b104ad14e Mon Sep 17 00:00:00 2001 From: Wei Fu Date: Wed, 24 Apr 2024 11:08:33 +0800 Subject: [PATCH] server/storage/mvcc: should update currentRev in revMu Signed-off-by: Wei Fu --- server/storage/mvcc/kvstore.go | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/server/storage/mvcc/kvstore.go b/server/storage/mvcc/kvstore.go index 055b9eafe..236b09981 100644 --- a/server/storage/mvcc/kvstore.go +++ b/server/storage/mvcc/kvstore.go @@ -367,6 +367,17 @@ func (s *store) restore() error { if s.currentRev < s.compactMainRev { 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 + } s.revMu.Unlock() } @@ -388,18 +399,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.RUnlock() s.lg.Info("kvstore restored", zap.Int64("current-rev", s.currentRev))