Dmitrii Stepanov
d62c6e4ce6
Add tracing spans for PUT requests. Add tracing spans for DELETE requests. Add tracing spans for SELECT requests. Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
86 lines
2.1 KiB
Go
86 lines
2.1 KiB
Go
package blobovnicza
|
|
|
|
import (
|
|
"context"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/pkg/tracing"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/internal/logs"
|
|
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("address", prm.addr.EncodeToString()),
|
|
))
|
|
defer span.End()
|
|
|
|
addrKey := addressKey(prm.addr)
|
|
|
|
removed := false
|
|
|
|
err := b.boltDB.Update(func(tx *bbolt.Tx) error {
|
|
return b.iterateBuckets(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
|
|
}
|
|
|
|
sz := uint64(len(objData))
|
|
|
|
// decrease fullness counter
|
|
b.decSize(sz)
|
|
|
|
// remove object from the bucket
|
|
err := buck.Delete(addrKey)
|
|
|
|
if err == nil {
|
|
b.log.Debug(logs.BlobovniczaObjectWasRemovedFromBucket,
|
|
zap.String("binary size", stringifyByteSize(sz)),
|
|
zap.String("range", stringifyBounds(lower, upper)),
|
|
)
|
|
}
|
|
|
|
removed = true
|
|
|
|
// stop iteration
|
|
return true, err
|
|
})
|
|
})
|
|
|
|
if err == nil && !removed {
|
|
var errNotFound apistatus.ObjectNotFound
|
|
|
|
return DeleteRes{}, errNotFound
|
|
}
|
|
|
|
return DeleteRes{}, err
|
|
}
|