mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
Merge pull request #17325 from ahrtr/verify_key_20240125
Add verification on keys: should be always mononically increasing
This commit is contained in:
commit
704c93c9ba
@ -16,6 +16,8 @@ package backend
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"sort"
|
||||
|
||||
"go.etcd.io/etcd/client/pkg/v3/verify"
|
||||
@ -52,7 +54,20 @@ func (txw *txWriteBuffer) put(bucket Bucket, k, v []byte) {
|
||||
}
|
||||
|
||||
func (txw *txWriteBuffer) putSeq(bucket Bucket, k, v []byte) {
|
||||
// TODO: Add (in tests?) verification whether k>b[len(b)]
|
||||
// putSeq is only be called for the data in the Key bucket. The keys
|
||||
// in the Key bucket should be monotonically increasing revisions.
|
||||
verify.Verify(func() {
|
||||
b, ok := txw.buckets[bucket.ID()]
|
||||
if !ok || b.used == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
existingMaxKey := b.buf[b.used-1].key
|
||||
if bytes.Compare(k, existingMaxKey) <= 0 {
|
||||
panic(fmt.Sprintf("Broke the rule of monotonically increasing, existingMaxKey: %s, currentKey: %s",
|
||||
hex.EncodeToString(existingMaxKey), hex.EncodeToString(k)))
|
||||
}
|
||||
})
|
||||
txw.putInternal(bucket, k, v)
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user