2020-12-01 11:06:14 +00:00
|
|
|
package engine
|
|
|
|
|
|
|
|
import (
|
2023-03-13 11:37:35 +00:00
|
|
|
"context"
|
2022-10-26 12:23:12 +00:00
|
|
|
"errors"
|
2023-12-20 14:18:28 +00:00
|
|
|
"sync/atomic"
|
2022-10-26 12:23:12 +00:00
|
|
|
|
2023-03-07 13:38:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/shard"
|
2023-08-04 11:14:07 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client"
|
2023-03-07 13:38:26 +00:00
|
|
|
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"
|
2023-12-20 14:18:28 +00:00
|
|
|
"golang.org/x/sync/errgroup"
|
2020-12-01 11:06:14 +00:00
|
|
|
)
|
|
|
|
|
2023-04-12 14:01:29 +00:00
|
|
|
func (e *StorageEngine) exists(ctx context.Context, addr oid.Address) (bool, error) {
|
2022-05-20 18:08:59 +00:00
|
|
|
var shPrm shard.ExistsPrm
|
2022-07-13 12:43:04 +00:00
|
|
|
shPrm.SetAddress(addr)
|
2023-12-20 14:18:28 +00:00
|
|
|
|
|
|
|
var exists atomic.Bool
|
|
|
|
eg, egCtx := errgroup.WithContext(ctx)
|
|
|
|
egCtx, cancel := context.WithCancel(egCtx)
|
|
|
|
defer cancel()
|
2020-12-01 11:06:14 +00:00
|
|
|
|
2022-01-31 14:58:32 +00:00
|
|
|
e.iterateOverSortedShards(addr, func(_ int, sh hashedShard) (stop bool) {
|
2023-12-20 14:18:28 +00:00
|
|
|
select {
|
|
|
|
case <-egCtx.Done():
|
|
|
|
return true
|
|
|
|
default:
|
|
|
|
}
|
2020-12-01 11:06:14 +00:00
|
|
|
|
2023-12-20 14:18:28 +00:00
|
|
|
eg.Go(func() error {
|
|
|
|
res, err := sh.Exists(egCtx, shPrm)
|
|
|
|
if err != nil {
|
|
|
|
if errors.Is(err, context.Canceled) {
|
|
|
|
return err
|
|
|
|
}
|
2020-12-01 11:06:14 +00:00
|
|
|
|
2023-12-20 14:18:28 +00:00
|
|
|
if client.IsErrObjectAlreadyRemoved(err) {
|
|
|
|
return err
|
|
|
|
}
|
2022-07-27 18:38:28 +00:00
|
|
|
|
2023-12-20 14:18:28 +00:00
|
|
|
var siErr *objectSDK.SplitInfoError
|
|
|
|
if errors.As(err, &siErr) {
|
|
|
|
return err
|
|
|
|
}
|
2022-07-27 18:38:28 +00:00
|
|
|
|
2023-12-20 14:18:28 +00:00
|
|
|
if shard.IsErrObjectExpired(err) {
|
|
|
|
return err
|
|
|
|
}
|
2020-12-01 11:06:14 +00:00
|
|
|
|
2023-12-20 14:18:28 +00:00
|
|
|
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
|
|
|
|
})
|
2020-12-01 11:06:14 +00:00
|
|
|
return false
|
|
|
|
})
|
|
|
|
|
2023-12-20 14:18:28 +00:00
|
|
|
err := eg.Wait()
|
|
|
|
if client.IsErrObjectAlreadyRemoved(err) {
|
2023-08-04 11:14:07 +00:00
|
|
|
return false, new(apistatus.ObjectAlreadyRemoved)
|
2020-12-01 11:06:14 +00:00
|
|
|
}
|
|
|
|
|
2023-12-20 14:18:28 +00:00
|
|
|
return exists.Load(), nil
|
2020-12-01 11:06:14 +00:00
|
|
|
}
|