satellite/metabase: delete migrated zombie objects
We noticed that in the system we have undeleted very old pending objects. General rule is to delete them after some inactivity. Turns out that all those objects are objects migrated to metabase from previous DB schema. During this migration we didn't set zombie_deletion_deadline to any value. This change takes into account pending objects with zombie deletion deadline set to nil during zombie deletion process. I also checked accross all production satellites and youngest pending objects with nil zombie_deletion_deadline are from 2021 so it is safe to delete them. Change-Id: Ie2b6a4b4e203c1750cf8408ee281c0631b263082
This commit is contained in:
parent
25f8f678ab
commit
917925bc11
@ -106,6 +106,8 @@ func (db *DB) DeleteZombieObjects(ctx context.Context, opts DeleteZombieObjects)
|
|||||||
defer mon.Task()(&ctx)(&err)
|
defer mon.Task()(&ctx)(&err)
|
||||||
|
|
||||||
return db.deleteObjectsAndSegmentsBatch(ctx, opts.BatchSize, func(startAfter ObjectStream, batchsize int) (last ObjectStream, err error) {
|
return db.deleteObjectsAndSegmentsBatch(ctx, opts.BatchSize, func(startAfter ObjectStream, batchsize int) (last ObjectStream, err error) {
|
||||||
|
// pending objects migrated to metabase didn't have zombie_deletion_deadline column set, because
|
||||||
|
// of that we need to get into account also object with zombie_deletion_deadline set to NULL
|
||||||
query := `
|
query := `
|
||||||
SELECT
|
SELECT
|
||||||
project_id, bucket_name, object_key, version, stream_id
|
project_id, bucket_name, object_key, version, stream_id
|
||||||
@ -114,7 +116,7 @@ func (db *DB) DeleteZombieObjects(ctx context.Context, opts DeleteZombieObjects)
|
|||||||
WHERE
|
WHERE
|
||||||
(project_id, bucket_name, object_key, version) > ($1, $2, $3, $4)
|
(project_id, bucket_name, object_key, version) > ($1, $2, $3, $4)
|
||||||
AND status = ` + pendingStatus + `
|
AND status = ` + pendingStatus + `
|
||||||
AND zombie_deletion_deadline < $5
|
AND (zombie_deletion_deadline IS NULL OR zombie_deletion_deadline < $5)
|
||||||
ORDER BY project_id, bucket_name, object_key, version
|
ORDER BY project_id, bucket_name, object_key, version
|
||||||
LIMIT $6;`
|
LIMIT $6;`
|
||||||
|
|
||||||
|
@ -7,6 +7,8 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
"storj.io/common/storj"
|
"storj.io/common/storj"
|
||||||
"storj.io/common/testcontext"
|
"storj.io/common/testcontext"
|
||||||
"storj.io/common/testrand"
|
"storj.io/common/testrand"
|
||||||
@ -456,5 +458,34 @@ func TestDeleteZombieObjects(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}.Check(ctx, t, db)
|
}.Check(ctx, t, db)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// pending objects migrated to metabase doesn't have zombie_deletion_deadline
|
||||||
|
// column set correctly but we need to delete them too
|
||||||
|
t.Run("migrated objects", func(t *testing.T) {
|
||||||
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
||||||
|
|
||||||
|
_, err := db.BeginObjectExactVersion(ctx, metabase.BeginObjectExactVersion{
|
||||||
|
ObjectStream: obj1,
|
||||||
|
})
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
// metabase is always setting default value for zombie_deletion_deadline
|
||||||
|
// so we need to set it manually
|
||||||
|
_, err = db.UnderlyingTagSQL().Exec(ctx, "UPDATE objects SET zombie_deletion_deadline = NULL")
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
objects, err := db.TestingAllObjects(ctx)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Nil(t, objects[0].ZombieDeletionDeadline)
|
||||||
|
|
||||||
|
metabasetest.DeleteZombieObjects{
|
||||||
|
Opts: metabase.DeleteZombieObjects{
|
||||||
|
DeadlineBefore: now,
|
||||||
|
InactiveDeadline: now.Add(1 * time.Hour),
|
||||||
|
},
|
||||||
|
}.Check(ctx, t, db)
|
||||||
|
|
||||||
|
metabasetest.Verify{}.Check(ctx, t, db)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user