[#242] engine: Support ContainerID argument in shard selects

Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
Alex Vanin 2020-12-10 16:24:27 +03:00
parent f585772746
commit 511b5f782a

View file

@ -1,6 +1,7 @@
package engine package engine
import ( import (
"github.com/nspcc-dev/neofs-api-go/pkg/container"
"github.com/nspcc-dev/neofs-api-go/pkg/object" "github.com/nspcc-dev/neofs-api-go/pkg/object"
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard"
"go.uber.org/zap" "go.uber.org/zap"
@ -8,6 +9,7 @@ import (
// SelectPrm groups the parameters of Select operation. // SelectPrm groups the parameters of Select operation.
type SelectPrm struct { type SelectPrm struct {
cid *container.ID
filters object.SearchFilters filters object.SearchFilters
} }
@ -16,6 +18,15 @@ type SelectRes struct {
addrList []*object.Address addrList []*object.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. // WithFilters is a Select option to set the object filters.
func (p *SelectPrm) WithFilters(fs object.SearchFilters) *SelectPrm { func (p *SelectPrm) WithFilters(fs object.SearchFilters) *SelectPrm {
if p != nil { if p != nil {
@ -38,6 +49,7 @@ func (e *StorageEngine) Select(prm *SelectPrm) (*SelectRes, error) {
uniqueMap := make(map[string]struct{}) uniqueMap := make(map[string]struct{})
shPrm := new(shard.SelectPrm). shPrm := new(shard.SelectPrm).
WithContainerID(prm.cid).
WithFilters(prm.filters) WithFilters(prm.filters)
e.iterateOverUnsortedShards(func(sh *shard.Shard) (stop bool) { e.iterateOverUnsortedShards(func(sh *shard.Shard) (stop bool) {
@ -104,8 +116,9 @@ func (e *StorageEngine) List(limit uint64) (*SelectRes, error) {
} }
// Select selects objects from local storage using provided filters. // Select selects objects from local storage using provided filters.
func Select(storage *StorageEngine, fs object.SearchFilters) ([]*object.Address, error) { func Select(storage *StorageEngine, cid *container.ID, fs object.SearchFilters) ([]*object.Address, error) {
res, err := storage.Select(new(SelectPrm). res, err := storage.Select(new(SelectPrm).
WithContainerID(cid).
WithFilters(fs), WithFilters(fs),
) )
if err != nil { if err != nil {