Skip to content

Commit 98b0ea6

Browse files
authored
ethdb/pebble: fix range compaction (#26771)
* ethdb/pebble: fix range compaction * ethdb/pebble: add comment
1 parent 2ea48f8 commit 98b0ea6

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

ethdb/pebble/pebble.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
package pebble
2121

2222
import (
23+
"bytes"
2324
"fmt"
2425
"runtime"
2526
"sync"
@@ -361,6 +362,17 @@ func (d *Database) Stat(property string) (string, error) {
361362
// is treated as a key after all keys in the data store. If both is nil then it
362363
// will compact entire data store.
363364
func (d *Database) Compact(start []byte, limit []byte) error {
365+
// There is no special flag to represent the end of key range
366+
// in pebble(nil in leveldb). Use an ugly hack to construct a
367+
// large key to represent it.
368+
// Note any prefixed database entry will be smaller than this
369+
// flag, as for trie nodes we need the 32 byte 0xff because
370+
// there might be a shared prefix starting with a number of
371+
// 0xff-s, so 32 ensures than only a hash collision could touch it.
372+
// https://github.com/cockroachdb/pebble/issues/2359#issuecomment-1443995833
373+
if limit == nil {
374+
limit = bytes.Repeat([]byte{0xff}, 32)
375+
}
364376
return d.db.Compact(start, limit, true) // Parallelization is preferred
365377
}
366378

0 commit comments

Comments
 (0)