Skip to content

Commit

Permalink
Add verification that the revision shouldn't decrease on bootstrap
Browse files Browse the repository at this point in the history
Signed-off-by: Benjamin Wang <[email protected]>
  • Loading branch information
ahrtr committed Apr 15, 2024
1 parent a7f5d4b commit 9ac964d
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions server/storage/mvcc/kvstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 9ac964d

Please sign in to comment.