2020-12-01 11:06:14 +00:00
|
|
|
package engine
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard"
|
2022-03-17 08:03:58 +00:00
|
|
|
apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status"
|
2022-07-01 11:21:33 +00:00
|
|
|
objectSDK "github.com/nspcc-dev/neofs-sdk-go/object"
|
2022-05-31 17:00:41 +00:00
|
|
|
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
2020-12-01 11:06:14 +00:00
|
|
|
)
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
func (e *StorageEngine) exists(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)
|
2020-12-01 11:06:14 +00:00
|
|
|
alreadyRemoved := false
|
|
|
|
exists := false
|
|
|
|
|
2022-01-31 14:58:32 +00:00
|
|
|
e.iterateOverSortedShards(addr, func(_ int, sh hashedShard) (stop bool) {
|
2020-12-01 11:06:14 +00:00
|
|
|
res, err := sh.Exists(shPrm)
|
|
|
|
if err != nil {
|
2022-03-17 08:03:58 +00:00
|
|
|
if shard.IsErrRemoved(err) {
|
2020-12-01 11:06:14 +00:00
|
|
|
alreadyRemoved = true
|
|
|
|
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2022-07-01 11:21:33 +00:00
|
|
|
_, ok := err.(*objectSDK.SplitInfoError)
|
|
|
|
if ok {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
if !shard.IsErrNotFound(err) {
|
|
|
|
e.reportShardError(sh, "could not check existence of object in shard", err)
|
|
|
|
}
|
|
|
|
return false
|
2020-12-01 11:06:14 +00:00
|
|
|
}
|
|
|
|
|
2022-05-20 18:08:59 +00:00
|
|
|
if !exists {
|
2020-12-01 11:06:14 +00:00
|
|
|
exists = res.Exists()
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
})
|
|
|
|
|
|
|
|
if alreadyRemoved {
|
2022-03-17 08:03:58 +00:00
|
|
|
var errRemoved apistatus.ObjectAlreadyRemoved
|
|
|
|
|
|
|
|
return false, errRemoved
|
2020-12-01 11:06:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return exists, nil
|
|
|
|
}
|