2022-07-05 13:47:39 +00:00
|
|
|
package blobovniczatree
|
|
|
|
|
|
|
|
import (
|
2023-03-13 11:37:35 +00:00
|
|
|
"context"
|
|
|
|
"encoding/hex"
|
2023-06-05 07:25:25 +00:00
|
|
|
"time"
|
2022-07-05 13:47:39 +00:00
|
|
|
|
2023-04-12 14:35:10 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/internal/logs"
|
2023-03-07 13:38:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobovnicza"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/common"
|
2023-09-27 08:02:06 +00:00
|
|
|
tracingPkg "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/tracing"
|
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-13 11:37:35 +00:00
|
|
|
"go.opentelemetry.io/otel/attribute"
|
|
|
|
"go.opentelemetry.io/otel/trace"
|
2022-07-05 13:47:39 +00:00
|
|
|
"go.uber.org/zap"
|
|
|
|
)
|
|
|
|
|
2022-07-08 07:09:48 +00:00
|
|
|
// Exists implements common.Storage.
|
2023-03-13 11:37:35 +00:00
|
|
|
func (b *Blobovniczas) Exists(ctx context.Context, prm common.ExistsPrm) (common.ExistsRes, error) {
|
2023-06-05 07:25:25 +00:00
|
|
|
var (
|
|
|
|
startedAt = time.Now()
|
|
|
|
success = false
|
|
|
|
found = false
|
|
|
|
)
|
|
|
|
defer func() {
|
|
|
|
b.metrics.Exists(time.Since(startedAt), success, prm.StorageID != nil)
|
|
|
|
}()
|
|
|
|
|
2023-03-13 11:37:35 +00:00
|
|
|
ctx, span := tracing.StartSpanFromContext(ctx, "Blobovniczas.Exists",
|
|
|
|
trace.WithAttributes(
|
2023-06-05 07:25:25 +00:00
|
|
|
attribute.String("path", b.rootPath),
|
2023-03-13 11:37:35 +00:00
|
|
|
attribute.String("address", prm.Address.EncodeToString()),
|
|
|
|
attribute.String("storage_id", hex.EncodeToString(prm.StorageID)),
|
|
|
|
))
|
|
|
|
defer span.End()
|
|
|
|
|
2022-11-17 06:29:35 +00:00
|
|
|
if prm.StorageID != nil {
|
2023-09-19 15:08:38 +00:00
|
|
|
id := NewIDFromBytes(prm.StorageID)
|
2024-10-21 08:20:17 +00:00
|
|
|
shBlz := b.getBlobovnicza(ctx, id.Path())
|
|
|
|
blz, err := shBlz.Open(ctx)
|
2022-11-17 06:29:35 +00:00
|
|
|
if err != nil {
|
|
|
|
return common.ExistsRes{}, err
|
|
|
|
}
|
2024-10-21 13:27:28 +00:00
|
|
|
defer shBlz.Close(ctx)
|
2022-11-17 06:29:35 +00:00
|
|
|
|
2023-06-20 08:24:14 +00:00
|
|
|
exists, err := blz.Exists(ctx, prm.Address)
|
2022-11-17 06:29:35 +00:00
|
|
|
return common.ExistsRes{Exists: exists}, err
|
|
|
|
}
|
|
|
|
|
2022-07-06 12:10:21 +00:00
|
|
|
var gPrm blobovnicza.GetPrm
|
|
|
|
gPrm.SetAddress(prm.Address)
|
2022-07-05 13:47:39 +00:00
|
|
|
|
2023-09-20 14:46:10 +00:00
|
|
|
err := b.iterateSortedDBPaths(ctx, prm.Address, func(p string) (bool, error) {
|
2023-08-30 20:36:48 +00:00
|
|
|
_, err := b.getObjectFromLevel(ctx, gPrm, p)
|
2022-07-05 13:47:39 +00:00
|
|
|
if err != nil {
|
2023-08-04 11:14:07 +00:00
|
|
|
if !client.IsErrObjectNotFound(err) {
|
2024-10-21 07:22:54 +00:00
|
|
|
b.log.Debug(ctx, logs.BlobovniczatreeCouldNotGetObjectFromLevel,
|
2022-07-05 13:47:39 +00:00
|
|
|
zap.String("level", p),
|
2024-12-13 08:44:56 +00:00
|
|
|
zap.Error(err),
|
2023-09-27 08:02:06 +00:00
|
|
|
zap.String("trace_id", tracingPkg.GetTraceID(ctx)))
|
2022-07-05 13:47:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
found = err == nil
|
|
|
|
return found, nil
|
|
|
|
})
|
|
|
|
|
2023-06-05 07:25:25 +00:00
|
|
|
success = err == nil
|
2022-07-06 12:10:21 +00:00
|
|
|
return common.ExistsRes{Exists: found}, err
|
2022-07-05 13:47:39 +00:00
|
|
|
}
|