Dmitrii Stepanov
f526f49995
All checks were successful
DCO action / DCO (pull_request) Successful in 1m36s
Vulncheck / Vulncheck (pull_request) Successful in 2m33s
Build / Build Components (1.21) (pull_request) Successful in 3m9s
Build / Build Components (1.20) (pull_request) Successful in 4m49s
Tests and linters / Tests (1.21) (pull_request) Successful in 6m5s
Tests and linters / Staticcheck (pull_request) Successful in 6m6s
Tests and linters / Tests (1.20) (pull_request) Successful in 6m39s
Tests and linters / Lint (pull_request) Successful in 7m0s
Tests and linters / Tests with -race (pull_request) Successful in 6m46s
Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
72 lines
1.6 KiB
Go
72 lines
1.6 KiB
Go
package engine
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"sync/atomic"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/shard"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client"
|
|
apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status"
|
|
objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
|
|
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
|
|
"golang.org/x/sync/errgroup"
|
|
)
|
|
|
|
func (e *StorageEngine) exists(ctx context.Context, addr oid.Address) (bool, error) {
|
|
var shPrm shard.ExistsPrm
|
|
shPrm.SetAddress(addr)
|
|
|
|
var exists atomic.Bool
|
|
eg, egCtx := errgroup.WithContext(ctx)
|
|
egCtx, cancel := context.WithCancel(egCtx)
|
|
defer cancel()
|
|
|
|
e.iterateOverSortedShards(addr, func(_ int, sh hashedShard) (stop bool) {
|
|
select {
|
|
case <-egCtx.Done():
|
|
return true
|
|
default:
|
|
}
|
|
|
|
eg.Go(func() error {
|
|
res, err := sh.Exists(egCtx, shPrm)
|
|
if err != nil {
|
|
if errors.Is(err, context.Canceled) {
|
|
return err
|
|
}
|
|
|
|
if client.IsErrObjectAlreadyRemoved(err) {
|
|
return err
|
|
}
|
|
|
|
var siErr *objectSDK.SplitInfoError
|
|
if errors.As(err, &siErr) {
|
|
return err
|
|
}
|
|
|
|
if shard.IsErrObjectExpired(err) {
|
|
return err
|
|
}
|
|
|
|
if !client.IsErrObjectNotFound(err) {
|
|
e.reportShardError(sh, "could not check existence of object in shard", err)
|
|
}
|
|
return nil
|
|
}
|
|
if res.Exists() {
|
|
exists.Store(true)
|
|
cancel()
|
|
}
|
|
return nil
|
|
})
|
|
return false
|
|
})
|
|
|
|
err := eg.Wait()
|
|
if client.IsErrObjectAlreadyRemoved(err) {
|
|
return false, new(apistatus.ObjectAlreadyRemoved)
|
|
}
|
|
|
|
return exists.Load(), nil
|
|
}
|