From 02e6df683aa4bf197e80261c2f03435eb2572747 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Fri, 24 Sep 2021 18:04:00 +0300 Subject: [PATCH] [#840] shard: Return only physically stored objects from List `List` method of `Shard` must return only physically stored objects. Use `AddPhyFilter` to select only phy objects. Signed-off-by: Leonard Lyubich --- pkg/local_object_storage/shard/list.go | 2 ++ pkg/local_object_storage/shard/list_test.go | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/pkg/local_object_storage/shard/list.go b/pkg/local_object_storage/shard/list.go index 9244ea350..c9f906909 100644 --- a/pkg/local_object_storage/shard/list.go +++ b/pkg/local_object_storage/shard/list.go @@ -19,6 +19,7 @@ func (r *ListContainersRes) Containers() []*cid.ID { return r.containers } +// List returns all objects physically stored in the Shard. func (s *Shard) List() (*SelectRes, error) { lst, err := s.metaBase.Containers() if err != nil { @@ -27,6 +28,7 @@ func (s *Shard) List() (*SelectRes, error) { res := new(SelectRes) filters := object.NewSearchFilters() + filters.AddPhyFilter() for i := range lst { ids, err := meta.Select(s.metaBase, lst[i], filters) // consider making List in metabase diff --git a/pkg/local_object_storage/shard/list_test.go b/pkg/local_object_storage/shard/list_test.go index 68998a4fb..04aee5a6f 100644 --- a/pkg/local_object_storage/shard/list_test.go +++ b/pkg/local_object_storage/shard/list_test.go @@ -40,6 +40,11 @@ func testShardList(t *testing.T, sh *shard.Shard) { obj := generateRawObjectWithCID(t, cid) addPayload(obj, 1<<2) + // add parent as virtual object, it must be ignored in List() + parent := generateRawObjectWithCID(t, cid) + obj.SetParentID(parent.Object().ID()) + obj.SetParent(parent.Object().SDK()) + objs[obj.Object().Address().String()] = 0 putPrm.WithObject(obj.Object()) @@ -53,7 +58,6 @@ func testShardList(t *testing.T, sh *shard.Shard) { require.NoError(t, err) for _, objID := range res.AddressList() { - i, ok := objs[objID.String()] require.True(t, ok) require.Equal(t, 0, i)