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-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"
|
2024-08-05 10:24:48 +00:00
|
|
|
"go.uber.org/zap"
|
2020-12-01 11:06:14 +00:00
|
|
|
)
|
|
|
|
|
2024-05-30 06:26:06 +00:00
|
|
|
// exists return in the first value true if object exists.
|
|
|
|
// Second return value marks is parent object locked.
|
|
|
|
func (e *StorageEngine) exists(ctx context.Context, shPrm shard.ExistsPrm) (bool, bool, error) {
|
2024-04-01 06:54:42 +00:00
|
|
|
alreadyRemoved := false
|
|
|
|
exists := false
|
2024-05-27 19:07:43 +00:00
|
|
|
locked := false
|
2020-12-01 11:06:14 +00:00
|
|
|
|
2024-05-30 06:26:06 +00:00
|
|
|
e.iterateOverSortedShards(shPrm.Address, func(_ int, sh hashedShard) (stop bool) {
|
2024-04-01 06:54:42 +00:00
|
|
|
res, err := sh.Exists(ctx, shPrm)
|
|
|
|
if err != nil {
|
|
|
|
if client.IsErrObjectAlreadyRemoved(err) {
|
|
|
|
alreadyRemoved = true
|
2020-12-01 11:06:14 +00:00
|
|
|
|
2024-04-01 06:54:42 +00:00
|
|
|
return true
|
|
|
|
}
|
2022-07-27 18:38:28 +00:00
|
|
|
|
2024-04-01 06:54:42 +00:00
|
|
|
var siErr *objectSDK.SplitInfoError
|
|
|
|
if errors.As(err, &siErr) {
|
|
|
|
return true
|
|
|
|
}
|
2020-12-01 11:06:14 +00:00
|
|
|
|
2024-04-01 06:54:42 +00:00
|
|
|
if shard.IsErrObjectExpired(err) {
|
|
|
|
return true
|
2023-12-20 14:18:28 +00:00
|
|
|
}
|
2024-04-01 06:54:42 +00:00
|
|
|
|
|
|
|
if !client.IsErrObjectNotFound(err) {
|
2024-10-21 13:27:28 +00:00
|
|
|
e.reportShardError(ctx, sh, "could not check existence of object in shard", err, zap.Stringer("address", shPrm.Address))
|
2023-12-20 14:18:28 +00:00
|
|
|
}
|
2024-04-01 06:54:42 +00:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
if !exists {
|
|
|
|
exists = res.Exists()
|
|
|
|
}
|
2024-05-27 19:07:43 +00:00
|
|
|
if !locked {
|
|
|
|
locked = res.Locked()
|
|
|
|
}
|
2024-04-01 06:54:42 +00:00
|
|
|
|
2020-12-01 11:06:14 +00:00
|
|
|
return false
|
|
|
|
})
|
|
|
|
|
2024-04-01 06:54:42 +00:00
|
|
|
if alreadyRemoved {
|
2024-05-27 19:07:43 +00:00
|
|
|
return false, false, new(apistatus.ObjectAlreadyRemoved)
|
2020-12-01 11:06:14 +00:00
|
|
|
}
|
|
|
|
|
2024-05-27 19:07:43 +00:00
|
|
|
return exists, locked, nil
|
2020-12-01 11:06:14 +00:00
|
|
|
}
|