2020-12-01 11:06:14 +00:00
|
|
|
package engine
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
|
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/core/object"
|
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard"
|
2022-01-26 12:11:13 +00:00
|
|
|
addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address"
|
2020-12-01 11:06:14 +00:00
|
|
|
)
|
|
|
|
|
2022-01-26 12:11:13 +00:00
|
|
|
func (e *StorageEngine) exists(addr *addressSDK.Address) (bool, error) {
|
2020-12-01 11:06:14 +00:00
|
|
|
shPrm := new(shard.ExistsPrm).WithAddress(addr)
|
|
|
|
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 {
|
|
|
|
if errors.Is(err, object.ErrAlreadyRemoved) {
|
|
|
|
alreadyRemoved = true
|
|
|
|
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2022-01-31 14:58:32 +00:00
|
|
|
e.reportShardError(sh, "could not check existence of object in shard", err)
|
2020-12-01 11:06:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if res != nil && !exists {
|
|
|
|
exists = res.Exists()
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
})
|
|
|
|
|
|
|
|
if alreadyRemoved {
|
|
|
|
return false, object.ErrAlreadyRemoved
|
|
|
|
}
|
|
|
|
|
|
|
|
return exists, nil
|
|
|
|
}
|