[#948] engine: Define EndOfListing error in component packages

Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
Alex Vanin 2021-11-17 14:31:31 +03:00 committed by Alex Vanin
parent c80c83b0b8
commit 1f911830a5
6 changed files with 24 additions and 17 deletions

View file

@ -12,8 +12,3 @@ var ErrRangeOutOfBounds = errors.New("payload range is out of bounds")
// ErrAlreadyRemoved returned when object has tombstone in graveyard. // ErrAlreadyRemoved returned when object has tombstone in graveyard.
var ErrAlreadyRemoved = errors.New("object already removed") var ErrAlreadyRemoved = errors.New("object already removed")
// ErrEndOfListing is returned from object listing with cursor
// when storage can't return any more objects after provided
// cursor. Use nil cursor object to start listing again.
var ErrEndOfListing = errors.New("end of object listing")

View file

@ -3,11 +3,15 @@ package engine
import ( import (
"sort" "sort"
core "github.com/nspcc-dev/neofs-node/pkg/core/object"
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard"
"github.com/nspcc-dev/neofs-sdk-go/object" "github.com/nspcc-dev/neofs-sdk-go/object"
) )
// ErrEndOfListing is returned from object listing with cursor
// when storage can't return any more objects after provided
// cursor. Use nil cursor object to start listing again.
var ErrEndOfListing = shard.ErrEndOfListing
// Cursor is a type for continuous object listing. // Cursor is a type for continuous object listing.
type Cursor struct { type Cursor struct {
shardID string shardID string
@ -69,7 +73,7 @@ func (e *StorageEngine) ListWithCursor(prm *ListWithCursorPrm) (*ListWithCursorR
e.mtx.RUnlock() e.mtx.RUnlock()
if len(shardIDs) == 0 { if len(shardIDs) == 0 {
return nil, core.ErrEndOfListing return nil, ErrEndOfListing
} }
sort.Slice(shardIDs, func(i, j int) bool { sort.Slice(shardIDs, func(i, j int) bool {
@ -116,7 +120,7 @@ func (e *StorageEngine) ListWithCursor(prm *ListWithCursorPrm) (*ListWithCursorR
} }
if len(result) == 0 { if len(result) == 0 {
return nil, core.ErrEndOfListing return nil, ErrEndOfListing
} }
return &ListWithCursorRes{ return &ListWithCursorRes{

View file

@ -6,7 +6,6 @@ import (
"sort" "sort"
"testing" "testing"
core "github.com/nspcc-dev/neofs-node/pkg/core/object"
cidtest "github.com/nspcc-dev/neofs-sdk-go/container/id/test" cidtest "github.com/nspcc-dev/neofs-sdk-go/container/id/test"
"github.com/nspcc-dev/neofs-sdk-go/object" "github.com/nspcc-dev/neofs-sdk-go/object"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
@ -46,14 +45,14 @@ func TestListWithCursor(t *testing.T) {
for i := 0; i < total-1; i++ { for i := 0; i < total-1; i++ {
res, err = e.ListWithCursor(prm.WithCursor(res.Cursor())) res, err = e.ListWithCursor(prm.WithCursor(res.Cursor()))
if errors.Is(err, core.ErrEndOfListing) { if errors.Is(err, ErrEndOfListing) {
break break
} }
got = append(got, res.AddressList()...) got = append(got, res.AddressList()...)
} }
_, err = e.ListWithCursor(prm.WithCursor(res.Cursor())) _, err = e.ListWithCursor(prm.WithCursor(res.Cursor()))
require.ErrorIs(t, err, core.ErrEndOfListing) require.ErrorIs(t, err, ErrEndOfListing)
got = sortAddresses(got) got = sortAddresses(got)
require.Equal(t, expected, got) require.Equal(t, expected, got)

View file

@ -1,14 +1,19 @@
package meta package meta
import ( import (
"errors"
"strings" "strings"
core "github.com/nspcc-dev/neofs-node/pkg/core/object"
cid "github.com/nspcc-dev/neofs-sdk-go/container/id" cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
"github.com/nspcc-dev/neofs-sdk-go/object" "github.com/nspcc-dev/neofs-sdk-go/object"
"go.etcd.io/bbolt" "go.etcd.io/bbolt"
) )
// ErrEndOfListing is returned from object listing with cursor
// when storage can't return any more objects after provided
// cursor. Use nil cursor object to start listing again.
var ErrEndOfListing = errors.New("end of object listing")
// Cursor is a type for continuous object listing. // Cursor is a type for continuous object listing.
type Cursor struct { type Cursor struct {
bucketName []byte bucketName []byte
@ -121,7 +126,7 @@ loop:
} }
if len(result) == 0 { if len(result) == 0 {
return nil, nil, core.ErrEndOfListing return nil, nil, ErrEndOfListing
} }
// new slice is much faster but less memory efficient // new slice is much faster but less memory efficient

View file

@ -5,7 +5,6 @@ import (
"sort" "sort"
"testing" "testing"
core "github.com/nspcc-dev/neofs-node/pkg/core/object"
meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase" meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase"
cidtest "github.com/nspcc-dev/neofs-sdk-go/container/id/test" cidtest "github.com/nspcc-dev/neofs-sdk-go/container/id/test"
objectSDK "github.com/nspcc-dev/neofs-sdk-go/object" objectSDK "github.com/nspcc-dev/neofs-sdk-go/object"
@ -91,7 +90,7 @@ func TestLisObjectsWithCursor(t *testing.T) {
} }
_, _, err = meta.ListWithCursor(db, uint32(countPerReq), cursor) _, _, err = meta.ListWithCursor(db, uint32(countPerReq), cursor)
require.ErrorIs(t, err, core.ErrEndOfListing, "count:%d", countPerReq, cursor) require.ErrorIs(t, err, meta.ErrEndOfListing, "count:%d", countPerReq, cursor)
got = sortAddresses(got) got = sortAddresses(got)
require.Equal(t, expected, got, "count:%d", countPerReq) require.Equal(t, expected, got, "count:%d", countPerReq)
@ -100,7 +99,7 @@ func TestLisObjectsWithCursor(t *testing.T) {
t.Run("invalid count", func(t *testing.T) { t.Run("invalid count", func(t *testing.T) {
_, _, err := meta.ListWithCursor(db, 0, nil) _, _, err := meta.ListWithCursor(db, 0, nil)
require.ErrorIs(t, err, core.ErrEndOfListing) require.ErrorIs(t, err, meta.ErrEndOfListing)
}) })
} }
@ -138,7 +137,7 @@ func TestAddObjectDuringListingWithCursor(t *testing.T) {
// get remaining objects // get remaining objects
for { for {
got, cursor, err = meta.ListWithCursor(db, total, cursor) got, cursor, err = meta.ListWithCursor(db, total, cursor)
if errors.Is(err, core.ErrEndOfListing) { if errors.Is(err, meta.ErrEndOfListing) {
break break
} }
for _, obj := range got { for _, obj := range got {

View file

@ -12,6 +12,11 @@ import (
// Cursor is a type for continuous object listing. // Cursor is a type for continuous object listing.
type Cursor = meta.Cursor type Cursor = meta.Cursor
// ErrEndOfListing is returned from object listing with cursor
// when storage can't return any more objects after provided
// cursor. Use nil cursor object to start listing again.
var ErrEndOfListing = meta.ErrEndOfListing
type ListContainersPrm struct{} type ListContainersPrm struct{}
type ListContainersRes struct { type ListContainersRes struct {