ethdb: moved DeleteRange from KeyValueWriter to RangeDeleter

This commit is contained in:
Zsolt Felfoldi 2024-10-25 13:38:25 +02:00
parent f596f79f61
commit c1f1ade52e
13 changed files with 14 additions and 62 deletions

View file

@ -217,11 +217,6 @@ func (b *tableBatch) Delete(key []byte) error {
return b.batch.Delete(append([]byte(b.prefix), key...)) return b.batch.Delete(append([]byte(b.prefix), key...))
} }
// DeleteRange implements KeyValueWriter (not supported on batches).
func (b *tableBatch) DeleteRange(start, end []byte) error {
panic("DeleteRange is not supported on batches")
}
// ValueSize retrieves the amount of data queued up for writing. // ValueSize retrieves the amount of data queued up for writing.
func (b *tableBatch) ValueSize() int { func (b *tableBatch) ValueSize() int {
return b.batch.ValueSize() return b.batch.ValueSize()
@ -256,12 +251,6 @@ func (r *tableReplayer) Delete(key []byte) error {
return r.w.Delete(trimmed) return r.w.Delete(trimmed)
} }
// DeleteRange implements the interface KeyValueWriter.
func (r *tableReplayer) DeleteRange(start, end []byte) error {
trimmedStart, trimmedEnd := start[len(r.prefix):], end[len(r.prefix):]
return r.w.DeleteRange(trimmedStart, trimmedEnd)
}
// Replay replays the batch contents. // Replay replays the batch contents.
func (b *tableBatch) Replay(w ethdb.KeyValueWriter) error { func (b *tableBatch) Replay(w ethdb.KeyValueWriter) error {
return b.batch.Replay(&tableReplayer{w: w, prefix: b.prefix}) return b.batch.Replay(&tableReplayer{w: w, prefix: b.prefix})

View file

@ -41,10 +41,6 @@ func (r *testReplayer) Delete(key []byte) error {
return nil return nil
} }
func (r *testReplayer) DeleteRange(start, end []byte) error {
panic("not implemented")
}
func testTableDatabase(t *testing.T, prefix string) { func testTableDatabase(t *testing.T, prefix string) {
db := NewTable(NewMemoryDatabase(), prefix) db := NewTable(NewMemoryDatabase(), prefix)

View file

@ -116,8 +116,6 @@ func (bloom *stateBloom) Put(key []byte, value []byte) error {
// Delete removes the key from the key-value data store. // Delete removes the key from the key-value data store.
func (bloom *stateBloom) Delete(key []byte) error { panic("not supported") } func (bloom *stateBloom) Delete(key []byte) error { panic("not supported") }
func (bloom *stateBloom) DeleteRange(start, end []byte) error { panic("not supported") }
// Contain is the wrapper of the underlying contains function which // Contain is the wrapper of the underlying contains function which
// reports whether the key is contained. // reports whether the key is contained.
// - If it says yes, the key may be contained // - If it says yes, the key may be contained

View file

@ -97,10 +97,6 @@ func (r *replayer) Delete(key []byte) error {
return nil return nil
} }
func (r *replayer) DeleteRange(start, end []byte) error {
panic("not implemented")
}
func byteToHex(str []byte) []byte { func byteToHex(str []byte) []byte {
l := len(str) * 2 l := len(str) * 2
var nibbles = make([]byte, l) var nibbles = make([]byte, l)
@ -245,7 +241,7 @@ func TestPartialGentree(t *testing.T) {
{2, len(entries) - 2}, // no left and right {2, len(entries) - 2}, // no left and right
{2, len(entries) - 2}, // no left and right {2, len(entries) - 2}, // no left and right
{len(entries) / 2, len(entries) / 2}, // single {len(entries) / 2, len(entries) / 2}, // single
{0, 0}, // single first {0, 0}, // single first
{len(entries) - 1, len(entries) - 1}, // single last {len(entries) - 1, len(entries) - 1}, // single last
} }
for _, c := range cases { for _, c := range cases {
@ -354,7 +350,7 @@ func TestGentreeDanglingClearing(t *testing.T) {
{2, len(entries) - 2}, // no left and right {2, len(entries) - 2}, // no left and right
{2, len(entries) - 2}, // no left and right {2, len(entries) - 2}, // no left and right
{len(entries) / 2, len(entries) / 2}, // single {len(entries) / 2, len(entries) / 2}, // single
{0, 0}, // single first {0, 0}, // single first
{len(entries) - 1, len(entries) - 1}, // single last {len(entries) - 1, len(entries) - 1}, // single last
} }
for _, c := range cases { for _, c := range cases {
@ -394,13 +390,13 @@ func TestFlushPartialTree(t *testing.T) {
first int first int
last int last int
}{ }{
{0, len(entries) - 1}, // full {0, len(entries) - 1}, // full
{1, len(entries) - 1}, // no left {1, len(entries) - 1}, // no left
{10, len(entries) - 1}, // no left {10, len(entries) - 1}, // no left
{10, len(entries) - 2}, // no left and right {10, len(entries) - 2}, // no left and right
{10, len(entries) - 10}, // no left and right {10, len(entries) - 10}, // no left and right
{11, 11}, // single {11, 11}, // single
{0, 0}, // single first {0, 0}, // single first
{len(entries) - 1, len(entries) - 1}, // single last {len(entries) - 1, len(entries) - 1}, // single last
} }
for _, c := range cases { for _, c := range cases {

View file

@ -35,7 +35,10 @@ type KeyValueWriter interface {
// Delete removes the key from the key-value data store. // Delete removes the key from the key-value data store.
Delete(key []byte) error Delete(key []byte) error
}
// RangeDeleter wraps the DeleteRange method of a backing data store.
type RangeDeleter interface {
// DeleteRange deletes all of the keys (and values) in the range [start,end) // DeleteRange deletes all of the keys (and values) in the range [start,end)
// (inclusive on start, exclusive on end). // (inclusive on start, exclusive on end).
DeleteRange(start, end []byte) error DeleteRange(start, end []byte) error
@ -65,6 +68,7 @@ type KeyValueStore interface {
KeyValueReader KeyValueReader
KeyValueWriter KeyValueWriter
KeyValueStater KeyValueStater
RangeDeleter
Batcher Batcher
Iteratee Iteratee
Compacter Compacter
@ -193,6 +197,7 @@ type ResettableAncientStore interface {
type Database interface { type Database interface {
Reader Reader
Writer Writer
RangeDeleter
Batcher Batcher
Iteratee Iteratee
Stater Stater

View file

@ -441,11 +441,6 @@ func (b *batch) Delete(key []byte) error {
return nil return nil
} }
// DeleteRange implements KeyValueWriter (not supported on batches).
func (b *batch) DeleteRange(start, end []byte) error {
panic("DeleteRange is not supported on batches")
}
// ValueSize retrieves the amount of data queued up for writing. // ValueSize retrieves the amount of data queued up for writing.
func (b *batch) ValueSize() int { func (b *batch) ValueSize() int {
return b.size return b.size

View file

@ -229,11 +229,6 @@ func (b *batch) Delete(key []byte) error {
return nil return nil
} }
// DeleteRange implements KeyValueWriter (not supported on batches).
func (b *batch) DeleteRange(start, end []byte) error {
panic("DeleteRange is not supported on batches")
}
// ValueSize retrieves the amount of data queued up for writing. // ValueSize retrieves the amount of data queued up for writing.
func (b *batch) ValueSize() int { func (b *batch) ValueSize() int {
return b.size return b.size

View file

@ -550,11 +550,6 @@ func (b *batch) Delete(key []byte) error {
return nil return nil
} }
// DeleteRange implements KeyValueWriter (not supported on batches).
func (b *batch) DeleteRange(start, end []byte) error {
panic("DeleteRange is not supported on batches")
}
// ValueSize retrieves the amount of data queued up for writing. // ValueSize retrieves the amount of data queued up for writing.
func (b *batch) ValueSize() int { func (b *batch) ValueSize() int {
return b.size return b.size

View file

@ -704,10 +704,6 @@ func (n *proofList) Delete(key []byte) error {
panic("not supported") panic("not supported")
} }
func (n *proofList) DeleteRange(start, end []byte) error {
panic("not supported")
}
// GetProof returns the Merkle-proof for a given account and optionally some storage keys. // GetProof returns the Merkle-proof for a given account and optionally some storage keys.
func (api *BlockChainAPI) GetProof(ctx context.Context, address common.Address, storageKeys []string, blockNrOrHash rpc.BlockNumberOrHash) (*AccountResult, error) { func (api *BlockChainAPI) GetProof(ctx context.Context, address common.Address, storageKeys []string, blockNrOrHash rpc.BlockNumberOrHash) (*AccountResult, error) {
var ( var (

View file

@ -918,10 +918,6 @@ func (w *hookWriter) Delete(key []byte) error {
return w.db.Delete(key) return w.db.Delete(key)
} }
func (w *hookWriter) DeleteRange(start, end []byte) error {
panic("not supported")
}
func testSyncAbort(t *testing.T, scheme string) { func testSyncAbort(t *testing.T, scheme string) {
var ( var (
srcDisk = rawdb.NewMemoryDatabase() srcDisk = rawdb.NewMemoryDatabase()

View file

@ -868,7 +868,6 @@ func (b *spongeBatch) Put(key, value []byte) error {
return nil return nil
} }
func (b *spongeBatch) Delete(key []byte) error { panic("implement me") } func (b *spongeBatch) Delete(key []byte) error { panic("implement me") }
func (b *spongeBatch) DeleteRange(start, end []byte) error { panic("implement me") }
func (b *spongeBatch) ValueSize() int { return 100 } func (b *spongeBatch) ValueSize() int { return 100 }
func (b *spongeBatch) Write() error { return nil } func (b *spongeBatch) Write() error { return nil }
func (b *spongeBatch) Reset() {} func (b *spongeBatch) Reset() {}

View file

@ -156,10 +156,6 @@ func (n *ProofList) Delete(key []byte) error {
panic("not supported") panic("not supported")
} }
func (n *ProofList) DeleteRange(start, end []byte) error {
panic("not supported")
}
// DataSize returns the aggregated data size of nodes in the list // DataSize returns the aggregated data size of nodes in the list
func (n ProofList) DataSize() int { func (n ProofList) DataSize() int {
var size int var size int

View file

@ -532,10 +532,6 @@ func (c *cleaner) Delete(key []byte) error {
panic("not implemented") panic("not implemented")
} }
func (c *cleaner) DeleteRange(start, end []byte) error {
panic("not supported")
}
// Initialized returns an indicator if state data is already initialized // Initialized returns an indicator if state data is already initialized
// in hash-based scheme by checking the presence of genesis state. // in hash-based scheme by checking the presence of genesis state.
func (db *Database) Initialized(genesisRoot common.Hash) bool { func (db *Database) Initialized(genesisRoot common.Hash) bool {