2020-11-25 09:40:41 +00:00
|
|
|
package blobstor
|
|
|
|
|
2020-11-25 11:18:54 +00:00
|
|
|
import (
|
2023-03-13 11:37:35 +00:00
|
|
|
"context"
|
|
|
|
"encoding/hex"
|
2023-06-06 06:05:52 +00:00
|
|
|
"time"
|
2023-03-13 11:37:35 +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/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-03-13 11:37:35 +00:00
|
|
|
"go.opentelemetry.io/otel/attribute"
|
|
|
|
"go.opentelemetry.io/otel/trace"
|
2022-03-03 14:16:49 +00:00
|
|
|
"go.uber.org/zap"
|
2020-11-25 11:18:54 +00:00
|
|
|
)
|
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// Exists checks if the object is presented in BLOB storage.
|
2020-11-25 09:40:41 +00:00
|
|
|
//
|
|
|
|
// Returns any error encountered that did not allow
|
|
|
|
// to completely check object existence.
|
2023-03-13 11:37:35 +00:00
|
|
|
func (b *BlobStor) Exists(ctx context.Context, prm common.ExistsPrm) (common.ExistsRes, error) {
|
2023-06-06 06:05:52 +00:00
|
|
|
var (
|
|
|
|
exists = false
|
|
|
|
startedAt = time.Now()
|
|
|
|
)
|
|
|
|
defer func() {
|
|
|
|
b.metrics.Exists(time.Since(startedAt), exists, prm.StorageID != nil)
|
|
|
|
}()
|
|
|
|
|
2023-03-13 11:37:35 +00:00
|
|
|
ctx, span := tracing.StartSpanFromContext(ctx, "BlobStor.Exists",
|
|
|
|
trace.WithAttributes(
|
|
|
|
attribute.String("address", prm.Address.EncodeToString()),
|
|
|
|
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-11-17 06:29:35 +00:00
|
|
|
if prm.StorageID != nil {
|
|
|
|
if len(prm.StorageID) == 0 {
|
2023-06-06 06:05:52 +00:00
|
|
|
res, err := b.storage[len(b.storage)-1].Storage.Exists(ctx, prm)
|
|
|
|
exists = err == nil && res.Exists
|
|
|
|
return res, err
|
2022-11-17 06:29:35 +00:00
|
|
|
}
|
2023-06-06 06:05:52 +00:00
|
|
|
res, err := b.storage[0].Storage.Exists(ctx, prm)
|
|
|
|
exists = err == nil && res.Exists
|
|
|
|
return res, err
|
2022-11-17 06:29:35 +00:00
|
|
|
}
|
|
|
|
|
2022-03-03 14:16:49 +00:00
|
|
|
// If there was an error during existence check below,
|
|
|
|
// it will be returned unless object was found in blobovnicza.
|
|
|
|
// Otherwise, it is logged and the latest error is returned.
|
|
|
|
// FSTree | Blobovnicza | Behaviour
|
|
|
|
// found | (not tried) | return true, nil
|
|
|
|
// not found | any result | return the result
|
|
|
|
// error | found | log the error, return true, nil
|
|
|
|
// error | not found | return the error
|
|
|
|
// error | error | log the first error, return the second
|
2024-04-01 06:54:42 +00:00
|
|
|
var errors []error
|
2022-07-08 11:33:49 +00:00
|
|
|
for i := range b.storage {
|
2023-03-13 11:37:35 +00:00
|
|
|
res, err := b.storage[i].Storage.Exists(ctx, prm)
|
2022-07-08 11:33:49 +00:00
|
|
|
if err == nil && res.Exists {
|
2023-06-06 06:05:52 +00:00
|
|
|
exists = true
|
2022-07-08 11:33:49 +00:00
|
|
|
return res, nil
|
|
|
|
} else if err != nil {
|
2024-04-01 06:54:42 +00:00
|
|
|
errors = append(errors, err)
|
2022-03-03 14:16:49 +00:00
|
|
|
}
|
2020-11-25 11:18:54 +00:00
|
|
|
}
|
|
|
|
|
2024-04-01 06:54:42 +00:00
|
|
|
if len(errors) == 0 {
|
2022-07-08 11:33:49 +00:00
|
|
|
return common.ExistsRes{}, nil
|
|
|
|
}
|
2020-11-25 11:18:54 +00:00
|
|
|
|
2024-04-01 06:54:42 +00:00
|
|
|
for _, err := range errors[:len(errors)-1] {
|
2024-10-21 07:22:54 +00:00
|
|
|
b.log.Warn(ctx, logs.BlobstorErrorOccurredDuringObjectExistenceChecking,
|
2022-07-08 11:33:49 +00:00
|
|
|
zap.Stringer("address", prm.Address),
|
2023-09-27 08:02:06 +00:00
|
|
|
zap.String("error", err.Error()),
|
|
|
|
zap.String("trace_id", tracingPkg.GetTraceID(ctx)))
|
2022-07-08 11:33:49 +00:00
|
|
|
}
|
2020-11-25 11:18:54 +00:00
|
|
|
|
2024-04-01 06:54:42 +00:00
|
|
|
return common.ExistsRes{}, errors[len(errors)-1]
|
2020-11-25 11:18:54 +00:00
|
|
|
}
|