frostfs-node/pkg/local_object_storage/shard/exists.go
Leonard Lyubich 70ffdf3478 [#1247] object: Return NOT_FOUND and ALREADY_REMOVED statuses
Replace `ErrNotFound`/`ErrAlreadyRemoved` error from
`pkg/core/object` package with `ObjectNotFound`/`ObjectAlreadyRemoved`
one from `apistatus` package. These errors are returned by storage
node's server as NeoFS API statuses.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
2022-03-17 16:34:00 +03:00

48 lines
1.1 KiB
Go

package shard
import (
meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase"
addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address"
)
// ExistsPrm groups the parameters of Exists operation.
type ExistsPrm struct {
addr *addressSDK.Address
}
// ExistsRes groups resulting values of Exists operation.
type ExistsRes struct {
ex bool
}
// WithAddress is an Exists option to set object checked for existence.
func (p *ExistsPrm) WithAddress(addr *addressSDK.Address) *ExistsPrm {
if p != nil {
p.addr = addr
}
return p
}
// Exists returns the fact that the object is in the shard.
func (p *ExistsRes) Exists() bool {
return p.ex
}
// Exists checks if object is presented in shard.
//
// Returns any error encountered that does not allow to
// unambiguously determine the presence of an object.
//
// Returns apistatus.ObjectAlreadyRemoved if object has been marked as removed.
func (s *Shard) Exists(prm *ExistsPrm) (*ExistsRes, error) {
exists, err := s.objectExists(prm.addr)
return &ExistsRes{
ex: exists,
}, err
}
func (s *Shard) objectExists(addr *addressSDK.Address) (bool, error) {
return meta.Exists(s.metaBase, addr)
}