65 lines
1.7 KiB
Go
65 lines
1.7 KiB
Go
package blobstor
|
|
|
|
import (
|
|
"context"
|
|
"encoding/hex"
|
|
"time"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/common"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/util/logicerr"
|
|
"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"
|
|
"go.opentelemetry.io/otel/attribute"
|
|
"go.opentelemetry.io/otel/trace"
|
|
)
|
|
|
|
func (b *BlobStor) Delete(ctx context.Context, prm common.DeletePrm) (common.DeleteRes, error) {
|
|
var (
|
|
startedAt = time.Now()
|
|
success = false
|
|
)
|
|
defer func() {
|
|
b.metrics.Delete(time.Since(startedAt), success, prm.StorageID != nil)
|
|
}()
|
|
|
|
ctx, span := tracing.StartSpanFromContext(ctx, "BlobStor.Delete",
|
|
trace.WithAttributes(
|
|
attribute.String("address", prm.Address.EncodeToString()),
|
|
attribute.String("storage_id", hex.EncodeToString(prm.StorageID)),
|
|
))
|
|
defer span.End()
|
|
|
|
b.modeMtx.RLock()
|
|
defer b.modeMtx.RUnlock()
|
|
|
|
if prm.StorageID == nil {
|
|
for i := range b.storage {
|
|
res, err := b.storage[i].Storage.Delete(ctx, prm)
|
|
if err == nil || !client.IsErrObjectNotFound(err) {
|
|
if err == nil {
|
|
success = true
|
|
logOp(ctx, b.log, deleteOp, prm.Address, b.storage[i].Storage.Type(), prm.StorageID)
|
|
}
|
|
return res, err
|
|
}
|
|
}
|
|
return common.DeleteRes{}, logicerr.Wrap(new(apistatus.ObjectNotFound))
|
|
}
|
|
|
|
var st common.Storage
|
|
|
|
if len(prm.StorageID) == 0 {
|
|
st = b.storage[len(b.storage)-1].Storage
|
|
} else {
|
|
st = b.storage[0].Storage
|
|
}
|
|
|
|
res, err := st.Delete(ctx, prm)
|
|
if err == nil {
|
|
success = true
|
|
logOp(ctx, b.log, deleteOp, prm.Address, st.Type(), prm.StorageID)
|
|
}
|
|
|
|
return res, err
|
|
}
|