From 9ea234913a99670d18b66aa23915781f89713177 Mon Sep 17 00:00:00 2001 From: Wei Fu Date: Thu, 18 Apr 2024 22:50:45 +0800 Subject: [PATCH] server/storage: update currentRev if scheduledCompact > currentRev Signed-off-by: Wei Fu --- server/storage/mvcc/kvstore.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/server/storage/mvcc/kvstore.go b/server/storage/mvcc/kvstore.go index 0edf0b72d..60564d6d7 100644 --- a/server/storage/mvcc/kvstore.go +++ b/server/storage/mvcc/kvstore.go @@ -388,6 +388,17 @@ 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))