ethdb: move ErrTooManyKeys to package ethdb

This commit is contained in:
Zsolt Felfoldi 2025-03-31 11:42:35 +02:00
parent ca98df771c
commit c825264e37
3 changed files with 10 additions and 6 deletions

View file

@ -30,7 +30,6 @@ import (
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/ethdb/leveldb"
"github.com/ethereum/go-ethereum/ethdb/memorydb" "github.com/ethereum/go-ethereum/ethdb/memorydb"
"github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/log"
"github.com/olekukonko/tablewriter" "github.com/olekukonko/tablewriter"
@ -631,7 +630,7 @@ func SafeDeleteRange(db ethdb.KeyValueStore, start, end []byte, hashScheme bool,
switch err := db.DeleteRange(start, end); err { switch err := db.DeleteRange(start, end); err {
case nil: case nil:
return nil return nil
case leveldb.ErrTooManyKeys: case ethdb.ErrTooManyKeys:
if stopCallback(true) { if stopCallback(true) {
return ErrDeleteRangeInterrupted return ErrDeleteRangeInterrupted
} }

View file

@ -17,7 +17,10 @@
// Package ethdb defines the interfaces for an Ethereum data store. // Package ethdb defines the interfaces for an Ethereum data store.
package ethdb package ethdb
import "io" import (
"errors"
"io"
)
// KeyValueReader wraps the Has and Get method of a backing data store. // KeyValueReader wraps the Has and Get method of a backing data store.
type KeyValueReader interface { type KeyValueReader interface {
@ -37,10 +40,14 @@ type KeyValueWriter interface {
Delete(key []byte) error Delete(key []byte) error
} }
var ErrTooManyKeys = errors.New("too many keys in deleted range")
// KeyValueRangeDeleter wraps the DeleteRange method of a backing data store. // KeyValueRangeDeleter wraps the DeleteRange method of a backing data store.
type KeyValueRangeDeleter interface { type KeyValueRangeDeleter 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).
// 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
} }

View file

@ -207,8 +207,6 @@ func (db *Database) Delete(key []byte) error {
return db.db.Delete(key, nil) return db.db.Delete(key, nil)
} }
var ErrTooManyKeys = errors.New("too many keys in deleted range")
// 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).
// Note that this is a fallback implementation as leveldb does not natively // Note that this is a fallback implementation as leveldb does not natively
@ -228,7 +226,7 @@ func (db *Database) DeleteRange(start, end []byte) error {
if err := batch.Write(); err != nil { if err := batch.Write(); err != nil {
return err return err
} }
return ErrTooManyKeys return ethdb.ErrTooManyKeys
} }
if err := batch.Delete(it.Key()); err != nil { if err := batch.Delete(it.Key()); err != nil {
return err return err