2020-11-26 14:26:53 +00:00
|
|
|
package blobovnicza
|
|
|
|
|
|
|
|
import (
|
2023-04-12 14:01:29 +00:00
|
|
|
"context"
|
2024-06-06 16:00:07 +00:00
|
|
|
"errors"
|
|
|
|
"syscall"
|
2023-04-12 14:01:29 +00:00
|
|
|
|
2023-04-12 14:35:10 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/internal/logs"
|
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-07 13:38:26 +00:00
|
|
|
apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status"
|
|
|
|
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
|
2020-11-26 14:26:53 +00:00
|
|
|
"go.etcd.io/bbolt"
|
2023-04-12 14:01:29 +00:00
|
|
|
"go.opentelemetry.io/otel/attribute"
|
|
|
|
"go.opentelemetry.io/otel/trace"
|
2020-11-26 14:26:53 +00:00
|
|
|
"go.uber.org/zap"
|
|
|
|
)
|
|
|
|
|
|
|
|
// DeletePrm groups the parameters of Delete operation.
|
|
|
|
type DeletePrm struct {
|
2022-05-31 17:00:41 +00:00
|
|
|
addr oid.Address
|
2020-11-26 14:26:53 +00:00
|
|
|
}
|
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// DeleteRes groups the resulting values of Delete operation.
|
2023-10-31 11:56:55 +00:00
|
|
|
type DeleteRes struct{}
|
2020-11-26 14:26:53 +00:00
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// SetAddress sets the address of the requested object.
|
2022-05-31 17:00:41 +00:00
|
|
|
func (p *DeletePrm) SetAddress(addr oid.Address) {
|
2020-11-26 14:26:53 +00:00
|
|
|
p.addr = addr
|
|
|
|
}
|
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// Delete removes an object from Blobovnicza by address.
|
2020-11-26 14:26:53 +00:00
|
|
|
//
|
|
|
|
// Returns any error encountered that
|
|
|
|
// did not allow to completely delete the object.
|
|
|
|
//
|
2022-03-17 13:26:17 +00:00
|
|
|
// Returns an error of type apistatus.ObjectNotFound if the object to be deleted is not in blobovnicza.
|
2021-09-14 14:44:07 +00:00
|
|
|
//
|
|
|
|
// Should not be called in read-only configuration.
|
2023-04-12 14:01:29 +00:00
|
|
|
func (b *Blobovnicza) Delete(ctx context.Context, prm DeletePrm) (DeleteRes, error) {
|
|
|
|
_, span := tracing.StartSpanFromContext(ctx, "Blobovnicza.Delete",
|
|
|
|
trace.WithAttributes(
|
2023-06-20 08:24:14 +00:00
|
|
|
attribute.String("path", b.path),
|
2023-04-12 14:01:29 +00:00
|
|
|
attribute.String("address", prm.addr.EncodeToString()),
|
|
|
|
))
|
|
|
|
defer span.End()
|
|
|
|
|
2020-11-26 14:26:53 +00:00
|
|
|
addrKey := addressKey(prm.addr)
|
|
|
|
|
2023-06-20 08:24:14 +00:00
|
|
|
found := false
|
2023-08-16 08:12:19 +00:00
|
|
|
var sizeUpperBound uint64
|
|
|
|
var sizeLowerBound uint64
|
|
|
|
var dataSize uint64
|
2023-10-12 18:35:08 +00:00
|
|
|
var recordSize uint64
|
2020-11-26 14:26:53 +00:00
|
|
|
|
|
|
|
err := b.boltDB.Update(func(tx *bbolt.Tx) error {
|
2023-10-12 12:25:16 +00:00
|
|
|
err := b.iterateAllDataBuckets(tx, func(lower, upper uint64, buck *bbolt.Bucket) (bool, error) {
|
2020-11-26 14:26:53 +00:00
|
|
|
objData := buck.Get(addrKey)
|
|
|
|
if objData == nil {
|
|
|
|
// object is not in bucket => continue iterating
|
|
|
|
return false, nil
|
|
|
|
}
|
2023-08-16 08:12:19 +00:00
|
|
|
dataSize = uint64(len(objData))
|
|
|
|
sizeLowerBound = lower
|
|
|
|
sizeUpperBound = upper
|
2023-10-12 18:35:08 +00:00
|
|
|
recordSize = dataSize + uint64(len(addrKey))
|
2023-06-20 08:24:14 +00:00
|
|
|
found = true
|
2023-08-16 08:12:19 +00:00
|
|
|
return true, buck.Delete(addrKey)
|
2020-11-26 14:26:53 +00:00
|
|
|
})
|
2023-10-12 12:25:16 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if found {
|
|
|
|
return updateMeta(tx, func(count, size uint64) (uint64, uint64) {
|
|
|
|
if count > 0 {
|
|
|
|
count--
|
|
|
|
}
|
2023-10-12 18:35:08 +00:00
|
|
|
if size >= recordSize {
|
|
|
|
size -= recordSize
|
|
|
|
} else {
|
|
|
|
size = 0
|
2023-10-12 12:25:16 +00:00
|
|
|
}
|
|
|
|
return count, size
|
|
|
|
})
|
|
|
|
}
|
|
|
|
return nil
|
2020-11-26 14:26:53 +00:00
|
|
|
})
|
|
|
|
|
2023-06-20 08:24:14 +00:00
|
|
|
if err == nil && !found {
|
2023-08-04 11:14:07 +00:00
|
|
|
return DeleteRes{}, new(apistatus.ObjectNotFound)
|
2020-11-26 14:26:53 +00:00
|
|
|
}
|
|
|
|
|
2023-08-16 08:12:19 +00:00
|
|
|
if err == nil && found {
|
2024-10-21 07:22:54 +00:00
|
|
|
b.log.Debug(ctx, logs.BlobovniczaObjectWasRemovedFromBucket,
|
2023-08-16 08:12:19 +00:00
|
|
|
zap.String("binary size", stringifyByteSize(dataSize)),
|
|
|
|
zap.String("range", stringifyBounds(sizeLowerBound, sizeUpperBound)),
|
2023-09-27 08:02:06 +00:00
|
|
|
zap.String("trace_id", tracingPkg.GetTraceID(ctx)),
|
2023-08-16 08:12:19 +00:00
|
|
|
)
|
2023-10-12 18:35:08 +00:00
|
|
|
b.itemDeleted(recordSize)
|
2023-08-16 08:12:19 +00:00
|
|
|
}
|
|
|
|
|
2024-06-06 16:00:07 +00:00
|
|
|
if errors.Is(err, syscall.ENOSPC) {
|
|
|
|
err = ErrNoSpace
|
|
|
|
}
|
|
|
|
|
2022-05-31 12:22:32 +00:00
|
|
|
return DeleteRes{}, err
|
2020-11-26 14:26:53 +00:00
|
|
|
}
|