[#948] core/object: Move listing objects error to core

Signed-off-by: Alex Vanin <alexey@nspcc.ru>
remotes/fyrchik/neofs-adm-update
Alex Vanin 2021-10-27 18:15:16 +03:00 committed by Alex Vanin
parent c02c7bee5b
commit 8d471c7e36
4 changed files with 14 additions and 14 deletions

View File

@ -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")

View File

@ -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)

View File

@ -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

View File

@ -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 {