Skip to content

Commit 8d7cc0e

Browse files
hadvprpeh
authored andcommitted
ethdb: Implement DeleteRange in batch
1 parent 2a1784b commit 8d7cc0e

File tree

6 files changed

+551
-18
lines changed

6 files changed

+551
-18
lines changed

ethdb/batch.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ const IdealBatchSize = 100 * 1024
2525
type Batch interface {
2626
KeyValueWriter
2727

28+
// DeleteRange deletes all of the keys (and values) in the range [start,end)
29+
// (inclusive on start, exclusive on end).
30+
DeleteRange(start, end []byte) error
31+
2832
// ValueSize retrieves the amount of data queued up for writing.
2933
ValueSize() int
3034

@@ -53,8 +57,9 @@ type Batcher interface {
5357
type HookedBatch struct {
5458
Batch
5559

56-
OnPut func(key []byte, value []byte) // Callback if a key is inserted
57-
OnDelete func(key []byte) // Callback if a key is deleted
60+
OnPut func(key []byte, value []byte) // Callback if a key is inserted
61+
OnDelete func(key []byte) // Callback if a key is deleted
62+
OnDeleteRange func(start, end []byte) // Callback if a range of keys is deleted
5863
}
5964

6065
// Put inserts the given value into the key-value data store.
@@ -72,3 +77,11 @@ func (b HookedBatch) Delete(key []byte) error {
7277
}
7378
return b.Batch.Delete(key)
7479
}
80+
81+
// DeleteRange removes all keys in the range [start, end) from the key-value data store.
82+
func (b HookedBatch) DeleteRange(start, end []byte) error {
83+
if b.OnDeleteRange != nil {
84+
b.OnDeleteRange(start, end)
85+
}
86+
return b.Batch.DeleteRange(start, end)
87+
}

ethdb/database.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,16 @@ type KeyValueWriter interface {
3838

3939
// Delete removes the key from the key-value data store.
4040
Delete(key []byte) error
41-
}
42-
43-
var ErrTooManyKeys = errors.New("too many keys in deleted range")
4441

45-
// KeyValueRangeDeleter wraps the DeleteRange method of a backing data store.
46-
type KeyValueRangeDeleter interface {
4742
// DeleteRange deletes all of the keys (and values) in the range [start,end)
4843
// (inclusive on start, exclusive on end).
4944
// Some implementations of DeleteRange may return ErrTooManyKeys after
5045
// partially deleting entries in the given range.
51-
DeleteRange(start, end []byte) error
46+
DeleteRange(start, end []byte) error
5247
}
5348

49+
var ErrTooManyKeys = errors.New("too many keys in deleted range")
50+
5451
// KeyValueStater wraps the Stat method of a backing data store.
5552
type KeyValueStater interface {
5653
// Stat returns the statistic data of the database.
@@ -83,7 +80,6 @@ type KeyValueStore interface {
8380
KeyValueWriter
8481
KeyValueStater
8582
KeyValueSyncer
86-
KeyValueRangeDeleter
8783
Batcher
8884
Iteratee
8985
Compacter

0 commit comments

Comments
 (0)