From 8d471c7e36691fde8c88c51576f195f9a8e9b8de Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Wed, 27 Oct 2021 18:15:16 +0300 Subject: [PATCH] [#948] core/object: Move listing objects error to core Signed-off-by: Alex Vanin --- pkg/core/object/errors.go | 5 +++++ pkg/local_object_storage/engine/list_test.go | 4 ++-- pkg/local_object_storage/metabase/list.go | 12 +++--------- pkg/local_object_storage/metabase/list_test.go | 7 ++++--- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/pkg/core/object/errors.go b/pkg/core/object/errors.go index b1ba11e1e..bfa049c27 100644 --- a/pkg/core/object/errors.go +++ b/pkg/core/object/errors.go @@ -12,3 +12,8 @@ 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_test.go b/pkg/local_object_storage/engine/list_test.go index edaf852eb..78d51eedd 100644 --- a/pkg/local_object_storage/engine/list_test.go +++ b/pkg/local_object_storage/engine/list_test.go @@ -7,7 +7,7 @@ import ( cidtest "github.com/nspcc-dev/neofs-api-go/pkg/container/id/test" "github.com/nspcc-dev/neofs-api-go/pkg/object" - meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase" + core "github.com/nspcc-dev/neofs-node/pkg/core/object" "github.com/stretchr/testify/require" ) @@ -45,7 +45,7 @@ func TestListWithCursor(t *testing.T) { got = append(got, res.AddressList()...) _, err = e.ListWithCursor(prm.WithCursor(res.Cursor())) - require.ErrorIs(t, err, meta.ErrEndOfListing) + require.ErrorIs(t, err, core.ErrEndOfListing) } got = sortAddresses(got) diff --git a/pkg/local_object_storage/metabase/list.go b/pkg/local_object_storage/metabase/list.go index 709d55ab3..af66c0b23 100644 --- a/pkg/local_object_storage/metabase/list.go +++ b/pkg/local_object_storage/metabase/list.go @@ -5,6 +5,7 @@ import ( "fmt" "github.com/nspcc-dev/neofs-api-go/pkg/object" + core "github.com/nspcc-dev/neofs-node/pkg/core/object" "go.etcd.io/bbolt" ) @@ -50,14 +51,7 @@ const ( cursorPrefixSG = 's' ) -var ( - // ErrEndOfListing returns from ListWithCursor when metabase can't return - // any more objects after provided cursor. - // Use empty cursor to start listing again. - ErrEndOfListing = errors.New("end of metabase records") - - errStopIterator = errors.New("stop") -) +var errStopIterator = errors.New("stop") // ListWithCursor lists physical objects available in metabase. Includes regular, // tombstone and storage group objects. Does not include inhumed objects. Use @@ -148,7 +142,7 @@ func (db *DB) listWithCursor(tx *bbolt.Tx, count int, cursor string) ([]*object. }) if len(result) == 0 { - return nil, "", ErrEndOfListing + return nil, "", core.ErrEndOfListing } return result, string(cursorPrefix) + cursor, nil diff --git a/pkg/local_object_storage/metabase/list_test.go b/pkg/local_object_storage/metabase/list_test.go index 88e30746a..84f5737c2 100644 --- a/pkg/local_object_storage/metabase/list_test.go +++ b/pkg/local_object_storage/metabase/list_test.go @@ -7,6 +7,7 @@ import ( cidtest "github.com/nspcc-dev/neofs-api-go/pkg/container/id/test" objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object" + core "github.com/nspcc-dev/neofs-node/pkg/core/object" meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase" "github.com/stretchr/testify/require" ) @@ -90,7 +91,7 @@ func TestLisObjectsWithCursor(t *testing.T) { } _, _, err = meta.ListWithCursor(db, uint32(countPerReq), cursor) - require.ErrorIs(t, err, meta.ErrEndOfListing, "count:%d", countPerReq, cursor) + require.ErrorIs(t, err, core.ErrEndOfListing, "count:%d", countPerReq, cursor) got = sortAddresses(got) require.Equal(t, expected, got, "count:%d", countPerReq) @@ -110,7 +111,7 @@ func TestLisObjectsWithCursor(t *testing.T) { t.Run("invalid count", func(t *testing.T) { _, _, err := meta.ListWithCursor(db, 0, "") - require.ErrorIs(t, err, meta.ErrEndOfListing) + require.ErrorIs(t, err, core.ErrEndOfListing) }) } @@ -148,7 +149,7 @@ func TestAddObjectDuringListingWithCursor(t *testing.T) { // get remaining objects for { got, cursor, err = meta.ListWithCursor(db, total, cursor) - if errors.Is(err, meta.ErrEndOfListing) { + if errors.Is(err, core.ErrEndOfListing) { break } for _, obj := range got {