From 3e678c9c96915af1e108c4d5422d7e41e5555125 Mon Sep 17 00:00:00 2001 From: Gary Rong Date: Mon, 27 Feb 2023 11:27:09 +0800 Subject: [PATCH 1/2] ethdb/pebble: fix range compaction --- ethdb/pebble/pebble.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/ethdb/pebble/pebble.go b/ethdb/pebble/pebble.go index fdad13b392e..632ea88f4bd 100644 --- a/ethdb/pebble/pebble.go +++ b/ethdb/pebble/pebble.go @@ -20,6 +20,7 @@ package pebble import ( + "bytes" "fmt" "runtime" "sync" @@ -361,6 +362,13 @@ func (d *Database) Stat(property string) (string, error) { // is treated as a key after all keys in the data store. If both is nil then it // will compact entire data store. func (d *Database) Compact(start []byte, limit []byte) error { + // There is no special flag to represent the end of key range + // in pebble(nil in leveldb). Use an ugly hack to construct a + // large key to represent it. + // https://github.com/cockroachdb/pebble/issues/2359#issuecomment-1443995833 + if limit == nil { + limit = bytes.Repeat([]byte{0xff}, 32) + } return d.db.Compact(start, limit, true) // Parallelization is preferred } From 83807df1c6c035ef5e500c8631e2fd74e7671d0b Mon Sep 17 00:00:00 2001 From: Gary Rong Date: Mon, 27 Feb 2023 16:08:30 +0800 Subject: [PATCH 2/2] ethdb/pebble: add comment --- ethdb/pebble/pebble.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ethdb/pebble/pebble.go b/ethdb/pebble/pebble.go index 632ea88f4bd..6a7573bdc69 100644 --- a/ethdb/pebble/pebble.go +++ b/ethdb/pebble/pebble.go @@ -365,6 +365,10 @@ func (d *Database) Compact(start []byte, limit []byte) error { // There is no special flag to represent the end of key range // in pebble(nil in leveldb). Use an ugly hack to construct a // large key to represent it. + // Note any prefixed database entry will be smaller than this + // flag, as for trie nodes we need the 32 byte 0xff because + // there might be a shared prefix starting with a number of + // 0xff-s, so 32 ensures than only a hash collision could touch it. // https://github.com/cockroachdb/pebble/issues/2359#issuecomment-1443995833 if limit == nil { limit = bytes.Repeat([]byte{0xff}, 32)