Evgenii Stratonikov
4c520be9f1
All checks were successful
Vulncheck / Vulncheck (pull_request) Successful in 1m59s
DCO action / DCO (pull_request) Successful in 1m53s
Build / Build Components (1.21) (pull_request) Successful in 2m20s
Build / Build Components (1.22) (pull_request) Successful in 2m26s
Pre-commit hooks / Pre-commit (pull_request) Successful in 2m56s
Tests and linters / Staticcheck (pull_request) Successful in 2m47s
Tests and linters / Tests (1.21) (pull_request) Successful in 2m56s
Tests and linters / Tests (1.22) (pull_request) Successful in 2m57s
Tests and linters / Lint (pull_request) Successful in 3m7s
Tests and linters / Tests with -race (pull_request) Successful in 3m7s
Tests and linters / gopls check (pull_request) Successful in 3m46s
Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
110 lines
2.8 KiB
Go
110 lines
2.8 KiB
Go
package blobovnicza
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"syscall"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/internal/logs"
|
|
tracingPkg "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/tracing"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-observability/tracing"
|
|
apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status"
|
|
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
|
|
"go.etcd.io/bbolt"
|
|
"go.opentelemetry.io/otel/attribute"
|
|
"go.opentelemetry.io/otel/trace"
|
|
"go.uber.org/zap"
|
|
)
|
|
|
|
// DeletePrm groups the parameters of Delete operation.
|
|
type DeletePrm struct {
|
|
addr oid.Address
|
|
}
|
|
|
|
// DeleteRes groups the resulting values of Delete operation.
|
|
type DeleteRes struct{}
|
|
|
|
// SetAddress sets the address of the requested object.
|
|
func (p *DeletePrm) SetAddress(addr oid.Address) {
|
|
p.addr = addr
|
|
}
|
|
|
|
// Delete removes an object from Blobovnicza by address.
|
|
//
|
|
// Returns any error encountered that
|
|
// did not allow to completely delete the object.
|
|
//
|
|
// Returns an error of type apistatus.ObjectNotFound if the object to be deleted is not in blobovnicza.
|
|
//
|
|
// Should not be called in read-only configuration.
|
|
func (b *Blobovnicza) Delete(ctx context.Context, prm DeletePrm) (DeleteRes, error) {
|
|
_, span := tracing.StartSpanFromContext(ctx, "Blobovnicza.Delete",
|
|
trace.WithAttributes(
|
|
attribute.String("path", b.path),
|
|
attribute.String("address", prm.addr.EncodeToString()),
|
|
))
|
|
defer span.End()
|
|
|
|
b.controlMtx.RLock()
|
|
defer b.controlMtx.RUnlock()
|
|
|
|
addrKey := addressKey(prm.addr)
|
|
|
|
found := false
|
|
var sizeUpperBound uint64
|
|
var sizeLowerBound uint64
|
|
var dataSize uint64
|
|
var recordSize uint64
|
|
|
|
err := b.boltDB.Update(func(tx *bbolt.Tx) error {
|
|
err := b.iterateAllDataBuckets(tx, func(lower, upper uint64, buck *bbolt.Bucket) (bool, error) {
|
|
objData := buck.Get(addrKey)
|
|
if objData == nil {
|
|
// object is not in bucket => continue iterating
|
|
return false, nil
|
|
}
|
|
dataSize = uint64(len(objData))
|
|
sizeLowerBound = lower
|
|
sizeUpperBound = upper
|
|
recordSize = dataSize + uint64(len(addrKey))
|
|
found = true
|
|
return true, buck.Delete(addrKey)
|
|
})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if found {
|
|
return updateMeta(tx, func(count, size uint64) (uint64, uint64) {
|
|
if count > 0 {
|
|
count--
|
|
}
|
|
if size >= recordSize {
|
|
size -= recordSize
|
|
} else {
|
|
size = 0
|
|
}
|
|
return count, size
|
|
})
|
|
}
|
|
return nil
|
|
})
|
|
|
|
if err == nil && !found {
|
|
return DeleteRes{}, new(apistatus.ObjectNotFound)
|
|
}
|
|
|
|
if err == nil && found {
|
|
b.log.Debug(logs.BlobovniczaObjectWasRemovedFromBucket,
|
|
zap.String("binary size", stringifyByteSize(dataSize)),
|
|
zap.String("range", stringifyBounds(sizeLowerBound, sizeUpperBound)),
|
|
zap.String("trace_id", tracingPkg.GetTraceID(ctx)),
|
|
)
|
|
b.itemDeleted(recordSize)
|
|
}
|
|
|
|
if errors.Is(err, syscall.ENOSPC) {
|
|
err = ErrNoSpace
|
|
}
|
|
|
|
return DeleteRes{}, err
|
|
}
|