Skip to content
This repository has been archived by the owner on Oct 18, 2023. It is now read-only.

Commit

Permalink
remove .SeekTo() method (erigontech#901)
Browse files Browse the repository at this point in the history
  • Loading branch information
AskAlexSharov authored Aug 10, 2020
1 parent 091819a commit 7a1b892
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 107 deletions.
1 change: 0 additions & 1 deletion ethdb/kv_abstract.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ type Cursor interface {

First() ([]byte, []byte, error)
Seek(seek []byte) ([]byte, []byte, error)
SeekTo(seek []byte) ([]byte, []byte, error)
Next() ([]byte, []byte, error)
Walk(walker func(k, v []byte) (bool, error)) error

Expand Down
6 changes: 3 additions & 3 deletions ethdb/kv_abstract_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,13 +233,13 @@ func testNoValuesIterator(t *testing.T, db ethdb.KV, bucket1 []byte) {
k, _, err = c.First()
assert.NoError(err)
assert.Equal([]byte{0}, k)
k, _, err = c.SeekTo([]byte{0, 0, 0, 0})
k, _, err = c.Seek([]byte{0, 0, 0, 0})
assert.NoError(err)
assert.Equal([]byte{0, 0, 0, 0, 0, 1}, k)
k, _, err = c.SeekTo([]byte{2})
k, _, err = c.Seek([]byte{2})
assert.NoError(err)
assert.Equal([]byte{2}, k)
k, _, err = c.SeekTo([]byte{99})
k, _, err = c.Seek([]byte{99})
assert.NoError(err)
assert.Nil(k)
c2 := b.Cursor().NoValues()
Expand Down
16 changes: 0 additions & 16 deletions ethdb/kv_bolt.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,22 +311,6 @@ func (c *boltCursor) Seek(seek []byte) (k, v []byte, err error) {
return k, v, nil
}

func (c *boltCursor) SeekTo(seek []byte) (k, v []byte, err error) {
select {
case <-c.ctx.Done():
return []byte{}, nil, c.ctx.Err()
default:
}

k, v = c.bolt.SeekTo(seek)
if c.prefix != nil {
if !bytes.HasPrefix(k, c.prefix) {
return nil, nil, nil
}
}
return k, v, nil
}

func (c *boltCursor) Next() (k, v []byte, err error) {
select {
case <-c.ctx.Done():
Expand Down
8 changes: 0 additions & 8 deletions ethdb/kv_lmdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -586,10 +586,6 @@ func (c *LmdbCursor) seekDupSort(seek []byte) (k, v []byte, err error) {
return k, v, nil
}

func (c *LmdbCursor) SeekTo(seek []byte) ([]byte, []byte, error) {
return c.Seek(seek)
}

func (c *LmdbCursor) Next() (k, v []byte, err error) {
select {
case <-c.ctx.Done():
Expand Down Expand Up @@ -883,10 +879,6 @@ func (c *lmdbNoValuesCursor) Seek(seek []byte) (k []byte, vSize uint32, err erro
return k, uint32(len(v)), err
}

func (c *lmdbNoValuesCursor) SeekTo(seek []byte) ([]byte, uint32, error) {
return c.Seek(seek)
}

func (c *lmdbNoValuesCursor) Next() (k []byte, vSize uint32, err error) {
k, v, err := c.LmdbCursor.Next()
if err != nil {
Expand Down
8 changes: 0 additions & 8 deletions ethdb/kv_remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,14 +231,6 @@ func (c *remoteCursor) Seek(seek []byte) ([]byte, []byte, error) {
return c.k, c.v, nil
}

func (c *remoteCursor) SeekTo(seek []byte) ([]byte, []byte, error) {
c.k, c.v, c.err = c.remote.SeekTo(seek)
if c.err != nil {
return []byte{}, c.v, c.err
}
return c.k, c.v, nil
}

func (c *remoteCursor) Next() ([]byte, []byte, error) {
c.k, c.v, c.err = c.remote.Next()
return c.k, c.v, c.err
Expand Down
6 changes: 0 additions & 6 deletions ethdb/kv_remote2.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,6 @@ func (b *remote2Bucket) Get(key []byte) (val []byte, err error) {

k, v, err := c.Seek(key)
if err != nil {
fmt.Printf("errr3: %s\n", err)
return nil, err
}
if !bytes.Equal(key, k) {
Expand Down Expand Up @@ -267,7 +266,6 @@ func (c *remote2Cursor) Seek(seek []byte) ([]byte, []byte, error) {
var err error
c.stream, err = c.bucket.tx.db.remoteKV.Seek(c.ctx)
if err != nil {
fmt.Printf("errr2: %s\n", err)
return []byte{}, nil, err
}
err = c.stream.Send(&remote.SeekRequest{BucketName: c.bucket.name, SeekKey: seek, Prefix: c.prefix, StartSreaming: false})
Expand All @@ -283,10 +281,6 @@ func (c *remote2Cursor) Seek(seek []byte) ([]byte, []byte, error) {
return pair.Key, pair.Value, nil
}

func (c *remote2Cursor) SeekTo(seek []byte) ([]byte, []byte, error) {
return c.Seek(seek)
}

// Next - returns next data element from server, request streaming (if configured by user)
func (c *remote2Cursor) Next() ([]byte, []byte, error) {
if !c.initialized {
Expand Down
2 changes: 1 addition & 1 deletion ethdb/object_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ func (db *ObjectDatabase) MultiWalk(bucket []byte, startkeys [][]byte, fixedbits
}
}
if cmp < 0 {
k, v, err = c.SeekTo(startkey)
k, v, err = c.Seek(startkey)
if err != nil {
return err
}
Expand Down
52 changes: 2 additions & 50 deletions ethdb/remote/kv_remote_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,7 @@ func (c *Cursor) SeekKey(seek []byte) (key []byte, vSize uint32, err error) {
}
}

c.cacheLastIdx = 0 // .Next() cache is invalid after .Seek() and .SeekTo() calls
c.cacheLastIdx = 0 // .Next() cache is invalid after .Seek() and .Seek() calls

select {
default:
Expand Down Expand Up @@ -790,7 +790,7 @@ func (c *Cursor) Seek(seek []byte) (key []byte, value []byte, err error) {
return nil, nil, err
}
}
c.cacheLastIdx = 0 // .Next() cache is invalid after .Seek() and .SeekTo() calls
c.cacheLastIdx = 0 // .Next() cache is invalid after .Seek() and .Seek() calls

select {
default:
Expand Down Expand Up @@ -835,54 +835,6 @@ func (c *Cursor) Seek(seek []byte) (key []byte, value []byte, err error) {
return key, value, nil
}

func (c *Cursor) SeekTo(seek []byte) (key []byte, value []byte, err error) {
if !c.initialized {
if err := c.init(); err != nil {
return nil, nil, err
}
}

c.cacheLastIdx = 0 // .Next() cache is invalid after .Seek() and .SeekTo() calls

select {
default:
case <-c.ctx.Done():
return nil, nil, c.ctx.Err()
}

decoder := codecpool.Decoder(c.in)
defer codecpool.Return(decoder)
encoder := codecpool.Encoder(c.out)
defer codecpool.Return(encoder)

if err := encoder.Encode(CmdCursorSeekTo); err != nil {
return nil, nil, fmt.Errorf("could not encode CmdCursorSeekTo: %w", err)
}
if err := encoder.Encode(c.cursorHandle); err != nil {
return nil, nil, fmt.Errorf("could not encode cursorHandle for CmdCursorSeekTo: %w", err)
}
if err := encoder.Encode(&seek); err != nil {
return nil, nil, fmt.Errorf("could not encode key for CmdCursorSeekTo: %w", err)
}

var responseCode ResponseCode
if err := decoder.Decode(&responseCode); err != nil {
return nil, nil, fmt.Errorf("could not decode ResponseCode for CmdCursorSeekTo: %w", err)
}

if responseCode != ResponseOk {
if err := decodeErr(decoder, responseCode); err != nil {
return nil, nil, fmt.Errorf("could not decode errorMessage for CmdCursorSeekTo: %w", err)
}
}

if err := decodeKeyValue(decoder, &key, &value); err != nil {
return nil, nil, fmt.Errorf("could not decode (key, value) for CmdCursorSeekTo: %w", err)
}

return key, value, nil
}

func (c *Cursor) needFetchNextPage() bool {
res := c.cacheLastIdx == 0 || // cache is empty
c.cacheIdx == c.cacheLastIdx // all cache read
Expand Down
28 changes: 14 additions & 14 deletions trie/flatdb_sub_trie_loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,26 +200,26 @@ func (fstl *FlatDbSubTrieLoader) iteration(c, ih ethdb.Cursor, first bool) error
// Looking for storage sub-tree
copy(fstl.accAddrHashWithInc[:], dbPrefix[:common.HashLength+common.IncarnationLength])
}
if fstl.k, fstl.v, err = c.SeekTo(dbPrefix); err != nil {
if fstl.k, fstl.v, err = c.Seek(dbPrefix); err != nil {
return err
}
if len(dbPrefix) <= common.HashLength && len(fstl.k) > common.HashLength {
// Advance past the storage to the first account
if nextAccount(fstl.k, fstl.nextAccountKey[:]) {
if fstl.k, fstl.v, err = c.SeekTo(fstl.nextAccountKey[:]); err != nil {
if fstl.k, fstl.v, err = c.Seek(fstl.nextAccountKey[:]); err != nil {
return err
}
} else {
fstl.k = nil
}
}
if fstl.ihK, fstl.ihV, err = ih.SeekTo(dbPrefix); err != nil {
if fstl.ihK, fstl.ihV, err = ih.Seek(dbPrefix); err != nil {
return err
}
if len(dbPrefix) <= common.HashLength && len(fstl.ihK) > common.HashLength {
// Advance to the first account
if nextAccount(fstl.ihK, fstl.nextAccountKey[:]) {
if fstl.ihK, fstl.ihV, err = ih.SeekTo(fstl.nextAccountKey[:]); err != nil {
if fstl.ihK, fstl.ihV, err = ih.Seek(fstl.nextAccountKey[:]); err != nil {
return err
}
} else {
Expand Down Expand Up @@ -264,12 +264,12 @@ func (fstl *FlatDbSubTrieLoader) iteration(c, ih ethdb.Cursor, first bool) error
if len(fstl.k) > common.HashLength && !bytes.HasPrefix(fstl.k, fstl.accAddrHashWithInc[:]) {
if bytes.Compare(fstl.k, fstl.accAddrHashWithInc[:]) < 0 {
// Skip all the irrelevant storage in the middle
if fstl.k, fstl.v, err = c.SeekTo(fstl.accAddrHashWithInc[:]); err != nil {
if fstl.k, fstl.v, err = c.Seek(fstl.accAddrHashWithInc[:]); err != nil {
return err
}
} else {
if nextAccount(fstl.k, fstl.nextAccountKey[:]) {
if fstl.k, fstl.v, err = c.SeekTo(fstl.nextAccountKey[:]); err != nil {
if fstl.k, fstl.v, err = c.Seek(fstl.nextAccountKey[:]); err != nil {
return err
}
} else {
Expand Down Expand Up @@ -306,14 +306,14 @@ func (fstl *FlatDbSubTrieLoader) iteration(c, ih ethdb.Cursor, first bool) error
// Now we know the correct incarnation of the account, and we can skip all irrelevant storage records
// Since 0 incarnation if 0xfff...fff, and we do not expect any records like that, this automatically
// skips over all storage items
if fstl.k, fstl.v, err = c.SeekTo(fstl.accAddrHashWithInc[:]); err != nil {
if fstl.k, fstl.v, err = c.Seek(fstl.accAddrHashWithInc[:]); err != nil {
return err
}
if fstl.trace {
fmt.Printf("k after accountWalker and SeekTo: %x\n", fstl.k)
fmt.Printf("k after accountWalker and Seek: %x\n", fstl.k)
}
if isBefore, _ := keyIsBefore(fstl.ihK, fstl.accAddrHashWithInc[:]); isBefore {
if fstl.ihK, fstl.ihV, err = ih.SeekTo(fstl.accAddrHashWithInc[:]); err != nil {
if fstl.ihK, fstl.ihV, err = ih.Seek(fstl.accAddrHashWithInc[:]); err != nil {
return err
}
}
Expand Down Expand Up @@ -355,12 +355,12 @@ func (fstl *FlatDbSubTrieLoader) iteration(c, ih ethdb.Cursor, first bool) error
if len(fstl.ihK) > common.HashLength && !bytes.HasPrefix(fstl.ihK, fstl.accAddrHashWithInc[:]) {
if bytes.Compare(fstl.ihK, fstl.accAddrHashWithInc[:]) < 0 {
// Skip all the irrelevant storage in the middle
if fstl.ihK, fstl.ihV, err = ih.SeekTo(fstl.accAddrHashWithInc[:]); err != nil {
if fstl.ihK, fstl.ihV, err = ih.Seek(fstl.accAddrHashWithInc[:]); err != nil {
return err
}
} else {
if nextAccount(fstl.ihK, fstl.nextAccountKey[:]) {
if fstl.ihK, fstl.ihV, err = ih.SeekTo(fstl.nextAccountKey[:]); err != nil {
if fstl.ihK, fstl.ihV, err = ih.Seek(fstl.nextAccountKey[:]); err != nil {
return err
}
} else {
Expand Down Expand Up @@ -400,14 +400,14 @@ func (fstl *FlatDbSubTrieLoader) iteration(c, ih ethdb.Cursor, first bool) error
}

if isBefore, _ := keyIsBefore(fstl.k, next); isBefore {
if fstl.k, fstl.v, err = c.SeekTo(next); err != nil {
if fstl.k, fstl.v, err = c.Seek(next); err != nil {
return err
}
}
if len(next) <= common.HashLength && len(fstl.k) > common.HashLength {
// Advance past the storage to the first account
if nextAccount(fstl.k, fstl.nextAccountKey[:]) {
if fstl.k, fstl.v, err = c.SeekTo(fstl.nextAccountKey[:]); err != nil {
if fstl.k, fstl.v, err = c.Seek(fstl.nextAccountKey[:]); err != nil {
return err
}
} else {
Expand All @@ -417,7 +417,7 @@ func (fstl *FlatDbSubTrieLoader) iteration(c, ih ethdb.Cursor, first bool) error
if fstl.trace {
fmt.Printf("k after next: %x\n", fstl.k)
}
if fstl.ihK, fstl.ihV, err = ih.SeekTo(next); err != nil {
if fstl.ihK, fstl.ihV, err = ih.Seek(next); err != nil {
return err
}
return nil
Expand Down

0 comments on commit 7a1b892

Please sign in to comment.