[#874] engine: Check object existance concurrently

Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
Dmitrii Stepanov 2023-12-20 17:18:28 +03:00
parent f5160b27fc
commit f526f49995
11 changed files with 124 additions and 35 deletions

View file

@ -3,6 +3,7 @@ package blobstor
import (
"context"
"encoding/hex"
"errors"
"time"
"git.frostfs.info/TrueCloudLab/frostfs-node/internal/logs"
@ -57,27 +58,30 @@ func (b *BlobStor) Exists(ctx context.Context, prm common.ExistsPrm) (common.Exi
// error | found | log the error, return true, nil
// error | not found | return the error
// error | error | log the first error, return the second
var errors []error
var storageErrors []error
for i := range b.storage {
res, err := b.storage[i].Storage.Exists(ctx, prm)
if err == nil && res.Exists {
exists = true
return res, nil
} else if err != nil {
errors = append(errors, err)
if errors.Is(err, context.Canceled) {
return common.ExistsRes{}, err
}
storageErrors = append(storageErrors, err)
}
}
if len(errors) == 0 {
if len(storageErrors) == 0 {
return common.ExistsRes{}, nil
}
for _, err := range errors[:len(errors)-1] {
for _, err := range storageErrors[:len(storageErrors)-1] {
b.log.Warn(logs.BlobstorErrorOccurredDuringObjectExistenceChecking,
zap.Stringer("address", prm.Address),
zap.String("error", err.Error()),
zap.String("trace_id", tracingPkg.GetTraceID(ctx)))
}
return common.ExistsRes{}, errors[len(errors)-1]
return common.ExistsRes{}, storageErrors[len(storageErrors)-1]
}