From 54beea82da67aec790e2de6fe499c70719bd9712 Mon Sep 17 00:00:00 2001 From: Egon Elbre Date: Wed, 19 Apr 2023 12:54:16 +0300 Subject: [PATCH] satellite/metabase: define a local ErrObjectNotFound Updates https://github.com/storj/storj/issues/5291 Change-Id: If847cd95a9b500fb18535d20b46b1b1714021584 --- satellite/gracefulexit/endpoint.go | 2 +- satellite/metabase/commit.go | 4 +++- satellite/metabase/commit_object.go | 3 +-- satellite/metabase/commit_object_test.go | 5 ++--- satellite/metabase/commit_test.go | 4 ++-- satellite/metabase/copy_object.go | 4 ++-- satellite/metabase/copy_object_test.go | 7 +++---- satellite/metabase/delete.go | 4 ++-- satellite/metabase/delete_test.go | 12 ++++++------ satellite/metabase/get.go | 7 +++---- satellite/metabase/get_test.go | 14 +++++++------- satellite/metabase/metadata.go | 3 +-- satellite/metabase/metadata_test.go | 3 +-- satellite/metabase/move_object.go | 4 ++-- satellite/metabase/move_object_test.go | 6 +++--- satellite/metainfo/endpoint.go | 2 +- 16 files changed, 40 insertions(+), 44 deletions(-) diff --git a/satellite/gracefulexit/endpoint.go b/satellite/gracefulexit/endpoint.go index 1130fbf92..348d405a2 100644 --- a/satellite/gracefulexit/endpoint.go +++ b/satellite/gracefulexit/endpoint.go @@ -981,7 +981,7 @@ func (endpoint *Endpoint) UpdatePiecesCheckDuplicates(ctx context.Context, segme }) if err != nil { if metabase.ErrSegmentNotFound.Has(err) { - err = storj.ErrObjectNotFound.Wrap(err) + err = metabase.ErrObjectNotFound.Wrap(err) } return Error.Wrap(err) } diff --git a/satellite/metabase/commit.go b/satellite/metabase/commit.go index 9d2822143..a354dec5f 100644 --- a/satellite/metabase/commit.go +++ b/satellite/metabase/commit.go @@ -26,6 +26,8 @@ const validatePlainSize = false const defaultZombieDeletionPeriod = 24 * time.Hour var ( + // ErrObjectNotFound is used to indicate that the object does not exist. + ErrObjectNotFound = storj.ErrObjectNotFound // ErrInvalidRequest is used to indicate invalid requests. ErrInvalidRequest = errs.Class("metabase: invalid request") // ErrConflict is used to indicate conflict with the request. @@ -653,7 +655,7 @@ func (db *DB) CommitObject(ctx context.Context, opts CommitObject) (object Objec ) if err != nil { if errors.Is(err, sql.ErrNoRows) { - return storj.ErrObjectNotFound.Wrap(Error.New("object with specified version and pending status is missing")) + return ErrObjectNotFound.Wrap(Error.New("object with specified version and pending status is missing")) } else if code := pgerrcode.FromError(err); code == pgxerrcode.NotNullViolation { // TODO maybe we should check message if 'encryption' label is there return ErrInvalidRequest.New("Encryption is missing") diff --git a/satellite/metabase/commit_object.go b/satellite/metabase/commit_object.go index d72a6afde..e38c545a0 100644 --- a/satellite/metabase/commit_object.go +++ b/satellite/metabase/commit_object.go @@ -11,7 +11,6 @@ import ( "github.com/zeebo/errs" - "storj.io/common/storj" "storj.io/common/uuid" "storj.io/private/dbutil/pgutil" "storj.io/private/dbutil/txutil" @@ -123,7 +122,7 @@ func (db *DB) CommitObjectWithSegments(ctx context.Context, opts CommitObjectWit ) if err != nil { if errors.Is(err, sql.ErrNoRows) { - return storj.ErrObjectNotFound.Wrap(Error.New("object with specified version and pending status is missing")) + return ErrObjectNotFound.Wrap(Error.New("object with specified version and pending status is missing")) } return Error.New("failed to update object: %w", err) } diff --git a/satellite/metabase/commit_object_test.go b/satellite/metabase/commit_object_test.go index 6ee04533c..c138be2fe 100644 --- a/satellite/metabase/commit_object_test.go +++ b/satellite/metabase/commit_object_test.go @@ -7,7 +7,6 @@ import ( "testing" "time" - "storj.io/common/storj" "storj.io/common/testcontext" "storj.io/common/testrand" "storj.io/storj/satellite/metabase" @@ -92,7 +91,7 @@ func TestCommitObjectWithSegments(t *testing.T) { StreamID: obj.StreamID, }, }, - ErrClass: &storj.ErrObjectNotFound, + ErrClass: &metabase.ErrObjectNotFound, ErrText: "metabase: object with specified version and pending status is missing", // TODO: this error message could be better }.Check(ctx, t, db) metabasetest.Verify{}.Check(ctx, t, db) @@ -146,7 +145,7 @@ func TestCommitObjectWithSegments(t *testing.T) { StreamID: obj.StreamID, }, }, - ErrClass: &storj.ErrObjectNotFound, + ErrClass: &metabase.ErrObjectNotFound, ErrText: "metabase: object with specified version and pending status is missing", // TODO: this error message could be better }.Check(ctx, t, db) diff --git a/satellite/metabase/commit_test.go b/satellite/metabase/commit_test.go index 026d38b63..5ea419915 100644 --- a/satellite/metabase/commit_test.go +++ b/satellite/metabase/commit_test.go @@ -2184,7 +2184,7 @@ func TestCommitObject(t *testing.T) { StreamID: obj.StreamID, }, }, - ErrClass: &storj.ErrObjectNotFound, + ErrClass: &metabase.ErrObjectNotFound, ErrText: "metabase: object with specified version and pending status is missing", // TODO: this error message could be better }.Check(ctx, t, db) metabasetest.Verify{}.Check(ctx, t, db) @@ -2239,7 +2239,7 @@ func TestCommitObject(t *testing.T) { StreamID: obj.StreamID, }, }, - ErrClass: &storj.ErrObjectNotFound, + ErrClass: &metabase.ErrObjectNotFound, ErrText: "metabase: object with specified version and pending status is missing", // TODO: this error message could be better }.Check(ctx, t, db) diff --git a/satellite/metabase/copy_object.go b/satellite/metabase/copy_object.go index 5200b5db7..7e077b494 100644 --- a/satellite/metabase/copy_object.go +++ b/satellite/metabase/copy_object.go @@ -407,7 +407,7 @@ func getObjectAtCopySourceAndDestination( }() if !rows.Next() { - return Object{}, uuid.UUID{}, nil, 0, storj.ErrObjectNotFound.New("source object not found") + return Object{}, uuid.UUID{}, nil, 0, ErrObjectNotFound.New("source object not found") } err = rows.Scan( @@ -425,7 +425,7 @@ func getObjectAtCopySourceAndDestination( return Object{}, uuid.UUID{}, nil, 0, Error.New("unable to query object status: %w", err) } if sourceObject.StreamID != opts.StreamID { - return Object{}, uuid.UUID{}, nil, 0, storj.ErrObjectNotFound.New("object was changed during copy") + return Object{}, uuid.UUID{}, nil, 0, ErrObjectNotFound.New("object was changed during copy") } if len(ancestorStreamIDBytes) != 0 { diff --git a/satellite/metabase/copy_object_test.go b/satellite/metabase/copy_object_test.go index 0bba817e6..b5432a9d8 100644 --- a/satellite/metabase/copy_object_test.go +++ b/satellite/metabase/copy_object_test.go @@ -9,7 +9,6 @@ import ( "github.com/stretchr/testify/require" - "storj.io/common/storj" "storj.io/common/testcontext" "storj.io/common/testrand" "storj.io/storj/satellite/metabase" @@ -224,7 +223,7 @@ func TestFinishCopyObject(t *testing.T) { NewStreamID: newStreamID, }, // validation pass without EncryptedMetadataKey and EncryptedMetadataKeyNonce - ErrClass: &storj.ErrObjectNotFound, + ErrClass: &metabase.ErrObjectNotFound, ErrText: "source object not found", }.Check(ctx, t, db) }) @@ -289,7 +288,7 @@ func TestFinishCopyObject(t *testing.T) { NewEncryptedMetadataKeyNonce: newEncryptedMetadataKeyNonce, NewEncryptedMetadataKey: newEncryptedMetadataKey, }, - ErrClass: &storj.ErrObjectNotFound, + ErrClass: &metabase.ErrObjectNotFound, ErrText: "source object not found", }.Check(ctx, t, db) @@ -330,7 +329,7 @@ func TestFinishCopyObject(t *testing.T) { NewEncryptedMetadataKeyNonce: testrand.Nonce(), NewEncryptedMetadataKey: testrand.Bytes(32), }, - ErrClass: &storj.ErrObjectNotFound, + ErrClass: &metabase.ErrObjectNotFound, ErrText: "object was changed during copy", }.Check(ctx, t, db) }) diff --git a/satellite/metabase/delete.go b/satellite/metabase/delete.go index ad5a6cc8d..a327dc3ee 100644 --- a/satellite/metabase/delete.go +++ b/satellite/metabase/delete.go @@ -557,7 +557,7 @@ func (db *DB) DeletePendingObject(ctx context.Context, opts DeletePendingObject) } if len(result.Objects) == 0 { - return DeleteObjectResult{}, storj.ErrObjectNotFound.Wrap(Error.New("no rows deleted")) + return DeleteObjectResult{}, ErrObjectNotFound.Wrap(Error.New("no rows deleted")) } mon.Meter("object_delete").Mark(len(result.Objects)) @@ -617,7 +617,7 @@ func (db *DB) DeleteObjectAnyStatusAllVersions(ctx context.Context, opts DeleteO } if len(result.Objects) == 0 { - return DeleteObjectResult{}, storj.ErrObjectNotFound.Wrap(Error.New("no rows deleted")) + return DeleteObjectResult{}, ErrObjectNotFound.Wrap(Error.New("no rows deleted")) } mon.Meter("object_delete").Mark(len(result.Objects)) diff --git a/satellite/metabase/delete_test.go b/satellite/metabase/delete_test.go index 8a5215d8c..599a346ca 100644 --- a/satellite/metabase/delete_test.go +++ b/satellite/metabase/delete_test.go @@ -54,7 +54,7 @@ func TestDeletePendingObject(t *testing.T) { Opts: metabase.DeletePendingObject{ ObjectStream: obj, }, - ErrClass: &storj.ErrObjectNotFound, + ErrClass: &metabase.ErrObjectNotFound, ErrText: "metabase: no rows deleted", }.Check(ctx, t, db) metabasetest.Verify{}.Check(ctx, t, db) @@ -81,7 +81,7 @@ func TestDeletePendingObject(t *testing.T) { StreamID: obj.StreamID, }, }, - ErrClass: &storj.ErrObjectNotFound, + ErrClass: &metabase.ErrObjectNotFound, ErrText: "metabase: no rows deleted", }.Check(ctx, t, db) metabasetest.Verify{ @@ -107,7 +107,7 @@ func TestDeletePendingObject(t *testing.T) { Opts: metabase.DeletePendingObject{ ObjectStream: object.ObjectStream, }, - ErrClass: &storj.ErrObjectNotFound, + ErrClass: &metabase.ErrObjectNotFound, ErrText: "metabase: no rows deleted", }.Check(ctx, t, db) @@ -146,7 +146,7 @@ func TestDeletePendingObject(t *testing.T) { }, }, Result: metabase.DeleteObjectResult{}, - ErrClass: &storj.ErrObjectNotFound, + ErrClass: &metabase.ErrObjectNotFound, ErrText: "metabase: no rows deleted", }.Check(ctx, t, db) @@ -492,7 +492,7 @@ func TestDeleteObjectAnyStatusAllVersions(t *testing.T) { metabasetest.DeleteObjectAnyStatusAllVersions{ Opts: metabase.DeleteObjectAnyStatusAllVersions{ObjectLocation: obj.Location()}, - ErrClass: &storj.ErrObjectNotFound, + ErrClass: &metabase.ErrObjectNotFound, ErrText: "metabase: no rows deleted", }.Check(ctx, t, db) metabasetest.Verify{}.Check(ctx, t, db) @@ -503,7 +503,7 @@ func TestDeleteObjectAnyStatusAllVersions(t *testing.T) { metabasetest.DeleteObjectAnyStatusAllVersions{ Opts: metabase.DeleteObjectAnyStatusAllVersions{ObjectLocation: obj.Location()}, - ErrClass: &storj.ErrObjectNotFound, + ErrClass: &metabase.ErrObjectNotFound, ErrText: "metabase: no rows deleted", }.Check(ctx, t, db) metabasetest.Verify{}.Check(ctx, t, db) diff --git a/satellite/metabase/get.go b/satellite/metabase/get.go index 9d8c37b1f..a3b91e4fd 100644 --- a/satellite/metabase/get.go +++ b/satellite/metabase/get.go @@ -12,7 +12,6 @@ import ( "github.com/zeebo/errs" "go.uber.org/zap" - "storj.io/common/storj" "storj.io/common/uuid" "storj.io/private/tagsql" ) @@ -111,7 +110,7 @@ func (db *DB) GetObjectExactVersion(ctx context.Context, opts GetObjectExactVers ) if err != nil { if errors.Is(err, sql.ErrNoRows) { - return Object{}, storj.ErrObjectNotFound.Wrap(Error.Wrap(err)) + return Object{}, ErrObjectNotFound.Wrap(Error.Wrap(err)) } return Object{}, Error.New("unable to query object status: %w", err) } @@ -194,7 +193,7 @@ func (db *DB) GetObjectLastCommitted(ctx context.Context, opts GetObjectLastComm }) if err != nil { if errors.Is(err, sql.ErrNoRows) { - return Object{}, storj.ErrObjectNotFound.Wrap(Error.Wrap(err)) + return Object{}, ErrObjectNotFound.Wrap(Error.Wrap(err)) } return Object{}, Error.New("unable to query object status: %w", err) @@ -330,7 +329,7 @@ func (db *DB) GetLatestObjectLastSegment(ctx context.Context, opts GetLatestObje ) if err != nil { if errors.Is(err, sql.ErrNoRows) { - return Segment{}, storj.ErrObjectNotFound.Wrap(Error.New("object or segment missing")) + return Segment{}, ErrObjectNotFound.Wrap(Error.New("object or segment missing")) } return Segment{}, Error.New("unable to query segment: %w", err) } diff --git a/satellite/metabase/get_test.go b/satellite/metabase/get_test.go index e9e6b558d..155114223 100644 --- a/satellite/metabase/get_test.go +++ b/satellite/metabase/get_test.go @@ -64,7 +64,7 @@ func TestGetObjectExactVersion(t *testing.T) { ObjectLocation: location, Version: 1, }, - ErrClass: &storj.ErrObjectNotFound, + ErrClass: &metabase.ErrObjectNotFound, ErrText: "metabase: sql: no rows in result set", }.Check(ctx, t, db) @@ -81,7 +81,7 @@ func TestGetObjectExactVersion(t *testing.T) { ObjectLocation: location, Version: 11, }, - ErrClass: &storj.ErrObjectNotFound, + ErrClass: &metabase.ErrObjectNotFound, ErrText: "metabase: sql: no rows in result set", }.Check(ctx, t, db) @@ -115,7 +115,7 @@ func TestGetObjectExactVersion(t *testing.T) { ObjectLocation: location, Version: 1, }, - ErrClass: &storj.ErrObjectNotFound, + ErrClass: &metabase.ErrObjectNotFound, ErrText: "metabase: sql: no rows in result set", }.Check(ctx, t, db) @@ -142,7 +142,7 @@ func TestGetObjectExactVersion(t *testing.T) { ObjectLocation: location, Version: 1, }, - ErrClass: &storj.ErrObjectNotFound, + ErrClass: &metabase.ErrObjectNotFound, }.Check(ctx, t, db) metabasetest.Verify{Objects: []metabase.RawObject{ { @@ -215,7 +215,7 @@ func TestGetObjectLastCommitted(t *testing.T) { Opts: metabase.GetObjectLastCommitted{ ObjectLocation: location, }, - ErrClass: &storj.ErrObjectNotFound, + ErrClass: &metabase.ErrObjectNotFound, ErrText: "metabase: sql: no rows in result set", }.Check(ctx, t, db) metabasetest.Verify{}.Check(ctx, t, db) @@ -235,7 +235,7 @@ func TestGetObjectLastCommitted(t *testing.T) { Opts: metabase.GetObjectLastCommitted{ ObjectLocation: location, }, - ErrClass: &storj.ErrObjectNotFound, + ErrClass: &metabase.ErrObjectNotFound, ErrText: "metabase: sql: no rows in result set", }.Check(ctx, t, db) @@ -1036,7 +1036,7 @@ func TestGetLatestObjectLastSegment(t *testing.T) { Opts: metabase.GetLatestObjectLastSegment{ ObjectLocation: location, }, - ErrClass: &storj.ErrObjectNotFound, + ErrClass: &metabase.ErrObjectNotFound, ErrText: "metabase: object or segment missing", }.Check(ctx, t, db) diff --git a/satellite/metabase/metadata.go b/satellite/metabase/metadata.go index 68d647c92..4ae4028da 100644 --- a/satellite/metabase/metadata.go +++ b/satellite/metabase/metadata.go @@ -8,7 +8,6 @@ import ( "go.uber.org/zap" - "storj.io/common/storj" "storj.io/common/uuid" ) @@ -83,7 +82,7 @@ func (db *DB) UpdateObjectMetadata(ctx context.Context, opts UpdateObjectMetadat } if affected == 0 { - return storj.ErrObjectNotFound.New("object with specified version and committed status is missing") + return ErrObjectNotFound.New("object with specified version and committed status is missing") } if affected > 1 { diff --git a/satellite/metabase/metadata_test.go b/satellite/metabase/metadata_test.go index 0e3a44f41..c268e2fc3 100644 --- a/satellite/metabase/metadata_test.go +++ b/satellite/metabase/metadata_test.go @@ -7,7 +7,6 @@ import ( "testing" "time" - "storj.io/common/storj" "storj.io/common/testcontext" "storj.io/common/testrand" "storj.io/common/uuid" @@ -63,7 +62,7 @@ func TestUpdateObjectMetadata(t *testing.T) { ObjectKey: obj.ObjectKey, StreamID: obj.StreamID, }, - ErrClass: &storj.ErrObjectNotFound, + ErrClass: &metabase.ErrObjectNotFound, ErrText: "object with specified version and committed status is missing", }.Check(ctx, t, db) metabasetest.Verify{}.Check(ctx, t, db) diff --git a/satellite/metabase/move_object.go b/satellite/metabase/move_object.go index 38d467514..d1daa54ce 100644 --- a/satellite/metabase/move_object.go +++ b/satellite/metabase/move_object.go @@ -227,12 +227,12 @@ func (db *DB) FinishMoveObject(ctx context.Context, opts FinishMoveObject) (err if code := pgerrcode.FromError(err); code == pgxerrcode.UniqueViolation { return Error.Wrap(ErrObjectAlreadyExists.New("")) } else if errors.Is(err, sql.ErrNoRows) { - return storj.ErrObjectNotFound.New("object not found") + return ErrObjectNotFound.New("object not found") } return Error.New("unable to update object: %w", err) } if streamID != opts.StreamID { - return storj.ErrObjectNotFound.New("object was changed during move") + return ErrObjectNotFound.New("object was changed during move") } if segmentsCount != len(opts.NewSegmentKeys) { return ErrInvalidRequest.New("wrong number of segments keys received") diff --git a/satellite/metabase/move_object_test.go b/satellite/metabase/move_object_test.go index 17dcaff51..b33cce411 100644 --- a/satellite/metabase/move_object_test.go +++ b/satellite/metabase/move_object_test.go @@ -227,7 +227,7 @@ func TestFinishMoveObject(t *testing.T) { NewEncryptedObjectKey: []byte{0}, }, // validation pass without EncryptedMetadataKey and EncryptedMetadataKeyNonce - ErrClass: &storj.ErrObjectNotFound, + ErrClass: &metabase.ErrObjectNotFound, ErrText: "object not found", }.Check(ctx, t, db) @@ -275,7 +275,7 @@ func TestFinishMoveObject(t *testing.T) { NewEncryptedMetadataKeyNonce: newEncryptedMetadataKeyNonce, NewEncryptedMetadataKey: newEncryptedMetadataKey, }, - ErrClass: &storj.ErrObjectNotFound, + ErrClass: &metabase.ErrObjectNotFound, ErrText: "object not found", }.Check(ctx, t, db) @@ -413,7 +413,7 @@ func TestFinishMoveObject(t *testing.T) { NewEncryptedMetadataKeyNonce: testrand.Nonce(), NewEncryptedMetadataKey: testrand.Bytes(32), }, - ErrClass: &storj.ErrObjectNotFound, + ErrClass: &metabase.ErrObjectNotFound, ErrText: "object was changed during move", }.Check(ctx, t, db) }) diff --git a/satellite/metainfo/endpoint.go b/satellite/metainfo/endpoint.go index 3898c9336..50a00b377 100644 --- a/satellite/metainfo/endpoint.go +++ b/satellite/metainfo/endpoint.go @@ -294,7 +294,7 @@ func (endpoint *Endpoint) convertMetabaseErr(err error) error { } switch { - case storj.ErrObjectNotFound.Has(err): + case metabase.ErrObjectNotFound.Has(err): return rpcstatus.Error(rpcstatus.NotFound, err.Error()) case metabase.ErrSegmentNotFound.Has(err): return rpcstatus.Error(rpcstatus.NotFound, err.Error())