From 9c17964edffa617f8eeda300097a59b15eb74b65 Mon Sep 17 00:00:00 2001 From: Alejandro Lopez Date: Fri, 4 Aug 2023 14:14:07 +0300 Subject: [PATCH] [#481] Update frostfs-sdk-go and error pointer receivers Signed-off-by: Alejandro Lopez --- cmd/frostfs-cli/internal/client/client.go | 2 +- cmd/frostfs-node/cache.go | 2 +- go.mod | 2 +- go.sum | Bin 100798 -> 100798 bytes pkg/core/container/storage.go | 9 --- .../processors/container/handlers_test.go | 2 +- .../blobovnicza/blobovnicza_test.go | 5 +- .../blobovnicza/delete.go | 4 +- .../blobovnicza/errors.go | 13 ---- pkg/local_object_storage/blobovnicza/get.go | 4 +- .../blobstor/blobovniczatree/delete.go | 11 +-- .../blobstor/blobovniczatree/errors.go | 3 +- .../blobstor/blobovniczatree/exists.go | 3 +- .../blobstor/blobovniczatree/get.go | 11 +-- .../blobstor/blobovniczatree/get_range.go | 13 ++-- pkg/local_object_storage/blobstor/delete.go | 5 +- .../blobstor/fstree/fstree.go | 6 +- pkg/local_object_storage/blobstor/get.go | 6 +- .../blobstor/get_range.go | 6 +- .../blobstor/internal/blobstortest/delete.go | 10 +-- .../blobstor/internal/blobstortest/get.go | 4 +- .../internal/blobstortest/get_range.go | 11 +-- .../blobstor/memstore/memstore.go | 6 +- pkg/local_object_storage/engine/delete.go | 13 ++-- .../engine/delete_test.go | 21 +++--- pkg/local_object_storage/engine/error_test.go | 3 +- pkg/local_object_storage/engine/exists.go | 9 +-- pkg/local_object_storage/engine/get.go | 9 ++- pkg/local_object_storage/engine/head.go | 15 ++-- pkg/local_object_storage/engine/inhume.go | 10 +-- pkg/local_object_storage/engine/lock.go | 6 +- pkg/local_object_storage/engine/lock_test.go | 11 ++- pkg/local_object_storage/engine/range.go | 15 ++-- .../metabase/control_test.go | 3 +- pkg/local_object_storage/metabase/delete.go | 5 +- .../metabase/delete_test.go | 6 +- pkg/local_object_storage/metabase/errors.go | 9 --- pkg/local_object_storage/metabase/exists.go | 4 +- .../metabase/exists_test.go | 4 +- pkg/local_object_storage/metabase/get.go | 12 +-- pkg/local_object_storage/metabase/get_test.go | 6 +- pkg/local_object_storage/metabase/inhume.go | 2 +- .../metabase/inhume_test.go | 15 ++-- pkg/local_object_storage/metabase/lock.go | 2 +- .../metabase/lock_test.go | 16 ++-- pkg/local_object_storage/shard/control.go | 3 +- .../shard/control_test.go | 13 ++-- pkg/local_object_storage/shard/delete.go | 3 +- pkg/local_object_storage/shard/delete_test.go | 6 +- pkg/local_object_storage/shard/errors.go | 15 +--- .../shard/gc_internal_test.go | 5 +- pkg/local_object_storage/shard/gc_test.go | 5 +- pkg/local_object_storage/shard/get.go | 5 +- pkg/local_object_storage/shard/get_test.go | 5 +- pkg/local_object_storage/shard/head_test.go | 5 +- pkg/local_object_storage/shard/inhume_test.go | 4 +- pkg/local_object_storage/shard/lock_test.go | 9 ++- pkg/local_object_storage/shard/range.go | 2 +- pkg/local_object_storage/shard/range_test.go | 3 +- .../writecache/writecachebadger/delete.go | 2 +- .../writecache/writecachebadger/get.go | 4 +- .../writecache/writecachebbolt/get.go | 4 +- .../writecache/writecachebbolt/storage.go | 5 +- pkg/morph/client/container/eacl.go | 4 +- pkg/morph/client/container/get.go | 4 +- pkg/services/object/acl/v2/service.go | 2 +- pkg/services/object/common.go | 18 ++--- pkg/services/object/get/assemble.go | 4 +- pkg/services/object/get/get_test.go | 71 ++++++++---------- pkg/services/object/get/local.go | 4 +- pkg/services/object/get/remote.go | 4 +- pkg/services/object/get/v2/util.go | 4 +- pkg/services/object/util/key.go | 8 +- .../object_manager/tombstone/source/source.go | 5 +- pkg/services/policer/check.go | 4 +- pkg/services/policer/policer_test.go | 8 +- pkg/services/util/sign.go | 2 +- 77 files changed, 263 insertions(+), 311 deletions(-) delete mode 100644 pkg/local_object_storage/blobovnicza/errors.go diff --git a/cmd/frostfs-cli/internal/client/client.go b/cmd/frostfs-cli/internal/client/client.go index babc0ef38..e250f8692 100644 --- a/cmd/frostfs-cli/internal/client/client.go +++ b/cmd/frostfs-cli/internal/client/client.go @@ -109,7 +109,7 @@ type GetContainerPrm struct { // SetContainer sets identifier of the container to be read. func (x *GetContainerPrm) SetContainer(id cid.ID) { - x.cliPrm.SetContainer(id) + *x.cliPrm.ContainerID = id } // GetContainerRes groups the resulting values of GetContainer operation. diff --git a/cmd/frostfs-node/cache.go b/cmd/frostfs-node/cache.go index bae38b299..fa5513640 100644 --- a/cmd/frostfs-node/cache.go +++ b/cmd/frostfs-node/cache.go @@ -208,7 +208,7 @@ func newCachedContainerStorage(v container.Source, ttl time.Duration) ttlContain } func (s ttlContainerStorage) handleRemoval(cnr cid.ID) { - s.set(cnr, nil, apistatus.ContainerNotFound{}) + s.set(cnr, nil, new(apistatus.ContainerNotFound)) } // Get returns container value from the cache. If value is missing in the cache diff --git a/go.mod b/go.mod index 7ad0fad88..bcb5e06bf 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( git.frostfs.info/TrueCloudLab/frostfs-api-go/v2 v2.15.1-0.20230802075510-964c3edb3f44 git.frostfs.info/TrueCloudLab/frostfs-contract v0.0.0-20230627134746-36f3d39c406a git.frostfs.info/TrueCloudLab/frostfs-observability v0.0.0-20230531082742-c97d21411eb6 - git.frostfs.info/TrueCloudLab/frostfs-sdk-go v0.0.0-20230802090410-95b987b818d9 + git.frostfs.info/TrueCloudLab/frostfs-sdk-go v0.0.0-20230804083501-3dc8129ed794 git.frostfs.info/TrueCloudLab/hrw v1.2.1 git.frostfs.info/TrueCloudLab/tzhash v1.8.0 github.com/cheggaaa/pb v1.0.29 diff --git a/go.sum b/go.sum index 07411ad4a88c83feac95e4d0fb80430f51bea044..0a442b1ed25d43bd0eb5c33a89d6330d1266c6e9 100644 GIT binary patch delta 115 zcmdltnQh->whfko&L##H#-;{_y2dHV7KTQasVU}`CJGsbR_V^38LsA*NtS7jz6JrA z73pRA{w3y_VYz-@Nshr5QRPk^K2CYz!RArPlN)$7CaVaFieNLV`K;jfvx1Bt%K^whfko&PE271}26Ex|XI%mKNqo7KRonmI@h$R>jWFAw|BP!9E#j<%LyA zxuI@le&H6rN#*{ASyi4Mk?F~<*%i6@**+;IlN)$7CaVaFieNLV`K;jfvx1Bt%K;Z| BBr^a2 diff --git a/pkg/core/container/storage.go b/pkg/core/container/storage.go index 3ed54529c..c79b7c041 100644 --- a/pkg/core/container/storage.go +++ b/pkg/core/container/storage.go @@ -1,9 +1,6 @@ package container import ( - "errors" - - apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status" "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container" cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id" frostfscrypto "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/crypto" @@ -37,12 +34,6 @@ type Source interface { Get(cid.ID) (*Container, error) } -// IsErrNotFound checks if the error returned by Source.Get corresponds -// to the missing container. -func IsErrNotFound(err error) bool { - return errors.As(err, new(apistatus.ContainerNotFound)) -} - // EACL groups information about the FrostFS container's extended ACL stored in // the FrostFS network. type EACL struct { diff --git a/pkg/innerring/processors/container/handlers_test.go b/pkg/innerring/processors/container/handlers_test.go index 1e518f474..77dbe876a 100644 --- a/pkg/innerring/processors/container/handlers_test.go +++ b/pkg/innerring/processors/container/handlers_test.go @@ -282,7 +282,7 @@ func (c *testContainerClient) Get(cid []byte) (*containercore.Container, error) if cont, found := c.get[key]; found { return cont, nil } - return nil, apistatus.ContainerNotFound{} + return nil, new(apistatus.ContainerNotFound) } type testIDClient struct { diff --git a/pkg/local_object_storage/blobovnicza/blobovnicza_test.go b/pkg/local_object_storage/blobovnicza/blobovnicza_test.go index 05f8906ac..c7b7bb8a9 100644 --- a/pkg/local_object_storage/blobovnicza/blobovnicza_test.go +++ b/pkg/local_object_storage/blobovnicza/blobovnicza_test.go @@ -8,6 +8,7 @@ import ( "testing" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger/test" + "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client" oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id" oidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id/test" "github.com/stretchr/testify/require" @@ -77,7 +78,7 @@ func TestBlobovnicza(t *testing.T) { require.NoError(t, blz.Init()) // try to read non-existent address - testGet(t, blz, oidtest.Address(), nil, IsErrNotFound) + testGet(t, blz, oidtest.Address(), nil, client.IsErrObjectNotFound) filled := uint64(15 * 1 << 10) @@ -92,7 +93,7 @@ func TestBlobovnicza(t *testing.T) { require.NoError(t, err) // should return 404 - testGet(t, blz, addr, nil, IsErrNotFound) + testGet(t, blz, addr, nil, client.IsErrObjectNotFound) // fill Blobovnicza fully for ; filled < sizeLim; filled += objSizeLim { diff --git a/pkg/local_object_storage/blobovnicza/delete.go b/pkg/local_object_storage/blobovnicza/delete.go index 8fbd363db..419e073c6 100644 --- a/pkg/local_object_storage/blobovnicza/delete.go +++ b/pkg/local_object_storage/blobovnicza/delete.go @@ -77,9 +77,7 @@ func (b *Blobovnicza) Delete(ctx context.Context, prm DeletePrm) (DeleteRes, err }) if err == nil && !found { - var errNotFound apistatus.ObjectNotFound - - return DeleteRes{}, errNotFound + return DeleteRes{}, new(apistatus.ObjectNotFound) } return DeleteRes{}, err diff --git a/pkg/local_object_storage/blobovnicza/errors.go b/pkg/local_object_storage/blobovnicza/errors.go deleted file mode 100644 index 2b0575c92..000000000 --- a/pkg/local_object_storage/blobovnicza/errors.go +++ /dev/null @@ -1,13 +0,0 @@ -package blobovnicza - -import ( - "errors" - - apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status" -) - -// IsErrNotFound checks if the error returned by Blobovnicza Get/Delete method -// corresponds to the missing object. -func IsErrNotFound(err error) bool { - return errors.As(err, new(apistatus.ObjectNotFound)) -} diff --git a/pkg/local_object_storage/blobovnicza/get.go b/pkg/local_object_storage/blobovnicza/get.go index d492b7559..3a613cfeb 100644 --- a/pkg/local_object_storage/blobovnicza/get.go +++ b/pkg/local_object_storage/blobovnicza/get.go @@ -72,9 +72,7 @@ func (b *Blobovnicza) Get(ctx context.Context, prm GetPrm) (GetRes, error) { } if data == nil { - var errNotFound apistatus.ObjectNotFound - - return GetRes{}, errNotFound + return GetRes{}, new(apistatus.ObjectNotFound) } return GetRes{ diff --git a/pkg/local_object_storage/blobstor/blobovniczatree/delete.go b/pkg/local_object_storage/blobstor/blobovniczatree/delete.go index 4d0801ef1..0698c232d 100644 --- a/pkg/local_object_storage/blobstor/blobovniczatree/delete.go +++ b/pkg/local_object_storage/blobstor/blobovniczatree/delete.go @@ -11,6 +11,7 @@ import ( "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/common" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/util/logicerr" "git.frostfs.info/TrueCloudLab/frostfs-observability/tracing" + "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client" apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status" "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/trace" @@ -69,7 +70,7 @@ func (b *Blobovniczas) Delete(ctx context.Context, prm common.DeletePrm) (res co res, err = b.deleteObjectFromLevel(ctx, bPrm, p, !ok) if err != nil { - if !blobovnicza.IsErrNotFound(err) { + if !client.IsErrObjectNotFound(err) { b.log.Debug(logs.BlobovniczatreeCouldNotRemoveObjectFromLevel, zap.String("level", p), zap.String("error", err.Error()), @@ -89,7 +90,7 @@ func (b *Blobovniczas) Delete(ctx context.Context, prm common.DeletePrm) (res co if err == nil && !objectFound { // not found in any blobovnicza - return common.DeleteRes{}, logicerr.Wrap(apistatus.ObjectNotFound{}) + return common.DeleteRes{}, logicerr.Wrap(new(apistatus.ObjectNotFound)) } success = err == nil @@ -109,7 +110,7 @@ func (b *Blobovniczas) deleteObjectFromLevel(ctx context.Context, prm blobovnicz if ok { if res, err := b.deleteObject(ctx, v, prm); err == nil { return res, err - } else if !blobovnicza.IsErrNotFound(err) { + } else if !client.IsErrObjectNotFound(err) { b.log.Debug(logs.BlobovniczatreeCouldNotRemoveObjectFromOpenedBlobovnicza, zap.String("path", blzPath), zap.String("error", err.Error()), @@ -128,7 +129,7 @@ func (b *Blobovniczas) deleteObjectFromLevel(ctx context.Context, prm blobovnicz if ok && tryActive { if res, err := b.deleteObject(ctx, active.blz, prm); err == nil { return res, err - } else if !blobovnicza.IsErrNotFound(err) { + } else if !client.IsErrObjectNotFound(err) { b.log.Debug(logs.BlobovniczatreeCouldNotRemoveObjectFromActiveBlobovnicza, zap.String("path", blzPath), zap.String("error", err.Error()), @@ -142,7 +143,7 @@ func (b *Blobovniczas) deleteObjectFromLevel(ctx context.Context, prm blobovnicz // (Blobovniczas "after" the active one are empty anyway, // and it's pointless to open them). if u64FromHexString(filepath.Base(blzPath)) > active.ind { - return common.DeleteRes{}, logicerr.Wrap(apistatus.ObjectNotFound{}) + return common.DeleteRes{}, logicerr.Wrap(new(apistatus.ObjectNotFound)) } // open blobovnicza (cached inside) diff --git a/pkg/local_object_storage/blobstor/blobovniczatree/errors.go b/pkg/local_object_storage/blobstor/blobovniczatree/errors.go index 4ef053d54..04247280a 100644 --- a/pkg/local_object_storage/blobstor/blobovniczatree/errors.go +++ b/pkg/local_object_storage/blobstor/blobovniczatree/errors.go @@ -8,7 +8,8 @@ import ( ) func isErrOutOfRange(err error) bool { - return errors.As(err, new(apistatus.ObjectOutOfRange)) + var target *apistatus.ObjectOutOfRange + return errors.As(err, &target) } func isLogical(err error) bool { diff --git a/pkg/local_object_storage/blobstor/blobovniczatree/exists.go b/pkg/local_object_storage/blobstor/blobovniczatree/exists.go index cd553ec30..c1964c227 100644 --- a/pkg/local_object_storage/blobstor/blobovniczatree/exists.go +++ b/pkg/local_object_storage/blobstor/blobovniczatree/exists.go @@ -10,6 +10,7 @@ import ( "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobovnicza" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/common" "git.frostfs.info/TrueCloudLab/frostfs-observability/tracing" + "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client" "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/trace" "go.uber.org/zap" @@ -57,7 +58,7 @@ func (b *Blobovniczas) Exists(ctx context.Context, prm common.ExistsPrm) (common _, err := b.getObjectFromLevel(ctx, gPrm, p, !ok) if err != nil { - if !blobovnicza.IsErrNotFound(err) { + if !client.IsErrObjectNotFound(err) { b.log.Debug(logs.BlobovniczatreeCouldNotGetObjectFromLevel, zap.String("level", p), zap.String("error", err.Error())) diff --git a/pkg/local_object_storage/blobstor/blobovniczatree/get.go b/pkg/local_object_storage/blobstor/blobovniczatree/get.go index e88310f8a..671d045b9 100644 --- a/pkg/local_object_storage/blobstor/blobovniczatree/get.go +++ b/pkg/local_object_storage/blobstor/blobovniczatree/get.go @@ -12,6 +12,7 @@ import ( "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/common" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/util/logicerr" "git.frostfs.info/TrueCloudLab/frostfs-observability/tracing" + "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client" apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status" objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object" "go.opentelemetry.io/otel/attribute" @@ -69,7 +70,7 @@ func (b *Blobovniczas) Get(ctx context.Context, prm common.GetPrm) (res common.G res, err = b.getObjectFromLevel(ctx, bPrm, p, !ok) if err != nil { - if !blobovnicza.IsErrNotFound(err) { + if !client.IsErrObjectNotFound(err) { b.log.Debug(logs.BlobovniczatreeCouldNotGetObjectFromLevel, zap.String("level", p), zap.String("error", err.Error()), @@ -85,7 +86,7 @@ func (b *Blobovniczas) Get(ctx context.Context, prm common.GetPrm) (res common.G if err == nil && res.Object == nil { // not found in any blobovnicza - return res, logicerr.Wrap(apistatus.ObjectNotFound{}) + return res, logicerr.Wrap(new(apistatus.ObjectNotFound)) } success = true @@ -107,7 +108,7 @@ func (b *Blobovniczas) getObjectFromLevel(ctx context.Context, prm blobovnicza.G if ok { if res, err := b.getObject(ctx, v, prm); err == nil { return res, err - } else if !blobovnicza.IsErrNotFound(err) { + } else if !client.IsErrObjectNotFound(err) { b.log.Debug(logs.BlobovniczatreeCouldNotReadObjectFromOpenedBlobovnicza, zap.String("path", blzPath), zap.String("error", err.Error()), @@ -127,7 +128,7 @@ func (b *Blobovniczas) getObjectFromLevel(ctx context.Context, prm blobovnicza.G if ok && tryActive { if res, err := b.getObject(ctx, active.blz, prm); err == nil { return res, err - } else if !blobovnicza.IsErrNotFound(err) { + } else if !client.IsErrObjectNotFound(err) { b.log.Debug(logs.BlobovniczatreeCouldNotGetObjectFromActiveBlobovnicza, zap.String("path", blzPath), zap.String("error", err.Error()), @@ -141,7 +142,7 @@ func (b *Blobovniczas) getObjectFromLevel(ctx context.Context, prm blobovnicza.G // (Blobovniczas "after" the active one are empty anyway, // and it's pointless to open them). if u64FromHexString(filepath.Base(blzPath)) > active.ind { - return common.GetRes{}, logicerr.Wrap(apistatus.ObjectNotFound{}) + return common.GetRes{}, logicerr.Wrap(new(apistatus.ObjectNotFound)) } // open blobovnicza (cached inside) diff --git a/pkg/local_object_storage/blobstor/blobovniczatree/get_range.go b/pkg/local_object_storage/blobstor/blobovniczatree/get_range.go index 8579502c0..088ebe249 100644 --- a/pkg/local_object_storage/blobstor/blobovniczatree/get_range.go +++ b/pkg/local_object_storage/blobstor/blobovniczatree/get_range.go @@ -13,6 +13,7 @@ import ( "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/common" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/util/logicerr" "git.frostfs.info/TrueCloudLab/frostfs-observability/tracing" + "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client" apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status" objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object" "go.opentelemetry.io/otel/attribute" @@ -70,7 +71,7 @@ func (b *Blobovniczas) GetRange(ctx context.Context, prm common.GetRangePrm) (re res, err = b.getRangeFromLevel(ctx, prm, p, !ok) if err != nil { outOfBounds := isErrOutOfRange(err) - if !outOfBounds && !blobovnicza.IsErrNotFound(err) { + if !outOfBounds && !client.IsErrObjectNotFound(err) { b.log.Debug(logs.BlobovniczatreeCouldNotGetObjectFromLevel, zap.String("level", p), zap.String("error", err.Error()), @@ -91,7 +92,7 @@ func (b *Blobovniczas) GetRange(ctx context.Context, prm common.GetRangePrm) (re if err == nil && !objectFound { // not found in any blobovnicza - return common.GetRangeRes{}, logicerr.Wrap(apistatus.ObjectNotFound{}) + return common.GetRangeRes{}, logicerr.Wrap(new(apistatus.ObjectNotFound)) } if err == nil { @@ -119,7 +120,7 @@ func (b *Blobovniczas) getRangeFromLevel(ctx context.Context, prm common.GetRang isErrOutOfRange(err): return res, err default: - if !blobovnicza.IsErrNotFound(err) { + if !client.IsErrObjectNotFound(err) { b.log.Debug(logs.BlobovniczatreeCouldNotReadPayloadRangeFromOpenedBlobovnicza, zap.String("path", blzPath), zap.String("error", err.Error()), @@ -144,7 +145,7 @@ func (b *Blobovniczas) getRangeFromLevel(ctx context.Context, prm common.GetRang isErrOutOfRange(err): return res, err default: - if !blobovnicza.IsErrNotFound(err) { + if !client.IsErrObjectNotFound(err) { b.log.Debug(logs.BlobovniczatreeCouldNotReadPayloadRangeFromActiveBlobovnicza, zap.String("path", blzPath), zap.String("error", err.Error()), @@ -159,7 +160,7 @@ func (b *Blobovniczas) getRangeFromLevel(ctx context.Context, prm common.GetRang // (Blobovniczas "after" the active one are empty anyway, // and it's pointless to open them). if u64FromHexString(filepath.Base(blzPath)) > active.ind { - return common.GetRangeRes{}, logicerr.Wrap(apistatus.ObjectNotFound{}) + return common.GetRangeRes{}, logicerr.Wrap(new(apistatus.ObjectNotFound)) } // open blobovnicza (cached inside) @@ -202,7 +203,7 @@ func (b *Blobovniczas) getObjectRange(ctx context.Context, blz *blobovnicza.Blob payload := obj.Payload() if pLen := uint64(len(payload)); to < from || pLen < from || pLen < to { - return common.GetRangeRes{}, logicerr.Wrap(apistatus.ObjectOutOfRange{}) + return common.GetRangeRes{}, logicerr.Wrap(new(apistatus.ObjectOutOfRange)) } return common.GetRangeRes{ diff --git a/pkg/local_object_storage/blobstor/delete.go b/pkg/local_object_storage/blobstor/delete.go index fe49fc46a..8930980a6 100644 --- a/pkg/local_object_storage/blobstor/delete.go +++ b/pkg/local_object_storage/blobstor/delete.go @@ -3,12 +3,11 @@ package blobstor import ( "context" "encoding/hex" - "errors" "time" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/common" "git.frostfs.info/TrueCloudLab/frostfs-observability/tracing" - apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status" + "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client" "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/trace" ) @@ -35,7 +34,7 @@ func (b *BlobStor) Delete(ctx context.Context, prm common.DeletePrm) (common.Del if prm.StorageID == nil { for i := range b.storage { res, err := b.storage[i].Storage.Delete(ctx, prm) - if err == nil || !errors.As(err, new(apistatus.ObjectNotFound)) { + if err == nil || !client.IsErrObjectNotFound(err) { if err == nil { success = true logOp(b.log, deleteOp, prm.Address, b.storage[i].Storage.Type(), prm.StorageID) diff --git a/pkg/local_object_storage/blobstor/fstree/fstree.go b/pkg/local_object_storage/blobstor/fstree/fstree.go index 9ca5d4bd9..5fbbdfea9 100644 --- a/pkg/local_object_storage/blobstor/fstree/fstree.go +++ b/pkg/local_object_storage/blobstor/fstree/fstree.go @@ -246,7 +246,7 @@ func (t *FSTree) Delete(ctx context.Context, prm common.DeletePrm) (common.Delet err = os.Remove(p) if err != nil && os.IsNotExist(err) { - err = logicerr.Wrap(apistatus.ObjectNotFound{}) + err = logicerr.Wrap(new(apistatus.ObjectNotFound)) } return common.DeleteRes{}, err } @@ -439,7 +439,7 @@ func (t *FSTree) Get(ctx context.Context, prm common.GetPrm) (common.GetRes, err p := t.treePath(prm.Address) if _, err := os.Stat(p); os.IsNotExist(err) { - return common.GetRes{}, logicerr.Wrap(apistatus.ObjectNotFound{}) + return common.GetRes{}, logicerr.Wrap(new(apistatus.ObjectNotFound)) } var data []byte @@ -498,7 +498,7 @@ func (t *FSTree) GetRange(ctx context.Context, prm common.GetRangePrm) (common.G to := from + prm.Range.GetLength() if pLen := uint64(len(payload)); to < from || pLen < from || pLen < to { - return common.GetRangeRes{}, logicerr.Wrap(apistatus.ObjectOutOfRange{}) + return common.GetRangeRes{}, logicerr.Wrap(new(apistatus.ObjectOutOfRange)) } success = true diff --git a/pkg/local_object_storage/blobstor/get.go b/pkg/local_object_storage/blobstor/get.go index fab86ea5d..00ed18d7b 100644 --- a/pkg/local_object_storage/blobstor/get.go +++ b/pkg/local_object_storage/blobstor/get.go @@ -3,12 +3,12 @@ package blobstor import ( "context" "encoding/hex" - "errors" "time" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/common" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/util/logicerr" "git.frostfs.info/TrueCloudLab/frostfs-observability/tracing" + "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client" apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status" "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/trace" @@ -39,12 +39,12 @@ func (b *BlobStor) Get(ctx context.Context, prm common.GetPrm) (res common.GetRe if prm.StorageID == nil { for i := range b.storage { res, err = b.storage[i].Storage.Get(ctx, prm) - if err == nil || !errors.As(err, new(apistatus.ObjectNotFound)) { + if err == nil || !client.IsErrObjectNotFound(err) { return res, err } } - return common.GetRes{}, logicerr.Wrap(apistatus.ObjectNotFound{}) + return common.GetRes{}, logicerr.Wrap(new(apistatus.ObjectNotFound)) } if len(prm.StorageID) == 0 { res, err = b.storage[len(b.storage)-1].Storage.Get(ctx, prm) diff --git a/pkg/local_object_storage/blobstor/get_range.go b/pkg/local_object_storage/blobstor/get_range.go index 671fbf02e..50abd19fa 100644 --- a/pkg/local_object_storage/blobstor/get_range.go +++ b/pkg/local_object_storage/blobstor/get_range.go @@ -3,13 +3,13 @@ package blobstor import ( "context" "encoding/hex" - "errors" "strconv" "time" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/common" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/util/logicerr" "git.frostfs.info/TrueCloudLab/frostfs-observability/tracing" + "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client" apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status" "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/trace" @@ -41,12 +41,12 @@ func (b *BlobStor) GetRange(ctx context.Context, prm common.GetRangePrm) (res co if prm.StorageID == nil { for i := range b.storage { res, err = b.storage[i].Storage.GetRange(ctx, prm) - if err == nil || !errors.As(err, new(apistatus.ObjectNotFound)) { + if err == nil || !client.IsErrObjectNotFound(err) { return res, err } } - return common.GetRangeRes{}, logicerr.Wrap(apistatus.ObjectNotFound{}) + return common.GetRangeRes{}, logicerr.Wrap(new(apistatus.ObjectNotFound)) } if len(prm.StorageID) == 0 { res, err = b.storage[len(b.storage)-1].Storage.GetRange(ctx, prm) diff --git a/pkg/local_object_storage/blobstor/internal/blobstortest/delete.go b/pkg/local_object_storage/blobstor/internal/blobstortest/delete.go index 7532a5b5f..0bfac2772 100644 --- a/pkg/local_object_storage/blobstor/internal/blobstortest/delete.go +++ b/pkg/local_object_storage/blobstor/internal/blobstortest/delete.go @@ -5,7 +5,7 @@ import ( "testing" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/common" - apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status" + "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client" oidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id/test" "github.com/stretchr/testify/require" ) @@ -23,7 +23,7 @@ func TestDelete(t *testing.T, cons Constructor, min, max uint64) { prm.Address = oidtest.Address() _, err := s.Delete(context.Background(), prm) - require.Error(t, err, new(apistatus.ObjectNotFound)) + require.True(t, client.IsErrObjectNotFound(err)) }) t.Run("with storage ID", func(t *testing.T) { @@ -43,12 +43,12 @@ func TestDelete(t *testing.T, cons Constructor, min, max uint64) { t.Run("get fail", func(t *testing.T) { prm := common.GetPrm{Address: oidtest.Address()} _, err := s.Get(context.Background(), prm) - require.ErrorAs(t, err, new(apistatus.ObjectNotFound)) + require.True(t, client.IsErrObjectNotFound(err)) }) t.Run("getrange fail", func(t *testing.T) { prm := common.GetRangePrm{Address: oidtest.Address()} _, err := s.GetRange(context.Background(), prm) - require.ErrorAs(t, err, new(apistatus.ObjectNotFound)) + require.True(t, client.IsErrObjectNotFound(err)) }) }) t.Run("without storage ID", func(t *testing.T) { @@ -68,7 +68,7 @@ func TestDelete(t *testing.T, cons Constructor, min, max uint64) { require.NoError(t, err) _, err = s.Delete(context.Background(), prm) - require.ErrorAs(t, err, new(apistatus.ObjectNotFound)) + require.True(t, client.IsErrObjectNotFound(err)) }) t.Run("non-deleted object is still available", func(t *testing.T) { diff --git a/pkg/local_object_storage/blobstor/internal/blobstortest/get.go b/pkg/local_object_storage/blobstor/internal/blobstortest/get.go index c5755dfba..9a7ebed09 100644 --- a/pkg/local_object_storage/blobstor/internal/blobstortest/get.go +++ b/pkg/local_object_storage/blobstor/internal/blobstortest/get.go @@ -5,7 +5,7 @@ import ( "testing" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/common" - apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status" + "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client" oidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id/test" "github.com/stretchr/testify/require" ) @@ -21,7 +21,7 @@ func TestGet(t *testing.T, cons Constructor, min, max uint64) { t.Run("missing object", func(t *testing.T) { gPrm := common.GetPrm{Address: oidtest.Address()} _, err := s.Get(context.Background(), gPrm) - require.ErrorAs(t, err, new(apistatus.ObjectNotFound)) + require.True(t, client.IsErrObjectNotFound(err)) }) for i := range objects { diff --git a/pkg/local_object_storage/blobstor/internal/blobstortest/get_range.go b/pkg/local_object_storage/blobstor/internal/blobstortest/get_range.go index b0c8aa95a..1a9da0726 100644 --- a/pkg/local_object_storage/blobstor/internal/blobstortest/get_range.go +++ b/pkg/local_object_storage/blobstor/internal/blobstortest/get_range.go @@ -6,6 +6,7 @@ import ( "testing" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/common" + "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client" apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status" oidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id/test" "github.com/stretchr/testify/require" @@ -22,7 +23,7 @@ func TestGetRange(t *testing.T, cons Constructor, min, max uint64) { t.Run("missing object", func(t *testing.T) { gPrm := common.GetRangePrm{Address: oidtest.Address()} _, err := s.GetRange(context.Background(), gPrm) - require.ErrorAs(t, err, new(apistatus.ObjectNotFound)) + require.True(t, client.IsErrObjectNotFound(err)) }) payload := objects[0].obj.Payload() @@ -56,7 +57,7 @@ func TestGetRange(t *testing.T, cons Constructor, min, max uint64) { gPrm.Range.SetLength(10) _, err := s.GetRange(context.Background(), gPrm) - require.ErrorAs(t, err, new(apistatus.ObjectOutOfRange)) + require.ErrorAs(t, err, new(*apistatus.ObjectOutOfRange)) }) t.Run("offset + length > len(payload)", func(t *testing.T) { @@ -64,7 +65,7 @@ func TestGetRange(t *testing.T, cons Constructor, min, max uint64) { gPrm.Range.SetLength(uint64(len(payload))) _, err := s.GetRange(context.Background(), gPrm) - require.ErrorAs(t, err, new(apistatus.ObjectOutOfRange)) + require.ErrorAs(t, err, new(*apistatus.ObjectOutOfRange)) }) t.Run("length is negative when converted to int64", func(t *testing.T) { @@ -72,7 +73,7 @@ func TestGetRange(t *testing.T, cons Constructor, min, max uint64) { gPrm.Range.SetLength(1 << 63) _, err := s.GetRange(context.Background(), gPrm) - require.ErrorAs(t, err, new(apistatus.ObjectOutOfRange)) + require.ErrorAs(t, err, new(*apistatus.ObjectOutOfRange)) }) t.Run("offset + length overflow uint64", func(t *testing.T) { @@ -80,6 +81,6 @@ func TestGetRange(t *testing.T, cons Constructor, min, max uint64) { gPrm.Range.SetLength(math.MaxUint64 - 2) _, err := s.GetRange(context.Background(), gPrm) - require.ErrorAs(t, err, new(apistatus.ObjectOutOfRange)) + require.ErrorAs(t, err, new(*apistatus.ObjectOutOfRange)) }) } diff --git a/pkg/local_object_storage/blobstor/memstore/memstore.go b/pkg/local_object_storage/blobstor/memstore/memstore.go index b6cca2551..9428f457f 100644 --- a/pkg/local_object_storage/blobstor/memstore/memstore.go +++ b/pkg/local_object_storage/blobstor/memstore/memstore.go @@ -41,7 +41,7 @@ func (s *memstoreImpl) Get(_ context.Context, req common.GetPrm) (common.GetRes, s.mu.RUnlock() if !exists { - return common.GetRes{}, logicerr.Wrap(apistatus.ObjectNotFound{}) + return common.GetRes{}, logicerr.Wrap(new(apistatus.ObjectNotFound)) } // Decompress the data. @@ -73,7 +73,7 @@ func (s *memstoreImpl) GetRange(ctx context.Context, req common.GetRangePrm) (co to := from + req.Range.GetLength() if pLen := uint64(len(payload)); to < from || pLen < from || pLen < to { - return common.GetRangeRes{}, logicerr.Wrap(apistatus.ObjectOutOfRange{}) + return common.GetRangeRes{}, logicerr.Wrap(new(apistatus.ObjectOutOfRange)) } return common.GetRangeRes{ @@ -123,7 +123,7 @@ func (s *memstoreImpl) Delete(_ context.Context, req common.DeletePrm) (common.D return common.DeleteRes{}, nil } - return common.DeleteRes{}, logicerr.Wrap(apistatus.ObjectNotFound{}) + return common.DeleteRes{}, logicerr.Wrap(new(apistatus.ObjectNotFound)) } func (s *memstoreImpl) Iterate(_ context.Context, req common.IteratePrm) (common.IterateRes, error) { diff --git a/pkg/local_object_storage/engine/delete.go b/pkg/local_object_storage/engine/delete.go index 4d6d838bc..8e3180560 100644 --- a/pkg/local_object_storage/engine/delete.go +++ b/pkg/local_object_storage/engine/delete.go @@ -7,6 +7,7 @@ import ( "git.frostfs.info/TrueCloudLab/frostfs-node/internal/logs" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/shard" "git.frostfs.info/TrueCloudLab/frostfs-observability/tracing" + "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client" apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status" objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object" oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id" @@ -71,8 +72,7 @@ func (e *StorageEngine) delete(ctx context.Context, prm DeletePrm) (DeleteRes, e } var locked struct { - is bool - err apistatus.ObjectLocked + is bool } var splitInfo *objectSDK.SplitInfo @@ -85,13 +85,13 @@ func (e *StorageEngine) delete(ctx context.Context, prm DeletePrm) (DeleteRes, e resExists, err := sh.Exists(ctx, existsPrm) if err != nil { - if shard.IsErrRemoved(err) || shard.IsErrObjectExpired(err) { + if client.IsErrObjectAlreadyRemoved(err) || shard.IsErrObjectExpired(err) { return true } var splitErr *objectSDK.SplitInfoError if !errors.As(err, &splitErr) { - if !shard.IsErrNotFound(err) { + if !client.IsErrObjectNotFound(err) { e.reportShardError(sh, "could not check object existence", err) } return false @@ -111,7 +111,8 @@ func (e *StorageEngine) delete(ctx context.Context, prm DeletePrm) (DeleteRes, e if err != nil { e.reportShardError(sh, "could not inhume object in shard", err) - locked.is = errors.As(err, &locked.err) + var target *apistatus.ObjectLocked + locked.is = errors.As(err, &target) return locked.is } @@ -121,7 +122,7 @@ func (e *StorageEngine) delete(ctx context.Context, prm DeletePrm) (DeleteRes, e }) if locked.is { - return DeleteRes{}, locked.err + return DeleteRes{}, new(apistatus.ObjectLocked) } if splitInfo != nil { diff --git a/pkg/local_object_storage/engine/delete_test.go b/pkg/local_object_storage/engine/delete_test.go index bbc27615a..3ea0291da 100644 --- a/pkg/local_object_storage/engine/delete_test.go +++ b/pkg/local_object_storage/engine/delete_test.go @@ -65,16 +65,14 @@ func TestDeleteBigObject(t *testing.T) { } require.NoError(t, Put(context.Background(), e, link)) - var splitErr *objectSDK.SplitInfoError - addrParent := object.AddressOf(parent) - checkGetError(t, e, addrParent, &splitErr) + checkGetError[*objectSDK.SplitInfoError](t, e, addrParent, true) addrLink := object.AddressOf(link) - checkGetError(t, e, addrLink, nil) + checkGetError[error](t, e, addrLink, false) for i := range children { - checkGetError(t, e, object.AddressOf(children[i]), nil) + checkGetError[error](t, e, object.AddressOf(children[i]), false) } var deletePrm DeletePrm @@ -84,20 +82,21 @@ func TestDeleteBigObject(t *testing.T) { _, err := e.Delete(context.Background(), deletePrm) require.NoError(t, err) - checkGetError(t, e, addrParent, &apistatus.ObjectNotFound{}) - checkGetError(t, e, addrLink, &apistatus.ObjectNotFound{}) + checkGetError[*apistatus.ObjectNotFound](t, e, addrParent, true) + checkGetError[*apistatus.ObjectNotFound](t, e, addrLink, true) for i := range children { - checkGetError(t, e, object.AddressOf(children[i]), &apistatus.ObjectNotFound{}) + checkGetError[*apistatus.ObjectNotFound](t, e, object.AddressOf(children[i]), true) } } -func checkGetError(t *testing.T, e *StorageEngine, addr oid.Address, expected any) { +func checkGetError[E error](t *testing.T, e *StorageEngine, addr oid.Address, shouldFail bool) { var getPrm GetPrm getPrm.WithAddress(addr) _, err := e.Get(context.Background(), getPrm) - if expected != nil { - require.ErrorAs(t, err, expected) + if shouldFail { + var target E + require.ErrorAs(t, err, &target) } else { require.NoError(t, err) } diff --git a/pkg/local_object_storage/engine/error_test.go b/pkg/local_object_storage/engine/error_test.go index 18bc72d65..a77149e7c 100644 --- a/pkg/local_object_storage/engine/error_test.go +++ b/pkg/local_object_storage/engine/error_test.go @@ -18,7 +18,6 @@ import ( "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/shard" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/shard/mode" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger" - apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status" cidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id/test" objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object" "github.com/stretchr/testify/require" @@ -216,7 +215,7 @@ func TestBlobstorFailback(t *testing.T) { require.Equal(t, objs[i].Payload()[1:11], rngRes.Object().Payload()) _, err = te.ng.GetRange(context.Background(), RngPrm{addr: addr, off: errSmallSize + 10, ln: 1}) - require.ErrorAs(t, err, &apistatus.ObjectOutOfRange{}) + require.True(t, shard.IsErrOutOfRange(err)) } checkShardState(t, te.ng, te.shards[0].id, 2, mode.ReadOnly) diff --git a/pkg/local_object_storage/engine/exists.go b/pkg/local_object_storage/engine/exists.go index 6208461e9..ef6292768 100644 --- a/pkg/local_object_storage/engine/exists.go +++ b/pkg/local_object_storage/engine/exists.go @@ -5,6 +5,7 @@ import ( "errors" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/shard" + "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client" apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status" objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object" oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id" @@ -19,7 +20,7 @@ func (e *StorageEngine) exists(ctx context.Context, addr oid.Address) (bool, err e.iterateOverSortedShards(addr, func(_ int, sh hashedShard) (stop bool) { res, err := sh.Exists(ctx, shPrm) if err != nil { - if shard.IsErrRemoved(err) { + if client.IsErrObjectAlreadyRemoved(err) { alreadyRemoved = true return true @@ -34,7 +35,7 @@ func (e *StorageEngine) exists(ctx context.Context, addr oid.Address) (bool, err return true } - if !shard.IsErrNotFound(err) { + if !client.IsErrObjectNotFound(err) { e.reportShardError(sh, "could not check existence of object in shard", err) } return false @@ -48,9 +49,7 @@ func (e *StorageEngine) exists(ctx context.Context, addr oid.Address) (bool, err }) if alreadyRemoved { - var errRemoved apistatus.ObjectAlreadyRemoved - - return false, errRemoved + return false, new(apistatus.ObjectAlreadyRemoved) } return exists, nil diff --git a/pkg/local_object_storage/engine/get.go b/pkg/local_object_storage/engine/get.go index bd094770a..2f736146c 100644 --- a/pkg/local_object_storage/engine/get.go +++ b/pkg/local_object_storage/engine/get.go @@ -8,6 +8,7 @@ import ( "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/util" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/util/logicerr" "git.frostfs.info/TrueCloudLab/frostfs-observability/tracing" + "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client" apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status" objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object" oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id" @@ -67,7 +68,7 @@ func (e *StorageEngine) get(ctx context.Context, prm GetPrm) (GetRes, error) { defer elapsed("Get", e.metrics.AddMethodDuration)() } - var errNotFound apistatus.ObjectNotFound + errNotFound := new(apistatus.ObjectNotFound) var shPrm shard.GetPrm shPrm.SetAddress(prm.addr) @@ -90,7 +91,7 @@ func (e *StorageEngine) get(ctx context.Context, prm GetPrm) (GetRes, error) { } if it.Object == nil { - if !it.HasDegraded && it.ShardWithMeta.Shard == nil || !shard.IsErrNotFound(it.OutError) { + if !it.HasDegraded && it.ShardWithMeta.Shard == nil || !client.IsErrObjectNotFound(it.OutError) { return GetRes{}, it.OutError } @@ -144,7 +145,7 @@ func (i *getShardIterator) tryGetWithMeta(ctx context.Context) { i.MetaError = err } switch { - case shard.IsErrNotFound(err): + case client.IsErrObjectNotFound(err): return false // ignore, go to next shard case errors.As(err, &i.splitInfoErr): if i.SplitInfo == nil { @@ -158,7 +159,7 @@ func (i *getShardIterator) tryGetWithMeta(ctx context.Context) { // stop iterating over shards if SplitInfo structure is complete return withLink && withLast - case shard.IsErrRemoved(err): + case client.IsErrObjectAlreadyRemoved(err): i.OutError = err return true // stop, return it back case shard.IsErrObjectExpired(err): diff --git a/pkg/local_object_storage/engine/head.go b/pkg/local_object_storage/engine/head.go index ca51015db..ba5e7cc1d 100644 --- a/pkg/local_object_storage/engine/head.go +++ b/pkg/local_object_storage/engine/head.go @@ -8,6 +8,7 @@ import ( "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/util" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/util/logicerr" "git.frostfs.info/TrueCloudLab/frostfs-observability/tracing" + "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client" apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status" objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object" oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id" @@ -74,11 +75,9 @@ func (e *StorageEngine) head(ctx context.Context, prm HeadPrm) (HeadRes, error) var ( head *objectSDK.Object siErr *objectSDK.SplitInfoError + outSI *objectSDK.SplitInfo - errNotFound apistatus.ObjectNotFound - - outSI *objectSDK.SplitInfo - outError error = errNotFound + outError error = new(apistatus.ObjectNotFound) ) var shPrm shard.HeadPrm @@ -89,7 +88,7 @@ func (e *StorageEngine) head(ctx context.Context, prm HeadPrm) (HeadRes, error) res, err := sh.Head(ctx, shPrm) if err != nil { switch { - case shard.IsErrNotFound(err): + case client.IsErrObjectNotFound(err): return false // ignore, go to next shard case errors.As(err, &siErr): if outSI == nil { @@ -107,16 +106,14 @@ func (e *StorageEngine) head(ctx context.Context, prm HeadPrm) (HeadRes, error) } return false - case shard.IsErrRemoved(err): + case client.IsErrObjectAlreadyRemoved(err): outError = err return true // stop, return it back case shard.IsErrObjectExpired(err): - var notFoundErr apistatus.ObjectNotFound - // object is found but should not // be returned - outError = notFoundErr + outError = new(apistatus.ObjectNotFound) return true default: diff --git a/pkg/local_object_storage/engine/inhume.go b/pkg/local_object_storage/engine/inhume.go index 0b9ae602b..e0f9d7ab3 100644 --- a/pkg/local_object_storage/engine/inhume.go +++ b/pkg/local_object_storage/engine/inhume.go @@ -8,6 +8,7 @@ import ( meta "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/metabase" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/shard" "git.frostfs.info/TrueCloudLab/frostfs-observability/tracing" + "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client" apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status" objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object" oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id" @@ -94,8 +95,7 @@ func (e *StorageEngine) inhume(ctx context.Context, prm InhumePrm) (InhumeRes, e zap.Error(err), zap.Stringer("addr", prm.addrs[i])) } else if locked { - var lockedErr apistatus.ObjectLocked - return InhumeRes{}, lockedErr + return InhumeRes{}, new(apistatus.ObjectLocked) } } @@ -125,7 +125,6 @@ func (e *StorageEngine) inhume(ctx context.Context, prm InhumePrm) (InhumeRes, e // Returns ok if object was inhumed during this invocation or before. func (e *StorageEngine) inhumeAddr(ctx context.Context, addr oid.Address, prm shard.InhumePrm, checkExists bool) (bool, error) { root := false - var errLocked apistatus.ObjectLocked var existPrm shard.ExistsPrm var retErr error var ok bool @@ -143,7 +142,7 @@ func (e *StorageEngine) inhumeAddr(ctx context.Context, addr oid.Address, prm sh existPrm.SetAddress(addr) exRes, err := sh.Exists(ctx, existPrm) if err != nil { - if shard.IsErrRemoved(err) || shard.IsErrObjectExpired(err) { + if client.IsErrObjectAlreadyRemoved(err) || shard.IsErrObjectExpired(err) { // inhumed once - no need to be inhumed again ok = true return true @@ -163,9 +162,10 @@ func (e *StorageEngine) inhumeAddr(ctx context.Context, addr oid.Address, prm sh _, err := sh.Inhume(ctx, prm) if err != nil { + var errLocked *apistatus.ObjectLocked switch { case errors.As(err, &errLocked): - retErr = apistatus.ObjectLocked{} + retErr = new(apistatus.ObjectLocked) return true case errors.Is(err, shard.ErrLockObjectRemoval): retErr = meta.ErrLockObjectRemoval diff --git a/pkg/local_object_storage/engine/lock.go b/pkg/local_object_storage/engine/lock.go index 61a5a0dc9..5ad603421 100644 --- a/pkg/local_object_storage/engine/lock.go +++ b/pkg/local_object_storage/engine/lock.go @@ -41,11 +41,11 @@ func (e *StorageEngine) lock(ctx context.Context, idCnr cid.ID, locker oid.ID, l for i := range locked { switch e.lockSingle(ctx, idCnr, locker, locked[i], true) { case 1: - return logicerr.Wrap(apistatus.LockNonRegularObject{}) + return logicerr.Wrap(new(apistatus.LockNonRegularObject)) case 0: switch e.lockSingle(ctx, idCnr, locker, locked[i], false) { case 1: - return logicerr.Wrap(apistatus.LockNonRegularObject{}) + return logicerr.Wrap(new(apistatus.LockNonRegularObject)) case 0: return logicerr.Wrap(errLockFailed) } @@ -62,7 +62,6 @@ func (e *StorageEngine) lock(ctx context.Context, idCnr cid.ID, locker oid.ID, l func (e *StorageEngine) lockSingle(ctx context.Context, idCnr cid.ID, locker, locked oid.ID, checkExists bool) (status uint8) { // code is pretty similar to inhumeAddr, maybe unify? root := false - var errIrregular apistatus.LockNonRegularObject var addrLocked oid.Address addrLocked.SetContainer(idCnr) @@ -105,6 +104,7 @@ func (e *StorageEngine) lockSingle(ctx context.Context, idCnr cid.ID, locker, lo if err != nil { e.reportShardError(sh, "could not lock object in shard", err) + var errIrregular *apistatus.LockNonRegularObject if errors.As(err, &errIrregular) { status = 1 return true diff --git a/pkg/local_object_storage/engine/lock_test.go b/pkg/local_object_storage/engine/lock_test.go index a7f0a1552..3e253bfc7 100644 --- a/pkg/local_object_storage/engine/lock_test.go +++ b/pkg/local_object_storage/engine/lock_test.go @@ -119,8 +119,9 @@ func TestLockUserScenario(t *testing.T) { var inhumePrm InhumePrm inhumePrm.WithTarget(tombAddr, objAddr) + var objLockedErr *apistatus.ObjectLocked _, err = e.Inhume(context.Background(), inhumePrm) - require.ErrorAs(t, err, new(apistatus.ObjectLocked)) + require.ErrorAs(t, err, &objLockedErr) // 4. tombObj.SetType(objectSDK.TypeTombstone) @@ -208,8 +209,9 @@ func TestLockExpiration(t *testing.T) { var inhumePrm InhumePrm inhumePrm.WithTarget(oidtest.Address(), objectcore.AddressOf(obj)) + var objLockedErr *apistatus.ObjectLocked _, err = e.Inhume(context.Background(), inhumePrm) - require.ErrorAs(t, err, new(apistatus.ObjectLocked)) + require.ErrorAs(t, err, &objLockedErr) // 3. e.HandleNewEpoch(lockerExpiresAfter + 1) @@ -281,13 +283,14 @@ func TestLockForceRemoval(t *testing.T) { var inhumePrm InhumePrm inhumePrm.MarkAsGarbage(objectcore.AddressOf(obj)) + var objLockedErr *apistatus.ObjectLocked _, err = e.Inhume(context.Background(), inhumePrm) - require.ErrorAs(t, err, new(apistatus.ObjectLocked)) + require.ErrorAs(t, err, &objLockedErr) inhumePrm.WithTarget(oidtest.Address(), objectcore.AddressOf(obj)) _, err = e.Inhume(context.Background(), inhumePrm) - require.ErrorAs(t, err, new(apistatus.ObjectLocked)) + require.ErrorAs(t, err, &objLockedErr) // 4. var deletePrm DeletePrm diff --git a/pkg/local_object_storage/engine/range.go b/pkg/local_object_storage/engine/range.go index 328df4587..b3aaea6f5 100644 --- a/pkg/local_object_storage/engine/range.go +++ b/pkg/local_object_storage/engine/range.go @@ -9,6 +9,7 @@ import ( "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/util" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/util/logicerr" "git.frostfs.info/TrueCloudLab/frostfs-observability/tracing" + "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client" apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status" objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object" oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id" @@ -83,14 +84,12 @@ func (e *StorageEngine) getRange(ctx context.Context, prm RngPrm) (RngRes, error defer elapsed("GetRange", e.metrics.AddMethodDuration)() } - var errNotFound apistatus.ObjectNotFound - var shPrm shard.RngPrm shPrm.SetAddress(prm.addr) shPrm.SetRange(prm.off, prm.ln) it := &getRangeShardIterator{ - OutError: errNotFound, + OutError: new(apistatus.ObjectNotFound), ShardPrm: shPrm, Address: prm.addr, Engine: e, @@ -105,7 +104,7 @@ func (e *StorageEngine) getRange(ctx context.Context, prm RngPrm) (RngRes, error if it.Object == nil { // If any shard is in a degraded mode, we should assume that metabase could store // info about some object. - if it.ShardWithMeta.Shard == nil && !it.HasDegraded || !shard.IsErrNotFound(it.OutError) { + if it.ShardWithMeta.Shard == nil && !it.HasDegraded || !client.IsErrObjectNotFound(it.OutError) { return RngRes{}, it.OutError } @@ -171,7 +170,7 @@ func (i *getRangeShardIterator) tryGetWithMeta(ctx context.Context) { i.MetaError = err } switch { - case shard.IsErrNotFound(err): + case client.IsErrObjectNotFound(err): return false // ignore, go to next shard case errors.As(err, &i.SplitInfoError): if i.SplitInfo == nil { @@ -186,7 +185,7 @@ func (i *getRangeShardIterator) tryGetWithMeta(ctx context.Context) { // stop iterating over shards if SplitInfo structure is complete return withLink && withLast case - shard.IsErrRemoved(err), + client.IsErrObjectAlreadyRemoved(err), shard.IsErrOutOfRange(err): i.OutError = err @@ -212,9 +211,7 @@ func (i *getRangeShardIterator) tryGetFromBlobstor(ctx context.Context) { res, err := sh.GetRange(ctx, i.ShardPrm) if shard.IsErrOutOfRange(err) { - var errOutOfRange apistatus.ObjectOutOfRange - - i.OutError = errOutOfRange + i.OutError = new(apistatus.ObjectOutOfRange) return true } i.Object = res.Object() diff --git a/pkg/local_object_storage/metabase/control_test.go b/pkg/local_object_storage/metabase/control_test.go index b67e748b3..8f36423fd 100644 --- a/pkg/local_object_storage/metabase/control_test.go +++ b/pkg/local_object_storage/metabase/control_test.go @@ -7,6 +7,7 @@ import ( "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/object" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/internal/testutil" meta "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/metabase" + "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client" oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id" oidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id/test" "github.com/stretchr/testify/require" @@ -43,7 +44,7 @@ func TestReset(t *testing.T) { require.NoError(t, err) assertExists(addr, true, nil) - assertExists(addrToInhume, false, meta.IsErrRemoved) + assertExists(addrToInhume, false, client.IsErrObjectAlreadyRemoved) err = db.Reset() require.NoError(t, err) diff --git a/pkg/local_object_storage/metabase/delete.go b/pkg/local_object_storage/metabase/delete.go index d387b3d04..f7ff7a129 100644 --- a/pkg/local_object_storage/metabase/delete.go +++ b/pkg/local_object_storage/metabase/delete.go @@ -11,7 +11,7 @@ import ( storagelog "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/internal/log" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/internal/metaerr" "git.frostfs.info/TrueCloudLab/frostfs-observability/tracing" - apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status" + "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client" objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object" oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id" "go.etcd.io/bbolt" @@ -204,9 +204,8 @@ func (db *DB) delete(tx *bbolt.Tx, addr oid.Address, refCounter referenceCounter obj, err := db.get(tx, addr, key, false, true, currEpoch) if err != nil { var siErr *objectSDK.SplitInfoError - var notFoundErr apistatus.ObjectNotFound - if errors.As(err, ¬FoundErr) || errors.As(err, &siErr) { + if client.IsErrObjectNotFound(err) || errors.As(err, &siErr) { return false, false, 0, nil } diff --git a/pkg/local_object_storage/metabase/delete_test.go b/pkg/local_object_storage/metabase/delete_test.go index d2a4bfa7b..9b68f0bf8 100644 --- a/pkg/local_object_storage/metabase/delete_test.go +++ b/pkg/local_object_storage/metabase/delete_test.go @@ -8,7 +8,7 @@ import ( "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/object" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/internal/testutil" meta "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/metabase" - apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status" + "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client" cidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id/test" objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object" oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id" @@ -68,11 +68,11 @@ func TestDB_Delete(t *testing.T) { // check if they marked as already removed ok, err := metaExists(db, object.AddressOf(child)) - require.ErrorAs(t, err, &apistatus.ObjectAlreadyRemoved{}) + require.True(t, client.IsErrObjectAlreadyRemoved(err)) require.False(t, ok) ok, err = metaExists(db, object.AddressOf(parent)) - require.ErrorAs(t, err, &apistatus.ObjectAlreadyRemoved{}) + require.True(t, client.IsErrObjectAlreadyRemoved(err)) require.False(t, ok) } diff --git a/pkg/local_object_storage/metabase/errors.go b/pkg/local_object_storage/metabase/errors.go index bc16dc01e..e9ffab439 100644 --- a/pkg/local_object_storage/metabase/errors.go +++ b/pkg/local_object_storage/metabase/errors.go @@ -1,19 +1,10 @@ package meta import ( - "errors" - "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/util/logicerr" - apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status" ) // ErrObjectIsExpired is returned when the requested object's // epoch is less than the current one. Such objects are considered // as removed and should not be returned from the Storage Engine. var ErrObjectIsExpired = logicerr.New("object is expired") - -// IsErrRemoved checks if error returned by Shard Exists/Get/Put method -// corresponds to removed object. -func IsErrRemoved(err error) bool { - return errors.As(err, new(apistatus.ObjectAlreadyRemoved)) -} diff --git a/pkg/local_object_storage/metabase/exists.go b/pkg/local_object_storage/metabase/exists.go index b6e5ea052..aa9aba106 100644 --- a/pkg/local_object_storage/metabase/exists.go +++ b/pkg/local_object_storage/metabase/exists.go @@ -82,9 +82,9 @@ func (db *DB) exists(tx *bbolt.Tx, addr oid.Address, currEpoch uint64) (exists b // check graveyard and object expiration first switch objectStatus(tx, addr, currEpoch) { case 1: - return false, logicerr.Wrap(apistatus.ObjectNotFound{}) + return false, logicerr.Wrap(new(apistatus.ObjectNotFound)) case 2: - return false, logicerr.Wrap(apistatus.ObjectAlreadyRemoved{}) + return false, logicerr.Wrap(new(apistatus.ObjectAlreadyRemoved)) case 3: return false, ErrObjectIsExpired } diff --git a/pkg/local_object_storage/metabase/exists_test.go b/pkg/local_object_storage/metabase/exists_test.go index 034bc0005..06394339a 100644 --- a/pkg/local_object_storage/metabase/exists_test.go +++ b/pkg/local_object_storage/metabase/exists_test.go @@ -7,7 +7,7 @@ import ( "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/object" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/internal/testutil" meta "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/metabase" - apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status" + "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client" cidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id/test" objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object" oidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id/test" @@ -40,7 +40,7 @@ func TestDB_Exists(t *testing.T) { require.NoError(t, err) exists, err := metaExists(db, object.AddressOf(regular)) - require.ErrorAs(t, err, new(apistatus.ObjectAlreadyRemoved)) + require.True(t, client.IsErrObjectAlreadyRemoved(err)) require.False(t, exists) }) }) diff --git a/pkg/local_object_storage/metabase/get.go b/pkg/local_object_storage/metabase/get.go index ad35b4c18..d18331a3d 100644 --- a/pkg/local_object_storage/metabase/get.go +++ b/pkg/local_object_storage/metabase/get.go @@ -91,9 +91,9 @@ func (db *DB) get(tx *bbolt.Tx, addr oid.Address, key []byte, checkStatus, raw b if checkStatus { switch objectStatus(tx, addr, currEpoch) { case 1: - return nil, logicerr.Wrap(apistatus.ObjectNotFound{}) + return nil, logicerr.Wrap(new(apistatus.ObjectNotFound)) case 2: - return nil, logicerr.Wrap(apistatus.ObjectAlreadyRemoved{}) + return nil, logicerr.Wrap(new(apistatus.ObjectAlreadyRemoved)) case 3: return nil, ErrObjectIsExpired } @@ -143,7 +143,7 @@ func getVirtualObject(tx *bbolt.Tx, cnr cid.ID, key []byte, raw bool) (*objectSD bucketName := make([]byte, bucketKeySize) parentBucket := tx.Bucket(parentBucketName(cnr, bucketName)) if parentBucket == nil { - return nil, logicerr.Wrap(apistatus.ObjectNotFound{}) + return nil, logicerr.Wrap(new(apistatus.ObjectNotFound)) } relativeLst, err := decodeList(parentBucket.Get(key)) @@ -152,7 +152,7 @@ func getVirtualObject(tx *bbolt.Tx, cnr cid.ID, key []byte, raw bool) (*objectSD } if len(relativeLst) == 0 { // this should never happen though - return nil, logicerr.Wrap(apistatus.ObjectNotFound{}) + return nil, logicerr.Wrap(new(apistatus.ObjectNotFound)) } // pick last item, for now there is not difference which address to pick @@ -171,7 +171,7 @@ func getVirtualObject(tx *bbolt.Tx, cnr cid.ID, key []byte, raw bool) (*objectSD par := child.Parent() if par == nil { // this should never happen though - return nil, logicerr.Wrap(apistatus.ObjectNotFound{}) + return nil, logicerr.Wrap(new(apistatus.ObjectNotFound)) } return par, nil @@ -183,5 +183,5 @@ func getSplitInfoError(tx *bbolt.Tx, cnr cid.ID, key []byte) error { return logicerr.Wrap(objectSDK.NewSplitInfoError(splitInfo)) } - return logicerr.Wrap(apistatus.ObjectNotFound{}) + return logicerr.Wrap(new(apistatus.ObjectNotFound)) } diff --git a/pkg/local_object_storage/metabase/get_test.go b/pkg/local_object_storage/metabase/get_test.go index c19fea8d8..98a4bd960 100644 --- a/pkg/local_object_storage/metabase/get_test.go +++ b/pkg/local_object_storage/metabase/get_test.go @@ -12,7 +12,7 @@ import ( "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/object" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/internal/testutil" meta "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/metabase" - apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status" + "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client" cidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id/test" objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object" oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id" @@ -114,7 +114,7 @@ func TestDB_Get(t *testing.T) { require.NoError(t, metaInhume(db, obj, ts)) _, err := metaGet(db, obj, false) - require.ErrorAs(t, err, new(apistatus.ObjectAlreadyRemoved)) + require.True(t, client.IsErrObjectAlreadyRemoved(err)) obj = oidtest.Address() @@ -124,7 +124,7 @@ func TestDB_Get(t *testing.T) { _, err = db.Inhume(context.Background(), prm) require.NoError(t, err) _, err = metaGet(db, obj, false) - require.ErrorAs(t, err, new(apistatus.ObjectNotFound)) + require.True(t, client.IsErrObjectNotFound(err)) }) t.Run("expired object", func(t *testing.T) { diff --git a/pkg/local_object_storage/metabase/inhume.go b/pkg/local_object_storage/metabase/inhume.go index 7ba5a68a2..fe8b8873e 100644 --- a/pkg/local_object_storage/metabase/inhume.go +++ b/pkg/local_object_storage/metabase/inhume.go @@ -166,7 +166,7 @@ func (db *DB) inhumeTx(tx *bbolt.Tx, epoch uint64, prm InhumePrm, res *InhumeRes // prevent locked objects to be inhumed if !prm.forceRemoval && objectLocked(tx, cnr, id) { - return apistatus.ObjectLocked{} + return new(apistatus.ObjectLocked) } var lockWasChecked bool diff --git a/pkg/local_object_storage/metabase/inhume_test.go b/pkg/local_object_storage/metabase/inhume_test.go index 0f0774227..378e38e79 100644 --- a/pkg/local_object_storage/metabase/inhume_test.go +++ b/pkg/local_object_storage/metabase/inhume_test.go @@ -7,6 +7,7 @@ import ( "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/object" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/internal/testutil" meta "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/metabase" + "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client" apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status" oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id" oidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id/test" @@ -28,10 +29,10 @@ func TestDB_Inhume(t *testing.T) { require.NoError(t, err) _, err = metaExists(db, object.AddressOf(raw)) - require.ErrorAs(t, err, new(apistatus.ObjectAlreadyRemoved)) + require.True(t, client.IsErrObjectAlreadyRemoved(err)) _, err = metaGet(db, object.AddressOf(raw), false) - require.ErrorAs(t, err, new(apistatus.ObjectAlreadyRemoved)) + require.True(t, client.IsErrObjectAlreadyRemoved(err)) } func TestInhumeTombOnTomb(t *testing.T) { @@ -58,7 +59,7 @@ func TestInhumeTombOnTomb(t *testing.T) { // addr1 should become inhumed {addr1:addr2} _, err = db.Exists(context.Background(), existsPrm) - require.ErrorAs(t, err, new(apistatus.ObjectAlreadyRemoved)) + require.True(t, client.IsErrObjectAlreadyRemoved(err)) inhumePrm.SetAddresses(addr3) inhumePrm.SetTombstoneAddress(addr1) @@ -72,13 +73,13 @@ func TestInhumeTombOnTomb(t *testing.T) { // NOT ObjectAlreadyRemoved since that record has been removed // from graveyard but addr1 is still marked with GC _, err = db.Exists(context.Background(), existsPrm) - require.ErrorAs(t, err, new(apistatus.ObjectNotFound)) + require.True(t, client.IsErrObjectNotFound(err)) existsPrm.SetAddress(addr3) // addr3 should be inhumed {addr3: addr1} _, err = db.Exists(context.Background(), existsPrm) - require.ErrorAs(t, err, new(apistatus.ObjectAlreadyRemoved)) + require.True(t, client.IsErrObjectAlreadyRemoved(err)) inhumePrm.SetAddresses(addr1) inhumePrm.SetTombstoneAddress(oidtest.Address()) @@ -93,7 +94,7 @@ func TestInhumeTombOnTomb(t *testing.T) { // (tomb can not be inhumed) but should be kept as object // with GC mark _, err = db.Exists(context.Background(), existsPrm) - require.ErrorAs(t, err, new(apistatus.ObjectNotFound)) + require.True(t, client.IsErrObjectNotFound(err)) } func TestInhumeLocked(t *testing.T) { @@ -109,7 +110,7 @@ func TestInhumeLocked(t *testing.T) { _, err = db.Inhume(context.Background(), prm) - var e apistatus.ObjectLocked + var e *apistatus.ObjectLocked require.ErrorAs(t, err, &e) } diff --git a/pkg/local_object_storage/metabase/lock.go b/pkg/local_object_storage/metabase/lock.go index 50aac223b..30a31ab87 100644 --- a/pkg/local_object_storage/metabase/lock.go +++ b/pkg/local_object_storage/metabase/lock.go @@ -80,7 +80,7 @@ func (db *DB) lockInternal(locked []oid.ID, cnr cid.ID, locker oid.ID) error { return metaerr.Wrap(db.boltDB.Update(func(tx *bbolt.Tx) error { if firstIrregularObjectType(tx, cnr, bucketKeysLocked...) != objectSDK.TypeRegular { - return logicerr.Wrap(apistatus.LockNonRegularObject{}) + return logicerr.Wrap(new(apistatus.LockNonRegularObject)) } bucketLocked := tx.Bucket(bucketNameLocked) diff --git a/pkg/local_object_storage/metabase/lock_test.go b/pkg/local_object_storage/metabase/lock_test.go index b442296fd..834ab07a7 100644 --- a/pkg/local_object_storage/metabase/lock_test.go +++ b/pkg/local_object_storage/metabase/lock_test.go @@ -41,7 +41,7 @@ func TestDB_Lock(t *testing.T) { err := metaPut(db, obj, nil) require.NoError(t, err, typ) - var e apistatus.LockNonRegularObject + var e *apistatus.LockNonRegularObject id, _ := obj.ID() @@ -66,13 +66,15 @@ func TestDB_Lock(t *testing.T) { // check locking relation + var objLockedErr *apistatus.ObjectLocked + inhumePrm.SetAddresses(objAddr) _, err := db.Inhume(context.Background(), inhumePrm) - require.ErrorAs(t, err, new(apistatus.ObjectLocked)) + require.ErrorAs(t, err, &objLockedErr) inhumePrm.SetTombstoneAddress(oidtest.Address()) _, err = db.Inhume(context.Background(), inhumePrm) - require.ErrorAs(t, err, new(apistatus.ObjectLocked)) + require.ErrorAs(t, err, &objLockedErr) // try to remove lock object inhumePrm.SetAddresses(lockAddr) @@ -84,11 +86,11 @@ func TestDB_Lock(t *testing.T) { inhumePrm.SetAddresses(objAddr) _, err = db.Inhume(context.Background(), inhumePrm) - require.ErrorAs(t, err, new(apistatus.ObjectLocked)) + require.ErrorAs(t, err, &objLockedErr) inhumePrm.SetTombstoneAddress(oidtest.Address()) _, err = db.Inhume(context.Background(), inhumePrm) - require.ErrorAs(t, err, new(apistatus.ObjectLocked)) + require.ErrorAs(t, err, &objLockedErr) }) t.Run("lock-unlock scenario", func(t *testing.T) { @@ -97,9 +99,11 @@ func TestDB_Lock(t *testing.T) { objAddr := objectcore.AddressOf(objs[0]) lockAddr := objectcore.AddressOf(lockObj) + var objLockedErr *apistatus.ObjectLocked + // try to inhume locked object using tombstone err := metaInhume(db, objAddr, lockAddr) - require.ErrorAs(t, err, new(apistatus.ObjectLocked)) + require.ErrorAs(t, err, &objLockedErr) // free locked object var inhumePrm meta.InhumePrm diff --git a/pkg/local_object_storage/shard/control.go b/pkg/local_object_storage/shard/control.go index db8248c02..a49a79043 100644 --- a/pkg/local_object_storage/shard/control.go +++ b/pkg/local_object_storage/shard/control.go @@ -11,6 +11,7 @@ import ( meta "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/metabase" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/shard/mode" "git.frostfs.info/TrueCloudLab/frostfs-observability/tracing" + "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client" objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object" oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id" "go.uber.org/zap" @@ -195,7 +196,7 @@ func (s *Shard) refillMetabase(ctx context.Context) error { mPrm.SetStorageID(descriptor) _, err = s.metaBase.Put(ctx, mPrm) - if err != nil && !meta.IsErrRemoved(err) && !errors.Is(err, meta.ErrObjectIsExpired) { + if err != nil && !client.IsErrObjectAlreadyRemoved(err) && !errors.Is(err, meta.ErrObjectIsExpired) { return err } diff --git a/pkg/local_object_storage/shard/control_test.go b/pkg/local_object_storage/shard/control_test.go index 23677c58a..deeb39300 100644 --- a/pkg/local_object_storage/shard/control_test.go +++ b/pkg/local_object_storage/shard/control_test.go @@ -20,6 +20,7 @@ import ( writecacheconfig "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/writecache/config" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/writecache/writecachebbolt" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger" + "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client" apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status" cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id" cidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id/test" @@ -170,7 +171,7 @@ func TestRefillMetabaseCorrupted(t *testing.T) { var getPrm GetPrm getPrm.SetAddress(addr) _, err = sh.Get(context.Background(), getPrm) - require.ErrorAs(t, err, new(apistatus.ObjectNotFound)) + require.True(t, client.IsErrObjectNotFound(err)) require.NoError(t, sh.Close()) } @@ -297,7 +298,7 @@ func TestRefillMetabase(t *testing.T) { res, err := sh.Head(context.Background(), headPrm) if expObj == nil { - require.ErrorAs(t, err, new(apistatus.ObjectNotFound)) + require.True(t, client.IsErrObjectNotFound(err)) return } @@ -322,9 +323,9 @@ func TestRefillMetabase(t *testing.T) { _, err := sh.Head(context.Background(), headPrm) if exists { - require.ErrorAs(t, err, new(apistatus.ObjectAlreadyRemoved)) + require.True(t, client.IsErrObjectAlreadyRemoved(err)) } else { - require.ErrorAs(t, err, new(apistatus.ObjectNotFound)) + require.True(t, client.IsErrObjectNotFound(err)) } } } @@ -339,9 +340,9 @@ func TestRefillMetabase(t *testing.T) { var prm InhumePrm prm.MarkAsGarbage(addr) + var target *apistatus.ObjectLocked _, err := sh.Inhume(context.Background(), prm) - require.ErrorAs(t, err, new(apistatus.ObjectLocked), - "object %s should be locked", locked[i]) + require.ErrorAs(t, err, &target, "object %s should be locked", locked[i]) } } diff --git a/pkg/local_object_storage/shard/delete.go b/pkg/local_object_storage/shard/delete.go index 2c7e0af27..c683d65a8 100644 --- a/pkg/local_object_storage/shard/delete.go +++ b/pkg/local_object_storage/shard/delete.go @@ -9,6 +9,7 @@ import ( meta "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/metabase" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/writecache" "git.frostfs.info/TrueCloudLab/frostfs-observability/tracing" + "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client" oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id" "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/trace" @@ -79,7 +80,7 @@ func (s *Shard) delete(ctx context.Context, prm DeletePrm) (DeleteRes, error) { func (s *Shard) deleteObjectFromWriteCacheSafe(ctx context.Context, addr oid.Address) { if s.hasWriteCache() { err := s.writeCache.Delete(ctx, addr) - if err != nil && !IsErrNotFound(err) && !errors.Is(err, writecache.ErrReadOnly) { + if err != nil && !client.IsErrObjectNotFound(err) && !errors.Is(err, writecache.ErrReadOnly) { s.log.Warn(logs.ShardCantDeleteObjectFromWriteCache, zap.Error(err)) } } diff --git a/pkg/local_object_storage/shard/delete_test.go b/pkg/local_object_storage/shard/delete_test.go index 441e1c455..aba204f36 100644 --- a/pkg/local_object_storage/shard/delete_test.go +++ b/pkg/local_object_storage/shard/delete_test.go @@ -7,7 +7,7 @@ import ( "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/object" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/internal/testutil" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/shard" - apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status" + "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client" cidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id/test" "github.com/stretchr/testify/require" ) @@ -57,7 +57,7 @@ func testShardDelete(t *testing.T, hasWriteCache bool) { require.NoError(t, err) _, err = sh.Get(context.Background(), getPrm) - require.ErrorAs(t, err, new(apistatus.ObjectNotFound)) + require.True(t, client.IsErrObjectNotFound(err)) }) t.Run("small object", func(t *testing.T) { @@ -81,6 +81,6 @@ func testShardDelete(t *testing.T, hasWriteCache bool) { require.NoError(t, err) _, err = sh.Get(context.Background(), getPrm) - require.ErrorAs(t, err, new(apistatus.ObjectNotFound)) + require.True(t, client.IsErrObjectNotFound(err)) }) } diff --git a/pkg/local_object_storage/shard/errors.go b/pkg/local_object_storage/shard/errors.go index 2958a492c..045ad1bba 100644 --- a/pkg/local_object_storage/shard/errors.go +++ b/pkg/local_object_storage/shard/errors.go @@ -10,22 +10,11 @@ import ( var ErrShardDisabled = logicerr.New("shard disabled") -// 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)) -} - -// 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)) -} - // 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)) + var target *apistatus.ObjectOutOfRange + return errors.As(err, &target) } // IsErrObjectExpired checks if an error returned by Shard corresponds to diff --git a/pkg/local_object_storage/shard/gc_internal_test.go b/pkg/local_object_storage/shard/gc_internal_test.go index bc895d67b..cf6633962 100644 --- a/pkg/local_object_storage/shard/gc_internal_test.go +++ b/pkg/local_object_storage/shard/gc_internal_test.go @@ -16,6 +16,7 @@ import ( "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/pilorama" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger" + "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client" cidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id/test" objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object" oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id" @@ -109,7 +110,7 @@ func Test_ObjectNotFoundIfNotDeletedFromMetabase(t *testing.T) { require.NoError(t, err, "failed to inhume") _, err = sh.Get(context.Background(), getPrm) require.Error(t, err, "get returned error") - require.True(t, IsErrNotFound(err), "invalid error type") + require.True(t, client.IsErrObjectNotFound(err), "invalid error type") //storageID var metaStIDPrm meta.StorageIDPrm @@ -140,5 +141,5 @@ func Test_ObjectNotFoundIfNotDeletedFromMetabase(t *testing.T) { //get should return object not found _, err = sh.Get(context.Background(), getPrm) require.Error(t, err, "get returned no error") - require.True(t, IsErrNotFound(err), "invalid error type") + require.True(t, client.IsErrObjectNotFound(err), "invalid error type") } diff --git a/pkg/local_object_storage/shard/gc_test.go b/pkg/local_object_storage/shard/gc_test.go index 4b154462c..9d2771ae4 100644 --- a/pkg/local_object_storage/shard/gc_test.go +++ b/pkg/local_object_storage/shard/gc_test.go @@ -12,6 +12,7 @@ import ( meta "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/metabase" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/shard" writecacheconfig "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/writecache/config" + "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client" cidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id/test" objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object" oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id" @@ -74,7 +75,7 @@ func Test_GCDropsLockedExpiredSimpleObject(t *testing.T) { getPrm.SetAddress(objectCore.AddressOf(obj)) require.Eventually(t, func() bool { _, err = sh.Get(context.Background(), getPrm) - return shard.IsErrNotFound(err) + return client.IsErrObjectNotFound(err) }, 3*time.Second, 1*time.Second, "expired object must be deleted") } @@ -171,6 +172,6 @@ func Test_GCDropsLockedExpiredComplexObject(t *testing.T) { require.Eventually(t, func() bool { _, err = sh.Get(context.Background(), getPrm) - return shard.IsErrNotFound(err) + return client.IsErrObjectNotFound(err) }, 3*time.Second, 1*time.Second, "expired complex object must be deleted on epoch after lock expires") } diff --git a/pkg/local_object_storage/shard/get.go b/pkg/local_object_storage/shard/get.go index 3eb70784e..91565a346 100644 --- a/pkg/local_object_storage/shard/get.go +++ b/pkg/local_object_storage/shard/get.go @@ -11,6 +11,7 @@ import ( "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/util/logicerr" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/writecache" "git.frostfs.info/TrueCloudLab/frostfs-observability/tracing" + "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client" apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status" objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object" oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id" @@ -129,7 +130,7 @@ func (s *Shard) fetchObjectData(ctx context.Context, addr oid.Address, skipMeta } if !mRes.Exists() { - return nil, false, logicerr.Wrap(apistatus.ObjectNotFound{}) + return nil, false, logicerr.Wrap(new(apistatus.ObjectNotFound)) } } else { s.log.Warn(logs.ShardFetchingObjectWithoutMeta, zap.Stringer("addr", addr)) @@ -140,7 +141,7 @@ func (s *Shard) fetchObjectData(ctx context.Context, addr oid.Address, skipMeta if err == nil || IsErrOutOfRange(err) { return res, false, err } - if IsErrNotFound(err) { + if client.IsErrObjectNotFound(err) { s.log.Debug(logs.ShardObjectIsMissingInWritecache, zap.Stringer("addr", addr), zap.Bool("skip_meta", skipMeta)) diff --git a/pkg/local_object_storage/shard/get_test.go b/pkg/local_object_storage/shard/get_test.go index 2db86c48a..25639902d 100644 --- a/pkg/local_object_storage/shard/get_test.go +++ b/pkg/local_object_storage/shard/get_test.go @@ -10,6 +10,7 @@ import ( "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/object" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/internal/testutil" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/shard" + "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client" cidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id/test" objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object" oidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id/test" @@ -119,10 +120,10 @@ func testGet(t *testing.T, sh *shard.Shard, getPrm shard.GetPrm, hasWriteCache b res, err := sh.Get(context.Background(), getPrm) if hasWriteCache { require.Eventually(t, func() bool { - if shard.IsErrNotFound(err) { + if client.IsErrObjectNotFound(err) { res, err = sh.Get(context.Background(), getPrm) } - return !shard.IsErrNotFound(err) + return !client.IsErrObjectNotFound(err) }, time.Second, time.Millisecond*100) } return res, err diff --git a/pkg/local_object_storage/shard/head_test.go b/pkg/local_object_storage/shard/head_test.go index 7e336ea06..3a7457ace 100644 --- a/pkg/local_object_storage/shard/head_test.go +++ b/pkg/local_object_storage/shard/head_test.go @@ -9,6 +9,7 @@ import ( "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/object" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/internal/testutil" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/shard" + "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client" cidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id/test" objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object" "github.com/stretchr/testify/require" @@ -90,10 +91,10 @@ func testHead(t *testing.T, sh *shard.Shard, headPrm shard.HeadPrm, hasWriteCach res, err := sh.Head(context.Background(), headPrm) if hasWriteCache { require.Eventually(t, func() bool { - if shard.IsErrNotFound(err) { + if client.IsErrObjectNotFound(err) { res, err = sh.Head(context.Background(), headPrm) } - return !shard.IsErrNotFound(err) + return !client.IsErrObjectNotFound(err) }, time.Second, time.Millisecond*100) } return res, err diff --git a/pkg/local_object_storage/shard/inhume_test.go b/pkg/local_object_storage/shard/inhume_test.go index 4151d6218..3fa6bc0a3 100644 --- a/pkg/local_object_storage/shard/inhume_test.go +++ b/pkg/local_object_storage/shard/inhume_test.go @@ -7,7 +7,7 @@ import ( "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/object" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/internal/testutil" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/shard" - apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status" + "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client" cidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id/test" "github.com/stretchr/testify/require" ) @@ -56,5 +56,5 @@ func testShardInhume(t *testing.T, hasWriteCache bool) { require.NoError(t, err) _, err = sh.Get(context.Background(), getPrm) - require.ErrorAs(t, err, new(apistatus.ObjectAlreadyRemoved)) + require.True(t, client.IsErrObjectAlreadyRemoved(err)) } diff --git a/pkg/local_object_storage/shard/lock_test.go b/pkg/local_object_storage/shard/lock_test.go index 61f2bb9f0..da71c4808 100644 --- a/pkg/local_object_storage/shard/lock_test.go +++ b/pkg/local_object_storage/shard/lock_test.go @@ -13,6 +13,7 @@ import ( meta "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/metabase" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/shard" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger" + "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client" apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status" cidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id/test" objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object" @@ -96,12 +97,14 @@ func TestShard_Lock(t *testing.T) { var inhumePrm shard.InhumePrm inhumePrm.SetTarget(objectcore.AddressOf(ts), objectcore.AddressOf(obj)) + var objLockedErr *apistatus.ObjectLocked + _, err = sh.Inhume(context.Background(), inhumePrm) - require.ErrorAs(t, err, new(apistatus.ObjectLocked)) + require.ErrorAs(t, err, &objLockedErr) inhumePrm.MarkAsGarbage(objectcore.AddressOf(obj)) _, err = sh.Inhume(context.Background(), inhumePrm) - require.ErrorAs(t, err, new(apistatus.ObjectLocked)) + require.ErrorAs(t, err, &objLockedErr) }) t.Run("inhuming lock objects", func(t *testing.T) { @@ -141,7 +144,7 @@ func TestShard_Lock(t *testing.T) { getPrm.SetAddress(objectcore.AddressOf(obj)) _, err = sh.Get(context.Background(), getPrm) - require.ErrorAs(t, err, new(apistatus.ObjectNotFound)) + require.True(t, client.IsErrObjectNotFound(err)) }) } diff --git a/pkg/local_object_storage/shard/range.go b/pkg/local_object_storage/shard/range.go index e94482e36..9491543c4 100644 --- a/pkg/local_object_storage/shard/range.go +++ b/pkg/local_object_storage/shard/range.go @@ -119,7 +119,7 @@ func (s *Shard) GetRange(ctx context.Context, prm RngPrm) (RngRes, error) { from := prm.off to := from + prm.ln if pLen := uint64(len(payload)); to < from || pLen < from || pLen < to { - return nil, logicerr.Wrap(apistatus.ObjectOutOfRange{}) + return nil, logicerr.Wrap(new(apistatus.ObjectOutOfRange)) } obj := objectSDK.New() diff --git a/pkg/local_object_storage/shard/range_test.go b/pkg/local_object_storage/shard/range_test.go index 11a8aab5e..1806990ab 100644 --- a/pkg/local_object_storage/shard/range_test.go +++ b/pkg/local_object_storage/shard/range_test.go @@ -119,7 +119,8 @@ func testShardGetRange(t *testing.T, hasWriteCache bool) { res, err := sh.GetRange(context.Background(), rngPrm) if tc.hasErr { - require.ErrorAs(t, err, &apistatus.ObjectOutOfRange{}) + var target *apistatus.ObjectOutOfRange + require.ErrorAs(t, err, &target) } else { require.Equal(t, payload[tc.rng.GetOffset():tc.rng.GetOffset()+tc.rng.GetLength()], diff --git a/pkg/local_object_storage/writecache/writecachebadger/delete.go b/pkg/local_object_storage/writecache/writecachebadger/delete.go index 1b46b2be9..f37371098 100644 --- a/pkg/local_object_storage/writecache/writecachebadger/delete.go +++ b/pkg/local_object_storage/writecache/writecachebadger/delete.go @@ -45,7 +45,7 @@ func (c *cache) Delete(ctx context.Context, addr oid.Address) error { it, err := tx.Get([]byte(saddr)) if err != nil { if err == badger.ErrKeyNotFound { - return logicerr.Wrap(apistatus.ObjectNotFound{}) + return logicerr.Wrap(new(apistatus.ObjectNotFound)) } return err } diff --git a/pkg/local_object_storage/writecache/writecachebadger/get.go b/pkg/local_object_storage/writecache/writecachebadger/get.go index 36896c569..42403e551 100644 --- a/pkg/local_object_storage/writecache/writecachebadger/get.go +++ b/pkg/local_object_storage/writecache/writecachebadger/get.go @@ -47,7 +47,7 @@ func (c *cache) getInternal(addr oid.Address) (*objectSDK.Object, error) { return obj, obj.Unmarshal(value) } - return nil, logicerr.Wrap(apistatus.ObjectNotFound{}) + return nil, logicerr.Wrap(new(apistatus.ObjectNotFound)) } // Head returns object header from write-cache. @@ -79,7 +79,7 @@ func Get(db *badger.DB, key []byte) ([]byte, error) { it, err := tx.Get(key) if err != nil { if err == badger.ErrKeyNotFound { - return logicerr.Wrap(apistatus.ObjectNotFound{}) + return logicerr.Wrap(new(apistatus.ObjectNotFound)) } return err } diff --git a/pkg/local_object_storage/writecache/writecachebbolt/get.go b/pkg/local_object_storage/writecache/writecachebbolt/get.go index 9d2bc39dc..dede1fece 100644 --- a/pkg/local_object_storage/writecache/writecachebbolt/get.go +++ b/pkg/local_object_storage/writecache/writecachebbolt/get.go @@ -52,7 +52,7 @@ func (c *cache) getInternal(ctx context.Context, saddr string, addr oid.Address) res, err := c.fsTree.Get(ctx, common.GetPrm{Address: addr}) if err != nil { - return nil, logicerr.Wrap(apistatus.ObjectNotFound{}) + return nil, logicerr.Wrap(new(apistatus.ObjectNotFound)) } found = true @@ -93,7 +93,7 @@ func Get(db *bbolt.DB, key []byte) ([]byte, error) { } value = b.Get(key) if value == nil { - return logicerr.Wrap(apistatus.ObjectNotFound{}) + return logicerr.Wrap(new(apistatus.ObjectNotFound)) } value = slice.Copy(value) return nil diff --git a/pkg/local_object_storage/writecache/writecachebbolt/storage.go b/pkg/local_object_storage/writecache/writecachebbolt/storage.go index 23f873d11..67397f985 100644 --- a/pkg/local_object_storage/writecache/writecachebbolt/storage.go +++ b/pkg/local_object_storage/writecache/writecachebbolt/storage.go @@ -2,7 +2,6 @@ package writecachebbolt import ( "context" - "errors" "fmt" "os" @@ -12,7 +11,7 @@ import ( storagelog "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/internal/log" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/writecache" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util" - apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status" + "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client" oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id" "go.etcd.io/bbolt" "go.uber.org/zap" @@ -98,7 +97,7 @@ func (c *cache) deleteFromDisk(ctx context.Context, keys []string) []string { } _, err := c.fsTree.Delete(ctx, common.DeletePrm{Address: addr}) - if err != nil && !errors.As(err, new(apistatus.ObjectNotFound)) { + if err != nil && !client.IsErrObjectNotFound(err) { c.log.Error(logs.WritecacheCantRemoveObjectFromWritecache, zap.Error(err)) // Save the key for the next iteration. diff --git a/pkg/morph/client/container/eacl.go b/pkg/morph/client/container/eacl.go index 54c83737d..8e9455050 100644 --- a/pkg/morph/client/container/eacl.go +++ b/pkg/morph/client/container/eacl.go @@ -55,9 +55,7 @@ func (c *Client) GetEACL(cnr cid.ID) (*container.EACL, error) { // The absence of a signature in the response can be taken as an eACL absence criterion, // since unsigned table cannot be approved in the storage by design. if len(sig) == 0 { - var errEACLNotFound apistatus.EACLNotFound - - return nil, errEACLNotFound + return nil, new(apistatus.EACLNotFound) } pub, err := client.BytesFromStackItem(arr[2]) diff --git a/pkg/morph/client/container/get.go b/pkg/morph/client/container/get.go index 0513eea4b..6715f870f 100644 --- a/pkg/morph/client/container/get.go +++ b/pkg/morph/client/container/get.go @@ -51,9 +51,7 @@ func (c *Client) Get(cid []byte) (*containercore.Container, error) { res, err := c.client.TestInvoke(prm) if err != nil { if strings.Contains(err.Error(), containerContract.NotFoundError) { - var errNotFound apistatus.ContainerNotFound - - return nil, errNotFound + return nil, new(apistatus.ContainerNotFound) } return nil, fmt.Errorf("could not perform test invocation (%s): %w", getMethod, err) } else if ln := len(res); ln != 1 { diff --git a/pkg/services/object/acl/v2/service.go b/pkg/services/object/acl/v2/service.go index 412708b1c..271c4d20b 100644 --- a/pkg/services/object/acl/v2/service.go +++ b/pkg/services/object/acl/v2/service.go @@ -639,7 +639,7 @@ func (b Service) findRequestInfo(req MetaWithToken, idCnr cid.ID, op acl.Op) (in return info, errors.New("can't fetch current epoch") } if req.token.ExpiredAt(currentEpoch) { - return info, apistatus.SessionTokenExpired{} + return info, new(apistatus.SessionTokenExpired) } if req.token.InvalidAt(currentEpoch) { return info, fmt.Errorf("%s: token is invalid at %d epoch)", diff --git a/pkg/services/object/common.go b/pkg/services/object/common.go index 0d39dce0b..73ee9f81b 100644 --- a/pkg/services/object/common.go +++ b/pkg/services/object/common.go @@ -32,11 +32,9 @@ func (x *Common) Init(state NodeState, nextHandler ServiceServer) { x.nextHandler = nextHandler } -var errMaintenance apistatus.NodeUnderMaintenance - func (x *Common) Get(req *objectV2.GetRequest, stream GetObjectStream) error { if x.state.IsMaintenance() { - return errMaintenance + return new(apistatus.NodeUnderMaintenance) } return x.nextHandler.Get(req, stream) @@ -44,7 +42,7 @@ func (x *Common) Get(req *objectV2.GetRequest, stream GetObjectStream) error { func (x *Common) Put() (PutObjectStream, error) { if x.state.IsMaintenance() { - return nil, errMaintenance + return nil, new(apistatus.NodeUnderMaintenance) } return x.nextHandler.Put() @@ -52,7 +50,7 @@ func (x *Common) Put() (PutObjectStream, error) { func (x *Common) Head(ctx context.Context, req *objectV2.HeadRequest) (*objectV2.HeadResponse, error) { if x.state.IsMaintenance() { - return nil, errMaintenance + return nil, new(apistatus.NodeUnderMaintenance) } return x.nextHandler.Head(ctx, req) @@ -60,7 +58,7 @@ func (x *Common) Head(ctx context.Context, req *objectV2.HeadRequest) (*objectV2 func (x *Common) Search(req *objectV2.SearchRequest, stream SearchStream) error { if x.state.IsMaintenance() { - return errMaintenance + return new(apistatus.NodeUnderMaintenance) } return x.nextHandler.Search(req, stream) @@ -68,7 +66,7 @@ func (x *Common) Search(req *objectV2.SearchRequest, stream SearchStream) error func (x *Common) Delete(ctx context.Context, req *objectV2.DeleteRequest) (*objectV2.DeleteResponse, error) { if x.state.IsMaintenance() { - return nil, errMaintenance + return nil, new(apistatus.NodeUnderMaintenance) } return x.nextHandler.Delete(ctx, req) @@ -76,7 +74,7 @@ func (x *Common) Delete(ctx context.Context, req *objectV2.DeleteRequest) (*obje func (x *Common) GetRange(req *objectV2.GetRangeRequest, stream GetObjectRangeStream) error { if x.state.IsMaintenance() { - return errMaintenance + return new(apistatus.NodeUnderMaintenance) } return x.nextHandler.GetRange(req, stream) @@ -84,7 +82,7 @@ func (x *Common) GetRange(req *objectV2.GetRangeRequest, stream GetObjectRangeSt func (x *Common) GetRangeHash(ctx context.Context, req *objectV2.GetRangeHashRequest) (*objectV2.GetRangeHashResponse, error) { if x.state.IsMaintenance() { - return nil, errMaintenance + return nil, new(apistatus.NodeUnderMaintenance) } return x.nextHandler.GetRangeHash(ctx, req) @@ -92,7 +90,7 @@ func (x *Common) GetRangeHash(ctx context.Context, req *objectV2.GetRangeHashReq func (x *Common) PutSingle(ctx context.Context, req *objectV2.PutSingleRequest) (*objectV2.PutSingleResponse, error) { if x.state.IsMaintenance() { - return nil, errMaintenance + return nil, new(apistatus.NodeUnderMaintenance) } return x.nextHandler.PutSingle(ctx, req) diff --git a/pkg/services/object/get/assemble.go b/pkg/services/object/get/assemble.go index 72ad506c7..6a8c5c818 100644 --- a/pkg/services/object/get/assemble.go +++ b/pkg/services/object/get/assemble.go @@ -63,8 +63,8 @@ func (r *request) assemble(ctx context.Context) { var errSplitInfo *objectSDK.SplitInfoError var errRemovedRemote *apistatus.ObjectAlreadyRemoved var errOutOfRangeRemote *apistatus.ObjectOutOfRange - var errRemovedLocal apistatus.ObjectAlreadyRemoved - var errOutOfRangeLocal apistatus.ObjectOutOfRange + var errRemovedLocal *apistatus.ObjectAlreadyRemoved + var errOutOfRangeLocal *apistatus.ObjectOutOfRange switch { default: diff --git a/pkg/services/object/get/get_test.go b/pkg/services/object/get/get_test.go index 9c5506064..5b391fe2b 100644 --- a/pkg/services/object/get/get_test.go +++ b/pkg/services/object/get/get_test.go @@ -16,6 +16,7 @@ import ( "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/object/util" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/object_manager/placement" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger/test" + clientSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client" apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status" "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container" cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id" @@ -128,9 +129,7 @@ func (c *testClient) addResult(addr oid.Address, obj *objectSDK.Object, err erro func (c *testClient) Get(ctx context.Context, address oid.Address, requestParams RemoteRequestParams) (*objectSDK.Object, error) { v, ok := c.results[address.EncodeToString()] if !ok { - var errNotFound apistatus.ObjectNotFound - - return nil, errNotFound + return nil, new(apistatus.ObjectNotFound) } if v.err != nil { @@ -172,9 +171,7 @@ func (s *testStorage) Range(_ context.Context, address oid.Address, rng *objectS ) if _, ok = s.inhumed[sAddr]; ok { - var errRemoved apistatus.ObjectAlreadyRemoved - - return nil, errRemoved + return nil, new(apistatus.ObjectAlreadyRemoved) } if info, ok := s.virtual[sAddr]; ok { @@ -185,9 +182,7 @@ func (s *testStorage) Range(_ context.Context, address oid.Address, rng *objectS return cutToRange(obj, rng), nil } - var errNotFound apistatus.ObjectNotFound - - return nil, errNotFound + return nil, new(apistatus.ObjectNotFound) } func cutToRange(o *objectSDK.Object, rng *objectSDK.Range) *objectSDK.Object { @@ -374,19 +369,19 @@ func TestGetLocalOnly(t *testing.T) { err := svc.Get(ctx, p) - require.ErrorAs(t, err, new(apistatus.ObjectAlreadyRemoved)) + require.True(t, clientSDK.IsErrObjectAlreadyRemoved(err)) rngPrm := newRngPrm(false, nil, 0, 0) rngPrm.WithAddress(addr) err = svc.GetRange(ctx, rngPrm) - require.ErrorAs(t, err, new(apistatus.ObjectAlreadyRemoved)) + require.True(t, clientSDK.IsErrObjectAlreadyRemoved(err)) headPrm := newHeadPrm(false, nil) headPrm.WithAddress(addr) err = svc.Head(ctx, headPrm) - require.ErrorAs(t, err, new(apistatus.ObjectAlreadyRemoved)) + require.True(t, clientSDK.IsErrObjectAlreadyRemoved(err)) }) t.Run("404", func(t *testing.T) { @@ -401,20 +396,20 @@ func TestGetLocalOnly(t *testing.T) { err := svc.Get(ctx, p) - require.ErrorAs(t, err, new(apistatus.ObjectNotFound)) + require.True(t, clientSDK.IsErrObjectNotFound(err)) rngPrm := newRngPrm(false, nil, 0, 0) rngPrm.WithAddress(addr) err = svc.GetRange(ctx, rngPrm) - require.ErrorAs(t, err, new(apistatus.ObjectNotFound)) + require.True(t, clientSDK.IsErrObjectNotFound(err)) headPrm := newHeadPrm(false, nil) headPrm.WithAddress(addr) err = svc.Head(ctx, headPrm) - require.ErrorAs(t, err, new(apistatus.ObjectNotFound)) + require.True(t, clientSDK.IsErrObjectNotFound(err)) }) t.Run("VIRTUAL", func(t *testing.T) { @@ -679,19 +674,19 @@ func TestGetRemoteSmall(t *testing.T) { p.WithAddress(addr) err := svc.Get(ctx, p) - require.ErrorAs(t, err, new(*apistatus.ObjectAlreadyRemoved)) + require.True(t, clientSDK.IsErrObjectAlreadyRemoved(err)) rngPrm := newRngPrm(false, nil, 0, 0) rngPrm.WithAddress(addr) err = svc.GetRange(ctx, rngPrm) - require.ErrorAs(t, err, new(*apistatus.ObjectAlreadyRemoved)) + require.True(t, clientSDK.IsErrObjectAlreadyRemoved(err)) headPrm := newHeadPrm(false, nil) headPrm.WithAddress(addr) err = svc.Head(ctx, headPrm) - require.ErrorAs(t, err, new(*apistatus.ObjectAlreadyRemoved)) + require.True(t, clientSDK.IsErrObjectAlreadyRemoved(err)) }) t.Run("404", func(t *testing.T) { @@ -723,19 +718,19 @@ func TestGetRemoteSmall(t *testing.T) { p.WithAddress(addr) err := svc.Get(ctx, p) - require.ErrorAs(t, err, new(apistatus.ObjectNotFound)) + require.True(t, clientSDK.IsErrObjectNotFound(err)) rngPrm := newRngPrm(false, nil, 0, 0) rngPrm.WithAddress(addr) err = svc.GetRange(ctx, rngPrm) - require.ErrorAs(t, err, new(apistatus.ObjectNotFound)) + require.True(t, clientSDK.IsErrObjectNotFound(err)) headPrm := newHeadPrm(false, nil) headPrm.WithAddress(addr) err = svc.Head(ctx, headPrm) - require.ErrorAs(t, err, new(apistatus.ObjectNotFound)) + require.True(t, clientSDK.IsErrObjectNotFound(err)) }) t.Run("VIRTUAL", func(t *testing.T) { @@ -768,11 +763,11 @@ func TestGetRemoteSmall(t *testing.T) { c1 := newTestClient() c1.addResult(addr, nil, errors.New("any error")) - c1.addResult(splitAddr, nil, apistatus.ObjectNotFound{}) + c1.addResult(splitAddr, nil, new(apistatus.ObjectNotFound)) c2 := newTestClient() c2.addResult(addr, nil, objectSDK.NewSplitInfoError(splitInfo)) - c2.addResult(splitAddr, nil, apistatus.ObjectNotFound{}) + c2.addResult(splitAddr, nil, new(apistatus.ObjectNotFound)) builder := &testPlacementBuilder{ vectors: map[string][][]netmap.NodeInfo{ @@ -794,13 +789,13 @@ func TestGetRemoteSmall(t *testing.T) { p.WithAddress(addr) err := svc.Get(ctx, p) - require.ErrorAs(t, err, new(apistatus.ObjectNotFound)) + require.True(t, clientSDK.IsErrObjectNotFound(err)) rngPrm := newRngPrm(false, nil, 0, 0) rngPrm.WithAddress(addr) err = svc.GetRange(ctx, rngPrm) - require.ErrorAs(t, err, new(apistatus.ObjectNotFound)) + require.True(t, clientSDK.IsErrObjectNotFound(err)) }) t.Run("get chain element failure", func(t *testing.T) { @@ -845,7 +840,7 @@ func TestGetRemoteSmall(t *testing.T) { c2.addResult(addr, nil, objectSDK.NewSplitInfoError(splitInfo)) c2.addResult(linkAddr, linkingObj, nil) c2.addResult(child1Addr, children[0], nil) - c2.addResult(child2Addr, nil, apistatus.ObjectNotFound{}) + c2.addResult(child2Addr, nil, new(apistatus.ObjectNotFound)) builder := &testPlacementBuilder{ vectors: map[string][][]netmap.NodeInfo{ @@ -869,13 +864,13 @@ func TestGetRemoteSmall(t *testing.T) { p.WithAddress(addr) err := svc.Get(ctx, p) - require.ErrorAs(t, err, new(apistatus.ObjectNotFound)) + require.True(t, clientSDK.IsErrObjectNotFound(err)) rngPrm := newRngPrm(false, NewSimpleObjectWriter(), 0, 1) rngPrm.WithAddress(addr) err = svc.GetRange(ctx, rngPrm) - require.ErrorAs(t, err, new(apistatus.ObjectNotFound)) + require.True(t, clientSDK.IsErrObjectNotFound(err)) }) t.Run("OK", func(t *testing.T) { @@ -1315,11 +1310,11 @@ func TestGetRemoteSmall(t *testing.T) { c1 := newTestClient() c1.addResult(addr, nil, errors.New("any error")) - c1.addResult(splitAddr, nil, apistatus.ObjectNotFound{}) + c1.addResult(splitAddr, nil, new(apistatus.ObjectNotFound)) c2 := newTestClient() c2.addResult(addr, nil, objectSDK.NewSplitInfoError(splitInfo)) - c2.addResult(splitAddr, nil, apistatus.ObjectNotFound{}) + c2.addResult(splitAddr, nil, new(apistatus.ObjectNotFound)) builder := &testPlacementBuilder{ vectors: map[string][][]netmap.NodeInfo{ @@ -1341,13 +1336,13 @@ func TestGetRemoteSmall(t *testing.T) { p.WithAddress(addr) err := svc.Get(ctx, p) - require.ErrorAs(t, err, new(apistatus.ObjectNotFound)) + require.True(t, clientSDK.IsErrObjectNotFound(err)) rngPrm := newRngPrm(false, nil, 0, 0) rngPrm.WithAddress(addr) err = svc.GetRange(ctx, rngPrm) - require.ErrorAs(t, err, new(apistatus.ObjectNotFound)) + require.True(t, clientSDK.IsErrObjectNotFound(err)) }) t.Run("get chain element failure", func(t *testing.T) { @@ -1403,19 +1398,19 @@ func TestGetRemoteSmall(t *testing.T) { testHeadVirtual(svc, addr, splitInfo) headSvc := newTestClient() - headSvc.addResult(preRightAddr, nil, apistatus.ObjectNotFound{}) + headSvc.addResult(preRightAddr, nil, new(apistatus.ObjectNotFound)) p := newPrm(false, NewSimpleObjectWriter()) p.WithAddress(addr) err := svc.Get(ctx, p) - require.ErrorAs(t, err, new(apistatus.ObjectNotFound)) + require.True(t, clientSDK.IsErrObjectNotFound(err)) rngPrm := newRngPrm(false, nil, 0, 1) rngPrm.WithAddress(addr) err = svc.GetRange(ctx, rngPrm) - require.ErrorAs(t, err, new(apistatus.ObjectNotFound)) + require.True(t, clientSDK.IsErrObjectNotFound(err)) }) t.Run("child has different parent", func(t *testing.T) { @@ -1711,7 +1706,7 @@ func TestGetFromPastEpoch(t *testing.T) { p.WithAddress(addr) err := svc.Get(ctx, p) - require.ErrorAs(t, err, new(apistatus.ObjectNotFound)) + require.True(t, clientSDK.IsErrObjectNotFound(err)) commonPrm.SetNetmapLookupDepth(1) @@ -1734,7 +1729,7 @@ func TestGetFromPastEpoch(t *testing.T) { rp.SetRange(r) err = svc.GetRange(ctx, rp) - require.ErrorAs(t, err, new(apistatus.ObjectNotFound)) + require.True(t, clientSDK.IsErrObjectNotFound(err)) w = NewSimpleObjectWriter() rp.SetChunkWriter(w) @@ -1751,7 +1746,7 @@ func TestGetFromPastEpoch(t *testing.T) { hp.WithAddress(addr) err = svc.Head(ctx, hp) - require.ErrorAs(t, err, new(apistatus.ObjectNotFound)) + require.True(t, clientSDK.IsErrObjectNotFound(err)) w = NewSimpleObjectWriter() hp.SetHeaderWriter(w) diff --git a/pkg/services/object/get/local.go b/pkg/services/object/get/local.go index 03ede58cc..257465019 100644 --- a/pkg/services/object/get/local.go +++ b/pkg/services/object/get/local.go @@ -22,8 +22,8 @@ func (r *request) executeLocal(ctx context.Context) { r.collectedObject, err = r.get(ctx) var errSplitInfo *objectSDK.SplitInfoError - var errRemoved apistatus.ObjectAlreadyRemoved - var errOutOfRange apistatus.ObjectOutOfRange + var errRemoved *apistatus.ObjectAlreadyRemoved + var errOutOfRange *apistatus.ObjectOutOfRange switch { default: diff --git a/pkg/services/object/get/remote.go b/pkg/services/object/get/remote.go index e3464f941..4434f036a 100644 --- a/pkg/services/object/get/remote.go +++ b/pkg/services/object/get/remote.go @@ -31,10 +31,8 @@ func (r *request) processNode(ctx context.Context, info client.NodeInfo) bool { switch { default: - var errNotFound apistatus.ObjectNotFound - r.status = statusUndefined - r.err = errNotFound + r.err = new(apistatus.ObjectNotFound) r.log.Debug(logs.GetRemoteCallFailed, zap.Error(err)) case err == nil: diff --git a/pkg/services/object/get/v2/util.go b/pkg/services/object/get/v2/util.go index 9ecc9167f..7f7dd7480 100644 --- a/pkg/services/object/get/v2/util.go +++ b/pkg/services/object/get/v2/util.go @@ -3,7 +3,6 @@ package getsvc import ( "context" "crypto/sha256" - "errors" "hash" objectV2 "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/object" @@ -15,6 +14,7 @@ import ( objectSvc "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/object" getsvc "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/object/get" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/object/util" + clientSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client" apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status" objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object" oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id" @@ -154,7 +154,7 @@ func (s *Service) toHashRangePrm(req *objectV2.GetRangeHashRequest) (*getsvc.Ran ID: tok.ID(), Owner: tok.Issuer(), }) - if err != nil && errors.As(err, new(apistatus.SessionTokenNotFound)) { + if err != nil && clientSDK.IsErrSessionNotFound(err) { commonPrm.ForgetTokens() signerKey, err = s.keyStorage.GetKey(nil) } diff --git a/pkg/services/object/util/key.go b/pkg/services/object/util/key.go index e2ece5849..8304bf13a 100644 --- a/pkg/services/object/util/key.go +++ b/pkg/services/object/util/key.go @@ -68,16 +68,12 @@ func (s *KeyStorage) GetKey(info *SessionInfo) (*ecdsa.PrivateKey, error) { pToken := s.tokenStore.Get(info.Owner, binID) if pToken != nil { if pToken.ExpiredAt() <= s.networkState.CurrentEpoch() { - var errExpired apistatus.SessionTokenExpired - - return nil, errExpired + return nil, new(apistatus.SessionTokenExpired) } return pToken.SessionKey(), nil } - var errNotFound apistatus.SessionTokenNotFound - - return nil, errNotFound + return nil, new(apistatus.SessionTokenNotFound) } return s.key, nil diff --git a/pkg/services/object_manager/tombstone/source/source.go b/pkg/services/object_manager/tombstone/source/source.go index 4d0a81cde..1ff07b05a 100644 --- a/pkg/services/object_manager/tombstone/source/source.go +++ b/pkg/services/object_manager/tombstone/source/source.go @@ -2,12 +2,11 @@ package tsourse import ( "context" - "errors" "fmt" getsvc "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/object/get" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/object/util" - apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status" + "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client" objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object" oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id" ) @@ -68,7 +67,7 @@ func (s Source) Tombstone(ctx context.Context, a oid.Address, _ uint64) (*object err := s.s.Head(ctx, headPrm) switch { - case errors.As(err, new(apistatus.ObjectNotFound)) || errors.As(err, new(apistatus.ObjectAlreadyRemoved)): + case client.IsErrObjectNotFound(err) || client.IsErrObjectAlreadyRemoved(err): return nil, nil case err != nil: return nil, fmt.Errorf("could not get tombstone from the source: %w", err) diff --git a/pkg/services/policer/check.go b/pkg/services/policer/check.go index a45c019eb..800ddb006 100644 --- a/pkg/services/policer/check.go +++ b/pkg/services/policer/check.go @@ -5,7 +5,6 @@ import ( "errors" "git.frostfs.info/TrueCloudLab/frostfs-node/internal/logs" - "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/container" objectcore "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/object" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/replicator" "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client" @@ -27,7 +26,7 @@ func (p *Policer) processObject(ctx context.Context, addrWithType objectcore.Add zap.Stringer("cid", idCnr), zap.String("error", err.Error()), ) - if container.IsErrNotFound(err) { + if client.IsErrContainerNotFound(err) { err := p.buryFn(ctx, addrWithType.Address) if err != nil { p.log.Error(logs.PolicerCouldNotInhumeObjectWithMissingContainer, @@ -218,7 +217,6 @@ func isClientErrMaintenance(err error) bool { default: return false case - apistatus.NodeUnderMaintenance, *apistatus.NodeUnderMaintenance: return true } diff --git a/pkg/services/policer/policer_test.go b/pkg/services/policer/policer_test.go index c0aeac515..37d6c0506 100644 --- a/pkg/services/policer/policer_test.go +++ b/pkg/services/policer/policer_test.go @@ -35,7 +35,7 @@ func TestBuryObjectWithoutContainer(t *testing.T) { // Container source and bury function buryCh := make(chan oid.Address) containerSrc := func(id cid.ID) (*container.Container, error) { - return nil, apistatus.ContainerNotFound{} + return nil, new(apistatus.ContainerNotFound) } buryFn := func(ctx context.Context, a oid.Address) error { buryCh <- a @@ -187,7 +187,7 @@ func TestProcessObject(t *testing.T) { return nil, nil } } - return nil, apistatus.ObjectNotFound{} + return nil, new(apistatus.ObjectNotFound) } // Container source @@ -199,7 +199,7 @@ func TestProcessObject(t *testing.T) { return cnr, nil } t.Errorf("unexpected container requested: got=%v, want=%v", id, addr.Container()) - return nil, apistatus.ContainerNotFound{} + return nil, new(apistatus.ContainerNotFound) } buryFn := func(ctx context.Context, a oid.Address) error { t.Errorf("unexpected object buried: %v", a) @@ -252,7 +252,7 @@ func TestIteratorContract(t *testing.T) { }} containerSrc := func(id cid.ID) (*container.Container, error) { - return nil, apistatus.ContainerNotFound{} + return nil, new(apistatus.ContainerNotFound) } buryFn := func(ctx context.Context, a oid.Address) error { return nil diff --git a/pkg/services/util/sign.go b/pkg/services/util/sign.go index 26586ff49..bce43d6e8 100644 --- a/pkg/services/util/sign.go +++ b/pkg/services/util/sign.go @@ -51,7 +51,7 @@ func (s *SignService) SignResponse(resp ResponseMessage, err error) error { func (s *SignService) VerifyRequest(req RequestMessage) error { if err := signature.VerifyServiceMessage(req); err != nil { - var sigErr apistatus.SignatureVerification + sigErr := new(apistatus.SignatureVerification) sigErr.SetMessage(err.Error()) return sigErr } -- 2.45.2