satellite/metainfo/metabase: align object status to those already in use

Change-Id: I33b2ce7282838e1172b7cb92d4e76169c96fddcb
This commit is contained in:
Fadila Khadar 2020-11-16 14:58:22 +01:00
parent b7df41a0a1
commit c9bbd83f96
6 changed files with 31 additions and 28 deletions

View File

@ -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)

View File

@ -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.

View File

@ -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,

View File

@ -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,

View File

@ -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

View File

@ -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