satellite/metabase: define a local ErrObjectNotFound
Updates https://github.com/storj/storj/issues/5291 Change-Id: If847cd95a9b500fb18535d20b46b1b1714021584
This commit is contained in:
parent
8632e28584
commit
54beea82da
@ -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)
|
||||
}
|
||||
|
@ -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")
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -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)
|
||||
})
|
||||
|
@ -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))
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -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)
|
||||
|
@ -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")
|
||||
|
@ -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)
|
||||
})
|
||||
|
@ -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())
|
||||
|
Loading…
Reference in New Issue
Block a user