From f585772746e494d8a900ea1e37f281792369bfa8 Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Thu, 10 Dec 2020 16:20:38 +0300 Subject: [PATCH] [#242] shard: Support ContainerID argument in metabase selects Signed-off-by: Alex Vanin --- pkg/local_object_storage/shard/list.go | 5 +---- pkg/local_object_storage/shard/select.go | 13 ++++++++++++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/pkg/local_object_storage/shard/list.go b/pkg/local_object_storage/shard/list.go index e137a768d..24dc5c18a 100644 --- a/pkg/local_object_storage/shard/list.go +++ b/pkg/local_object_storage/shard/list.go @@ -18,10 +18,7 @@ func (s *Shard) List() (*SelectRes, error) { filters := object.NewSearchFilters() for i := range lst { - filters = filters[:0] - filters.AddObjectContainerIDFilter(object.MatchStringEqual, lst[i]) - - ids, err := meta.Select(s.metaBase, filters) // consider making List in metabase + ids, err := meta.Select(s.metaBase, lst[i], filters) // consider making List in metabase if err != nil { s.log.Debug("can't select all objects", zap.Stringer("cid", lst[i]), diff --git a/pkg/local_object_storage/shard/select.go b/pkg/local_object_storage/shard/select.go index cf97f1e61..0ce4823db 100644 --- a/pkg/local_object_storage/shard/select.go +++ b/pkg/local_object_storage/shard/select.go @@ -1,6 +1,7 @@ package shard import ( + "github.com/nspcc-dev/neofs-api-go/pkg/container" objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object" meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase" "github.com/pkg/errors" @@ -8,6 +9,7 @@ import ( // SelectPrm groups the parameters of Select operation. type SelectPrm struct { + cid *container.ID filters objectSDK.SearchFilters } @@ -16,6 +18,15 @@ type SelectRes struct { addrList []*objectSDK.Address } +// WithContainerID is a Select option to set the container id to search in. +func (p *SelectPrm) WithContainerID(cid *container.ID) *SelectPrm { + if p != nil { + p.cid = cid + } + + return p +} + // WithFilters is a Select option to set the object filters. func (p *SelectPrm) WithFilters(fs objectSDK.SearchFilters) *SelectPrm { if p != nil { @@ -35,7 +46,7 @@ func (r *SelectRes) AddressList() []*objectSDK.Address { // Returns any error encountered that // did not allow to completely select the objects. func (s *Shard) Select(prm *SelectPrm) (*SelectRes, error) { - addrList, err := meta.Select(s.metaBase, prm.filters) + addrList, err := meta.Select(s.metaBase, prm.cid, prm.filters) if err != nil { return nil, errors.Wrap(err, "could not select objects from metabase") }