From 67d4b0db12fb069a35de5b6efb715068926d81f5 Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Tue, 1 Dec 2020 13:48:28 +0300 Subject: [PATCH] [#222] Move ErrAlreadyRemoved to core package Signed-off-by: Alex Vanin --- pkg/core/object/errors.go | 3 +++ pkg/local_object_storage/engine/get.go | 5 ++--- pkg/local_object_storage/engine/put.go | 5 ++--- pkg/local_object_storage/engine/range.go | 5 ++--- pkg/local_object_storage/metabase/v2/errors.go | 14 -------------- pkg/local_object_storage/metabase/v2/exists.go | 3 ++- pkg/local_object_storage/metabase/v2/get.go | 8 ++++---- .../metabase/v2/inhume_test.go | 6 +++--- 8 files changed, 18 insertions(+), 31 deletions(-) delete mode 100644 pkg/local_object_storage/metabase/v2/errors.go diff --git a/pkg/core/object/errors.go b/pkg/core/object/errors.go index fe872d293..b09c1c35f 100644 --- a/pkg/core/object/errors.go +++ b/pkg/core/object/errors.go @@ -9,3 +9,6 @@ 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") + +// ErrAlreadyRemoved returned when object has tombstone in graveyard. +var ErrAlreadyRemoved = errors.New("object already removed") diff --git a/pkg/local_object_storage/engine/get.go b/pkg/local_object_storage/engine/get.go index 041f660f5..8bc69edeb 100644 --- a/pkg/local_object_storage/engine/get.go +++ b/pkg/local_object_storage/engine/get.go @@ -5,7 +5,6 @@ import ( objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/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" "go.uber.org/zap" ) @@ -58,7 +57,7 @@ func (e *StorageEngine) Get(prm *GetPrm) (*GetRes, error) { switch { case errors.Is(err, object.ErrNotFound): return false // ignore, go to next shard - case errors.Is(err, meta.ErrAlreadyRemoved): + case errors.Is(err, object.ErrAlreadyRemoved): alreadyRemoved = true return true // stop, return it back @@ -81,7 +80,7 @@ func (e *StorageEngine) Get(prm *GetPrm) (*GetRes, error) { if obj == nil { if alreadyRemoved { - return nil, meta.ErrAlreadyRemoved + return nil, object.ErrAlreadyRemoved } return nil, object.ErrNotFound diff --git a/pkg/local_object_storage/engine/put.go b/pkg/local_object_storage/engine/put.go index 071477192..55d212aa2 100644 --- a/pkg/local_object_storage/engine/put.go +++ b/pkg/local_object_storage/engine/put.go @@ -4,7 +4,6 @@ import ( "errors" "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" "go.uber.org/zap" ) @@ -43,7 +42,7 @@ func (e *StorageEngine) Put(prm *PutPrm) (*PutRes, error) { // todo: make this check parallel e.iterateOverUnsortedShards(func(s *shard.Shard) (stop bool) { _, err := s.Exists(existPrm) - if err != nil && errors.Is(err, meta.ErrAlreadyRemoved) { + if err != nil && errors.Is(err, object.ErrAlreadyRemoved) { alreadyRemoved = true return true @@ -53,7 +52,7 @@ func (e *StorageEngine) Put(prm *PutPrm) (*PutRes, error) { }) if alreadyRemoved { - return nil, meta.ErrAlreadyRemoved + return nil, object.ErrAlreadyRemoved } finished := false diff --git a/pkg/local_object_storage/engine/range.go b/pkg/local_object_storage/engine/range.go index 8736224f5..1afb8b25d 100644 --- a/pkg/local_object_storage/engine/range.go +++ b/pkg/local_object_storage/engine/range.go @@ -5,7 +5,6 @@ import ( objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/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" "go.uber.org/zap" ) @@ -75,7 +74,7 @@ func (e *StorageEngine) GetRange(prm *RngPrm) (*RngRes, error) { switch { case errors.Is(err, object.ErrNotFound): return false // ignore, go to next shard - case errors.Is(err, meta.ErrAlreadyRemoved): + case errors.Is(err, object.ErrAlreadyRemoved): alreadyRemoved = true return true // stop, return it back @@ -98,7 +97,7 @@ func (e *StorageEngine) GetRange(prm *RngPrm) (*RngRes, error) { if obj == nil { if alreadyRemoved { - return nil, meta.ErrAlreadyRemoved + return nil, object.ErrAlreadyRemoved } return nil, object.ErrNotFound diff --git a/pkg/local_object_storage/metabase/v2/errors.go b/pkg/local_object_storage/metabase/v2/errors.go deleted file mode 100644 index 33ba78d5f..000000000 --- a/pkg/local_object_storage/metabase/v2/errors.go +++ /dev/null @@ -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") -) diff --git a/pkg/local_object_storage/metabase/v2/exists.go b/pkg/local_object_storage/metabase/v2/exists.go index 4ccefa0ac..34b73e26a 100644 --- a/pkg/local_object_storage/metabase/v2/exists.go +++ b/pkg/local_object_storage/metabase/v2/exists.go @@ -2,6 +2,7 @@ package meta import ( objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object" + "github.com/nspcc-dev/neofs-node/pkg/core/object" "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) { // check graveyard first if inGraveyard(tx, addr) { - return false, ErrAlreadyRemoved + return false, object.ErrAlreadyRemoved } objKey := objectKey(addr.ObjectID()) diff --git a/pkg/local_object_storage/metabase/v2/get.go b/pkg/local_object_storage/metabase/v2/get.go index 7b7a1015a..695ad8fb2 100644 --- a/pkg/local_object_storage/metabase/v2/get.go +++ b/pkg/local_object_storage/metabase/v2/get.go @@ -26,7 +26,7 @@ func (db *DB) get(tx *bbolt.Tx, addr *objectSDK.Address, checkGraveyard bool) (* cid := addr.ContainerID() if checkGraveyard && inGraveyard(tx, addr) { - return nil, ErrAlreadyRemoved + return nil, object.ErrAlreadyRemoved } // 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) { parentBucket := tx.Bucket(parentBucketName(cid)) if parentBucket == nil { - return nil, ErrNotFound + return nil, object.ErrNotFound } 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 - return nil, ErrNotFound + return nil, object.ErrNotFound } // 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 - return nil, ErrNotFound + return nil, object.ErrNotFound } return child.GetParent(), nil diff --git a/pkg/local_object_storage/metabase/v2/inhume_test.go b/pkg/local_object_storage/metabase/v2/inhume_test.go index b1ea9c469..6ec304354 100644 --- a/pkg/local_object_storage/metabase/v2/inhume_test.go +++ b/pkg/local_object_storage/metabase/v2/inhume_test.go @@ -3,7 +3,7 @@ package meta_test import ( "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" ) @@ -23,8 +23,8 @@ func TestDB_Inhume(t *testing.T) { require.NoError(t, err) _, 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()) - require.EqualError(t, err, meta.ErrAlreadyRemoved.Error()) + require.EqualError(t, err, object.ErrAlreadyRemoved.Error()) }