Skip to content

ethdb: Implement DeleteRange in batch #31947

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions core/rawdb/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,11 @@ func (b *tableBatch) Delete(key []byte) error {
return b.batch.Delete(append([]byte(b.prefix), key...))
}

// DeleteRange removes all keys in the range [start, end) from the batch for later committing.
func (b *tableBatch) DeleteRange(start, end []byte) error {
return b.batch.DeleteRange(append([]byte(b.prefix), start...), append([]byte(b.prefix), end...))
}

// ValueSize retrieves the amount of data queued up for writing.
func (b *tableBatch) ValueSize() int {
return b.batch.ValueSize()
Expand Down
14 changes: 12 additions & 2 deletions ethdb/batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const IdealBatchSize = 100 * 1024
// when Write is called. A batch cannot be used concurrently.
type Batch interface {
KeyValueWriter
KeyValueRangeDeleter

// ValueSize retrieves the amount of data queued up for writing.
ValueSize() int
Expand Down Expand Up @@ -53,8 +54,9 @@ type Batcher interface {
type HookedBatch struct {
Batch

OnPut func(key []byte, value []byte) // Callback if a key is inserted
OnDelete func(key []byte) // Callback if a key is deleted
OnPut func(key []byte, value []byte) // Callback if a key is inserted
OnDelete func(key []byte) // Callback if a key is deleted
OnDeleteRange func(start, end []byte) // Callback if a range of keys is deleted
}

// Put inserts the given value into the key-value data store.
Expand All @@ -72,3 +74,11 @@ func (b HookedBatch) Delete(key []byte) error {
}
return b.Batch.Delete(key)
}

// DeleteRange removes all keys in the range [start, end) from the key-value data store.
func (b HookedBatch) DeleteRange(start, end []byte) error {
if b.OnDeleteRange != nil {
b.OnDeleteRange(start, end)
}
return b.Batch.DeleteRange(start, end)
}
2 changes: 1 addition & 1 deletion ethdb/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
// (inclusive on start, exclusive on end).
// Some implementations of DeleteRange may return ErrTooManyKeys after
// partially deleting entries in the given range.
DeleteRange(start, end []byte) error
DeleteRange(start, end []byte) error

Check failure on line 51 in ethdb/database.go

View workflow job for this annotation

GitHub Actions / Lint

File is not properly formatted (goimports)
}

// KeyValueStater wraps the Stat method of a backing data store.
Expand Down
Loading
Loading