2020-11-17 12:23:15 +00:00
|
|
|
package shard
|
|
|
|
|
|
|
|
import (
|
2021-05-18 08:12:51 +00:00
|
|
|
"fmt"
|
|
|
|
|
2020-12-08 09:56:14 +00:00
|
|
|
meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase"
|
2021-11-10 07:08:33 +00:00
|
|
|
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
|
2022-03-03 14:19:05 +00:00
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/object"
|
2022-01-26 12:11:13 +00:00
|
|
|
addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address"
|
2020-11-17 12:23:15 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// SelectPrm groups the parameters of Select operation.
|
|
|
|
type SelectPrm struct {
|
2021-05-31 11:03:17 +00:00
|
|
|
cid *cid.ID
|
2022-03-03 14:19:05 +00:00
|
|
|
filters object.SearchFilters
|
2020-11-17 12:23:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// SelectRes groups resulting values of Select operation.
|
|
|
|
type SelectRes struct {
|
2022-01-26 12:11:13 +00:00
|
|
|
addrList []*addressSDK.Address
|
2020-11-17 12:23:15 +00:00
|
|
|
}
|
|
|
|
|
2020-12-10 13:20:38 +00:00
|
|
|
// WithContainerID is a Select option to set the container id to search in.
|
2021-05-31 11:03:17 +00:00
|
|
|
func (p *SelectPrm) WithContainerID(cid *cid.ID) *SelectPrm {
|
2020-12-10 13:20:38 +00:00
|
|
|
if p != nil {
|
|
|
|
p.cid = cid
|
|
|
|
}
|
|
|
|
|
|
|
|
return p
|
|
|
|
}
|
|
|
|
|
2020-11-17 12:23:15 +00:00
|
|
|
// WithFilters is a Select option to set the object filters.
|
2022-03-03 14:19:05 +00:00
|
|
|
func (p *SelectPrm) WithFilters(fs object.SearchFilters) *SelectPrm {
|
2020-11-17 12:23:15 +00:00
|
|
|
if p != nil {
|
|
|
|
p.filters = fs
|
|
|
|
}
|
|
|
|
|
|
|
|
return p
|
|
|
|
}
|
|
|
|
|
|
|
|
// AddressList returns list of addresses of the selected objects.
|
2022-01-26 12:11:13 +00:00
|
|
|
func (r *SelectRes) AddressList() []*addressSDK.Address {
|
2020-11-17 12:23:15 +00:00
|
|
|
return r.addrList
|
|
|
|
}
|
|
|
|
|
|
|
|
// Select selects the objects from shard that match select parameters.
|
|
|
|
//
|
|
|
|
// Returns any error encountered that
|
|
|
|
// did not allow to completely select the objects.
|
|
|
|
func (s *Shard) Select(prm *SelectPrm) (*SelectRes, error) {
|
2020-12-10 13:20:38 +00:00
|
|
|
addrList, err := meta.Select(s.metaBase, prm.cid, prm.filters)
|
2020-11-17 17:39:43 +00:00
|
|
|
if err != nil {
|
2021-05-18 08:12:51 +00:00
|
|
|
return nil, fmt.Errorf("could not select objects from metabase: %w", err)
|
2020-11-17 17:39:43 +00:00
|
|
|
}
|
2020-11-17 12:23:15 +00:00
|
|
|
|
2020-11-17 17:39:43 +00:00
|
|
|
return &SelectRes{
|
|
|
|
addrList: addrList,
|
|
|
|
}, nil
|
2020-11-17 12:23:15 +00:00
|
|
|
}
|