diff --git a/pkg/local_object_storage/engine/inhume.go b/pkg/local_object_storage/engine/inhume.go index 2cf0e82529..f39ac404f5 100644 --- a/pkg/local_object_storage/engine/inhume.go +++ b/pkg/local_object_storage/engine/inhume.go @@ -154,6 +154,10 @@ func (e *StorageEngine) inhumeAddr(addr oid.Address, prm shard.InhumePrm) (bool, res, err := sh.Exists(existPrm) if err != nil { + if shard.IsErrNotFound(err) { + return false + } + if shard.IsErrRemoved(err) || shard.IsErrObjectExpired(err) { // inhumed once - no need to be inhumed again ok = true @@ -162,7 +166,7 @@ func (e *StorageEngine) inhumeAddr(addr oid.Address, prm shard.InhumePrm) (bool, var siErr *objectSDK.SplitInfoError if !errors.As(err, &siErr) { - e.reportShardError(sh, "could not check for presents in shard", err) + e.reportShardError(sh, "could not check for presence in shard", err, zap.Stringer("addr", addr)) return } diff --git a/pkg/local_object_storage/engine/inhume_test.go b/pkg/local_object_storage/engine/inhume_test.go index 651a4a0a32..2028368e75 100644 --- a/pkg/local_object_storage/engine/inhume_test.go +++ b/pkg/local_object_storage/engine/inhume_test.go @@ -10,6 +10,7 @@ import ( cidtest "github.com/nspcc-dev/neofs-sdk-go/container/id/test" objectSDK "github.com/nspcc-dev/neofs-sdk-go/object" oid "github.com/nspcc-dev/neofs-sdk-go/object/id" + oidtest "github.com/nspcc-dev/neofs-sdk-go/object/id/test" "github.com/stretchr/testify/require" ) @@ -153,4 +154,21 @@ func TestStorageEngine_Inhume(t *testing.T) { _, err = wrongShard.Get(getPrm) require.ErrorAs(t, err, new(apistatus.ObjectNotFound)) }) + + t.Run("inhuming object twice", func(t *testing.T) { + addr := oidtest.Address() + + e := testNewEngineWithShardNum(t, 3) + defer e.Close() + + var inhumePrm InhumePrm + inhumePrm.MarkAsGarbage(addr) + + _, err := e.Inhume(inhumePrm) + require.NoError(t, err) + + // object is marked as garbage but marking it again should not be a problem + _, err = e.Inhume(inhumePrm) + require.NoError(t, err) + }) } diff --git a/pkg/local_object_storage/shard/errors.go b/pkg/local_object_storage/shard/errors.go index 31cd5836a8..c0851afd96 100644 --- a/pkg/local_object_storage/shard/errors.go +++ b/pkg/local_object_storage/shard/errors.go @@ -10,19 +10,19 @@ import ( // IsErrNotFound checks if error returned by Shard Get/Head/GetRange method // corresponds to missing object. func IsErrNotFound(err error) bool { - return errors.As(err, new(apistatus.ObjectNotFound)) + return errors.Is(err, apistatus.ErrObjectNotFound) } // IsErrRemoved checks if error returned by Shard Exists/Get/Head/GetRange method // corresponds to removed object. func IsErrRemoved(err error) bool { - return errors.As(err, new(apistatus.ObjectAlreadyRemoved)) + return errors.Is(err, apistatus.ErrObjectAlreadyRemoved) } // IsErrOutOfRange checks if an error returned by Shard GetRange method // corresponds to exceeding the object bounds. func IsErrOutOfRange(err error) bool { - return errors.As(err, new(apistatus.ObjectOutOfRange)) + return errors.Is(err, apistatus.ErrObjectOutOfRange) } // IsErrObjectExpired checks if an error returned by Shard corresponds to