[#222] Move ErrAlreadyRemoved to core package

Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
Alex Vanin 2020-12-01 13:48:28 +03:00
parent 6a3e3e5642
commit 67d4b0db12
8 changed files with 18 additions and 31 deletions

View file

@ -9,3 +9,6 @@ var ErrNotFound = errors.New("object not found")
// ErrRangeOutOfBounds is a basic error of violation of the boundaries of the // ErrRangeOutOfBounds is a basic error of violation of the boundaries of the
// payload of an object. // payload of an object.
var ErrRangeOutOfBounds = errors.New("payload range is out of bounds") var ErrRangeOutOfBounds = errors.New("payload range is out of bounds")
// ErrAlreadyRemoved returned when object has tombstone in graveyard.
var ErrAlreadyRemoved = errors.New("object already removed")

View file

@ -5,7 +5,6 @@ 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/nspcc-dev/neofs-node/pkg/core/object"
meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase/v2"
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard"
"go.uber.org/zap" "go.uber.org/zap"
) )
@ -58,7 +57,7 @@ func (e *StorageEngine) Get(prm *GetPrm) (*GetRes, error) {
switch { switch {
case errors.Is(err, object.ErrNotFound): case errors.Is(err, object.ErrNotFound):
return false // ignore, go to next shard return false // ignore, go to next shard
case errors.Is(err, meta.ErrAlreadyRemoved): case errors.Is(err, object.ErrAlreadyRemoved):
alreadyRemoved = true alreadyRemoved = true
return true // stop, return it back return true // stop, return it back
@ -81,7 +80,7 @@ func (e *StorageEngine) Get(prm *GetPrm) (*GetRes, error) {
if obj == nil { if obj == nil {
if alreadyRemoved { if alreadyRemoved {
return nil, meta.ErrAlreadyRemoved return nil, object.ErrAlreadyRemoved
} }
return nil, object.ErrNotFound return nil, object.ErrNotFound

View file

@ -4,7 +4,6 @@ import (
"errors" "errors"
"github.com/nspcc-dev/neofs-node/pkg/core/object" "github.com/nspcc-dev/neofs-node/pkg/core/object"
meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase/v2"
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard"
"go.uber.org/zap" "go.uber.org/zap"
) )
@ -43,7 +42,7 @@ func (e *StorageEngine) Put(prm *PutPrm) (*PutRes, error) {
// todo: make this check parallel // todo: make this check parallel
e.iterateOverUnsortedShards(func(s *shard.Shard) (stop bool) { e.iterateOverUnsortedShards(func(s *shard.Shard) (stop bool) {
_, err := s.Exists(existPrm) _, err := s.Exists(existPrm)
if err != nil && errors.Is(err, meta.ErrAlreadyRemoved) { if err != nil && errors.Is(err, object.ErrAlreadyRemoved) {
alreadyRemoved = true alreadyRemoved = true
return true return true
@ -53,7 +52,7 @@ func (e *StorageEngine) Put(prm *PutPrm) (*PutRes, error) {
}) })
if alreadyRemoved { if alreadyRemoved {
return nil, meta.ErrAlreadyRemoved return nil, object.ErrAlreadyRemoved
} }
finished := false finished := false

View file

@ -5,7 +5,6 @@ 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/nspcc-dev/neofs-node/pkg/core/object"
meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase/v2"
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard"
"go.uber.org/zap" "go.uber.org/zap"
) )
@ -75,7 +74,7 @@ func (e *StorageEngine) GetRange(prm *RngPrm) (*RngRes, error) {
switch { switch {
case errors.Is(err, object.ErrNotFound): case errors.Is(err, object.ErrNotFound):
return false // ignore, go to next shard return false // ignore, go to next shard
case errors.Is(err, meta.ErrAlreadyRemoved): case errors.Is(err, object.ErrAlreadyRemoved):
alreadyRemoved = true alreadyRemoved = true
return true // stop, return it back return true // stop, return it back
@ -98,7 +97,7 @@ func (e *StorageEngine) GetRange(prm *RngPrm) (*RngRes, error) {
if obj == nil { if obj == nil {
if alreadyRemoved { if alreadyRemoved {
return nil, meta.ErrAlreadyRemoved return nil, object.ErrAlreadyRemoved
} }
return nil, object.ErrNotFound return nil, object.ErrNotFound

View file

@ -1,14 +0,0 @@
package meta
import (
"errors"
)
var (
// ErrNotFound returned when object header should exist in primary index but
// it is not present there.
ErrNotFound = errors.New("address not found")
// ErrAlreadyRemoved returned when object has tombstone in graveyard.
ErrAlreadyRemoved = errors.New("object already removed")
)

View file

@ -2,6 +2,7 @@ package meta
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"
) )
@ -20,7 +21,7 @@ func (db *DB) Exists(addr *objectSDK.Address) (exists bool, err error) {
func (db *DB) exists(tx *bbolt.Tx, addr *objectSDK.Address) (exists bool, err error) { func (db *DB) exists(tx *bbolt.Tx, addr *objectSDK.Address) (exists bool, err error) {
// check graveyard first // check graveyard first
if inGraveyard(tx, addr) { if inGraveyard(tx, addr) {
return false, ErrAlreadyRemoved return false, object.ErrAlreadyRemoved
} }
objKey := objectKey(addr.ObjectID()) objKey := objectKey(addr.ObjectID())

View file

@ -26,7 +26,7 @@ func (db *DB) get(tx *bbolt.Tx, addr *objectSDK.Address, checkGraveyard bool) (*
cid := addr.ContainerID() cid := addr.ContainerID()
if checkGraveyard && inGraveyard(tx, addr) { if checkGraveyard && inGraveyard(tx, addr) {
return nil, ErrAlreadyRemoved return nil, object.ErrAlreadyRemoved
} }
// check in primary index // check in primary index
@ -63,7 +63,7 @@ func getFromBucket(tx *bbolt.Tx, name, key []byte) []byte {
func getVirtualObject(tx *bbolt.Tx, cid *container.ID, key []byte) (*object.Object, error) { func getVirtualObject(tx *bbolt.Tx, cid *container.ID, key []byte) (*object.Object, error) {
parentBucket := tx.Bucket(parentBucketName(cid)) parentBucket := tx.Bucket(parentBucketName(cid))
if parentBucket == nil { if parentBucket == nil {
return nil, ErrNotFound return nil, object.ErrNotFound
} }
relativeLst, err := decodeList(parentBucket.Get(key)) relativeLst, err := decodeList(parentBucket.Get(key))
@ -72,7 +72,7 @@ func getVirtualObject(tx *bbolt.Tx, cid *container.ID, key []byte) (*object.Obje
} }
if len(relativeLst) == 0 { // this should never happen though if len(relativeLst) == 0 { // this should never happen though
return nil, ErrNotFound return nil, object.ErrNotFound
} }
// pick last item, for now there is not difference which address to pick // pick last item, for now there is not difference which address to pick
@ -89,7 +89,7 @@ func getVirtualObject(tx *bbolt.Tx, cid *container.ID, key []byte) (*object.Obje
} }
if child.GetParent() == nil { // this should never happen though if child.GetParent() == nil { // this should never happen though
return nil, ErrNotFound return nil, object.ErrNotFound
} }
return child.GetParent(), nil return child.GetParent(), nil

View file

@ -3,7 +3,7 @@ package meta_test
import ( import (
"testing" "testing"
meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase/v2" "github.com/nspcc-dev/neofs-node/pkg/core/object"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
@ -23,8 +23,8 @@ func TestDB_Inhume(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
_, err = db.Exists(raw.Object().Address()) _, err = db.Exists(raw.Object().Address())
require.EqualError(t, err, meta.ErrAlreadyRemoved.Error()) require.EqualError(t, err, object.ErrAlreadyRemoved.Error())
_, err = db.Get(raw.Object().Address()) _, err = db.Get(raw.Object().Address())
require.EqualError(t, err, meta.ErrAlreadyRemoved.Error()) require.EqualError(t, err, object.ErrAlreadyRemoved.Error())
} }