2020-11-17 16:29:00 +00:00
|
|
|
package blobstor
|
|
|
|
|
|
|
|
import (
|
2023-03-13 11:37:35 +00:00
|
|
|
"context"
|
|
|
|
"encoding/hex"
|
2023-06-06 06:05:52 +00:00
|
|
|
"time"
|
2021-05-18 08:12:51 +00:00
|
|
|
|
2023-03-07 13:38:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/common"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/util/logicerr"
|
2023-05-31 09:24:04 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-observability/tracing"
|
2023-08-04 11:14:07 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client"
|
2023-03-07 13:38:26 +00:00
|
|
|
apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status"
|
2023-03-13 11:37:35 +00:00
|
|
|
"go.opentelemetry.io/otel/attribute"
|
|
|
|
"go.opentelemetry.io/otel/trace"
|
2020-11-17 16:29:00 +00:00
|
|
|
)
|
|
|
|
|
2022-07-06 12:39:35 +00:00
|
|
|
// 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.
|
2023-06-06 06:05:52 +00:00
|
|
|
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)
|
|
|
|
}()
|
|
|
|
|
2023-03-13 11:37:35 +00:00
|
|
|
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()
|
|
|
|
|
2022-11-15 12:33:48 +00:00
|
|
|
b.modeMtx.RLock()
|
|
|
|
defer b.modeMtx.RUnlock()
|
|
|
|
|
2022-07-06 14:09:50 +00:00
|
|
|
if prm.StorageID == nil {
|
2022-07-08 11:33:49 +00:00
|
|
|
for i := range b.storage {
|
2023-06-06 06:05:52 +00:00
|
|
|
res, err = b.storage[i].Storage.Get(ctx, prm)
|
2023-08-04 11:14:07 +00:00
|
|
|
if err == nil || !client.IsErrObjectNotFound(err) {
|
2022-07-08 11:33:49 +00:00
|
|
|
return res, err
|
|
|
|
}
|
2022-07-06 12:39:35 +00:00
|
|
|
}
|
2022-07-08 11:33:49 +00:00
|
|
|
|
2023-08-04 11:14:07 +00:00
|
|
|
return common.GetRes{}, logicerr.Wrap(new(apistatus.ObjectNotFound))
|
2022-07-06 12:39:35 +00:00
|
|
|
}
|
2022-07-06 14:09:50 +00:00
|
|
|
if len(prm.StorageID) == 0 {
|
2023-06-06 06:05:52 +00:00
|
|
|
res, err = b.storage[len(b.storage)-1].Storage.Get(ctx, prm)
|
|
|
|
} else {
|
|
|
|
res, err = b.storage[0].Storage.Get(ctx, prm)
|
2022-07-06 12:39:35 +00:00
|
|
|
}
|
2023-06-06 06:05:52 +00:00
|
|
|
return res, err
|
2022-07-05 13:47:39 +00:00
|
|
|
}
|