Alexander Chuprov
033eaf77e1
All checks were successful
Build / Build Components (1.20) (pull_request) Successful in 3m52s
Build / Build Components (1.19) (pull_request) Successful in 4m1s
ci/woodpecker/pr/pre-commit Pipeline was successful
Tests and linters / Tests with -race (pull_request) Successful in 5m36s
Tests and linters / Tests (1.20) (pull_request) Successful in 5m55s
Tests and linters / Lint (pull_request) Successful in 14m40s
Tests and linters / Tests (1.19) (pull_request) Successful in 15m29s
ci/woodpecker/push/pre-commit Pipeline was successful
Standardize the alias of the import frostfs-sdk-go/object as objectSDK. Signed-off-by: Alexander Chuprov <a.chuprov@yadro.com>
73 lines
2 KiB
Go
73 lines
2 KiB
Go
package shard
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
meta "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/metabase"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-observability/tracing"
|
|
cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id"
|
|
objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
|
|
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
|
|
"go.opentelemetry.io/otel/attribute"
|
|
"go.opentelemetry.io/otel/trace"
|
|
)
|
|
|
|
// SelectPrm groups the parameters of Select operation.
|
|
type SelectPrm struct {
|
|
cnr cid.ID
|
|
filters objectSDK.SearchFilters
|
|
}
|
|
|
|
// SelectRes groups the resulting values of Select operation.
|
|
type SelectRes struct {
|
|
addrList []oid.Address
|
|
}
|
|
|
|
// SetContainerID is a Select option to set the container id to search in.
|
|
func (p *SelectPrm) SetContainerID(cnr cid.ID) {
|
|
p.cnr = cnr
|
|
}
|
|
|
|
// SetFilters is a Select option to set the object filters.
|
|
func (p *SelectPrm) SetFilters(fs objectSDK.SearchFilters) {
|
|
p.filters = fs
|
|
}
|
|
|
|
// AddressList returns list of addresses of the selected objects.
|
|
func (r SelectRes) AddressList() []oid.Address {
|
|
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(ctx context.Context, prm SelectPrm) (SelectRes, error) {
|
|
ctx, span := tracing.StartSpanFromContext(ctx, "Shard.Select",
|
|
trace.WithAttributes(
|
|
attribute.String("shard_id", s.ID().String()),
|
|
attribute.String("container_id", prm.cnr.EncodeToString()),
|
|
))
|
|
defer span.End()
|
|
|
|
s.m.RLock()
|
|
defer s.m.RUnlock()
|
|
|
|
if s.info.Mode.NoMetabase() {
|
|
return SelectRes{}, ErrDegradedMode
|
|
}
|
|
|
|
var selectPrm meta.SelectPrm
|
|
selectPrm.SetFilters(prm.filters)
|
|
selectPrm.SetContainerID(prm.cnr)
|
|
|
|
mRes, err := s.metaBase.Select(ctx, selectPrm)
|
|
if err != nil {
|
|
return SelectRes{}, fmt.Errorf("could not select objects from metabase: %w", err)
|
|
}
|
|
|
|
return SelectRes{
|
|
addrList: mRes.AddressList(),
|
|
}, nil
|
|
}
|