Aleksey Savchuk
f0c43c8d80
All checks were successful
Vulncheck / Vulncheck (pull_request) Successful in 3m1s
Pre-commit hooks / Pre-commit (pull_request) Successful in 3m29s
Tests and linters / gopls check (pull_request) Successful in 3m50s
Tests and linters / Lint (pull_request) Successful in 4m35s
DCO action / DCO (pull_request) Successful in 5m12s
Tests and linters / Run gofumpt (pull_request) Successful in 5m33s
Build / Build Components (pull_request) Successful in 5m45s
Tests and linters / Tests with -race (pull_request) Successful in 6m37s
Tests and linters / Tests (pull_request) Successful in 7m17s
Tests and linters / Staticcheck (pull_request) Successful in 7m36s
Tests and linters / Run gofumpt (push) Successful in 1m22s
Tests and linters / Staticcheck (push) Successful in 3m19s
Tests and linters / Lint (push) Successful in 4m35s
Vulncheck / Vulncheck (push) Successful in 5m20s
Build / Build Components (push) Successful in 6m16s
Pre-commit hooks / Pre-commit (push) Successful in 6m37s
Tests and linters / Tests (push) Successful in 6m48s
Tests and linters / Tests with -race (push) Successful in 7m15s
Tests and linters / gopls check (push) Successful in 7m27s
Use `zap.Error` instead of `zap.String` for logging errors: change all expressions like `zap.String("error", err.Error())` or `zap.String("err", err.Error())` to `zap.Error(err)`. Leave similar expressions with other messages unchanged, for example, `zap.String("last_error", lastErr.Error())` or `zap.String("reason", ctx.Err().Error())`. This change was made by applying the following patch: ```diff @@ var err expression @@ -zap.String("error", err.Error()) +zap.Error(err) @@ var err expression @@ -zap.String("err", err.Error()) +zap.Error(err) ``` Signed-off-by: Aleksey Savchuk <a.savchuk@yadro.com>
128 lines
3.7 KiB
Go
128 lines
3.7 KiB
Go
package blobovniczatree
|
|
|
|
import (
|
|
"context"
|
|
"encoding/hex"
|
|
"fmt"
|
|
"time"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/internal/logs"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobovnicza"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/common"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/util/logicerr"
|
|
tracingPkg "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/tracing"
|
|
"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"
|
|
objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
|
|
"go.opentelemetry.io/otel/attribute"
|
|
"go.opentelemetry.io/otel/trace"
|
|
"go.uber.org/zap"
|
|
)
|
|
|
|
// Get reads object from blobovnicza tree.
|
|
//
|
|
// If blobocvnicza ID is specified, only this blobovnicza is processed.
|
|
// Otherwise, all Blobovniczas are processed descending weight.
|
|
func (b *Blobovniczas) Get(ctx context.Context, prm common.GetPrm) (res common.GetRes, err error) {
|
|
var (
|
|
startedAt = time.Now()
|
|
success = false
|
|
size = 0
|
|
)
|
|
defer func() {
|
|
b.metrics.Get(time.Since(startedAt), size, success, prm.StorageID != nil)
|
|
}()
|
|
|
|
ctx, span := tracing.StartSpanFromContext(ctx, "Blobovniczas.Get",
|
|
trace.WithAttributes(
|
|
attribute.String("path", b.rootPath),
|
|
attribute.String("address", prm.Address.EncodeToString()),
|
|
attribute.String("storage_id", hex.EncodeToString(prm.StorageID)),
|
|
attribute.Bool("raw", prm.Raw),
|
|
))
|
|
defer span.End()
|
|
|
|
var bPrm blobovnicza.GetPrm
|
|
bPrm.SetAddress(prm.Address)
|
|
|
|
if prm.StorageID != nil {
|
|
id := NewIDFromBytes(prm.StorageID)
|
|
shBlz := b.getBlobovnicza(ctx, id.Path())
|
|
blz, err := shBlz.Open(ctx)
|
|
if err != nil {
|
|
return res, err
|
|
}
|
|
defer shBlz.Close(ctx)
|
|
|
|
res, err = b.getObject(ctx, blz, bPrm)
|
|
if err == nil {
|
|
success = true
|
|
size = len(res.RawData)
|
|
}
|
|
return res, err
|
|
}
|
|
|
|
err = b.iterateSortedDBPaths(ctx, prm.Address, func(p string) (bool, error) {
|
|
res, err = b.getObjectFromLevel(ctx, bPrm, p)
|
|
if err != nil {
|
|
if !client.IsErrObjectNotFound(err) {
|
|
b.log.Debug(ctx, logs.BlobovniczatreeCouldNotGetObjectFromLevel,
|
|
zap.String("level", p),
|
|
zap.Error(err),
|
|
zap.String("trace_id", tracingPkg.GetTraceID(ctx)),
|
|
)
|
|
}
|
|
}
|
|
|
|
// abort iterator if found, otherwise process all Blobovniczas
|
|
return err == nil, nil
|
|
})
|
|
|
|
if err == nil && res.Object == nil {
|
|
// not found in any blobovnicza
|
|
return res, logicerr.Wrap(new(apistatus.ObjectNotFound))
|
|
}
|
|
|
|
success = true
|
|
size = len(res.RawData)
|
|
|
|
return
|
|
}
|
|
|
|
// tries to read object from particular blobovnicza.
|
|
//
|
|
// returns error if object could not be read from any blobovnicza of the same level.
|
|
func (b *Blobovniczas) getObjectFromLevel(ctx context.Context, prm blobovnicza.GetPrm, blzPath string) (common.GetRes, error) {
|
|
// open blobovnicza (cached inside)
|
|
shBlz := b.getBlobovnicza(ctx, blzPath)
|
|
blz, err := shBlz.Open(ctx)
|
|
if err != nil {
|
|
return common.GetRes{}, err
|
|
}
|
|
defer shBlz.Close(ctx)
|
|
|
|
return b.getObject(ctx, blz, prm)
|
|
}
|
|
|
|
// reads object from blobovnicza and returns GetSmallRes.
|
|
func (b *Blobovniczas) getObject(ctx context.Context, blz *blobovnicza.Blobovnicza, prm blobovnicza.GetPrm) (common.GetRes, error) {
|
|
res, err := blz.Get(ctx, prm)
|
|
if err != nil {
|
|
return common.GetRes{}, err
|
|
}
|
|
|
|
// decompress the data
|
|
data, err := b.compression.Decompress(res.Object())
|
|
if err != nil {
|
|
return common.GetRes{}, fmt.Errorf("could not decompress object data: %w", err)
|
|
}
|
|
|
|
// unmarshal the object
|
|
obj := objectSDK.New()
|
|
if err := obj.Unmarshal(data); err != nil {
|
|
return common.GetRes{}, fmt.Errorf("could not unmarshal the object: %w", err)
|
|
}
|
|
|
|
return common.GetRes{Object: obj, RawData: data}, nil
|
|
}
|