satellite/metabase: commit object is not respecting expiration time

With pending_objects table support enabled we missed passing correctly
expiration time from pending object to committed object. This change
updates commit query to take into account expiration time.

Change-Id: I67146d5b2f7f0bda02925d16275fbc59acb705bd
This commit is contained in:
Michal Niewrzal 2023-09-14 15:47:40 +02:00
parent 8f27425284
commit 881137539c
3 changed files with 79 additions and 3 deletions

View File

@ -766,7 +766,7 @@ func (db *DB) CommitObject(ctx context.Context, opts CommitObject) (object Objec
stream_id = $5
RETURNING
project_id, bucket_name, object_key, $4::INT4 as version, stream_id,
`+committedStatus+` as status, $6::INT4 as segment_count, $7::INT8 as total_plain_size, $8::INT8 as total_encrypted_size, $9::INT4 as fixed_segment_size,
`+committedStatus+` as status, expires_at, $6::INT4 as segment_count, $7::INT8 as total_plain_size, $8::INT8 as total_encrypted_size, $9::INT4 as fixed_segment_size,
NULL::timestamp as zombie_deletion_deadline,
CASE
WHEN encryption = 0 AND $10 <> 0 THEN $10
@ -778,7 +778,7 @@ func (db *DB) CommitObject(ctx context.Context, opts CommitObject) (object Objec
), object_to_commit AS (
SELECT
project_id, bucket_name, object_key, version, stream_id,
status, segment_count, total_plain_size, total_encrypted_size, fixed_segment_size,
status, expires_at, segment_count, total_plain_size, total_encrypted_size, fixed_segment_size,
zombie_deletion_deadline, encryption,
CASE
WHEN $14::BOOL = true THEN $11
@ -799,7 +799,7 @@ func (db *DB) CommitObject(ctx context.Context, opts CommitObject) (object Objec
)
INSERT INTO objects (
project_id, bucket_name, object_key, version, stream_id,
status, segment_count, total_plain_size, total_encrypted_size, fixed_segment_size, zombie_deletion_deadline,
status, expires_at, segment_count, total_plain_size, total_encrypted_size, fixed_segment_size, zombie_deletion_deadline,
encryption,
encrypted_metadata_nonce, encrypted_metadata, encrypted_metadata_encrypted_key
)

View File

@ -4336,6 +4336,59 @@ func TestCommitObject(t *testing.T) {
}.Check(ctx, t, db)
}
})
t.Run("upload with expiration time", func(t *testing.T) {
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
now := time.Now()
expectedExpiresAt := now.Add(time.Hour).Truncate(time.Millisecond)
obj := obj
obj.Version = metabase.NextVersion
metabasetest.BeginObjectNextVersion{
Opts: metabase.BeginObjectNextVersion{
ObjectStream: obj,
Encryption: metabasetest.DefaultEncryption,
EncryptedMetadata: testrand.Bytes(memory.KiB),
EncryptedMetadataEncryptedKey: testrand.Bytes(32),
EncryptedMetadataNonce: testrand.Nonce().Bytes(),
ExpiresAt: &expectedExpiresAt,
UsePendingObjectsTable: true,
},
Version: metabase.PendingVersion,
}.Check(ctx, t, db)
obj.Version = metabase.DefaultVersion
metabasetest.CommitObject{
Opts: metabase.CommitObject{
ObjectStream: obj,
Encryption: metabasetest.DefaultEncryption,
OverrideEncryptedMetadata: true,
EncryptedMetadata: nil,
EncryptedMetadataEncryptedKey: nil,
EncryptedMetadataNonce: nil,
UsePendingObjectsTable: true,
},
}.Check(ctx, t, db)
metabasetest.Verify{
Objects: []metabase.RawObject{
{
ObjectStream: obj,
CreatedAt: now,
Status: metabase.Committed,
SegmentCount: 0,
ExpiresAt: &expectedExpiresAt,
Encryption: metabasetest.DefaultEncryption,
},
},
}.Check(ctx, t, db)
})
})
})
}

View File

@ -956,6 +956,29 @@ func TestEndpoint_Object_No_StorageNodes_UsePendingObjectsTable(t *testing.T) {
require.NoError(t, err)
require.Len(t, segments, 1)
})
t.Run("upload with expiration time", func(t *testing.T) {
defer ctx.Check(deleteBucket)
expectedExpirateAt := time.Now().Add(time.Hour)
err := planet.Uplinks[0].UploadWithExpiration(ctx, planet.Satellites[0], bucketName, "test-object", testrand.Bytes(1*memory.KiB), expectedExpirateAt)
require.NoError(t, err)
project, err := planet.Uplinks[0].OpenProject(ctx, planet.Satellites[0])
require.NoError(t, err)
defer ctx.Check(project.Close)
object, err := project.StatObject(ctx, bucketName, "test-object")
require.NoError(t, err)
require.WithinDuration(t, expectedExpirateAt, object.System.Expires, time.Second)
iterator := project.ListObjects(ctx, bucketName, &uplink.ListObjectsOptions{
System: true,
})
require.True(t, iterator.Next())
require.WithinDuration(t, expectedExpirateAt, iterator.Item().System.Expires, time.Second)
require.NoError(t, iterator.Err())
})
})
}