From 1f911830a531bb50e4790ddb6647316e3dae1210 Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Wed, 17 Nov 2021 14:31:31 +0300 Subject: [PATCH] [#948] engine: Define EndOfListing error in component packages Signed-off-by: Alex Vanin --- pkg/core/object/errors.go | 5 ----- pkg/local_object_storage/engine/list.go | 10 +++++++--- pkg/local_object_storage/engine/list_test.go | 5 ++--- pkg/local_object_storage/metabase/list.go | 9 +++++++-- pkg/local_object_storage/metabase/list_test.go | 7 +++---- pkg/local_object_storage/shard/list.go | 5 +++++ 6 files changed, 24 insertions(+), 17 deletions(-) diff --git a/pkg/core/object/errors.go b/pkg/core/object/errors.go index bfa049c2..b1ba11e1 100644 --- a/pkg/core/object/errors.go +++ b/pkg/core/object/errors.go @@ -12,8 +12,3 @@ var ErrRangeOutOfBounds = errors.New("payload range is out of bounds") // ErrAlreadyRemoved returned when object has tombstone in graveyard. 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") diff --git a/pkg/local_object_storage/engine/list.go b/pkg/local_object_storage/engine/list.go index 8be1c83f..8076cd24 100644 --- a/pkg/local_object_storage/engine/list.go +++ b/pkg/local_object_storage/engine/list.go @@ -3,11 +3,15 @@ package engine import ( "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-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. type Cursor struct { shardID string @@ -69,7 +73,7 @@ func (e *StorageEngine) ListWithCursor(prm *ListWithCursorPrm) (*ListWithCursorR e.mtx.RUnlock() if len(shardIDs) == 0 { - return nil, core.ErrEndOfListing + return nil, ErrEndOfListing } sort.Slice(shardIDs, func(i, j int) bool { @@ -116,7 +120,7 @@ func (e *StorageEngine) ListWithCursor(prm *ListWithCursorPrm) (*ListWithCursorR } if len(result) == 0 { - return nil, core.ErrEndOfListing + return nil, ErrEndOfListing } return &ListWithCursorRes{ diff --git a/pkg/local_object_storage/engine/list_test.go b/pkg/local_object_storage/engine/list_test.go index 496b5eae..84edb304 100644 --- a/pkg/local_object_storage/engine/list_test.go +++ b/pkg/local_object_storage/engine/list_test.go @@ -6,7 +6,6 @@ import ( "sort" "testing" - core "github.com/nspcc-dev/neofs-node/pkg/core/object" cidtest "github.com/nspcc-dev/neofs-sdk-go/container/id/test" "github.com/nspcc-dev/neofs-sdk-go/object" "github.com/stretchr/testify/require" @@ -46,14 +45,14 @@ func TestListWithCursor(t *testing.T) { for i := 0; i < total-1; i++ { res, err = e.ListWithCursor(prm.WithCursor(res.Cursor())) - if errors.Is(err, core.ErrEndOfListing) { + if errors.Is(err, ErrEndOfListing) { break } got = append(got, res.AddressList()...) } _, err = e.ListWithCursor(prm.WithCursor(res.Cursor())) - require.ErrorIs(t, err, core.ErrEndOfListing) + require.ErrorIs(t, err, ErrEndOfListing) got = sortAddresses(got) require.Equal(t, expected, got) diff --git a/pkg/local_object_storage/metabase/list.go b/pkg/local_object_storage/metabase/list.go index 436f8112..052a1077 100644 --- a/pkg/local_object_storage/metabase/list.go +++ b/pkg/local_object_storage/metabase/list.go @@ -1,14 +1,19 @@ package meta import ( + "errors" "strings" - core "github.com/nspcc-dev/neofs-node/pkg/core/object" cid "github.com/nspcc-dev/neofs-sdk-go/container/id" "github.com/nspcc-dev/neofs-sdk-go/object" "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. type Cursor struct { bucketName []byte @@ -121,7 +126,7 @@ loop: } if len(result) == 0 { - return nil, nil, core.ErrEndOfListing + return nil, nil, ErrEndOfListing } // new slice is much faster but less memory efficient diff --git a/pkg/local_object_storage/metabase/list_test.go b/pkg/local_object_storage/metabase/list_test.go index 22292c89..17475278 100644 --- a/pkg/local_object_storage/metabase/list_test.go +++ b/pkg/local_object_storage/metabase/list_test.go @@ -5,7 +5,6 @@ import ( "sort" "testing" - core "github.com/nspcc-dev/neofs-node/pkg/core/object" meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase" cidtest "github.com/nspcc-dev/neofs-sdk-go/container/id/test" 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) - require.ErrorIs(t, err, core.ErrEndOfListing, "count:%d", countPerReq, cursor) + require.ErrorIs(t, err, meta.ErrEndOfListing, "count:%d", countPerReq, cursor) got = sortAddresses(got) 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) { _, _, 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 for { got, cursor, err = meta.ListWithCursor(db, total, cursor) - if errors.Is(err, core.ErrEndOfListing) { + if errors.Is(err, meta.ErrEndOfListing) { break } for _, obj := range got { diff --git a/pkg/local_object_storage/shard/list.go b/pkg/local_object_storage/shard/list.go index 53486065..137ff98f 100644 --- a/pkg/local_object_storage/shard/list.go +++ b/pkg/local_object_storage/shard/list.go @@ -12,6 +12,11 @@ import ( // Cursor is a type for continuous object listing. 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 ListContainersRes struct {