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"
|
2021-11-10 07:08:33 +00:00
|
|
|
objectSDK "github.com/nspcc-dev/neofs-sdk-go/object"
|
2020-12-01 11:06:14 +00:00
|
|
|
"go.uber.org/zap"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (e *StorageEngine) exists(addr *objectSDK.Address) (bool, error) {
|
|
|
|
shPrm := new(shard.ExistsPrm).WithAddress(addr)
|
|
|
|
alreadyRemoved := false
|
|
|
|
exists := false
|
|
|
|
|
|
|
|
e.iterateOverSortedShards(addr, func(_ int, sh *shard.Shard) (stop bool) {
|
|
|
|
res, err := sh.Exists(shPrm)
|
|
|
|
if err != nil {
|
|
|
|
if errors.Is(err, object.ErrAlreadyRemoved) {
|
|
|
|
alreadyRemoved = true
|
|
|
|
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: smth wrong with shard, need to be processed
|
|
|
|
e.log.Warn("could not check existence of object in shard",
|
|
|
|
zap.Stringer("shard", sh.ID()),
|
|
|
|
zap.String("error", err.Error()),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
if res != nil && !exists {
|
|
|
|
exists = res.Exists()
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
})
|
|
|
|
|
|
|
|
if alreadyRemoved {
|
|
|
|
return false, object.ErrAlreadyRemoved
|
|
|
|
}
|
|
|
|
|
|
|
|
return exists, nil
|
|
|
|
}
|