[#1709] shard: Check if context canceled for shard iteration

If context has already been canceled, then there is no need to check other shards.
At the same time, it is necessary to avoid handling context cancellation
in each handler. Therefore, the context check has been moved to the shard
iteration method, which now returns an error.

Change-Id: I70030ace36593ce7d2b8376bee39fe82e9dbf88f
Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
Dmitrii Stepanov 2025-04-21 12:13:32 +03:00
parent a27e003508
commit 3a441f072f
Signed by: dstepanov-yadro
GPG key ID: 237AF1A763293BC0
12 changed files with 149 additions and 86 deletions

View file

@ -71,7 +71,7 @@ func (e *StorageEngine) delete(ctx context.Context, prm DeletePrm) error {
// 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.
e.iterateOverSortedShards(prm.addr, func(_ int, sh hashedShard) (stop bool) {
if err := e.iterateOverSortedShards(ctx, prm.addr, func(_ int, sh hashedShard) (stop bool) {
var existsPrm shard.ExistsPrm
existsPrm.Address = prm.addr
@ -116,20 +116,22 @@ func (e *StorageEngine) delete(ctx context.Context, prm DeletePrm) error {
// If a parent object is removed we should set GC mark on each shard.
return splitInfo == nil
})
}); err != nil {
return err
}
if locked.is {
return new(apistatus.ObjectLocked)
}
if splitInfo != nil {
e.deleteChildren(ctx, prm.addr, prm.forceRemoval, splitInfo.SplitID())
return e.deleteChildren(ctx, prm.addr, prm.forceRemoval, splitInfo.SplitID())
}
return nil
}
func (e *StorageEngine) deleteChildren(ctx context.Context, addr oid.Address, force bool, splitID *objectSDK.SplitID) {
func (e *StorageEngine) deleteChildren(ctx context.Context, addr oid.Address, force bool, splitID *objectSDK.SplitID) error {
var fs objectSDK.SearchFilters
fs.AddSplitIDFilter(objectSDK.MatchStringEqual, splitID)
@ -142,7 +144,7 @@ func (e *StorageEngine) deleteChildren(ctx context.Context, addr oid.Address, fo
inhumePrm.ForceRemoval()
}
e.iterateOverSortedShards(addr, func(_ int, sh hashedShard) (stop bool) {
return e.iterateOverSortedShards(ctx, addr, func(_ int, sh hashedShard) (stop bool) {
res, err := sh.Select(ctx, selectPrm)
if err != nil {
e.log.Warn(ctx, logs.EngineErrorDuringSearchingForObjectChildren,