[#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

@ -93,7 +93,9 @@ func (e *StorageEngine) getRange(ctx context.Context, prm RngPrm) (RngRes, error
Engine: e,
}
it.tryGetWithMeta(ctx)
if err := it.tryGetWithMeta(ctx); err != nil {
return RngRes{}, err
}
if it.SplitInfo != nil {
return RngRes{}, logicerr.Wrap(objectSDK.NewSplitInfoError(it.SplitInfo))
@ -109,7 +111,9 @@ func (e *StorageEngine) getRange(ctx context.Context, prm RngPrm) (RngRes, error
return RngRes{}, it.OutError
}
it.tryGetFromBlobstor(ctx)
if err := it.tryGetFromBlobstor(ctx); err != nil {
return RngRes{}, err
}
if it.Object == nil {
return RngRes{}, it.OutError
@ -157,8 +161,8 @@ type getRangeShardIterator struct {
Engine *StorageEngine
}
func (i *getRangeShardIterator) tryGetWithMeta(ctx context.Context) {
i.Engine.iterateOverSortedShards(i.Address, func(_ int, sh hashedShard) (stop bool) {
func (i *getRangeShardIterator) tryGetWithMeta(ctx context.Context) error {
return i.Engine.iterateOverSortedShards(ctx, i.Address, func(_ int, sh hashedShard) (stop bool) {
noMeta := sh.GetMode().NoMetabase()
i.HasDegraded = i.HasDegraded || noMeta
i.ShardPrm.SetIgnoreMeta(noMeta)
@ -209,13 +213,13 @@ func (i *getRangeShardIterator) tryGetWithMeta(ctx context.Context) {
})
}
func (i *getRangeShardIterator) tryGetFromBlobstor(ctx context.Context) {
func (i *getRangeShardIterator) tryGetFromBlobstor(ctx context.Context) error {
// If the object is not found but is present in metabase,
// try to fetch it from blobstor directly. If it is found in any
// blobstor, increase the error counter for the shard which contains the meta.
i.ShardPrm.SetIgnoreMeta(true)
i.Engine.iterateOverSortedShards(i.Address, func(_ int, sh hashedShard) (stop bool) {
return i.Engine.iterateOverSortedShards(ctx, i.Address, func(_ int, sh hashedShard) (stop bool) {
if sh.GetMode().NoMetabase() {
// Already processed it without a metabase.
return false