satellite/metabase: remove AOST from deleteInactiveObjectsAndSegments

By mistake AOST was added to query in deleteInactiveObjectsAndSegments
in DeleteZombieObjects. Delete statement is not supporting it.
Unfortunately unit tests didn't cover this case. This change removes
AOST from mentioned method and it adding AOST cases to unit tests.

Change-Id: Ib7f65134290df08c490c96b7e367d12f497a3373
This commit is contained in:
Michal Niewrzal 2023-06-28 15:23:12 +02:00
parent 683f0c493f
commit e129841130
3 changed files with 7 additions and 7 deletions

View File

@ -249,7 +249,8 @@ func (db *DB) deleteInactiveObjectsAndSegments(ctx context.Context, objects []Ob
for _, obj := range objects { for _, obj := range objects {
batch.Queue(` batch.Queue(`
WITH check_segments AS ( WITH check_segments AS (
SELECT 1 FROM segments WHERE stream_id = $5::BYTEA AND created_at > $6 SELECT 1 FROM segments
WHERE stream_id = $5::BYTEA AND created_at > $6
), deleted_objects AS ( ), deleted_objects AS (
DELETE FROM objects DELETE FROM objects
WHERE WHERE
@ -258,9 +259,7 @@ func (db *DB) deleteInactiveObjectsAndSegments(ctx context.Context, objects []Ob
RETURNING stream_id RETURNING stream_id
) )
DELETE FROM segments DELETE FROM segments
`+db.impl.AsOfSystemInterval(opts.AsOfSystemInterval)+` WHERE segments.stream_id IN (SELECT stream_id FROM deleted_objects)
WHERE
segments.stream_id IN (SELECT stream_id FROM deleted_objects)
`, obj.ProjectID, []byte(obj.BucketName), []byte(obj.ObjectKey), obj.Version, obj.StreamID, opts.InactiveDeadline) `, obj.ProjectID, []byte(obj.BucketName), []byte(obj.ObjectKey), obj.Version, obj.StreamID, opts.InactiveDeadline)
} }

View File

@ -334,6 +334,7 @@ func TestDeleteZombieObjects(t *testing.T) {
Opts: metabase.DeleteZombieObjects{ Opts: metabase.DeleteZombieObjects{
DeadlineBefore: now.Add(1 * time.Hour), DeadlineBefore: now.Add(1 * time.Hour),
InactiveDeadline: now.Add(2 * time.Hour), InactiveDeadline: now.Add(2 * time.Hour),
AsOfSystemInterval: -1 * time.Microsecond,
}, },
}.Check(ctx, t, db) }.Check(ctx, t, db)

View File

@ -27,7 +27,7 @@ func TestZombieDeletion(t *testing.T) {
Reconfigure: testplanet.Reconfigure{ Reconfigure: testplanet.Reconfigure{
Satellite: func(log *zap.Logger, index int, config *satellite.Config) { Satellite: func(log *zap.Logger, index int, config *satellite.Config) {
config.ZombieDeletion.Interval = 500 * time.Millisecond config.ZombieDeletion.Interval = 500 * time.Millisecond
config.ZombieDeletion.AsOfSystemInterval = 0 config.ZombieDeletion.AsOfSystemInterval = -1 * time.Microsecond
}, },
}, },
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) { }, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {