forked from TrueCloudLab/frostfs-node
[#948] engine: Define EndOfListing error in component packages
Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
parent
c80c83b0b8
commit
1f911830a5
6 changed files with 24 additions and 17 deletions
|
@ -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")
|
||||
|
|
|
@ -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{
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue