2020-11-17 12:23:15 +00:00
|
|
|
package shard
|
|
|
|
|
|
|
|
import (
|
2021-05-18 08:12:51 +00:00
|
|
|
"fmt"
|
|
|
|
|
2023-03-07 13:38:26 +00:00
|
|
|
meta "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/metabase"
|
|
|
|
cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
|
|
|
|
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
|
2020-11-17 12:23:15 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// SelectPrm groups the parameters of Select operation.
|
|
|
|
type SelectPrm struct {
|
2022-05-31 17:00:41 +00:00
|
|
|
cnr cid.ID
|
2022-03-03 14:19:05 +00:00
|
|
|
filters object.SearchFilters
|
2020-11-17 12:23:15 +00:00
|
|
|
}
|
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// SelectRes groups the resulting values of Select operation.
|
2020-11-17 12:23:15 +00:00
|
|
|
type SelectRes struct {
|
2022-05-31 17:00:41 +00:00
|
|
|
addrList []oid.Address
|
2020-11-17 12:23:15 +00:00
|
|
|
}
|
|
|
|
|
2022-07-13 12:43:04 +00:00
|
|
|
// SetContainerID is a Select option to set the container id to search in.
|
|
|
|
func (p *SelectPrm) SetContainerID(cnr cid.ID) {
|
|
|
|
p.cnr = cnr
|
2020-12-10 13:20:38 +00:00
|
|
|
}
|
|
|
|
|
2022-07-13 12:43:04 +00:00
|
|
|
// SetFilters is a Select option to set the object filters.
|
|
|
|
func (p *SelectPrm) SetFilters(fs object.SearchFilters) {
|
|
|
|
p.filters = fs
|
2020-11-17 12:23:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// AddressList returns list of addresses of the selected objects.
|
2022-05-20 18:08:59 +00:00
|
|
|
func (r SelectRes) AddressList() []oid.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.
|
2022-05-31 11:50:39 +00:00
|
|
|
func (s *Shard) Select(prm SelectPrm) (SelectRes, error) {
|
2022-12-07 17:42:35 +00:00
|
|
|
s.m.RLock()
|
|
|
|
defer s.m.RUnlock()
|
|
|
|
|
|
|
|
if s.info.Mode.NoMetabase() {
|
2022-06-29 11:27:36 +00:00
|
|
|
return SelectRes{}, ErrDegradedMode
|
|
|
|
}
|
|
|
|
|
2022-07-12 14:42:55 +00:00
|
|
|
var selectPrm meta.SelectPrm
|
2022-07-12 14:59:37 +00:00
|
|
|
selectPrm.SetFilters(prm.filters)
|
|
|
|
selectPrm.SetContainerID(prm.cnr)
|
2022-07-12 14:42:55 +00:00
|
|
|
|
|
|
|
mRes, err := s.metaBase.Select(selectPrm)
|
2020-11-17 17:39:43 +00:00
|
|
|
if err != nil {
|
2022-05-31 11:50:39 +00:00
|
|
|
return SelectRes{}, 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
|
|
|
|
2022-05-31 11:50:39 +00:00
|
|
|
return SelectRes{
|
2022-07-12 14:42:55 +00:00
|
|
|
addrList: mRes.AddressList(),
|
2020-11-17 17:39:43 +00:00
|
|
|
}, nil
|
2020-11-17 12:23:15 +00:00
|
|
|
}
|