diff --git a/pkg/core/object/errors.go b/pkg/core/object/errors.go index fe872d29..b09c1c35 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 041f660f..8bc69ede 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 07147719..55d212aa 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 8736224f..1afb8b25 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 33ba78d5..00000000 --- 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 4ccefa0a..34b73e26 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 7b7a1015..695ad8fb 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 b1ea9c46..6ec30435 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()) }