frostfs-node/pkg/local_object_storage/blobstor/get.go
Dmitrii Stepanov 98ca6a7e53
All checks were successful
DCO action / DCO (pull_request) Successful in 2m27s
Vulncheck / Vulncheck (pull_request) Successful in 2m7s
Build / Build Components (1.20) (pull_request) Successful in 2m44s
Tests and linters / Staticcheck (pull_request) Successful in 3m18s
Tests and linters / Tests (1.21) (pull_request) Successful in 5m0s
Tests and linters / Tests with -race (pull_request) Successful in 5m40s
Build / Build Components (1.21) (pull_request) Successful in 12m49s
Tests and linters / Lint (pull_request) Successful in 12m57s
Tests and linters / Tests (1.20) (pull_request) Successful in 2m8s
[#661] blobstor: Refactor storage selection
Use special flag to select storages by storage ID.

Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
2023-09-18 15:46:38 +03:00

47 lines
1.4 KiB
Go

package blobstor
import (
"context"
"encoding/hex"
"time"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/common"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/util/logicerr"
"git.frostfs.info/TrueCloudLab/frostfs-observability/tracing"
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client"
apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/trace"
)
// Get reads the object from b.
// If the descriptor is present, only one sub-storage is tried,
// Otherwise, each sub-storage is tried in order.
func (b *BlobStor) Get(ctx context.Context, prm common.GetPrm) (res common.GetRes, err error) {
var (
startedAt = time.Now()
)
defer func() {
b.metrics.Get(time.Since(startedAt), len(res.RawData), err == nil, prm.StorageID != nil)
}()
ctx, span := tracing.StartSpanFromContext(ctx, "BlobStor.Get",
trace.WithAttributes(
attribute.String("address", prm.Address.EncodeToString()),
attribute.Bool("raw", prm.Raw),
attribute.String("storage_id", hex.EncodeToString(prm.StorageID)),
))
defer span.End()
b.modeMtx.RLock()
defer b.modeMtx.RUnlock()
for _, storage := range b.selectStorages(prm.StorageID) {
res, err = storage.Get(ctx, prm)
if err == nil || !client.IsErrObjectNotFound(err) {
return res, err
}
}
return common.GetRes{}, logicerr.Wrap(new(apistatus.ObjectNotFound))
}