2020-12-01 09:35:42 +00:00
|
|
|
package engine
|
|
|
|
|
|
|
|
import (
|
2021-02-17 12:27:40 +00:00
|
|
|
"context"
|
2021-02-11 15:43:50 +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
|
|
|
meta "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/metabase"
|
|
|
|
"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"
|
2023-12-27 15:58:36 +00:00
|
|
|
cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id"
|
2023-03-07 13:38:26 +00:00
|
|
|
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-11-12 12:27:54 +00:00
|
|
|
"go.uber.org/zap"
|
2020-12-01 09:35:42 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// InhumePrm encapsulates parameters for inhume operation.
|
|
|
|
type InhumePrm struct {
|
2022-05-31 17:00:41 +00:00
|
|
|
tombstone *oid.Address
|
|
|
|
addrs []oid.Address
|
2022-06-14 17:48:33 +00:00
|
|
|
|
|
|
|
forceRemoval bool
|
2020-12-01 09:35:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// InhumeRes encapsulates results of inhume operation.
|
|
|
|
type InhumeRes struct{}
|
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// WithTarget sets a list of objects that should be inhumed and tombstone address
|
2020-12-01 09:35:42 +00:00
|
|
|
// as the reason for inhume operation.
|
2021-02-19 14:01:01 +00:00
|
|
|
//
|
|
|
|
// tombstone should not be nil, addr should not be empty.
|
2021-02-19 14:08:41 +00:00
|
|
|
// Should not be called along with MarkAsGarbage.
|
2022-05-23 13:12:32 +00:00
|
|
|
func (p *InhumePrm) WithTarget(tombstone oid.Address, addrs ...oid.Address) {
|
2022-09-14 14:36:37 +00:00
|
|
|
p.addrs = addrs
|
|
|
|
p.tombstone = &tombstone
|
2020-12-01 09:35:42 +00:00
|
|
|
}
|
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// MarkAsGarbage marks an object to be physically removed from local storage.
|
2021-02-19 14:08:41 +00:00
|
|
|
//
|
|
|
|
// Should not be called along with WithTarget.
|
2022-05-23 13:12:32 +00:00
|
|
|
func (p *InhumePrm) MarkAsGarbage(addrs ...oid.Address) {
|
2022-09-14 14:36:37 +00:00
|
|
|
p.addrs = addrs
|
|
|
|
p.tombstone = nil
|
2021-02-19 14:08:41 +00:00
|
|
|
}
|
|
|
|
|
2022-06-14 17:48:33 +00:00
|
|
|
// WithForceRemoval inhumes objects specified via MarkAsGarbage with GC mark
|
|
|
|
// without any object restrictions checks.
|
|
|
|
func (p *InhumePrm) WithForceRemoval() {
|
2022-09-14 14:36:37 +00:00
|
|
|
p.forceRemoval = true
|
|
|
|
p.tombstone = nil
|
2022-06-14 17:48:33 +00:00
|
|
|
}
|
|
|
|
|
2021-02-11 15:43:50 +00:00
|
|
|
var errInhumeFailure = errors.New("inhume operation failed")
|
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// Inhume calls metabase. Inhume method to mark an object as removed. It won't be
|
|
|
|
// removed physically from the shard until `Delete` operation.
|
2021-11-09 15:46:12 +00:00
|
|
|
//
|
2022-02-15 22:24:43 +00:00
|
|
|
// Allows inhuming non-locked objects only. Returns apistatus.ObjectLocked
|
|
|
|
// if at least one object is locked.
|
|
|
|
//
|
2022-07-07 12:33:27 +00:00
|
|
|
// NOTE: Marks any object as removed (despite any prohibitions on operations
|
|
|
|
// with that object) if WithForceRemoval option has been provided.
|
|
|
|
//
|
2021-11-09 15:46:12 +00:00
|
|
|
// Returns an error if executions are blocked (see BlockExecution).
|
2023-04-04 11:40:01 +00:00
|
|
|
func (e *StorageEngine) Inhume(ctx context.Context, prm InhumePrm) (res InhumeRes, err error) {
|
2023-04-12 14:01:29 +00:00
|
|
|
ctx, span := tracing.StartSpanFromContext(ctx, "StorageEngine.Inhume")
|
|
|
|
defer span.End()
|
2024-11-11 09:46:55 +00:00
|
|
|
defer elapsed("Inhume", e.metrics.AddMethodDuration)()
|
2023-04-12 14:01:29 +00:00
|
|
|
|
2021-11-10 15:00:30 +00:00
|
|
|
err = e.execIfNotBlocked(func() error {
|
2023-04-04 11:40:01 +00:00
|
|
|
res, err = e.inhume(ctx, prm)
|
2021-11-09 15:46:12 +00:00
|
|
|
return err
|
|
|
|
})
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-04-04 11:40:01 +00:00
|
|
|
func (e *StorageEngine) inhume(ctx context.Context, prm InhumePrm) (InhumeRes, error) {
|
2024-11-18 11:40:10 +00:00
|
|
|
addrsPerShard, err := e.groupObjectsByShard(ctx, prm.addrs, !prm.forceRemoval)
|
|
|
|
if err != nil {
|
|
|
|
return InhumeRes{}, err
|
|
|
|
}
|
|
|
|
|
2022-05-20 18:08:59 +00:00
|
|
|
var shPrm shard.InhumePrm
|
2022-06-14 17:48:33 +00:00
|
|
|
if prm.forceRemoval {
|
|
|
|
shPrm.ForceRemoval()
|
|
|
|
}
|
2020-12-01 09:35:42 +00:00
|
|
|
|
2024-11-18 11:40:10 +00:00
|
|
|
var errLocked *apistatus.ObjectLocked
|
2022-11-12 12:27:54 +00:00
|
|
|
|
2024-11-18 11:40:10 +00:00
|
|
|
for shardID, addrs := range addrsPerShard {
|
2021-02-19 14:08:41 +00:00
|
|
|
if prm.tombstone != nil {
|
2024-11-18 11:40:10 +00:00
|
|
|
shPrm.SetTarget(*prm.tombstone, addrs...)
|
2021-02-19 14:08:41 +00:00
|
|
|
} else {
|
2024-11-18 11:40:10 +00:00
|
|
|
shPrm.MarkAsGarbage(addrs...)
|
2021-02-19 14:08:41 +00:00
|
|
|
}
|
2021-02-19 14:01:01 +00:00
|
|
|
|
2024-11-18 11:40:10 +00:00
|
|
|
sh, exists := e.shards[shardID]
|
|
|
|
if !exists {
|
|
|
|
e.log.Warn(ctx, logs.EngineCouldNotInhumeObjectInShard,
|
|
|
|
zap.Error(errors.New("this shard was expected to exist")),
|
|
|
|
zap.String("shard_id", shardID),
|
|
|
|
zap.String("trace_id", tracingPkg.GetTraceID(ctx)),
|
|
|
|
)
|
|
|
|
return InhumeRes{}, errInhumeFailure
|
2022-10-05 10:48:09 +00:00
|
|
|
}
|
2024-11-18 11:40:10 +00:00
|
|
|
|
|
|
|
if _, err := sh.Inhume(ctx, shPrm); err != nil {
|
|
|
|
switch {
|
|
|
|
case errors.As(err, &errLocked):
|
|
|
|
case errors.Is(err, shard.ErrLockObjectRemoval):
|
|
|
|
case errors.Is(err, shard.ErrReadOnlyMode):
|
|
|
|
case errors.Is(err, shard.ErrDegradedMode):
|
|
|
|
default:
|
|
|
|
e.reportShardError(ctx, sh, "couldn't inhume object in shard", err)
|
2021-02-19 14:01:01 +00:00
|
|
|
}
|
2024-11-18 11:40:10 +00:00
|
|
|
return InhumeRes{}, err
|
2021-02-11 15:43:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-31 11:56:59 +00:00
|
|
|
return InhumeRes{}, nil
|
2021-02-11 15:43:50 +00:00
|
|
|
}
|
|
|
|
|
2024-11-18 11:40:10 +00:00
|
|
|
// groupObjectsByShard groups objects based on the shard(s) they are stored on.
|
|
|
|
//
|
|
|
|
// If checkLocked is set, [apistatus.ObjectLocked] will be returned if any of
|
|
|
|
// the objects are locked.
|
|
|
|
func (e *StorageEngine) groupObjectsByShard(ctx context.Context, addrs []oid.Address, checkLocked bool) (map[string][]oid.Address, error) {
|
|
|
|
groups := make(map[string][]oid.Address)
|
|
|
|
|
|
|
|
for _, addr := range addrs {
|
|
|
|
ids, err := e.findShards(ctx, addr, checkLocked)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
for _, id := range ids {
|
|
|
|
groups[id] = append(groups[id], addr)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return groups, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// findShards determines the shard(s) where the object is stored.
|
|
|
|
//
|
|
|
|
// If the object is a root object, multiple shards will be returned.
|
|
|
|
//
|
|
|
|
// If checkLocked is set, [apistatus.ObjectLocked] will be returned if any of
|
|
|
|
// the objects are locked.
|
|
|
|
func (e *StorageEngine) findShards(ctx context.Context, addr oid.Address, checkLocked bool) ([]string, error) {
|
|
|
|
var (
|
|
|
|
ids []string
|
|
|
|
retErr error
|
|
|
|
|
|
|
|
prm shard.ExistsPrm
|
|
|
|
|
|
|
|
siErr *objectSDK.SplitInfoError
|
|
|
|
ecErr *objectSDK.ECInfoError
|
|
|
|
|
|
|
|
isRootObject bool
|
|
|
|
objectExists bool
|
|
|
|
)
|
2021-05-20 14:31:47 +00:00
|
|
|
|
2022-01-31 14:58:32 +00:00
|
|
|
e.iterateOverSortedShards(addr, func(_ int, sh hashedShard) (stop bool) {
|
2024-11-18 11:40:10 +00:00
|
|
|
objectExists = false
|
|
|
|
|
|
|
|
prm.Address = addr
|
|
|
|
switch res, err := sh.Exists(ctx, prm); {
|
|
|
|
case client.IsErrObjectAlreadyRemoved(err) || shard.IsErrObjectExpired(err):
|
|
|
|
// NOTE(@a-savchuk): there were some considerations that we can stop
|
|
|
|
// immediately if the object is already removed or expired. However,
|
|
|
|
// the previous method behavior was:
|
|
|
|
// - keep iterating if it's a root object and already removed,
|
|
|
|
// - stop iterating if it's not a root object and removed.
|
|
|
|
//
|
|
|
|
// Since my task was only improving method speed, let's keep the
|
|
|
|
// previous method behavior. Continue if it's a root object.
|
|
|
|
return !isRootObject
|
|
|
|
case errors.As(err, &siErr) || errors.As(err, &ecErr):
|
|
|
|
isRootObject = true
|
|
|
|
objectExists = true
|
|
|
|
case err != nil:
|
|
|
|
e.reportShardError(
|
|
|
|
ctx, sh, "couldn't check for presence in shard",
|
|
|
|
err, zap.Stringer("address", addr),
|
|
|
|
)
|
|
|
|
case res.Exists():
|
|
|
|
objectExists = true
|
|
|
|
default:
|
2021-02-11 15:43:50 +00:00
|
|
|
}
|
|
|
|
|
2024-11-18 11:40:10 +00:00
|
|
|
if !objectExists {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if checkLocked {
|
|
|
|
if isLocked, err := sh.IsLocked(ctx, addr); err != nil {
|
|
|
|
e.log.Warn(ctx, logs.EngineRemovingAnObjectWithoutFullLockingCheck,
|
|
|
|
zap.Error(err),
|
|
|
|
zap.Stringer("address", addr),
|
|
|
|
zap.String("trace_id", tracingPkg.GetTraceID(ctx)),
|
|
|
|
)
|
|
|
|
} else if isLocked {
|
2023-08-04 11:14:07 +00:00
|
|
|
retErr = new(apistatus.ObjectLocked)
|
2022-02-15 22:24:43 +00:00
|
|
|
return true
|
|
|
|
}
|
2020-12-01 09:35:42 +00:00
|
|
|
}
|
|
|
|
|
2024-11-18 11:40:10 +00:00
|
|
|
ids = append(ids, sh.ID().String())
|
|
|
|
|
|
|
|
// Continue if it's a root object.
|
|
|
|
return !isRootObject
|
2020-12-01 09:35:42 +00:00
|
|
|
})
|
|
|
|
|
2024-11-18 11:40:10 +00:00
|
|
|
if retErr != nil {
|
|
|
|
return nil, retErr
|
|
|
|
}
|
|
|
|
return ids, nil
|
2020-12-01 09:35:42 +00:00
|
|
|
}
|
2021-02-17 12:27:40 +00:00
|
|
|
|
2023-03-15 00:42:49 +00:00
|
|
|
// IsLocked checks whether an object is locked according to StorageEngine's state.
|
2023-04-12 14:01:29 +00:00
|
|
|
func (e *StorageEngine) IsLocked(ctx context.Context, addr oid.Address) (bool, error) {
|
|
|
|
ctx, span := tracing.StartSpanFromContext(ctx, "StorageEngine.IsLocked",
|
|
|
|
trace.WithAttributes(
|
|
|
|
attribute.String("address", addr.EncodeToString()),
|
|
|
|
))
|
|
|
|
defer span.End()
|
|
|
|
|
2022-11-12 12:27:54 +00:00
|
|
|
var locked bool
|
|
|
|
var err error
|
|
|
|
var outErr error
|
|
|
|
|
|
|
|
e.iterateOverUnsortedShards(func(h hashedShard) (stop bool) {
|
2023-04-12 14:01:29 +00:00
|
|
|
locked, err = h.Shard.IsLocked(ctx, addr)
|
2022-11-12 12:27:54 +00:00
|
|
|
if err != nil {
|
2024-10-21 13:27:28 +00:00
|
|
|
e.reportShardError(ctx, h, "can't check object's lockers", err, zap.Stringer("address", addr),
|
2023-09-27 08:02:06 +00:00
|
|
|
zap.String("trace_id", tracingPkg.GetTraceID(ctx)))
|
2022-11-12 12:27:54 +00:00
|
|
|
outErr = err
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
return locked
|
|
|
|
})
|
|
|
|
|
|
|
|
if locked {
|
|
|
|
return locked, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return locked, outErr
|
|
|
|
}
|
|
|
|
|
2024-05-27 19:07:43 +00:00
|
|
|
// GetLocked return lock id's if object is locked according to StorageEngine's state.
|
|
|
|
func (e *StorageEngine) GetLocked(ctx context.Context, addr oid.Address) ([]oid.ID, error) {
|
|
|
|
ctx, span := tracing.StartSpanFromContext(ctx, "StorageEngine.GetLocked",
|
|
|
|
trace.WithAttributes(
|
|
|
|
attribute.String("address", addr.EncodeToString()),
|
|
|
|
))
|
|
|
|
defer span.End()
|
|
|
|
|
|
|
|
var locked []oid.ID
|
|
|
|
var outErr error
|
|
|
|
|
|
|
|
e.iterateOverUnsortedShards(func(h hashedShard) (stop bool) {
|
|
|
|
ld, err := h.Shard.GetLocked(ctx, addr)
|
|
|
|
if err != nil {
|
2024-10-21 13:27:28 +00:00
|
|
|
e.reportShardError(ctx, h, logs.EngineInterruptGettingLockers, err, zap.Stringer("address", addr),
|
2024-05-27 19:07:43 +00:00
|
|
|
zap.String("trace_id", tracingPkg.GetTraceID(ctx)))
|
|
|
|
outErr = err
|
|
|
|
}
|
|
|
|
locked = append(locked, ld...)
|
|
|
|
return false
|
|
|
|
})
|
|
|
|
if len(locked) > 0 {
|
|
|
|
return locked, nil
|
|
|
|
}
|
|
|
|
return locked, outErr
|
|
|
|
}
|
|
|
|
|
2022-04-19 18:00:22 +00:00
|
|
|
func (e *StorageEngine) processExpiredTombstones(ctx context.Context, addrs []meta.TombstonedObject) {
|
2022-01-31 14:58:32 +00:00
|
|
|
e.iterateOverUnsortedShards(func(sh hashedShard) (stop bool) {
|
2023-04-12 14:01:29 +00:00
|
|
|
sh.HandleExpiredTombstones(ctx, addrs)
|
2021-02-17 12:27:40 +00:00
|
|
|
|
|
|
|
select {
|
|
|
|
case <-ctx.Done():
|
|
|
|
return true
|
|
|
|
default:
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2022-03-10 17:58:58 +00:00
|
|
|
|
2023-03-28 08:17:15 +00:00
|
|
|
func (e *StorageEngine) processExpiredLocks(ctx context.Context, epoch uint64, lockers []oid.Address) {
|
2022-03-10 17:58:58 +00:00
|
|
|
e.iterateOverUnsortedShards(func(sh hashedShard) (stop bool) {
|
2023-03-28 08:17:15 +00:00
|
|
|
sh.HandleExpiredLocks(ctx, epoch, lockers)
|
2022-03-10 17:58:58 +00:00
|
|
|
|
|
|
|
select {
|
|
|
|
case <-ctx.Done():
|
2024-10-21 07:22:54 +00:00
|
|
|
e.log.Info(ctx, logs.EngineInterruptProcessingTheExpiredLocks, zap.Error(ctx.Err()))
|
2022-03-10 17:58:58 +00:00
|
|
|
return true
|
|
|
|
default:
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2022-05-26 17:38:32 +00:00
|
|
|
|
|
|
|
func (e *StorageEngine) processDeletedLocks(ctx context.Context, lockers []oid.Address) {
|
|
|
|
e.iterateOverUnsortedShards(func(sh hashedShard) (stop bool) {
|
2024-10-21 13:27:28 +00:00
|
|
|
sh.HandleDeletedLocks(ctx, lockers)
|
2022-05-26 17:38:32 +00:00
|
|
|
|
|
|
|
select {
|
|
|
|
case <-ctx.Done():
|
2024-10-21 07:22:54 +00:00
|
|
|
e.log.Info(ctx, logs.EngineInterruptProcessingTheDeletedLocks, zap.Error(ctx.Err()))
|
2022-05-26 17:38:32 +00:00
|
|
|
return true
|
|
|
|
default:
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2023-12-27 15:58:36 +00:00
|
|
|
|
|
|
|
func (e *StorageEngine) processZeroSizeContainers(ctx context.Context, ids []cid.ID) {
|
|
|
|
if len(ids) == 0 {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-12-27 15:23:12 +00:00
|
|
|
idMap, err := e.selectNonExistentIDs(ctx, ids)
|
2023-12-27 15:58:36 +00:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(idMap) == 0 {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
var failed bool
|
|
|
|
var prm shard.ContainerSizePrm
|
|
|
|
e.iterateOverUnsortedShards(func(sh hashedShard) bool {
|
|
|
|
select {
|
|
|
|
case <-ctx.Done():
|
2024-10-21 07:22:54 +00:00
|
|
|
e.log.Info(ctx, logs.EngineInterruptProcessingZeroSizeContainers, zap.Error(ctx.Err()))
|
2023-12-27 15:58:36 +00:00
|
|
|
failed = true
|
|
|
|
return true
|
|
|
|
default:
|
|
|
|
}
|
|
|
|
|
|
|
|
var drop []cid.ID
|
|
|
|
for id := range idMap {
|
|
|
|
prm.SetContainerID(id)
|
|
|
|
s, err := sh.ContainerSize(prm)
|
|
|
|
if err != nil {
|
2024-10-21 07:22:54 +00:00
|
|
|
e.log.Warn(ctx, logs.EngineFailedToGetContainerSize, zap.Stringer("container_id", id), zap.Error(err))
|
2023-12-27 15:58:36 +00:00
|
|
|
failed = true
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
if s.Size() > 0 {
|
|
|
|
drop = append(drop, id)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for _, id := range drop {
|
|
|
|
delete(idMap, id)
|
|
|
|
}
|
|
|
|
|
|
|
|
return len(idMap) == 0
|
|
|
|
})
|
|
|
|
|
|
|
|
if failed || len(idMap) == 0 {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
e.iterateOverUnsortedShards(func(sh hashedShard) bool {
|
|
|
|
select {
|
|
|
|
case <-ctx.Done():
|
2024-10-21 07:22:54 +00:00
|
|
|
e.log.Info(ctx, logs.EngineInterruptProcessingZeroSizeContainers, zap.Error(ctx.Err()))
|
2023-12-27 15:58:36 +00:00
|
|
|
failed = true
|
|
|
|
return true
|
|
|
|
default:
|
|
|
|
}
|
|
|
|
|
|
|
|
for id := range idMap {
|
|
|
|
if err := sh.DeleteContainerSize(ctx, id); err != nil {
|
2024-10-21 07:22:54 +00:00
|
|
|
e.log.Warn(ctx, logs.EngineFailedToDeleteContainerSize, zap.Stringer("container_id", id), zap.Error(err))
|
2023-12-27 15:58:36 +00:00
|
|
|
failed = true
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
})
|
|
|
|
|
|
|
|
if failed {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
for id := range idMap {
|
|
|
|
e.metrics.DeleteContainerSize(id.EncodeToString())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-27 15:23:12 +00:00
|
|
|
func (e *StorageEngine) processZeroCountContainers(ctx context.Context, ids []cid.ID) {
|
|
|
|
if len(ids) == 0 {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
idMap, err := e.selectNonExistentIDs(ctx, ids)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(idMap) == 0 {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
var failed bool
|
|
|
|
var prm shard.ContainerCountPrm
|
|
|
|
e.iterateOverUnsortedShards(func(sh hashedShard) bool {
|
|
|
|
select {
|
|
|
|
case <-ctx.Done():
|
2024-10-21 07:22:54 +00:00
|
|
|
e.log.Info(ctx, logs.EngineInterruptProcessingZeroCountContainers, zap.Error(ctx.Err()))
|
2023-12-27 15:23:12 +00:00
|
|
|
failed = true
|
|
|
|
return true
|
|
|
|
default:
|
|
|
|
}
|
|
|
|
|
|
|
|
var drop []cid.ID
|
|
|
|
for id := range idMap {
|
|
|
|
prm.ContainerID = id
|
|
|
|
s, err := sh.ContainerCount(ctx, prm)
|
|
|
|
if err != nil {
|
2024-10-21 07:22:54 +00:00
|
|
|
e.log.Warn(ctx, logs.EngineFailedToGetContainerCounters, zap.Stringer("container_id", id), zap.Error(err))
|
2023-12-27 15:23:12 +00:00
|
|
|
failed = true
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
if s.User > 0 || s.Logic > 0 || s.Phy > 0 {
|
|
|
|
drop = append(drop, id)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for _, id := range drop {
|
|
|
|
delete(idMap, id)
|
|
|
|
}
|
|
|
|
|
|
|
|
return len(idMap) == 0
|
|
|
|
})
|
|
|
|
|
|
|
|
if failed || len(idMap) == 0 {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
e.iterateOverUnsortedShards(func(sh hashedShard) bool {
|
|
|
|
select {
|
|
|
|
case <-ctx.Done():
|
2024-10-21 07:22:54 +00:00
|
|
|
e.log.Info(ctx, logs.EngineInterruptProcessingZeroCountContainers, zap.Error(ctx.Err()))
|
2023-12-27 15:23:12 +00:00
|
|
|
failed = true
|
|
|
|
return true
|
|
|
|
default:
|
|
|
|
}
|
|
|
|
|
|
|
|
for id := range idMap {
|
2024-01-30 08:13:29 +00:00
|
|
|
if err := sh.DeleteContainerCount(ctx, id); err != nil {
|
2024-10-21 07:22:54 +00:00
|
|
|
e.log.Warn(ctx, logs.EngineFailedToDeleteContainerSize, zap.Stringer("container_id", id), zap.Error(err))
|
2023-12-27 15:23:12 +00:00
|
|
|
failed = true
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
})
|
|
|
|
|
|
|
|
if failed {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
for id := range idMap {
|
|
|
|
e.metrics.DeleteContainerCount(id.EncodeToString())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *StorageEngine) selectNonExistentIDs(ctx context.Context, ids []cid.ID) (map[cid.ID]struct{}, error) {
|
2023-12-27 15:58:36 +00:00
|
|
|
cs := e.containerSource.Load()
|
|
|
|
|
|
|
|
idMap := make(map[cid.ID]struct{})
|
|
|
|
for _, id := range ids {
|
|
|
|
isAvailable, err := cs.IsContainerAvailable(ctx, id)
|
|
|
|
if err != nil {
|
2024-10-21 07:22:54 +00:00
|
|
|
e.log.Warn(ctx, logs.EngineFailedToCheckContainerAvailability, zap.Stringer("container_id", id), zap.Error(err))
|
2023-12-27 15:58:36 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if isAvailable {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
idMap[id] = struct{}{}
|
|
|
|
}
|
|
|
|
return idMap, nil
|
|
|
|
}
|