[#231] shard: Add List method to return all available objects
Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
parent
a1cb48f800
commit
a7087faa1a
2 changed files with 98 additions and 0 deletions
36
pkg/local_object_storage/shard/list.go
Normal file
36
pkg/local_object_storage/shard/list.go
Normal file
|
@ -0,0 +1,36 @@
|
|||
package shard
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/nspcc-dev/neofs-api-go/pkg/object"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
func (s *Shard) List() (*SelectRes, error) {
|
||||
lst, err := s.metaBase.Containers()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("can't list stored containers: %w", err)
|
||||
}
|
||||
|
||||
res := new(SelectRes)
|
||||
filters := object.NewSearchFilters()
|
||||
|
||||
for i := range lst {
|
||||
filters = filters[:0]
|
||||
filters.AddObjectContainerIDFilter(object.MatchStringEqual, lst[i])
|
||||
|
||||
ids, err := s.metaBase.Select(filters) // consider making List in metabase
|
||||
if err != nil {
|
||||
s.log.Debug("can't select all objects",
|
||||
zap.Stringer("cid", lst[i]),
|
||||
zap.String("error", err.Error()))
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
res.addrList = append(res.addrList, ids...)
|
||||
}
|
||||
|
||||
return res, nil
|
||||
}
|
62
pkg/local_object_storage/shard/list_test.go
Normal file
62
pkg/local_object_storage/shard/list_test.go
Normal file
|
@ -0,0 +1,62 @@
|
|||
package shard_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestShard_List(t *testing.T) {
|
||||
sh := newShard(t, false)
|
||||
shWC := newShard(t, true)
|
||||
|
||||
defer func() {
|
||||
releaseShard(sh, t)
|
||||
releaseShard(shWC, t)
|
||||
}()
|
||||
|
||||
t.Run("without write cache", func(t *testing.T) {
|
||||
testShardList(t, sh)
|
||||
})
|
||||
|
||||
t.Run("with write cache", func(t *testing.T) {
|
||||
testShardList(t, shWC)
|
||||
})
|
||||
}
|
||||
|
||||
func testShardList(t *testing.T, sh *shard.Shard) {
|
||||
const C = 10
|
||||
const N = 5
|
||||
|
||||
objs := make(map[string]int)
|
||||
putPrm := new(shard.PutPrm)
|
||||
|
||||
for i := 0; i < C; i++ {
|
||||
cid := generateCID()
|
||||
|
||||
for j := 0; j < N; j++ {
|
||||
obj := generateRawObjectWithCID(t, cid)
|
||||
addPayload(obj, 1<<2)
|
||||
|
||||
objs[obj.Object().Address().String()] = 0
|
||||
|
||||
putPrm.WithObject(obj.Object())
|
||||
|
||||
_, err := sh.Put(putPrm)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
}
|
||||
|
||||
res, err := sh.List()
|
||||
require.NoError(t, err)
|
||||
|
||||
for _, objID := range res.AddressList() {
|
||||
|
||||
i, ok := objs[objID.String()]
|
||||
require.True(t, ok)
|
||||
require.Equal(t, 0, i)
|
||||
|
||||
objs[objID.String()] = 1
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue