forked from TrueCloudLab/frostfs-node
45 lines
1.4 KiB
Go
45 lines
1.4 KiB
Go
package blobstor
|
|
|
|
import (
|
|
"context"
|
|
"encoding/hex"
|
|
"errors"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/pkg/tracing"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/common"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/util/logicerr"
|
|
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) (common.GetRes, error) {
|
|
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()
|
|
|
|
if prm.StorageID == nil {
|
|
for i := range b.storage {
|
|
res, err := b.storage[i].Storage.Get(ctx, prm)
|
|
if err == nil || !errors.As(err, new(apistatus.ObjectNotFound)) {
|
|
return res, err
|
|
}
|
|
}
|
|
|
|
return common.GetRes{}, logicerr.Wrap(apistatus.ObjectNotFound{})
|
|
}
|
|
if len(prm.StorageID) == 0 {
|
|
return b.storage[len(b.storage)-1].Storage.Get(ctx, prm)
|
|
}
|
|
return b.storage[0].Storage.Get(ctx, prm)
|
|
}
|