[#220] localstorage: Replace basic errors to core library

Replace ErrNotFound and ErrRangeOutOfBounds to core/object package in order
to share them across the libraries.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2020-11-30 19:39:05 +03:00 committed by Alex Vanin
parent 7512a5ba18
commit 47d2239332
15 changed files with 68 additions and 82 deletions

11
pkg/core/object/errors.go Normal file
View file

@ -0,0 +1,11 @@
package object
import "github.com/pkg/errors"
// ErrNotFound is a basic "not found" error returned by
// object read functions.
var ErrNotFound = errors.New("object not found")
// ErrRangeOutOfBounds is a basic error of violation of the boundaries of the
// payload of an object.
var ErrRangeOutOfBounds = errors.New("payload range is out of bounds")

View file

@ -109,7 +109,7 @@ func TestBlobovnicza(t *testing.T) {
require.NoError(t, blz.Init()) require.NoError(t, blz.Init())
// try to read non-existent address // try to read non-existent address
testGet(t, blz, testAddress(), nil, ErrObjectNotFound) testGet(t, blz, testAddress(), nil, object.ErrNotFound)
filled := uint64(15 * 1 << 10) filled := uint64(15 * 1 << 10)
@ -124,7 +124,7 @@ func TestBlobovnicza(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
// should return 404 // should return 404
testGet(t, blz, addr, nil, ErrObjectNotFound) testGet(t, blz, addr, nil, object.ErrNotFound)
// fill Blobovnicza fully // fill Blobovnicza fully
for ; filled < sizeLim; filled += objSizeLim { for ; filled < sizeLim; filled += objSizeLim {

View file

@ -2,6 +2,7 @@ package blobovnicza
import ( import (
objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object" objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object"
"github.com/nspcc-dev/neofs-node/pkg/core/object"
"go.etcd.io/bbolt" "go.etcd.io/bbolt"
"go.uber.org/zap" "go.uber.org/zap"
) )
@ -25,7 +26,7 @@ func (p *DeletePrm) SetAddress(addr *objectSDK.Address) {
// Returns any error encountered that // Returns any error encountered that
// did not allow to completely delete the object. // did not allow to completely delete the object.
// //
// Returns ErrObjectNotFound if the object to be deleted is not in blobovnicza. // Returns ErrNotFound if the object to be deleted is not in blobovnicza.
func (b *Blobovnicza) Delete(prm *DeletePrm) (*DeleteRes, error) { func (b *Blobovnicza) Delete(prm *DeletePrm) (*DeleteRes, error) {
addrKey := addressKey(prm.addr) addrKey := addressKey(prm.addr)
@ -62,7 +63,7 @@ func (b *Blobovnicza) Delete(prm *DeletePrm) (*DeleteRes, error) {
}) })
if err == nil && !removed { if err == nil && !removed {
err = ErrObjectNotFound err = object.ErrNotFound
} }
return nil, err return nil, err

View file

@ -18,9 +18,6 @@ type GetRes struct {
obj *object.Object obj *object.Object
} }
// ErrObjectNotFound is returns on read operations requested on a missing object.
var ErrObjectNotFound = errors.New("object not found")
// SetAddress sets address of the requested object. // SetAddress sets address of the requested object.
func (p *GetPrm) SetAddress(addr *objectSDK.Address) { func (p *GetPrm) SetAddress(addr *objectSDK.Address) {
p.addr = addr p.addr = addr
@ -35,6 +32,9 @@ func (p *GetRes) Object() *object.Object {
// //
// Returns any error encountered that // Returns any error encountered that
// did not allow to completely read the object. // did not allow to completely read the object.
//
// Returns ErrNotFound if requested object is not
// presented in Blobovnicza.
func (b *Blobovnicza) Get(prm *GetPrm) (*GetRes, error) { func (b *Blobovnicza) Get(prm *GetPrm) (*GetRes, error) {
var ( var (
data []byte data []byte
@ -61,7 +61,7 @@ func (b *Blobovnicza) Get(prm *GetPrm) (*GetRes, error) {
} }
if data == nil { if data == nil {
return nil, ErrObjectNotFound return nil, object.ErrNotFound
} }
// TODO: add decompression step // TODO: add decompression step

View file

@ -2,6 +2,7 @@ package blobovnicza
import ( import (
objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object" objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object"
"github.com/nspcc-dev/neofs-node/pkg/core/object"
"github.com/pkg/errors" "github.com/pkg/errors"
) )
@ -17,8 +18,6 @@ type GetRangeRes struct {
rngData []byte rngData []byte
} }
var ErrRangeOutOfBounds = errors.New("payload range is out of bounds")
// SetAddress sets address of the requested object. // SetAddress sets address of the requested object.
func (p *GetRangePrm) SetAddress(addr *objectSDK.Address) { func (p *GetRangePrm) SetAddress(addr *objectSDK.Address) {
p.addr = addr p.addr = addr
@ -38,6 +37,10 @@ func (p *GetRangeRes) RangeData() []byte {
// //
// Returns any error encountered that // Returns any error encountered that
// did not allow to completely read the object. // did not allow to completely read the object.
//
// Returns ErrNotFound if requested object is not
// presented in Blobovnicza. Returns ErrRangeOutOfBounds
// if requested range is outside the payload.
func (b *Blobovnicza) GetRange(prm *GetRangePrm) (*GetRangeRes, error) { func (b *Blobovnicza) GetRange(prm *GetRangePrm) (*GetRangeRes, error) {
res, err := b.Get(&GetPrm{ res, err := b.Get(&GetPrm{
addr: prm.addr, addr: prm.addr,
@ -53,7 +56,7 @@ func (b *Blobovnicza) GetRange(prm *GetRangePrm) (*GetRangeRes, error) {
if from > to { if from > to {
return nil, errors.Errorf("invalid range [%d:%d]", from, to) return nil, errors.Errorf("invalid range [%d:%d]", from, to)
} else if uint64(len(payload)) < to { } else if uint64(len(payload)) < to {
return nil, ErrRangeOutOfBounds return nil, object.ErrRangeOutOfBounds
} }
return &GetRangeRes{ return &GetRangeRes{

View file

@ -9,6 +9,7 @@ import (
lru "github.com/hashicorp/golang-lru" lru "github.com/hashicorp/golang-lru"
"github.com/nspcc-dev/hrw" "github.com/nspcc-dev/hrw"
objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object" objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object"
"github.com/nspcc-dev/neofs-node/pkg/core/object"
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobovnicza" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobovnicza"
"github.com/pkg/errors" "github.com/pkg/errors"
"go.uber.org/zap" "go.uber.org/zap"
@ -216,7 +217,7 @@ func (b *blobovniczas) get(prm *GetSmallPrm) (res *GetSmallRes, err error) {
res, err = b.getObjectFromLevel(bPrm, p, !ok) res, err = b.getObjectFromLevel(bPrm, p, !ok)
if err != nil { if err != nil {
if !errors.Is(err, ErrObjectNotFound) { if !errors.Is(err, object.ErrNotFound) {
b.log.Debug("could not get object from level", b.log.Debug("could not get object from level",
zap.String("level", p), zap.String("level", p),
zap.String("error", err.Error()), zap.String("error", err.Error()),
@ -232,7 +233,7 @@ func (b *blobovniczas) get(prm *GetSmallPrm) (res *GetSmallRes, err error) {
if err == nil && res == nil { if err == nil && res == nil {
// not found in any blobovnicza // not found in any blobovnicza
err = ErrObjectNotFound err = object.ErrNotFound
} }
return return
@ -267,7 +268,7 @@ func (b *blobovniczas) delete(prm *DeleteSmallPrm) (res *DeleteSmallRes, err err
res, err = b.deleteObjectFromLevel(bPrm, p, !ok) res, err = b.deleteObjectFromLevel(bPrm, p, !ok)
if err != nil { if err != nil {
if !errors.Is(err, ErrObjectNotFound) { if !errors.Is(err, object.ErrNotFound) {
b.log.Debug("could not remove object from level", b.log.Debug("could not remove object from level",
zap.String("level", p), zap.String("level", p),
zap.String("error", err.Error()), zap.String("error", err.Error()),
@ -287,7 +288,7 @@ func (b *blobovniczas) delete(prm *DeleteSmallPrm) (res *DeleteSmallRes, err err
if err == nil && res == nil { if err == nil && res == nil {
// not found in any blobovnicza // not found in any blobovnicza
err = ErrObjectNotFound err = object.ErrNotFound
} }
return return
@ -322,7 +323,7 @@ func (b *blobovniczas) getRange(prm *GetRangeSmallPrm) (res *GetRangeSmallRes, e
res, err = b.getRangeFromLevel(bPrm, p, !ok) res, err = b.getRangeFromLevel(bPrm, p, !ok)
if err != nil { if err != nil {
if !errors.Is(err, ErrObjectNotFound) { if !errors.Is(err, object.ErrNotFound) {
b.log.Debug("could not get object from level", b.log.Debug("could not get object from level",
zap.String("level", p), zap.String("level", p),
zap.String("error", err.Error()), zap.String("error", err.Error()),
@ -338,7 +339,7 @@ func (b *blobovniczas) getRange(prm *GetRangeSmallPrm) (res *GetRangeSmallRes, e
if err == nil && res == nil { if err == nil && res == nil {
// not found in any blobovnicza // not found in any blobovnicza
err = ErrObjectNotFound err = object.ErrNotFound
} }
return return
@ -359,7 +360,7 @@ func (b *blobovniczas) deleteObjectFromLevel(prm *blobovnicza.DeletePrm, blzPath
if ok { if ok {
if res, err := b.deleteObject(v.(*blobovnicza.Blobovnicza), prm); err == nil { if res, err := b.deleteObject(v.(*blobovnicza.Blobovnicza), prm); err == nil {
return res, err return res, err
} else if !errors.Is(err, ErrObjectNotFound) { } else if !errors.Is(err, object.ErrNotFound) {
log.Debug("could not remove object from opened blobovnicza", log.Debug("could not remove object from opened blobovnicza",
zap.String("error", err.Error()), zap.String("error", err.Error()),
) )
@ -377,7 +378,7 @@ func (b *blobovniczas) deleteObjectFromLevel(prm *blobovnicza.DeletePrm, blzPath
if ok && tryActive { if ok && tryActive {
if res, err := b.deleteObject(active.blz, prm); err == nil { if res, err := b.deleteObject(active.blz, prm); err == nil {
return res, err return res, err
} else if !errors.Is(err, ErrObjectNotFound) { } else if !errors.Is(err, object.ErrNotFound) {
log.Debug("could not remove object from active blobovnicza", log.Debug("could not remove object from active blobovnicza",
zap.String("error", err.Error()), zap.String("error", err.Error()),
) )
@ -391,7 +392,7 @@ func (b *blobovniczas) deleteObjectFromLevel(prm *blobovnicza.DeletePrm, blzPath
// and it's pointless to open them). // and it's pointless to open them).
if u64FromHexString(path.Base(blzPath)) > active.ind { if u64FromHexString(path.Base(blzPath)) > active.ind {
log.Debug("index is too big") log.Debug("index is too big")
return nil, ErrObjectNotFound return nil, object.ErrNotFound
} }
// open blobovnicza (cached inside) // open blobovnicza (cached inside)
@ -418,7 +419,7 @@ func (b *blobovniczas) getObjectFromLevel(prm *blobovnicza.GetPrm, blzPath strin
if ok { if ok {
if res, err := b.getObject(v.(*blobovnicza.Blobovnicza), prm); err == nil { if res, err := b.getObject(v.(*blobovnicza.Blobovnicza), prm); err == nil {
return res, err return res, err
} else if !errors.Is(err, ErrObjectNotFound) { } else if !errors.Is(err, object.ErrNotFound) {
log.Debug("could not read object from opened blobovnicza", log.Debug("could not read object from opened blobovnicza",
zap.String("error", err.Error()), zap.String("error", err.Error()),
) )
@ -437,7 +438,7 @@ func (b *blobovniczas) getObjectFromLevel(prm *blobovnicza.GetPrm, blzPath strin
if ok && tryActive { if ok && tryActive {
if res, err := b.getObject(active.blz, prm); err == nil { if res, err := b.getObject(active.blz, prm); err == nil {
return res, err return res, err
} else if !errors.Is(err, ErrObjectNotFound) { } else if !errors.Is(err, object.ErrNotFound) {
log.Debug("could not get object from active blobovnicza", log.Debug("could not get object from active blobovnicza",
zap.String("error", err.Error()), zap.String("error", err.Error()),
) )
@ -451,7 +452,7 @@ func (b *blobovniczas) getObjectFromLevel(prm *blobovnicza.GetPrm, blzPath strin
// and it's pointless to open them). // and it's pointless to open them).
if u64FromHexString(path.Base(blzPath)) > active.ind { if u64FromHexString(path.Base(blzPath)) > active.ind {
log.Debug("index is too big") log.Debug("index is too big")
return nil, ErrObjectNotFound return nil, object.ErrNotFound
} }
// open blobovnicza (cached inside) // open blobovnicza (cached inside)
@ -478,7 +479,7 @@ func (b *blobovniczas) getRangeFromLevel(prm *blobovnicza.GetRangePrm, blzPath s
if ok { if ok {
if res, err := b.getObjectRange(v.(*blobovnicza.Blobovnicza), prm); err == nil { if res, err := b.getObjectRange(v.(*blobovnicza.Blobovnicza), prm); err == nil {
return res, err return res, err
} else if !errors.Is(err, ErrObjectNotFound) { } else if !errors.Is(err, object.ErrNotFound) {
log.Debug("could not read payload range from opened blobovnicza", log.Debug("could not read payload range from opened blobovnicza",
zap.String("error", err.Error()), zap.String("error", err.Error()),
) )
@ -497,7 +498,7 @@ func (b *blobovniczas) getRangeFromLevel(prm *blobovnicza.GetRangePrm, blzPath s
if ok && tryActive { if ok && tryActive {
if res, err := b.getObjectRange(active.blz, prm); err == nil { if res, err := b.getObjectRange(active.blz, prm); err == nil {
return res, err return res, err
} else if !errors.Is(err, ErrObjectNotFound) { } else if !errors.Is(err, object.ErrNotFound) {
log.Debug("could not read payload range from active blobovnicza", log.Debug("could not read payload range from active blobovnicza",
zap.String("error", err.Error()), zap.String("error", err.Error()),
) )
@ -511,7 +512,7 @@ func (b *blobovniczas) getRangeFromLevel(prm *blobovnicza.GetRangePrm, blzPath s
// and it's pointless to open them). // and it's pointless to open them).
if u64FromHexString(path.Base(blzPath)) > active.ind { if u64FromHexString(path.Base(blzPath)) > active.ind {
log.Debug("index is too big") log.Debug("index is too big")
return nil, ErrObjectNotFound return nil, object.ErrNotFound
} }
// open blobovnicza (cached inside) // open blobovnicza (cached inside)
@ -527,10 +528,6 @@ func (b *blobovniczas) getRangeFromLevel(prm *blobovnicza.GetRangePrm, blzPath s
func (b *blobovniczas) deleteObject(blz *blobovnicza.Blobovnicza, prm *blobovnicza.DeletePrm) (*DeleteSmallRes, error) { func (b *blobovniczas) deleteObject(blz *blobovnicza.Blobovnicza, prm *blobovnicza.DeletePrm) (*DeleteSmallRes, error) {
_, err := blz.Delete(prm) _, err := blz.Delete(prm)
if err != nil { if err != nil {
if errors.Is(err, blobovnicza.ErrObjectNotFound) {
err = ErrObjectNotFound
}
return nil, err return nil, err
} }
@ -541,10 +538,6 @@ func (b *blobovniczas) deleteObject(blz *blobovnicza.Blobovnicza, prm *blobovnic
func (b *blobovniczas) getObject(blz *blobovnicza.Blobovnicza, prm *blobovnicza.GetPrm) (*GetSmallRes, error) { func (b *blobovniczas) getObject(blz *blobovnicza.Blobovnicza, prm *blobovnicza.GetPrm) (*GetSmallRes, error) {
res, err := blz.Get(prm) res, err := blz.Get(prm)
if err != nil { if err != nil {
if errors.Is(err, blobovnicza.ErrObjectNotFound) {
err = ErrObjectNotFound
}
return nil, err return nil, err
} }
@ -559,10 +552,6 @@ func (b *blobovniczas) getObject(blz *blobovnicza.Blobovnicza, prm *blobovnicza.
func (b *blobovniczas) getObjectRange(blz *blobovnicza.Blobovnicza, prm *blobovnicza.GetRangePrm) (*GetRangeSmallRes, error) { func (b *blobovniczas) getObjectRange(blz *blobovnicza.Blobovnicza, prm *blobovnicza.GetRangePrm) (*GetRangeSmallRes, error) {
res, err := blz.GetRange(prm) res, err := blz.GetRange(prm)
if err != nil { if err != nil {
if errors.Is(err, blobovnicza.ErrObjectNotFound) {
err = ErrObjectNotFound
}
return nil, err return nil, err
} }

View file

@ -152,9 +152,9 @@ func TestBlobovniczas(t *testing.T) {
gPrm.SetAddress(addrList[i]) gPrm.SetAddress(addrList[i])
_, err = b.get(gPrm) _, err = b.get(gPrm)
require.True(t, errors.Is(err, ErrObjectNotFound)) require.True(t, errors.Is(err, object.ErrNotFound))
_, err = b.delete(dPrm) _, err = b.delete(dPrm)
require.True(t, errors.Is(err, ErrObjectNotFound)) require.True(t, errors.Is(err, object.ErrNotFound))
} }
} }

View file

@ -3,7 +3,8 @@ package blobstor
import ( import (
"os" "os"
"github.com/nspcc-dev/neofs-api-go/pkg/object" objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object"
"github.com/nspcc-dev/neofs-node/pkg/core/object"
"github.com/pkg/errors" "github.com/pkg/errors"
) )
@ -20,17 +21,17 @@ type DeleteBigRes struct{}
// Returns any error encountered that did not allow // Returns any error encountered that did not allow
// to completely remove the object. // to completely remove the object.
// //
// Returns ErrObjectNotFound if there is no object to delete. // Returns ErrNotFound if there is no object to delete.
func (b *BlobStor) DeleteBig(prm *DeleteBigPrm) (*DeleteBigRes, error) { func (b *BlobStor) DeleteBig(prm *DeleteBigPrm) (*DeleteBigRes, error) {
err := b.fsTree.delete(prm.addr) err := b.fsTree.delete(prm.addr)
if errors.Is(err, errFileNotFound) { if errors.Is(err, errFileNotFound) {
err = ErrObjectNotFound err = object.ErrNotFound
} }
return nil, err return nil, err
} }
func (t *fsTree) delete(addr *object.Address) error { func (t *fsTree) delete(addr *objectSDK.Address) error {
p, err := t.exists(addr) p, err := t.exists(addr)
if err != nil { if err != nil {
return err return err

View file

@ -19,19 +19,19 @@ type GetBigRes struct {
roObject roObject
} }
// ErrObjectNotFound is returns on read operations requested on a missing object.
var ErrObjectNotFound = errors.New("object not found")
// GetBig reads the object from shallow dir of BLOB storage by address. // GetBig reads the object from shallow dir of BLOB storage by address.
// //
// Returns any error encountered that // Returns any error encountered that
// did not allow to completely read the object. // did not allow to completely read the object.
//
// Returns ErrNotFound if requested object is not
// presented in shallow dir.
func (b *BlobStor) GetBig(prm *GetBigPrm) (*GetBigRes, error) { func (b *BlobStor) GetBig(prm *GetBigPrm) (*GetBigRes, error) {
// get compressed object data // get compressed object data
data, err := b.fsTree.get(prm.addr) data, err := b.fsTree.get(prm.addr)
if err != nil { if err != nil {
if errors.Is(err, errFileNotFound) { if errors.Is(err, errFileNotFound) {
return nil, ErrObjectNotFound return nil, object.ErrNotFound
} }
return nil, errors.Wrap(err, "could not read object from fs tree") return nil, errors.Wrap(err, "could not read object from fs tree")

View file

@ -21,9 +21,6 @@ type GetRes struct {
obj *object.Object obj *object.Object
} }
// ErrObjectNotFound is returns on read operations requested on a missing object.
var ErrObjectNotFound = errors.New("object not found")
// WithAddress is a Get option to set the address of the requested object. // WithAddress is a Get option to set the address of the requested object.
// //
// Option is required. // Option is required.
@ -59,7 +56,7 @@ func (r *GetRes) Object() *object.Object {
// Returns any error encountered that // Returns any error encountered that
// did not allow to completely read the object part. // did not allow to completely read the object part.
// //
// Returns ErrObjectNotFound if requested object is missing in local storage. // Returns ErrNotFound if requested object is missing in local storage.
func (e *StorageEngine) Get(prm *GetPrm) (*GetRes, error) { func (e *StorageEngine) Get(prm *GetPrm) (*GetRes, error) {
var obj *object.Object var obj *object.Object
@ -75,7 +72,7 @@ func (e *StorageEngine) Get(prm *GetPrm) (*GetRes, error) {
e.iterateOverSortedShards(prm.addr, func(sh *shard.Shard) (stop bool) { e.iterateOverSortedShards(prm.addr, func(sh *shard.Shard) (stop bool) {
res, err := sh.Get(shPrm) res, err := sh.Get(shPrm)
if err != nil { if err != nil {
if !errors.Is(err, shard.ErrObjectNotFound) { if !errors.Is(err, object.ErrNotFound) {
// TODO: smth wrong with shard, need to be processed // TODO: smth wrong with shard, need to be processed
e.log.Warn("could not get object from shard", e.log.Warn("could not get object from shard",
zap.Stringer("shard", sh.ID()), zap.Stringer("shard", sh.ID()),
@ -90,7 +87,7 @@ func (e *StorageEngine) Get(prm *GetPrm) (*GetRes, error) {
}) })
if obj == nil { if obj == nil {
return nil, ErrObjectNotFound return nil, object.ErrNotFound
} }
return &GetRes{ return &GetRes{

View file

@ -41,7 +41,7 @@ func (r *HeadRes) Header() *object.Object {
// Returns any error encountered that // Returns any error encountered that
// did not allow to completely read the object header. // did not allow to completely read the object header.
// //
// Returns ErrObjectNotFound if requested object is missing in local storage. // Returns ErrNotFound if requested object is missing in local storage.
func (e *StorageEngine) Head(prm *HeadPrm) (*HeadRes, error) { func (e *StorageEngine) Head(prm *HeadPrm) (*HeadRes, error) {
var head *object.Object var head *object.Object
@ -51,7 +51,7 @@ func (e *StorageEngine) Head(prm *HeadPrm) (*HeadRes, error) {
e.iterateOverSortedShards(prm.addr, func(sh *shard.Shard) (stop bool) { e.iterateOverSortedShards(prm.addr, func(sh *shard.Shard) (stop bool) {
res, err := sh.Get(shPrm) res, err := sh.Get(shPrm)
if err != nil { if err != nil {
if !errors.Is(err, shard.ErrObjectNotFound) { if !errors.Is(err, object.ErrNotFound) {
// TODO: smth wrong with shard, need to be processed // TODO: smth wrong with shard, need to be processed
e.log.Warn("could not get object from shard", e.log.Warn("could not get object from shard",
zap.Stringer("shard", sh.ID()), zap.Stringer("shard", sh.ID()),
@ -66,7 +66,7 @@ func (e *StorageEngine) Head(prm *HeadPrm) (*HeadRes, error) {
}) })
if head == nil { if head == nil {
return nil, ErrObjectNotFound return nil, object.ErrNotFound
} }
return &HeadRes{ return &HeadRes{

View file

@ -244,7 +244,7 @@ func TestVirtualObject(t *testing.T) {
// parent object must not be readable // parent object must not be readable
_, err = db.Get(parAddr) _, err = db.Get(parAddr)
require.True(t, errors.Is(err, errNotFound)) require.True(t, errors.Is(err, object.ErrNotFound))
fs := objectSDK.SearchFilters{} fs := objectSDK.SearchFilters{}

View file

@ -1,16 +1,17 @@
package meta package meta
import ( import (
"github.com/nspcc-dev/neofs-api-go/pkg/object" objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object"
"github.com/nspcc-dev/neofs-node/pkg/core/object"
"github.com/pkg/errors" "github.com/pkg/errors"
) )
// Exists checks if object is presented in metabase. // Exists checks if object is presented in metabase.
func (db *DB) Exists(addr *object.Address) (bool, error) { func (db *DB) Exists(addr *objectSDK.Address) (bool, error) {
// FIXME: temp solution, avoid direct Get usage // FIXME: temp solution, avoid direct Get usage
_, err := db.Get(addr) _, err := db.Get(addr)
if err != nil { if err != nil {
if errors.Is(err, errNotFound) { if errors.Is(err, object.ErrNotFound) {
return false, nil return false, nil
} }

View file

@ -1,15 +1,11 @@
package meta package meta
import ( import (
"errors"
objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object" objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object"
"github.com/nspcc-dev/neofs-node/pkg/core/object" "github.com/nspcc-dev/neofs-node/pkg/core/object"
"go.etcd.io/bbolt" "go.etcd.io/bbolt"
) )
var errNotFound = errors.New("object not found")
// Get returns object header for specified address. // Get returns object header for specified address.
func (db *DB) Get(addr *objectSDK.Address) (*object.Object, error) { func (db *DB) Get(addr *objectSDK.Address) (*object.Object, error) {
var obj *object.Object var obj *object.Object
@ -19,17 +15,17 @@ func (db *DB) Get(addr *objectSDK.Address) (*object.Object, error) {
// check if object marked as deleted // check if object marked as deleted
if objectRemoved(tx, addrKey) { if objectRemoved(tx, addrKey) {
return errNotFound return object.ErrNotFound
} }
primaryBucket := tx.Bucket(primaryBucket) primaryBucket := tx.Bucket(primaryBucket)
if primaryBucket == nil { if primaryBucket == nil {
return errNotFound return object.ErrNotFound
} }
data := primaryBucket.Get(addrKey) data := primaryBucket.Get(addrKey)
if data == nil { if data == nil {
return errNotFound return object.ErrNotFound
} }
var err error var err error

View file

@ -1,8 +1,6 @@
package shard package shard
import ( import (
"errors"
objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object" objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object"
"github.com/nspcc-dev/neofs-node/pkg/core/object" "github.com/nspcc-dev/neofs-node/pkg/core/object"
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor"
@ -22,9 +20,6 @@ type GetRes struct {
obj *object.Object obj *object.Object
} }
// ErrObjectNotFound is returns on read operations requested on a missing object.
var ErrObjectNotFound = errors.New("object not found")
// WithAddress is a Get option to set the address of the requested object. // WithAddress is a Get option to set the address of the requested object.
// //
// Option is required. // Option is required.
@ -72,7 +67,7 @@ func (r *GetRes) Object() *object.Object {
// Returns any error encountered that // Returns any error encountered that
// did not allow to completely read the object part. // did not allow to completely read the object part.
// //
// Returns ErrObjectNotFound if requested object is missing in shard. // Returns ErrNotFound if requested object is missing in shard.
func (s *Shard) Get(prm *GetPrm) (*GetRes, error) { func (s *Shard) Get(prm *GetPrm) (*GetRes, error) {
if prm.ln < 0 { if prm.ln < 0 {
// try to read from WriteCache // try to read from WriteCache
@ -84,10 +79,6 @@ func (s *Shard) Get(prm *GetPrm) (*GetRes, error) {
res, err := s.blobStor.GetBig(getBigPrm) res, err := s.blobStor.GetBig(getBigPrm)
if err != nil { if err != nil {
if errors.Is(err, blobstor.ErrObjectNotFound) {
err = ErrObjectNotFound
}
return nil, err return nil, err
} }
@ -120,10 +111,6 @@ func (s *Shard) Get(prm *GetPrm) (*GetRes, error) {
res, err := s.blobStor.GetRangeBig(getRngBigPrm) res, err := s.blobStor.GetRangeBig(getRngBigPrm)
if err != nil { if err != nil {
if errors.Is(err, blobstor.ErrObjectNotFound) {
err = ErrObjectNotFound
}
return nil, err return nil, err
} }