Skip to content
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

Generalize iterator exhausted error #13060

Merged
merged 2 commits into from
Dec 10, 2024
Merged
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
6 changes: 6 additions & 0 deletions erigon-lib/kv/stream/stream_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package stream

import "errors"

// Streams - it's iterator-like composable high-level abstraction - which designed for inter-process communication and between processes:
// - cancelable
// - return errors
Expand All @@ -38,6 +40,10 @@ package stream
// check in loops on stream. Duo has very limited API - user has no way to
// terminate it - but user can specify more strict conditions when creating stream (then server knows better when to stop)

// Indicates the iterator has no more elements. Meant to be returned by implementations of Next()
// when there are no more elements.
var ErrIteratorExhausted = errors.New("iterator exhausted")

// Uno - return 1 item. Example:
//
// for s.HasNext() {
Expand Down
6 changes: 2 additions & 4 deletions erigon-lib/recsplit/eliasfano32/elias_fano.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package eliasfano32

import (
"encoding/binary"
"errors"
"fmt"
"io"
"math"
Expand All @@ -27,6 +26,7 @@ import (
"unsafe"

"github.com/erigontech/erigon-lib/common/bitutil"
"github.com/erigontech/erigon-lib/kv/stream"
)

// EliasFano algo overview https://www.antoniomallia.it/sorted-integers-compression-with-elias-fano-encoding.html
Expand All @@ -44,8 +44,6 @@ const (
superQSize uint64 = 1 + qPerSuperQ/2 // 1 + 64/2 = 33
)

var ErrEliasFanoIterExhausted = errors.New("elias fano iterator exhausted")

// EliasFano can be used to encode one monotone sequence
type EliasFano struct {
data []uint64
Expand Down Expand Up @@ -486,7 +484,7 @@ func (efi *EliasFanoIter) decrement() {

func (efi *EliasFanoIter) Next() (uint64, error) {
if !efi.HasNext() {
return 0, ErrEliasFanoIterExhausted
return 0, stream.ErrIteratorExhausted
}
idx64, shift := efi.lowerIdx/64, efi.lowerIdx%64
lower := efi.lowerBits[idx64] >> shift
Expand Down
4 changes: 2 additions & 2 deletions erigon-lib/recsplit/eliasfano32/elias_fano_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,15 +355,15 @@ func TestIterator(t *testing.T) {
require.NoError(t, err)
}
_, err := it.Next()
require.ErrorIs(t, err, ErrEliasFanoIterExhausted)
require.ErrorIs(t, err, stream.ErrIteratorExhausted)

it = ef.ReverseIterator()
for range offsets {
_, err := it.Next()
require.NoError(t, err)
}
_, err = it.Next()
require.ErrorIs(t, err, ErrEliasFanoIterExhausted)
require.ErrorIs(t, err, stream.ErrIteratorExhausted)
})

t.Run("article-example1", func(t *testing.T) {
Expand Down
Loading