From 40a56c6b424195414656fe885501fe75f3aacf32 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Fri, 1 Jul 2022 14:21:33 +0300 Subject: [PATCH] [#1559] engine: Do not count logical errors as storage ones Signed-off-by: Evgenii Stratonikov --- pkg/local_object_storage/engine/delete.go | 9 ++++++++- pkg/local_object_storage/engine/exists.go | 10 +++++++++- .../metabase/exists_test.go | 19 +++++++++++++++++++ 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/pkg/local_object_storage/engine/delete.go b/pkg/local_object_storage/engine/delete.go index 45fec21df..ccf64ca6d 100644 --- a/pkg/local_object_storage/engine/delete.go +++ b/pkg/local_object_storage/engine/delete.go @@ -5,6 +5,7 @@ import ( "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard" apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status" + objectSDK "github.com/nspcc-dev/neofs-sdk-go/object" oid "github.com/nspcc-dev/neofs-sdk-go/object/id" ) @@ -72,7 +73,13 @@ func (e *StorageEngine) delete(prm DeletePrm) (DeleteRes, error) { resExists, err := sh.Exists(existsPrm) if err != nil { - e.reportShardError(sh, "could not check object existence", err) + _, ok := err.(*objectSDK.SplitInfoError) + if ok || shard.IsErrRemoved(err) { + return true + } + if !shard.IsErrNotFound(err) { + e.reportShardError(sh, "could not check object existence", err) + } return false } else if !resExists.Exists() { return false diff --git a/pkg/local_object_storage/engine/exists.go b/pkg/local_object_storage/engine/exists.go index 4822752d8..a0d8549ec 100644 --- a/pkg/local_object_storage/engine/exists.go +++ b/pkg/local_object_storage/engine/exists.go @@ -3,6 +3,7 @@ package engine import ( "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard" apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status" + objectSDK "github.com/nspcc-dev/neofs-sdk-go/object" oid "github.com/nspcc-dev/neofs-sdk-go/object/id" ) @@ -21,7 +22,14 @@ func (e *StorageEngine) exists(addr oid.Address) (bool, error) { return true } - e.reportShardError(sh, "could not check existence of object in shard", err) + _, ok := err.(*objectSDK.SplitInfoError) + if ok { + return true + } + if !shard.IsErrNotFound(err) { + e.reportShardError(sh, "could not check existence of object in shard", err) + } + return false } if !exists { diff --git a/pkg/local_object_storage/metabase/exists_test.go b/pkg/local_object_storage/metabase/exists_test.go index 8e03c0f89..155d04be9 100644 --- a/pkg/local_object_storage/metabase/exists_test.go +++ b/pkg/local_object_storage/metabase/exists_test.go @@ -5,8 +5,10 @@ import ( "testing" "github.com/nspcc-dev/neofs-node/pkg/core/object" + apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status" cidtest "github.com/nspcc-dev/neofs-sdk-go/container/id/test" objectSDK "github.com/nspcc-dev/neofs-sdk-go/object" + oidtest "github.com/nspcc-dev/neofs-sdk-go/object/id/test" "github.com/stretchr/testify/require" ) @@ -28,6 +30,15 @@ func TestDB_Exists(t *testing.T) { exists, err := metaExists(db, object.AddressOf(regular)) require.NoError(t, err) require.True(t, exists) + + t.Run("removed object", func(t *testing.T) { + err := metaInhume(db, object.AddressOf(regular), oidtest.Address()) + require.NoError(t, err) + + exists, err := metaExists(db, object.AddressOf(regular)) + require.ErrorAs(t, err, new(apistatus.ObjectAlreadyRemoved)) + require.False(t, exists) + }) }) t.Run("tombstone object", func(t *testing.T) { @@ -152,4 +163,12 @@ func TestDB_Exists(t *testing.T) { require.Equal(t, id1, id2) }) }) + + t.Run("random object", func(t *testing.T) { + addr := oidtest.Address() + + exists, err := metaExists(db, addr) + require.NoError(t, err) + require.False(t, exists) + }) }