From 9ac964d1ccb3f5f9d6a63a3c3eacf8ddff57dfc2 Mon Sep 17 00:00:00 2001 From: Benjamin Wang Date: Mon, 15 Apr 2024 13:49:57 +0100 Subject: [PATCH] Add verification that the revision shouldn't decrease on bootstrap Signed-off-by: Benjamin Wang --- server/storage/mvcc/kvstore.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/server/storage/mvcc/kvstore.go b/server/storage/mvcc/kvstore.go index 0edf0b72d3b..264bc7184fb 100644 --- a/server/storage/mvcc/kvstore.go +++ b/server/storage/mvcc/kvstore.go @@ -25,6 +25,7 @@ import ( "go.uber.org/zap" "go.etcd.io/etcd/api/v3/mvccpb" + "go.etcd.io/etcd/client/pkg/v3/verify" "go.etcd.io/etcd/pkg/v3/schedule" "go.etcd.io/etcd/pkg/v3/traceutil" "go.etcd.io/etcd/server/v3/lease" @@ -439,8 +440,15 @@ func restoreIntoIndex(lg *zap.Logger, idx index) (chan<- revKeyValue, <-chan int ok = true } } + rev := BytesToRev(rkv.key) + verify.Verify(func() { + if rev.Main < currentRev { + panic(fmt.Errorf("revision %d shouldn't be less than the previous revision %d", rev.Main, currentRev)) + } + }) currentRev = rev.Main + if ok { if isTombstone(rkv.key) { if err := ki.tombstone(lg, rev.Main, rev.Sub); err != nil {