From 0af22abc6c2183c4dfdbd8faed8bca1125743392 Mon Sep 17 00:00:00 2001 From: Wei Fu Date: Wed, 24 Apr 2024 11:08:33 +0800 Subject: [PATCH] server/mvcc: should update currentRev in revMu Signed-off-by: Wei Fu --- server/mvcc/kvstore.go | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/server/mvcc/kvstore.go b/server/mvcc/kvstore.go index 1e46e2ec33a..828d81549a9 100644 --- a/server/mvcc/kvstore.go +++ b/server/mvcc/kvstore.go @@ -380,6 +380,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() } @@ -402,17 +413,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() s.lg.Info("kvstore restored", zap.Int64("current-rev", s.currentRev))