2022-07-05 13:47:39 +00:00
|
|
|
package blobovniczatree
|
|
|
|
|
|
|
|
import (
|
2023-03-13 11:37:35 +00:00
|
|
|
"context"
|
|
|
|
"encoding/hex"
|
2022-07-05 13:47:39 +00:00
|
|
|
"path/filepath"
|
|
|
|
|
2023-03-13 11:37:35 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/pkg/tracing"
|
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-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) {
|
|
|
|
ctx, span := tracing.StartSpanFromContext(ctx, "Blobovniczas.Exists",
|
|
|
|
trace.WithAttributes(
|
|
|
|
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 {
|
|
|
|
id := blobovnicza.NewIDFromBytes(prm.StorageID)
|
|
|
|
blz, err := b.openBlobovnicza(id.String())
|
|
|
|
if err != nil {
|
|
|
|
return common.ExistsRes{}, err
|
|
|
|
}
|
|
|
|
|
|
|
|
exists, err := blz.Exists(prm.Address)
|
|
|
|
return common.ExistsRes{Exists: exists}, err
|
|
|
|
}
|
|
|
|
|
2022-07-05 13:47:39 +00:00
|
|
|
activeCache := make(map[string]struct{})
|
|
|
|
|
2022-07-06 12:10:21 +00:00
|
|
|
var gPrm blobovnicza.GetPrm
|
|
|
|
gPrm.SetAddress(prm.Address)
|
2022-07-05 13:47:39 +00:00
|
|
|
|
|
|
|
var found bool
|
2022-07-06 12:10:21 +00:00
|
|
|
err := b.iterateSortedLeaves(&prm.Address, func(p string) (bool, error) {
|
2022-07-05 13:47:39 +00:00
|
|
|
dirPath := filepath.Dir(p)
|
|
|
|
|
|
|
|
_, ok := activeCache[dirPath]
|
|
|
|
|
2023-03-13 11:37:35 +00:00
|
|
|
_, err := b.getObjectFromLevel(ctx, gPrm, p, !ok)
|
2022-07-05 13:47:39 +00:00
|
|
|
if err != nil {
|
|
|
|
if !blobovnicza.IsErrNotFound(err) {
|
2023-04-12 14:35:10 +00:00
|
|
|
b.log.Debug(logs.BlobovniczatreeCouldNotGetObjectFromLevel,
|
2022-07-05 13:47:39 +00:00
|
|
|
zap.String("level", p),
|
|
|
|
zap.String("error", err.Error()))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
activeCache[dirPath] = struct{}{}
|
|
|
|
found = err == nil
|
|
|
|
return found, nil
|
|
|
|
})
|
|
|
|
|
2022-07-06 12:10:21 +00:00
|
|
|
return common.ExistsRes{Exists: found}, err
|
2022-07-05 13:47:39 +00:00
|
|
|
}
|