all: rename Iteratee.NewIteratorWith -> NewIterator

This commit is contained in:
Martin Holst Swende 2020-04-14 10:57:03 +02:00
parent c138efe415
commit 1bae9a606c
No known key found for this signature in database
GPG key ID: 683B438C05A5DDF0
21 changed files with 48 additions and 70 deletions

View file

@ -301,7 +301,7 @@ func ExportPreimages(db ethdb.Database, fn string) error {
defer writer.(*gzip.Writer).Close()
}
// Iterate over the preimages and export them
it := db.NewIteratorWith([]byte("secure-key-"), nil)
it := db.NewIterator([]byte("secure-key-"), nil)
defer it.Release()
for it.Next() {

View file

@ -69,7 +69,7 @@ func ReadAllHashes(db ethdb.Iteratee, number uint64) []common.Hash {
prefix := headerKeyPrefix(number)
hashes := make([]common.Hash, 0, 1)
it := db.NewIteratorWith(prefix, nil)
it := db.NewIterator(prefix, nil)
defer it.Release()
for it.Next() {

View file

@ -93,7 +93,7 @@ func DeleteStorageSnapshot(db ethdb.KeyValueWriter, accountHash, storageHash com
// IterateStorageSnapshots returns an iterator for walking the entire storage
// space of a specific account.
func IterateStorageSnapshots(db ethdb.Iteratee, accountHash common.Hash) ethdb.Iterator {
return db.NewIteratorWith(storageSnapshotsKey(accountHash), nil)
return db.NewIterator(storageSnapshotsKey(accountHash), nil)
}
// ReadSnapshotJournal retrieves the serialized in-memory diff layers saved at

View file

@ -221,7 +221,7 @@ func NewLevelDBDatabaseWithFreezer(file string, cache int, handles int, freezer
// InspectDatabase traverses the entire database and checks the size
// of all different categories of data.
func InspectDatabase(db ethdb.Database) error {
it := db.NewIterator()
it := db.NewIterator(nil, nil)
defer it.Release()
var (

View file

@ -103,18 +103,12 @@ func (t *table) Delete(key []byte) error {
return t.db.Delete(append([]byte(t.prefix), key...))
}
// NewIterator creates a binary-alphabetical iterator over the entire keyspace
// contained within the database.
func (t *table) NewIterator() ethdb.Iterator {
return t.NewIteratorWith(nil, nil)
}
// NewIteratorWith creates a binary-alphabetical iterator over a subset
// NewIterator creates a binary-alphabetical iterator over a subset
// of database content with a particular key prefix, starting at a particular
// initial key (or after, if it does not exist).
func (t *table) NewIteratorWith(prefix []byte, start []byte) ethdb.Iterator {
func (t *table) NewIterator(prefix []byte, start []byte) ethdb.Iterator {
innerPrefix := append([]byte(t.prefix), prefix...)
iter := t.db.NewIteratorWith(innerPrefix, start)
iter := t.db.NewIterator(innerPrefix, start)
return &tableIterator{
iter: iter,
prefix: t.prefix,

View file

@ -117,12 +117,12 @@ func testTableDatabase(t *testing.T, prefix string) {
iter.Release()
}
// Test iterators
check(db.NewIterator(), 6, 0)
check(db.NewIterator(nil, nil), 6, 0)
// Test iterators with prefix
check(db.NewIteratorWith([]byte{0xff, 0xff}, nil), 3, 3)
check(db.NewIterator([]byte{0xff, 0xff}, nil), 3, 3)
// Test iterators with start point
check(db.NewIteratorWith(nil, []byte{0xff, 0xff, 0x02}), 2, 4)
check(db.NewIterator(nil, []byte{0xff, 0xff, 0x02}), 2, 4)
// Test iterators with prefix and start point
check(db.NewIteratorWith([]byte{0xee}, nil), 0, 0)
check(db.NewIteratorWith(nil, []byte{0x00}), 6, 0)
check(db.NewIterator([]byte{0xee}, nil), 0, 0)
check(db.NewIterator(nil, []byte{0x00}), 6, 0)
}

View file

@ -51,7 +51,7 @@ func TestNodeIteratorCoverage(t *testing.T) {
t.Errorf("state entry not reported %x", hash)
}
}
it := db.TrieDB().DiskDB().(ethdb.Database).NewIterator()
it := db.TrieDB().DiskDB().(ethdb.Database).NewIterator(nil, nil)
for it.Next() {
key := it.Key()
if bytes.HasPrefix(key, []byte("secure-key-")) {

View file

@ -151,7 +151,7 @@ func (dl *diskLayer) AccountIterator(seek common.Hash) AccountIterator {
pos := common.TrimRightZeroes(seek[:])
return &diskAccountIterator{
layer: dl,
it: dl.diskdb.NewIteratorWith(rawdb.SnapshotAccountPrefix, pos),
it: dl.diskdb.NewIterator(rawdb.SnapshotAccountPrefix, pos),
}
}

View file

@ -92,7 +92,7 @@ func wipeKeyRange(db ethdb.KeyValueStore, kind string, prefix []byte, keylen int
// Iterate over the key-range and delete all of them
start, logged := time.Now(), time.Now()
it := db.NewIteratorWith(prefix, nil)
it := db.NewIterator(prefix, nil)
for it.Next() {
// Skip any keys with the correct prefix but wrong lenth (trie nodes)
key := it.Key()
@ -114,7 +114,7 @@ func wipeKeyRange(db ethdb.KeyValueStore, kind string, prefix []byte, keylen int
}
batch.Reset()
seekPos := key[len(prefix):]
it = db.NewIteratorWith(prefix, seekPos)
it = db.NewIterator(prefix, seekPos)
if time.Since(logged) > 8*time.Second {
log.Info("Deleting state snapshot leftovers", "kind", kind, "wiped", items, "elapsed", common.PrettyDuration(time.Since(start)))

View file

@ -60,7 +60,7 @@ func TestWipe(t *testing.T) {
// Sanity check that all the keys are present
var items int
it := db.NewIteratorWith(rawdb.SnapshotAccountPrefix, nil)
it := db.NewIterator(rawdb.SnapshotAccountPrefix, nil)
defer it.Release()
for it.Next() {
@ -69,7 +69,7 @@ func TestWipe(t *testing.T) {
items++
}
}
it = db.NewIteratorWith(rawdb.SnapshotStoragePrefix, nil)
it = db.NewIterator(rawdb.SnapshotStoragePrefix, nil)
defer it.Release()
for it.Next() {
@ -88,7 +88,7 @@ func TestWipe(t *testing.T) {
<-wipeSnapshot(db, true)
// Iterate over the database end ensure no snapshot information remains
it = db.NewIteratorWith(rawdb.SnapshotAccountPrefix, nil)
it = db.NewIterator(rawdb.SnapshotAccountPrefix, nil)
defer it.Release()
for it.Next() {
@ -97,7 +97,7 @@ func TestWipe(t *testing.T) {
t.Errorf("snapshot entry remained after wipe: %x", key)
}
}
it = db.NewIteratorWith(rawdb.SnapshotStoragePrefix, nil)
it = db.NewIterator(rawdb.SnapshotStoragePrefix, nil)
defer it.Release()
for it.Next() {
@ -112,7 +112,7 @@ func TestWipe(t *testing.T) {
// Iterate over the database and ensure miscellaneous items are present
items = 0
it = db.NewIterator()
it = db.NewIterator(nil, nil)
defer it.Release()
for it.Next() {

View file

@ -60,7 +60,7 @@ func TestUpdateLeaks(t *testing.T) {
}
// Ensure that no data was leaked into the database
it := db.NewIterator()
it := db.NewIterator(nil, nil)
for it.Next() {
t.Errorf("State leaked into database: %x -> %x", it.Key(), it.Value())
}
@ -118,7 +118,7 @@ func TestIntermediateLeaks(t *testing.T) {
t.Errorf("can not commit trie %v to persistent database", finalRoot.Hex())
}
it := finalDb.NewIterator()
it := finalDb.NewIterator(nil, nil)
for it.Next() {
key, fvalue := it.Key(), it.Value()
tvalue, err := transDb.Get(key)
@ -131,7 +131,7 @@ func TestIntermediateLeaks(t *testing.T) {
}
it.Release()
it = transDb.NewIterator()
it = transDb.NewIterator(nil, nil)
for it.Next() {
key, tvalue := it.Key(), it.Value()
fvalue, err := finalDb.Get(key)

View file

@ -147,7 +147,7 @@ var bloomBitsPrefix = []byte("bloomBits-")
func clearBloomBits(db ethdb.Database) {
fmt.Println("Clearing bloombits data...")
it := db.NewIteratorWith(bloomBitsPrefix, nil)
it := db.NewIterator(bloomBitsPrefix, nil)
for it.Next() {
db.Delete(it.Key())
}

View file

@ -317,7 +317,7 @@ func testGetNodeData(t *testing.T, protocol int) {
// Fetch for now the entire chain db
hashes := []common.Hash{}
it := db.NewIterator()
it := db.NewIterator(nil, nil)
for it.Next() {
if key := it.Key(); len(key) == common.HashLength {
hashes = append(hashes, common.BytesToHash(key))

View file

@ -104,7 +104,7 @@ func TestDatabaseSuite(t *testing.T, New func() ethdb.KeyValueStore) {
}
}
// Iterate over the database with the given configs and verify the results
it, idx := db.NewIteratorWith([]byte(tt.prefix), []byte(tt.start)), 0
it, idx := db.NewIterator([]byte(tt.prefix), []byte(tt.start)), 0
for it.Next() {
if len(tt.order) <= idx {
t.Errorf("test %d: prefix=%q more items than expected: checking idx=%d (key %q), expecting len=%d", i, tt.prefix, idx, it.Key(), len(tt.order))
@ -142,7 +142,7 @@ func TestDatabaseSuite(t *testing.T, New func() ethdb.KeyValueStore) {
}
{
it := db.NewIterator()
it := db.NewIterator(nil, nil)
got, want := iterateKeys(it), keys
if err := it.Error(); err != nil {
t.Fatal(err)
@ -153,7 +153,7 @@ func TestDatabaseSuite(t *testing.T, New func() ethdb.KeyValueStore) {
}
{
it := db.NewIteratorWith([]byte("1"), nil)
it := db.NewIterator([]byte("1"), nil)
got, want := iterateKeys(it), []string{"1", "10", "11", "12"}
if err := it.Error(); err != nil {
t.Fatal(err)
@ -164,7 +164,7 @@ func TestDatabaseSuite(t *testing.T, New func() ethdb.KeyValueStore) {
}
{
it := db.NewIteratorWith([]byte("5"), nil)
it := db.NewIterator([]byte("5"), nil)
got, want := iterateKeys(it), []string{}
if err := it.Error(); err != nil {
t.Fatal(err)
@ -175,7 +175,7 @@ func TestDatabaseSuite(t *testing.T, New func() ethdb.KeyValueStore) {
}
{
it := db.NewIteratorWith(nil, []byte("2"))
it := db.NewIterator(nil, []byte("2"))
got, want := iterateKeys(it), []string{"2", "20", "21", "22", "3", "4", "6"}
if err := it.Error(); err != nil {
t.Fatal(err)
@ -186,7 +186,7 @@ func TestDatabaseSuite(t *testing.T, New func() ethdb.KeyValueStore) {
}
{
it := db.NewIteratorWith(nil, []byte("5"))
it := db.NewIterator(nil, []byte("5"))
got, want := iterateKeys(it), []string{"6"}
if err := it.Error(); err != nil {
t.Fatal(err)
@ -259,7 +259,7 @@ func TestDatabaseSuite(t *testing.T, New func() ethdb.KeyValueStore) {
}
{
it := db.NewIterator()
it := db.NewIterator(nil, nil)
if got, want := iterateKeys(it), []string{"1", "2", "3", "4"}; !reflect.DeepEqual(got, want) {
t.Errorf("got: %s; want: %s", got, want)
}
@ -279,7 +279,7 @@ func TestDatabaseSuite(t *testing.T, New func() ethdb.KeyValueStore) {
}
{
it := db.NewIterator()
it := db.NewIterator(nil, nil)
if got, want := iterateKeys(it), []string{"2", "3", "4", "5", "6"}; !reflect.DeepEqual(got, want) {
t.Errorf("got: %s; want: %s", got, want)
}
@ -307,7 +307,7 @@ func TestDatabaseSuite(t *testing.T, New func() ethdb.KeyValueStore) {
t.Fatal(err)
}
it := db.NewIterator()
it := db.NewIterator(nil, nil)
if got := iterateKeys(it); !reflect.DeepEqual(got, want) {
t.Errorf("got: %s; want: %s", got, want)
}

View file

@ -51,12 +51,8 @@ type Iterator interface {
// Iteratee wraps the NewIterator methods of a backing data store.
type Iteratee interface {
// NewIterator creates a binary-alphabetical iterator over the entire keyspace
// contained within the key-value database.
NewIterator() Iterator
// NewIteratorWith creates a binary-alphabetical iterator over a subset
// NewIterator creates a binary-alphabetical iterator over a subset
// of database content with a particular key prefix, starting at a particular
// initial key (or after, if it does not exist).
NewIteratorWith(prefix []byte, start []byte) Iterator
NewIterator(prefix []byte, start []byte) Iterator
}

View file

@ -183,16 +183,10 @@ func (db *Database) NewBatch() ethdb.Batch {
}
}
// NewIterator creates a binary-alphabetical iterator over the entire keyspace
// contained within the leveldb database.
func (db *Database) NewIterator() ethdb.Iterator {
return db.db.NewIterator(new(util.Range), nil)
}
// NewIteratorWith creates a binary-alphabetical iterator over a subset
// NewIterator creates a binary-alphabetical iterator over a subset
// of database content with a particular key prefix, starting at a particular
// initial key (or after, if it does not exist).
func (db *Database) NewIteratorWith(prefix []byte, start []byte) ethdb.Iterator {
func (db *Database) NewIterator(prefix []byte, start []byte) ethdb.Iterator {
return db.db.NewIterator(BytesPrefixRange(prefix, start), nil)
}

View file

@ -129,18 +129,12 @@ func (db *Database) NewBatch() ethdb.Batch {
}
}
// NewIterator creates a binary-alphabetical iterator over the entire keyspace
// contained within the memory database.
func (db *Database) NewIterator() ethdb.Iterator {
return db.NewIteratorWith(nil, nil)
}
// NewIteratorWith creates a binary-alphabetical iterator over a subset
// NewIterator creates a binary-alphabetical iterator over a subset
// of database content with a particular key prefix, starting at a particular
// initial key (or after, if it does not exist).
// Note: This method assumes that the prefix is NOT part of the start, so there's
// no need for the caller to prepend the prefix to the start
func (db *Database) NewIteratorWith(prefix []byte, start []byte) ethdb.Iterator {
func (db *Database) NewIterator(prefix []byte, start []byte) ethdb.Iterator {
db.lock.RLock()
defer db.lock.RUnlock()

View file

@ -770,7 +770,7 @@ func (db *nodeDB) getPosBalanceIDs(start, stop enode.ID, maxCount int) (result [
return
}
prefix := db.getPrefix(false)
it := db.db.NewIteratorWith(prefix, start.Bytes())
it := db.db.NewIterator(prefix, start.Bytes())
defer it.Release()
for i := len(stop[:]) - 1; i >= 0; i-- {
stop[i]--
@ -851,7 +851,7 @@ func (db *nodeDB) expireNodes() {
start = time.Now()
prefix = db.getPrefix(true)
)
iter := db.db.NewIteratorWith(prefix, nil)
iter := db.db.NewIterator(prefix, nil)
for iter.Next() {
visited += 1
var balance negBalance

View file

@ -120,7 +120,7 @@ func TestNodeIteratorCoverage(t *testing.T) {
}
}
}
it := db.diskdb.NewIterator()
it := db.diskdb.NewIterator(nil, nil)
for it.Next() {
key := it.Key()
if _, ok := hashes[common.BytesToHash(key)]; !ok {
@ -312,7 +312,7 @@ func testIteratorContinueAfterError(t *testing.T, memonly bool) {
if memonly {
memKeys = triedb.Nodes()
} else {
it := diskdb.NewIterator()
it := diskdb.NewIterator(nil, nil)
for it.Next() {
diskKeys = append(diskKeys, it.Key())
}

View file

@ -106,7 +106,7 @@ func TestBadProof(t *testing.T) {
if proof == nil {
t.Fatalf("prover %d: nil proof", i)
}
it := proof.NewIterator()
it := proof.NewIterator(nil, nil)
for i, d := 0, mrand.Intn(proof.Len()); i <= d; i++ {
it.Next()
}

View file

@ -99,7 +99,7 @@ func (b *SyncBloom) init(database ethdb.Iteratee) {
// Note, this is fine, because everything inserted into leveldb by fast sync is
// also pushed into the bloom directly, so we're not missing anything when the
// iterator is swapped out for a new one.
it := database.NewIterator()
it := database.NewIterator(nil, nil)
var (
start = time.Now()
@ -116,7 +116,7 @@ func (b *SyncBloom) init(database ethdb.Iteratee) {
key := common.CopyBytes(it.Key())
it.Release()
it = database.NewIteratorWith(nil, key)
it = database.NewIterator(nil, key)
log.Info("Initializing fast sync bloom", "items", b.bloom.N(), "errorrate", b.errorRate(), "elapsed", common.PrettyDuration(time.Since(start)))
swap = time.Now()