2020-11-17 12:26:03 +00:00
|
|
|
package engine
|
|
|
|
|
|
|
|
import (
|
2023-04-04 11:40:01 +00:00
|
|
|
"context"
|
2022-02-15 22:25:27 +00:00
|
|
|
"errors"
|
|
|
|
|
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/shard"
|
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-08-04 11:14:07 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client"
|
2023-03-07 13:38:26 +00:00
|
|
|
apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status"
|
|
|
|
objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
|
|
|
|
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
|
2023-04-12 14:01:29 +00:00
|
|
|
"go.opentelemetry.io/otel/attribute"
|
|
|
|
"go.opentelemetry.io/otel/trace"
|
2022-10-05 10:48:09 +00:00
|
|
|
"go.uber.org/zap"
|
2020-11-17 12:26:03 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// DeletePrm groups the parameters of Delete operation.
|
|
|
|
type DeletePrm struct {
|
2022-09-14 14:18:11 +00:00
|
|
|
addr oid.Address
|
2022-05-31 20:11:42 +00:00
|
|
|
|
|
|
|
forceRemoval bool
|
2020-11-17 12:26:03 +00:00
|
|
|
}
|
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// DeleteRes groups the resulting values of Delete operation.
|
2020-11-17 12:26:03 +00:00
|
|
|
type DeleteRes struct{}
|
|
|
|
|
2022-09-14 14:18:11 +00:00
|
|
|
// WithAddress is a Delete option to set the addresses of the objects to delete.
|
2020-11-17 12:26:03 +00:00
|
|
|
//
|
|
|
|
// Option is required.
|
2022-09-14 14:18:11 +00:00
|
|
|
func (p *DeletePrm) WithAddress(addr oid.Address) {
|
2022-09-14 14:36:37 +00:00
|
|
|
p.addr = addr
|
2020-11-17 12:26:03 +00:00
|
|
|
}
|
|
|
|
|
2022-05-31 20:11:42 +00:00
|
|
|
// WithForceRemoval is a Delete option to remove an object despite any
|
|
|
|
// restrictions imposed on deleting that object. Expected to be used
|
|
|
|
// only in control service.
|
|
|
|
func (p *DeletePrm) WithForceRemoval() {
|
2022-09-14 14:36:37 +00:00
|
|
|
p.forceRemoval = true
|
2022-05-31 20:11:42 +00:00
|
|
|
}
|
|
|
|
|
2021-02-15 11:42:54 +00:00
|
|
|
// Delete marks the objects to be removed.
|
2021-11-09 15:46:12 +00:00
|
|
|
//
|
|
|
|
// Returns an error if executions are blocked (see BlockExecution).
|
2022-02-15 22:25:27 +00:00
|
|
|
//
|
|
|
|
// Returns apistatus.ObjectLocked if at least one object is locked.
|
|
|
|
// In this case no object from the list is marked to be deleted.
|
2022-07-07 12:33:27 +00:00
|
|
|
//
|
|
|
|
// NOTE: Marks any object to be deleted (despite any prohibitions
|
|
|
|
// on operations with that object) if WithForceRemoval option has
|
|
|
|
// been provided.
|
2023-04-04 11:40:01 +00:00
|
|
|
func (e *StorageEngine) Delete(ctx context.Context, prm DeletePrm) (res DeleteRes, err error) {
|
2023-04-12 14:01:29 +00:00
|
|
|
ctx, span := tracing.StartSpanFromContext(ctx, "StorageEngine.Delete",
|
|
|
|
trace.WithAttributes(
|
|
|
|
attribute.String("address", prm.addr.EncodeToString()),
|
|
|
|
attribute.Bool("force_removal", prm.forceRemoval),
|
|
|
|
))
|
|
|
|
defer span.End()
|
|
|
|
|
2021-11-10 15:00:30 +00:00
|
|
|
err = e.execIfNotBlocked(func() error {
|
2023-04-04 11:40:01 +00:00
|
|
|
res, err = e.delete(ctx, prm)
|
2021-11-09 15:46:12 +00:00
|
|
|
return err
|
|
|
|
})
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-04-04 11:40:01 +00:00
|
|
|
func (e *StorageEngine) delete(ctx context.Context, prm DeletePrm) (DeleteRes, error) {
|
2021-03-16 08:14:56 +00:00
|
|
|
if e.metrics != nil {
|
2023-06-13 16:48:15 +00:00
|
|
|
defer elapsed("Delete", e.metrics.AddMethodDuration)()
|
2021-03-15 13:09:27 +00:00
|
|
|
}
|
|
|
|
|
2022-02-15 22:25:27 +00:00
|
|
|
var locked struct {
|
2023-08-04 11:14:07 +00:00
|
|
|
is bool
|
2022-02-15 22:25:27 +00:00
|
|
|
}
|
2022-10-04 14:59:18 +00:00
|
|
|
var splitInfo *objectSDK.SplitInfo
|
2024-05-27 19:07:43 +00:00
|
|
|
var ecInfo *objectSDK.ECInfo
|
2021-02-15 11:42:54 +00:00
|
|
|
|
2022-10-04 14:59:18 +00:00
|
|
|
// Removal of a big object is done in multiple stages:
|
|
|
|
// 1. Remove the parent object. If it is locked or already removed, return immediately.
|
|
|
|
// 2. Otherwise, search for all objects with a particular SplitID and delete them too.
|
2022-09-14 14:18:11 +00:00
|
|
|
e.iterateOverSortedShards(prm.addr, func(_ int, sh hashedShard) (stop bool) {
|
|
|
|
var existsPrm shard.ExistsPrm
|
2024-05-30 06:26:06 +00:00
|
|
|
existsPrm.Address = prm.addr
|
2021-02-15 11:42:54 +00:00
|
|
|
|
2023-03-13 11:37:35 +00:00
|
|
|
resExists, err := sh.Exists(ctx, existsPrm)
|
2022-09-14 14:18:11 +00:00
|
|
|
if err != nil {
|
2023-08-04 11:14:07 +00:00
|
|
|
if client.IsErrObjectAlreadyRemoved(err) || shard.IsErrObjectExpired(err) {
|
2022-09-14 14:18:11 +00:00
|
|
|
return true
|
|
|
|
}
|
2022-10-04 14:59:18 +00:00
|
|
|
|
2022-10-26 12:23:12 +00:00
|
|
|
var splitErr *objectSDK.SplitInfoError
|
2024-05-27 19:07:43 +00:00
|
|
|
var ecErr *objectSDK.ECInfoError
|
|
|
|
if errors.As(err, &splitErr) {
|
|
|
|
splitInfo = splitErr.SplitInfo()
|
|
|
|
} else if errors.As(err, &ecErr) {
|
|
|
|
e.deleteChunks(ctx, sh, ecInfo, prm)
|
|
|
|
return false
|
|
|
|
} else {
|
2023-08-04 11:14:07 +00:00
|
|
|
if !client.IsErrObjectNotFound(err) {
|
2024-08-05 10:24:48 +00:00
|
|
|
e.reportShardError(sh, "could not check object existence", err, zap.Stringer("address", prm.addr))
|
2022-10-04 14:59:18 +00:00
|
|
|
}
|
|
|
|
return false
|
2022-05-31 20:11:42 +00:00
|
|
|
}
|
2022-09-14 14:18:11 +00:00
|
|
|
} else if !resExists.Exists() {
|
|
|
|
return false
|
|
|
|
}
|
2022-05-20 18:08:59 +00:00
|
|
|
|
2022-09-14 14:18:11 +00:00
|
|
|
var shPrm shard.InhumePrm
|
|
|
|
shPrm.MarkAsGarbage(prm.addr)
|
|
|
|
if prm.forceRemoval {
|
|
|
|
shPrm.ForceRemoval()
|
|
|
|
}
|
2022-02-15 22:25:27 +00:00
|
|
|
|
2023-04-04 11:40:01 +00:00
|
|
|
_, err = sh.Inhume(ctx, shPrm)
|
2022-09-14 14:18:11 +00:00
|
|
|
if err != nil {
|
2024-08-05 10:24:48 +00:00
|
|
|
e.reportShardError(sh, "could not inhume object in shard", err, zap.Stringer("address", prm.addr))
|
2022-02-15 22:25:27 +00:00
|
|
|
|
2023-08-04 11:14:07 +00:00
|
|
|
var target *apistatus.ObjectLocked
|
|
|
|
locked.is = errors.As(err, &target)
|
2021-02-15 11:42:54 +00:00
|
|
|
|
2022-09-14 14:18:11 +00:00
|
|
|
return locked.is
|
|
|
|
}
|
|
|
|
|
2022-10-04 14:59:18 +00:00
|
|
|
// If a parent object is removed we should set GC mark on each shard.
|
|
|
|
return splitInfo == nil
|
2022-09-14 14:18:11 +00:00
|
|
|
})
|
2020-11-17 12:26:03 +00:00
|
|
|
|
2022-02-15 22:25:27 +00:00
|
|
|
if locked.is {
|
2023-08-04 11:14:07 +00:00
|
|
|
return DeleteRes{}, new(apistatus.ObjectLocked)
|
2022-02-15 22:25:27 +00:00
|
|
|
}
|
|
|
|
|
2022-10-04 14:59:18 +00:00
|
|
|
if splitInfo != nil {
|
2023-04-04 11:40:01 +00:00
|
|
|
e.deleteChildren(ctx, prm.addr, prm.forceRemoval, splitInfo.SplitID())
|
2022-10-04 14:59:18 +00:00
|
|
|
}
|
|
|
|
|
2022-05-31 11:56:59 +00:00
|
|
|
return DeleteRes{}, nil
|
2020-11-17 12:26:03 +00:00
|
|
|
}
|
2022-10-04 14:59:18 +00:00
|
|
|
|
2023-04-04 11:40:01 +00:00
|
|
|
func (e *StorageEngine) deleteChildren(ctx context.Context, addr oid.Address, force bool, splitID *objectSDK.SplitID) {
|
2022-10-04 14:59:18 +00:00
|
|
|
var fs objectSDK.SearchFilters
|
|
|
|
fs.AddSplitIDFilter(objectSDK.MatchStringEqual, splitID)
|
|
|
|
|
|
|
|
var selectPrm shard.SelectPrm
|
|
|
|
selectPrm.SetFilters(fs)
|
|
|
|
selectPrm.SetContainerID(addr.Container())
|
|
|
|
|
|
|
|
var inhumePrm shard.InhumePrm
|
|
|
|
if force {
|
|
|
|
inhumePrm.ForceRemoval()
|
|
|
|
}
|
|
|
|
|
|
|
|
e.iterateOverSortedShards(addr, func(_ int, sh hashedShard) (stop bool) {
|
2023-04-12 14:01:29 +00:00
|
|
|
res, err := sh.Select(ctx, selectPrm)
|
2022-10-04 14:59:18 +00:00
|
|
|
if err != nil {
|
2023-04-12 14:35:10 +00:00
|
|
|
e.log.Warn(logs.EngineErrorDuringSearchingForObjectChildren,
|
2022-10-04 14:59:18 +00:00
|
|
|
zap.Stringer("addr", addr),
|
2023-09-27 08:02:06 +00:00
|
|
|
zap.String("error", err.Error()),
|
|
|
|
zap.String("trace_id", tracingPkg.GetTraceID(ctx)))
|
2022-10-04 14:59:18 +00:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, addr := range res.AddressList() {
|
|
|
|
inhumePrm.MarkAsGarbage(addr)
|
|
|
|
|
2023-04-04 11:40:01 +00:00
|
|
|
_, err = sh.Inhume(ctx, inhumePrm)
|
2022-10-04 14:59:18 +00:00
|
|
|
if err != nil {
|
2023-04-12 14:35:10 +00:00
|
|
|
e.log.Debug(logs.EngineCouldNotInhumeObjectInShard,
|
2022-10-04 14:59:18 +00:00
|
|
|
zap.Stringer("addr", addr),
|
2023-09-27 08:02:06 +00:00
|
|
|
zap.String("err", err.Error()),
|
|
|
|
zap.String("trace_id", tracingPkg.GetTraceID(ctx)))
|
2022-10-04 14:59:18 +00:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
})
|
|
|
|
}
|
2024-05-27 19:07:43 +00:00
|
|
|
|
|
|
|
func (e *StorageEngine) deleteChunks(
|
|
|
|
ctx context.Context, sh hashedShard, ecInfo *objectSDK.ECInfo, prm DeletePrm,
|
|
|
|
) {
|
|
|
|
var inhumePrm shard.InhumePrm
|
|
|
|
if prm.forceRemoval {
|
|
|
|
inhumePrm.ForceRemoval()
|
|
|
|
}
|
|
|
|
for _, chunk := range ecInfo.Chunks {
|
|
|
|
var addr oid.Address
|
|
|
|
addr.SetContainer(prm.addr.Container())
|
|
|
|
var objID oid.ID
|
|
|
|
err := objID.ReadFromV2(chunk.ID)
|
|
|
|
if err != nil {
|
2024-08-05 10:24:48 +00:00
|
|
|
e.reportShardError(sh, "could not delete EC chunk", err, zap.Stringer("address", prm.addr))
|
2024-05-27 19:07:43 +00:00
|
|
|
}
|
|
|
|
addr.SetObject(objID)
|
|
|
|
inhumePrm.MarkAsGarbage(addr)
|
|
|
|
_, err = sh.Inhume(ctx, inhumePrm)
|
|
|
|
if err != nil {
|
|
|
|
e.log.Debug(logs.EngineCouldNotInhumeObjectInShard,
|
|
|
|
zap.Stringer("addr", addr),
|
|
|
|
zap.String("err", err.Error()),
|
|
|
|
zap.String("trace_id", tracingPkg.GetTraceID(ctx)))
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|