forked from TrueCloudLab/frostfs-node
[#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:
parent
a27e003508
commit
3a441f072f
12 changed files with 149 additions and 86 deletions
|
@ -54,14 +54,15 @@ func (e *StorageEngine) Select(ctx context.Context, prm SelectPrm) (res SelectRe
|
|||
defer elapsed("Select", e.metrics.AddMethodDuration)()
|
||||
|
||||
err = e.execIfNotBlocked(func() error {
|
||||
res = e._select(ctx, prm)
|
||||
return nil
|
||||
var sErr error
|
||||
res, sErr = e._select(ctx, prm)
|
||||
return sErr
|
||||
})
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (e *StorageEngine) _select(ctx context.Context, prm SelectPrm) SelectRes {
|
||||
func (e *StorageEngine) _select(ctx context.Context, prm SelectPrm) (SelectRes, error) {
|
||||
addrList := make([]oid.Address, 0)
|
||||
uniqueMap := make(map[string]struct{})
|
||||
|
||||
|
@ -69,7 +70,7 @@ func (e *StorageEngine) _select(ctx context.Context, prm SelectPrm) SelectRes {
|
|||
shPrm.SetContainerID(prm.cnr, prm.indexedContainer)
|
||||
shPrm.SetFilters(prm.filters)
|
||||
|
||||
e.iterateOverUnsortedShards(func(sh hashedShard) (stop bool) {
|
||||
if err := e.iterateOverUnsortedShards(ctx, func(sh hashedShard) (stop bool) {
|
||||
res, err := sh.Select(ctx, shPrm)
|
||||
if err != nil {
|
||||
e.reportShardError(ctx, sh, "could not select objects from shard", err)
|
||||
|
@ -84,11 +85,13 @@ func (e *StorageEngine) _select(ctx context.Context, prm SelectPrm) SelectRes {
|
|||
}
|
||||
|
||||
return false
|
||||
})
|
||||
}); err != nil {
|
||||
return SelectRes{}, err
|
||||
}
|
||||
|
||||
return SelectRes{
|
||||
addrList: addrList,
|
||||
}
|
||||
}, nil
|
||||
}
|
||||
|
||||
// List returns `limit` available physically storage object addresses in engine.
|
||||
|
@ -98,20 +101,21 @@ func (e *StorageEngine) _select(ctx context.Context, prm SelectPrm) SelectRes {
|
|||
func (e *StorageEngine) List(ctx context.Context, limit uint64) (res SelectRes, err error) {
|
||||
defer elapsed("List", e.metrics.AddMethodDuration)()
|
||||
err = e.execIfNotBlocked(func() error {
|
||||
res = e.list(ctx, limit)
|
||||
return nil
|
||||
var lErr error
|
||||
res, lErr = e.list(ctx, limit)
|
||||
return lErr
|
||||
})
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (e *StorageEngine) list(ctx context.Context, limit uint64) SelectRes {
|
||||
func (e *StorageEngine) list(ctx context.Context, limit uint64) (SelectRes, error) {
|
||||
addrList := make([]oid.Address, 0, limit)
|
||||
uniqueMap := make(map[string]struct{})
|
||||
ln := uint64(0)
|
||||
|
||||
// consider iterating over shuffled shards
|
||||
e.iterateOverUnsortedShards(func(sh hashedShard) (stop bool) {
|
||||
if err := e.iterateOverUnsortedShards(ctx, func(sh hashedShard) (stop bool) {
|
||||
res, err := sh.List(ctx) // consider limit result of shard iterator
|
||||
if err != nil {
|
||||
e.reportShardError(ctx, sh, "could not select objects from shard", err)
|
||||
|
@ -130,11 +134,13 @@ func (e *StorageEngine) list(ctx context.Context, limit uint64) SelectRes {
|
|||
}
|
||||
|
||||
return false
|
||||
})
|
||||
}); err != nil {
|
||||
return SelectRes{}, err
|
||||
}
|
||||
|
||||
return SelectRes{
|
||||
addrList: addrList,
|
||||
}
|
||||
}, nil
|
||||
}
|
||||
|
||||
// Select selects objects from local storage using provided filters.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue