diff --git a/satellite/metainfo/metabase/commit.go b/satellite/metainfo/metabase/commit.go index 599cb87b2..be1f25e68 100644 --- a/satellite/metainfo/metabase/commit.go +++ b/satellite/metainfo/metabase/commit.go @@ -174,8 +174,8 @@ func (db *DB) BeginSegment(ctx context.Context, opts BeginSegment) (err error) { object_key = $3 AND version = $4 AND stream_id = $5 AND - status = 0 - `, opts.ProjectID, opts.BucketName, []byte(opts.ObjectKey), opts.Version, opts.StreamID).Scan(&value) + status = `+pendingStatus, + opts.ProjectID, opts.BucketName, []byte(opts.ObjectKey), opts.Version, opts.StreamID).Scan(&value) if err != nil { if errors.Is(err, sql.ErrNoRows) { return Error.New("pending object missing") @@ -259,8 +259,8 @@ func (db *DB) CommitSegment(ctx context.Context, opts CommitSegment) (err error) object_key = $3 AND version = $4 AND stream_id = $5 AND - status = 0 - `, opts.ProjectID, opts.BucketName, []byte(opts.ObjectKey), opts.Version, opts.StreamID).Scan(&value) + status = `+pendingStatus, + opts.ProjectID, opts.BucketName, []byte(opts.ObjectKey), opts.Version, opts.StreamID).Scan(&value) if err != nil { if errors.Is(err, sql.ErrNoRows) { return Error.New("pending object missing") @@ -349,8 +349,8 @@ func (db *DB) CommitInlineSegment(ctx context.Context, opts CommitInlineSegment) object_key = $3 AND version = $4 AND stream_id = $5 AND - status = 0 - `, opts.ProjectID, opts.BucketName, []byte(opts.ObjectKey), opts.Version, opts.StreamID).Scan(&value) + status = `+pendingStatus, + opts.ProjectID, opts.BucketName, []byte(opts.ObjectKey), opts.Version, opts.StreamID).Scan(&value) if err != nil { if errors.Is(err, sql.ErrNoRows) { return Error.New("pending object missing") @@ -489,7 +489,7 @@ func (db *DB) commitObjectWithoutProofs(ctx context.Context, opts CommitObject) err = tx.QueryRow(ctx, ` UPDATE objects SET - status = 1, -- committed + status =`+committedStatus+`, segment_count = $6, encrypted_metadata_nonce = $7, @@ -505,7 +505,7 @@ func (db *DB) commitObjectWithoutProofs(ctx context.Context, opts CommitObject) object_key = $3 AND version = $4 AND stream_id = $5 AND - status = 0 + status = `+pendingStatus+` RETURNING created_at, expires_at, encryption; @@ -588,8 +588,8 @@ func (db *DB) UpdateObjectMetadata(ctx context.Context, opts UpdateObjectMetadat object_key = $3 AND version = $4 AND stream_id = $5 AND - status = 1 - `, opts.ProjectID, opts.BucketName, []byte(opts.ObjectKey), opts.Version, opts.StreamID, + status = `+committedStatus, + opts.ProjectID, opts.BucketName, []byte(opts.ObjectKey), opts.Version, opts.StreamID, opts.EncryptedMetadataNonce, opts.EncryptedMetadata, opts.EncryptedMetadataEncryptedKey) if err != nil { return Error.New("unable to update object metadata: %w", err) diff --git a/satellite/metainfo/metabase/common.go b/satellite/metainfo/metabase/common.go index 8c73562fd..3a7e252df 100644 --- a/satellite/metainfo/metabase/common.go +++ b/satellite/metainfo/metabase/common.go @@ -271,9 +271,12 @@ type ObjectStatus byte const ( // Pending means that the object is being uploaded or that the client failed during upload. // The failed upload may be continued in the future. - Pending = ObjectStatus(0) + Pending = ObjectStatus(1) // Committed means that the object is finished and should be visible for general listing. - Committed = ObjectStatus(1) + Committed = ObjectStatus(3) + + pendingStatus = "1" + committedStatus = "3" ) // Pieces defines information for pieces. diff --git a/satellite/metainfo/metabase/db.go b/satellite/metainfo/metabase/db.go index 0b2fda84a..d7c55768a 100644 --- a/satellite/metainfo/metabase/db.go +++ b/satellite/metainfo/metabase/db.go @@ -93,7 +93,7 @@ func (db *DB) PostgresMigration() *migrate.Migration { created_at TIMESTAMPTZ NOT NULL default now(), expires_at TIMESTAMPTZ, - status INT2 NOT NULL default 0, + status INT2 NOT NULL default ` + pendingStatus + `, segment_count INT4 NOT NULL default 0, encrypted_metadata_nonce BYTEA default NULL, diff --git a/satellite/metainfo/metabase/delete.go b/satellite/metainfo/metabase/delete.go index 9982583ce..a3e55bfe1 100644 --- a/satellite/metainfo/metabase/delete.go +++ b/satellite/metainfo/metabase/delete.go @@ -110,7 +110,7 @@ func (db *DB) DeleteObjectExactVersion(ctx context.Context, opts DeleteObjectExa bucket_name = $2 AND object_key = $3 AND version = $4 AND - status = 1 + status = `+committedStatus+` RETURNING version, stream_id, created_at, expires_at, @@ -186,10 +186,10 @@ func (db *DB) DeleteObjectLatestVersion(ctx context.Context, opts DeleteObjectLa project_id = $1 AND bucket_name = $2 AND object_key = $3 AND - status = 1 + status = `+committedStatus+` ORDER BY version DESC LIMIT 1 ) AND - status = 1 + status = `+committedStatus+` RETURNING version, stream_id, created_at, expires_at, @@ -245,7 +245,7 @@ func (db *DB) DeleteObjectAllVersions(ctx context.Context, opts DeleteObjectAllV project_id = $1 AND bucket_name = $2 AND object_key = $3 AND - status = 1 + status = `+committedStatus+` RETURNING version, stream_id, created_at, expires_at, @@ -322,7 +322,7 @@ func (db *DB) DeleteObjectsAllVersions(ctx context.Context, opts DeleteObjectsAl project_id = $1 AND bucket_name = $2 AND object_key = ANY ($3) AND - status = 1 + status = `+committedStatus+` RETURNING project_id, bucket_name, object_key, version, stream_id, diff --git a/satellite/metainfo/metabase/get.go b/satellite/metainfo/metabase/get.go index c0b933edf..365989559 100644 --- a/satellite/metainfo/metabase/get.go +++ b/satellite/metainfo/metabase/get.go @@ -49,7 +49,7 @@ func (db *DB) GetObjectExactVersion(ctx context.Context, opts GetObjectExactVers object := Object{} // TODO handle encryption column err = db.db.QueryRow(ctx, ` - SELECT + SELECT stream_id, created_at, expires_at, segment_count, @@ -62,8 +62,8 @@ func (db *DB) GetObjectExactVersion(ctx context.Context, opts GetObjectExactVers bucket_name = $2 AND object_key = $3 AND version = $4 AND - status = 1 - `, opts.ProjectID, opts.BucketName, []byte(opts.ObjectKey), opts.Version). + status = `+committedStatus, + opts.ProjectID, opts.BucketName, []byte(opts.ObjectKey), opts.Version). Scan( &object.StreamID, &object.CreatedAt, &object.ExpiresAt, @@ -105,7 +105,7 @@ func (db *DB) GetObjectLatestVersion(ctx context.Context, opts GetObjectLatestVe object := Object{} err = db.db.QueryRow(ctx, ` - SELECT + SELECT stream_id, version, created_at, expires_at, segment_count, @@ -117,7 +117,7 @@ func (db *DB) GetObjectLatestVersion(ctx context.Context, opts GetObjectLatestVe project_id = $1 AND bucket_name = $2 AND object_key = $3 AND - status = 1 + status = `+committedStatus+` ORDER BY version desc LIMIT 1 `, opts.ProjectID, opts.BucketName, []byte(opts.ObjectKey)). @@ -168,9 +168,9 @@ func (db *DB) GetSegmentByPosition(ctx context.Context, opts GetSegmentByPositio } err = db.db.QueryRow(ctx, ` - SELECT + SELECT root_piece_id, encrypted_key_nonce, encrypted_key, - encrypted_size, plain_offset, plain_size, + encrypted_size, plain_offset, plain_size, redundancy, inline_data, remote_pieces FROM objects, segments @@ -223,7 +223,7 @@ func (db *DB) GetLatestObjectLastSegment(ctx context.Context, opts GetLatestObje project_id = $1 AND bucket_name = $2 AND object_key = $3 AND - status = 1 + status = `+committedStatus+` ORDER BY version DESC LIMIT 1 ) @@ -278,7 +278,7 @@ func (db *DB) GetSegmentByOffset(ctx context.Context, opts GetSegmentByOffset) ( project_id = $1 AND bucket_name = $2 AND object_key = $3 AND - status = 1 + status = `+committedStatus+` ORDER BY version DESC LIMIT 1 ) AND diff --git a/satellite/metainfo/metabase/iterator.go b/satellite/metainfo/metabase/iterator.go index 593485a4e..9c7019c54 100644 --- a/satellite/metainfo/metabase/iterator.go +++ b/satellite/metainfo/metabase/iterator.go @@ -124,7 +124,7 @@ func (it *objectsIterator) doNextQuery(ctx context.Context) (_ tagsql.Rows, err object_key, stream_id, version, status, created_at, expires_at, segment_count, - encrypted_metadata_nonce, encrypted_metadata, + encrypted_metadata_nonce, encrypted_metadata, encrypted_metadata_encrypted_key, total_encrypted_size, fixed_segment_size, encryption FROM objects