Skip to content

Commit

Permalink
fix iteration
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangchiqing committed Jul 10, 2024
1 parent db380d1 commit 2dcc6f8
Showing 1 changed file with 3 additions and 14 deletions.
17 changes: 3 additions & 14 deletions storage/pebble/operation/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,12 @@ func iterate(start []byte, end []byte, iteration iterationFunc, prefetchValues b
}
defer it.Close()

maxEndWithPrefix := append(end, ffBytes...)

for it.SeekGE(start); it.Valid(); it.Next() {
key := it.Key()
// Break the loop if we have passed the end key prefix
if bytes.Compare(key, end) > 0 && !startsWithPrefix(key, end) {
if bytes.Compare(key, maxEndWithPrefix) > 0 {
break
}

Expand Down Expand Up @@ -419,16 +421,3 @@ func BatchUpdate(db *pebble.DB, fn func(tx pebble.Writer) error) error {
}
return batch.Commit(nil)
}

// startsWithPrefix checks if a key starts with the given prefix
func startsWithPrefix(key, prefix []byte) bool {
if len(key) < len(prefix) {
return false
}
for i := range prefix {
if key[i] != prefix[i] {
return false
}
}
return true
}

0 comments on commit 2dcc6f8

Please sign in to comment.