2020-11-09 14:55:10 +00:00
|
|
|
// Copyright (C) 2020 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package metabase_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2022-08-09 20:43:27 +01:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
2020-11-09 14:55:10 +00:00
|
|
|
"storj.io/common/storj"
|
|
|
|
"storj.io/common/testcontext"
|
2021-04-29 10:21:29 +01:00
|
|
|
"storj.io/common/testrand"
|
2021-04-21 13:42:57 +01:00
|
|
|
"storj.io/storj/satellite/metabase"
|
2021-04-26 10:35:44 +01:00
|
|
|
"storj.io/storj/satellite/metabase/metabasetest"
|
2020-11-09 14:55:10 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestDeleteExpiredObjects(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Run(t, func(ctx *testcontext.Context, t *testing.T, db *metabase.DB) {
|
|
|
|
obj1 := metabasetest.RandObjectStream()
|
|
|
|
obj2 := metabasetest.RandObjectStream()
|
|
|
|
obj3 := metabasetest.RandObjectStream()
|
2020-11-09 14:55:10 +00:00
|
|
|
|
|
|
|
now := time.Now()
|
2021-05-06 12:42:20 +01:00
|
|
|
zombieDeadline := now.Add(24 * time.Hour)
|
2020-11-09 14:55:10 +00:00
|
|
|
pastTime := now.Add(-1 * time.Hour)
|
|
|
|
futureTime := now.Add(1 * time.Hour)
|
|
|
|
|
2021-04-16 10:14:27 +01:00
|
|
|
t.Run("none", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2020-11-09 14:55:10 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.DeleteExpiredObjects{
|
2021-04-16 10:14:27 +01:00
|
|
|
Opts: metabase.DeleteExpiredObjects{
|
|
|
|
ExpiredBefore: time.Now(),
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{}.Check(ctx, t, db)
|
2020-11-09 14:55:10 +00:00
|
|
|
})
|
|
|
|
|
2021-04-16 10:14:27 +01:00
|
|
|
t.Run("partial objects", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2020-11-09 14:55:10 +00:00
|
|
|
|
|
|
|
// pending object without expiration time
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.BeginObjectExactVersion{
|
2020-11-09 14:55:10 +00:00
|
|
|
Opts: metabase.BeginObjectExactVersion{
|
|
|
|
ObjectStream: obj1,
|
2021-04-26 10:35:44 +01:00
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
2020-11-09 14:55:10 +00:00
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
// pending object with expiration time in the past
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.BeginObjectExactVersion{
|
2020-11-09 14:55:10 +00:00
|
|
|
Opts: metabase.BeginObjectExactVersion{
|
|
|
|
ObjectStream: obj2,
|
|
|
|
ExpiresAt: &pastTime,
|
2021-04-26 10:35:44 +01:00
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
2020-11-09 14:55:10 +00:00
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
// pending object with expiration time in the future
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.BeginObjectExactVersion{
|
2020-11-09 14:55:10 +00:00
|
|
|
Opts: metabase.BeginObjectExactVersion{
|
|
|
|
ObjectStream: obj3,
|
|
|
|
ExpiresAt: &futureTime,
|
2021-04-26 10:35:44 +01:00
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
2020-11-09 14:55:10 +00:00
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.DeleteExpiredObjects{
|
2021-04-16 10:14:27 +01:00
|
|
|
Opts: metabase.DeleteExpiredObjects{
|
|
|
|
ExpiredBefore: time.Now(),
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
2020-11-09 14:55:10 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{ // the object with expiration time in the past is gone
|
2020-11-09 14:55:10 +00:00
|
|
|
Objects: []metabase.RawObject{
|
|
|
|
{
|
|
|
|
ObjectStream: obj1,
|
|
|
|
CreatedAt: now,
|
|
|
|
Status: metabase.Pending,
|
|
|
|
|
2021-05-06 12:42:20 +01:00
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
|
|
|
ZombieDeletionDeadline: &zombieDeadline,
|
2020-11-09 14:55:10 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
ObjectStream: obj3,
|
|
|
|
CreatedAt: now,
|
|
|
|
ExpiresAt: &futureTime,
|
|
|
|
Status: metabase.Pending,
|
|
|
|
|
2021-05-06 12:42:20 +01:00
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
|
|
|
ZombieDeletionDeadline: &zombieDeadline,
|
2020-11-09 14:55:10 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
})
|
|
|
|
|
2021-04-16 10:14:27 +01:00
|
|
|
t.Run("batch size", func(t *testing.T) {
|
|
|
|
expiresAt := time.Now().Add(-30 * 24 * time.Hour)
|
|
|
|
for i := 0; i < 32; i++ {
|
2021-04-26 10:35:44 +01:00
|
|
|
_ = metabasetest.CreateExpiredObject(ctx, t, db, metabasetest.RandObjectStream(), 3, expiresAt)
|
2021-04-16 10:14:27 +01:00
|
|
|
}
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.DeleteExpiredObjects{
|
2021-04-16 10:14:27 +01:00
|
|
|
Opts: metabase.DeleteExpiredObjects{
|
|
|
|
ExpiredBefore: time.Now().Add(time.Hour),
|
|
|
|
BatchSize: 4,
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{}.Check(ctx, t, db)
|
2021-04-16 10:14:27 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("committed objects", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2020-11-09 14:55:10 +00:00
|
|
|
|
2022-02-24 14:26:05 +00:00
|
|
|
object1, _ := metabasetest.CreateTestObject{}.Run(ctx, t, db, obj1, 1)
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.CreateTestObject{
|
2020-11-09 14:55:10 +00:00
|
|
|
BeginObjectExactVersion: &metabase.BeginObjectExactVersion{
|
|
|
|
ObjectStream: obj2,
|
|
|
|
ExpiresAt: &pastTime,
|
2021-04-26 10:35:44 +01:00
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
2020-11-09 14:55:10 +00:00
|
|
|
},
|
|
|
|
}.Run(ctx, t, db, obj2, 1)
|
2022-02-24 14:26:05 +00:00
|
|
|
object3, _ := metabasetest.CreateTestObject{
|
2020-11-09 14:55:10 +00:00
|
|
|
BeginObjectExactVersion: &metabase.BeginObjectExactVersion{
|
|
|
|
ObjectStream: obj3,
|
|
|
|
ExpiresAt: &futureTime,
|
2021-04-26 10:35:44 +01:00
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
2020-11-09 14:55:10 +00:00
|
|
|
},
|
|
|
|
}.Run(ctx, t, db, obj3, 1)
|
|
|
|
|
|
|
|
expectedObj1Segment := metabase.Segment{
|
|
|
|
StreamID: obj1.StreamID,
|
|
|
|
RootPieceID: storj.PieceID{1},
|
2021-08-05 00:56:50 +01:00
|
|
|
CreatedAt: now,
|
2020-11-09 14:55:10 +00:00
|
|
|
EncryptedKey: []byte{3},
|
2021-10-12 14:37:12 +01:00
|
|
|
EncryptedKeyNonce: []byte{4},
|
2021-03-25 07:53:10 +00:00
|
|
|
EncryptedETag: []byte{5},
|
2020-11-09 14:55:10 +00:00
|
|
|
EncryptedSize: 1060,
|
|
|
|
PlainSize: 512,
|
|
|
|
Pieces: metabase.Pieces{{Number: 0, StorageNode: storj.NodeID{2}}},
|
2021-04-26 10:35:44 +01:00
|
|
|
Redundancy: metabasetest.DefaultRedundancy,
|
2020-11-09 14:55:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
expectedObj3Segment := expectedObj1Segment
|
|
|
|
expectedObj3Segment.StreamID = obj3.StreamID
|
2021-06-10 11:08:21 +01:00
|
|
|
expectedObj3Segment.ExpiresAt = &futureTime
|
2020-11-09 14:55:10 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.DeleteExpiredObjects{
|
2021-04-16 10:14:27 +01:00
|
|
|
Opts: metabase.DeleteExpiredObjects{
|
|
|
|
ExpiredBefore: time.Now(),
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
2020-11-09 14:55:10 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{ // the object with expiration time in the past is gone
|
2020-11-09 14:55:10 +00:00
|
|
|
Objects: []metabase.RawObject{
|
|
|
|
metabase.RawObject(object1),
|
|
|
|
metabase.RawObject(object3),
|
|
|
|
},
|
|
|
|
Segments: []metabase.RawSegment{
|
|
|
|
metabase.RawSegment(expectedObj1Segment),
|
|
|
|
metabase.RawSegment(expectedObj3Segment),
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
2021-04-29 10:21:29 +01:00
|
|
|
|
|
|
|
func TestDeleteZombieObjects(t *testing.T) {
|
|
|
|
metabasetest.Run(t, func(ctx *testcontext.Context, t *testing.T, db *metabase.DB) {
|
|
|
|
obj1 := metabasetest.RandObjectStream()
|
|
|
|
obj2 := metabasetest.RandObjectStream()
|
|
|
|
obj3 := metabasetest.RandObjectStream()
|
|
|
|
|
|
|
|
now := time.Now()
|
2021-05-06 12:42:20 +01:00
|
|
|
zombieDeadline := now.Add(24 * time.Hour)
|
2021-04-29 10:21:29 +01:00
|
|
|
pastTime := now.Add(-1 * time.Hour)
|
|
|
|
futureTime := now.Add(1 * time.Hour)
|
|
|
|
|
|
|
|
t.Run("none", func(t *testing.T) {
|
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
metabasetest.DeleteZombieObjects{
|
|
|
|
Opts: metabase.DeleteZombieObjects{
|
2021-05-10 11:43:43 +01:00
|
|
|
DeadlineBefore: now,
|
2021-04-29 10:21:29 +01:00
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
metabasetest.Verify{}.Check(ctx, t, db)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("partial objects", func(t *testing.T) {
|
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
// zombie object with default deadline
|
|
|
|
metabasetest.BeginObjectExactVersion{
|
|
|
|
Opts: metabase.BeginObjectExactVersion{
|
|
|
|
ObjectStream: obj1,
|
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
// zombie object with deadline time in the past
|
|
|
|
metabasetest.BeginObjectExactVersion{
|
|
|
|
Opts: metabase.BeginObjectExactVersion{
|
|
|
|
ObjectStream: obj2,
|
|
|
|
ZombieDeletionDeadline: &pastTime,
|
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
// pending object with expiration time in the future
|
|
|
|
metabasetest.BeginObjectExactVersion{
|
|
|
|
Opts: metabase.BeginObjectExactVersion{
|
|
|
|
ObjectStream: obj3,
|
|
|
|
ZombieDeletionDeadline: &futureTime,
|
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
metabasetest.DeleteZombieObjects{
|
|
|
|
Opts: metabase.DeleteZombieObjects{
|
2021-05-10 11:43:43 +01:00
|
|
|
DeadlineBefore: now,
|
|
|
|
InactiveDeadline: now,
|
2021-04-29 10:21:29 +01:00
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
metabasetest.Verify{ // the object with zombie deadline time in the past is gone
|
|
|
|
Objects: []metabase.RawObject{
|
|
|
|
{
|
|
|
|
ObjectStream: obj1,
|
|
|
|
CreatedAt: now,
|
|
|
|
Status: metabase.Pending,
|
|
|
|
|
2021-05-06 12:42:20 +01:00
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
|
|
|
ZombieDeletionDeadline: &zombieDeadline,
|
2021-04-29 10:21:29 +01:00
|
|
|
},
|
|
|
|
{
|
2021-05-06 12:42:20 +01:00
|
|
|
ObjectStream: obj3,
|
|
|
|
CreatedAt: now,
|
|
|
|
Status: metabase.Pending,
|
2021-04-29 10:21:29 +01:00
|
|
|
|
2021-05-06 12:42:20 +01:00
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
|
|
|
ZombieDeletionDeadline: &futureTime,
|
2021-04-29 10:21:29 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
})
|
|
|
|
|
2021-05-10 11:43:43 +01:00
|
|
|
t.Run("partial object with segment", func(t *testing.T) {
|
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
metabasetest.BeginObjectExactVersion{
|
|
|
|
Opts: metabase.BeginObjectExactVersion{
|
|
|
|
ObjectStream: obj1,
|
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
|
|
|
ZombieDeletionDeadline: &now,
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
metabasetest.BeginSegment{
|
|
|
|
Opts: metabase.BeginSegment{
|
|
|
|
ObjectStream: obj1,
|
|
|
|
RootPieceID: storj.PieceID{1},
|
|
|
|
Pieces: []metabase.Piece{{
|
|
|
|
Number: 1,
|
|
|
|
StorageNode: testrand.NodeID(),
|
|
|
|
}},
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
metabasetest.CommitSegment{
|
|
|
|
Opts: metabase.CommitSegment{
|
|
|
|
ObjectStream: obj1,
|
|
|
|
RootPieceID: storj.PieceID{1},
|
|
|
|
Pieces: metabase.Pieces{{Number: 0, StorageNode: storj.NodeID{2}}},
|
|
|
|
|
|
|
|
EncryptedKey: []byte{3},
|
2021-10-12 14:37:12 +01:00
|
|
|
EncryptedKeyNonce: []byte{4},
|
2021-05-10 11:43:43 +01:00
|
|
|
EncryptedETag: []byte{5},
|
|
|
|
|
|
|
|
EncryptedSize: 1024,
|
|
|
|
PlainSize: 512,
|
|
|
|
PlainOffset: 0,
|
|
|
|
Redundancy: metabasetest.DefaultRedundancy,
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
// object will be checked if is inactive but inactive time is in future
|
|
|
|
metabasetest.DeleteZombieObjects{
|
|
|
|
Opts: metabase.DeleteZombieObjects{
|
|
|
|
DeadlineBefore: now.Add(1 * time.Hour),
|
|
|
|
InactiveDeadline: now.Add(-1 * time.Hour),
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
metabasetest.Verify{
|
|
|
|
Objects: []metabase.RawObject{
|
|
|
|
{
|
|
|
|
ObjectStream: obj1,
|
|
|
|
CreatedAt: now,
|
|
|
|
Status: metabase.Pending,
|
|
|
|
|
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
|
|
|
ZombieDeletionDeadline: &now,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Segments: []metabase.RawSegment{
|
|
|
|
{
|
|
|
|
StreamID: obj1.StreamID,
|
|
|
|
RootPieceID: storj.PieceID{1},
|
|
|
|
Pieces: metabase.Pieces{{Number: 0, StorageNode: storj.NodeID{2}}},
|
|
|
|
CreatedAt: now,
|
|
|
|
|
|
|
|
EncryptedKey: []byte{3},
|
2021-10-12 14:37:12 +01:00
|
|
|
EncryptedKeyNonce: []byte{4},
|
2021-05-10 11:43:43 +01:00
|
|
|
EncryptedETag: []byte{5},
|
|
|
|
|
|
|
|
EncryptedSize: 1024,
|
|
|
|
PlainSize: 512,
|
|
|
|
PlainOffset: 0,
|
|
|
|
Redundancy: metabasetest.DefaultRedundancy,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
// object will be checked if is inactive and will be deleted with segment
|
|
|
|
metabasetest.DeleteZombieObjects{
|
|
|
|
Opts: metabase.DeleteZombieObjects{
|
2023-06-28 14:23:12 +01:00
|
|
|
DeadlineBefore: now.Add(1 * time.Hour),
|
|
|
|
InactiveDeadline: now.Add(2 * time.Hour),
|
|
|
|
AsOfSystemInterval: -1 * time.Microsecond,
|
2021-05-10 11:43:43 +01:00
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
metabasetest.Verify{}.Check(ctx, t, db)
|
|
|
|
})
|
|
|
|
|
2021-04-29 10:21:29 +01:00
|
|
|
t.Run("batch size", func(t *testing.T) {
|
|
|
|
for i := 0; i < 33; i++ {
|
|
|
|
obj := metabasetest.RandObjectStream()
|
|
|
|
|
|
|
|
metabasetest.BeginObjectExactVersion{
|
|
|
|
Opts: metabase.BeginObjectExactVersion{
|
2021-05-10 11:43:43 +01:00
|
|
|
ObjectStream: obj,
|
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
|
|
|
// use default 24h zombie deletion deadline
|
2021-04-29 10:21:29 +01:00
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
for i := byte(0); i < 3; i++ {
|
|
|
|
metabasetest.BeginSegment{
|
|
|
|
Opts: metabase.BeginSegment{
|
|
|
|
ObjectStream: obj,
|
|
|
|
Position: metabase.SegmentPosition{Part: 0, Index: uint32(i)},
|
|
|
|
RootPieceID: storj.PieceID{i + 1},
|
|
|
|
Pieces: []metabase.Piece{{
|
|
|
|
Number: 1,
|
|
|
|
StorageNode: testrand.NodeID(),
|
|
|
|
}},
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
metabasetest.CommitSegment{
|
|
|
|
Opts: metabase.CommitSegment{
|
|
|
|
ObjectStream: obj,
|
|
|
|
Position: metabase.SegmentPosition{Part: 0, Index: uint32(i)},
|
|
|
|
RootPieceID: storj.PieceID{1},
|
|
|
|
Pieces: metabase.Pieces{{Number: 0, StorageNode: storj.NodeID{2}}},
|
|
|
|
|
|
|
|
EncryptedKey: []byte{3},
|
2021-10-12 14:37:12 +01:00
|
|
|
EncryptedKeyNonce: []byte{4},
|
2021-04-29 10:21:29 +01:00
|
|
|
EncryptedETag: []byte{5},
|
|
|
|
|
|
|
|
EncryptedSize: 1024,
|
|
|
|
PlainSize: 512,
|
|
|
|
PlainOffset: 0,
|
|
|
|
Redundancy: metabasetest.DefaultRedundancy,
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
metabasetest.DeleteZombieObjects{
|
|
|
|
Opts: metabase.DeleteZombieObjects{
|
2021-05-10 11:43:43 +01:00
|
|
|
DeadlineBefore: now.Add(25 * time.Hour),
|
|
|
|
InactiveDeadline: now.Add(48 * time.Hour),
|
|
|
|
BatchSize: 4,
|
2021-04-29 10:21:29 +01:00
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
metabasetest.Verify{}.Check(ctx, t, db)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("committed objects", func(t *testing.T) {
|
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
|
|
|
|
2022-02-24 14:26:05 +00:00
|
|
|
object1, _ := metabasetest.CreateTestObject{}.Run(ctx, t, db, obj1, 1)
|
2021-04-29 10:21:29 +01:00
|
|
|
|
|
|
|
object2 := object1
|
|
|
|
object2.ObjectStream = obj2
|
|
|
|
metabasetest.CreateTestObject{
|
|
|
|
BeginObjectExactVersion: &metabase.BeginObjectExactVersion{
|
|
|
|
ObjectStream: object2.ObjectStream,
|
|
|
|
ZombieDeletionDeadline: &pastTime,
|
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
|
|
|
},
|
|
|
|
}.Run(ctx, t, db, object2.ObjectStream, 1)
|
|
|
|
|
2022-02-24 14:26:05 +00:00
|
|
|
object3, _ := metabasetest.CreateTestObject{
|
2021-04-29 10:21:29 +01:00
|
|
|
BeginObjectExactVersion: &metabase.BeginObjectExactVersion{
|
|
|
|
ObjectStream: obj3,
|
|
|
|
ZombieDeletionDeadline: &futureTime,
|
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
|
|
|
},
|
|
|
|
}.Run(ctx, t, db, obj3, 1)
|
|
|
|
|
|
|
|
expectedObj1Segment := metabase.Segment{
|
|
|
|
StreamID: obj1.StreamID,
|
|
|
|
RootPieceID: storj.PieceID{1},
|
2021-08-05 00:56:50 +01:00
|
|
|
CreatedAt: now,
|
2021-04-29 10:21:29 +01:00
|
|
|
EncryptedKey: []byte{3},
|
2021-10-12 14:37:12 +01:00
|
|
|
EncryptedKeyNonce: []byte{4},
|
2021-04-29 10:21:29 +01:00
|
|
|
EncryptedETag: []byte{5},
|
|
|
|
EncryptedSize: 1060,
|
|
|
|
PlainSize: 512,
|
|
|
|
Pieces: metabase.Pieces{{Number: 0, StorageNode: storj.NodeID{2}}},
|
|
|
|
Redundancy: metabasetest.DefaultRedundancy,
|
|
|
|
}
|
|
|
|
|
|
|
|
expectedObj2Segment := expectedObj1Segment
|
|
|
|
expectedObj2Segment.StreamID = object2.StreamID
|
|
|
|
expectedObj3Segment := expectedObj1Segment
|
|
|
|
expectedObj3Segment.StreamID = object3.StreamID
|
|
|
|
|
|
|
|
metabasetest.DeleteZombieObjects{
|
|
|
|
Opts: metabase.DeleteZombieObjects{
|
2021-05-10 11:43:43 +01:00
|
|
|
DeadlineBefore: now,
|
|
|
|
InactiveDeadline: now.Add(1 * time.Hour),
|
2021-04-29 10:21:29 +01:00
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
metabasetest.Verify{ // all committed objects should NOT be deleted
|
|
|
|
Objects: []metabase.RawObject{
|
|
|
|
metabase.RawObject(object1),
|
|
|
|
metabase.RawObject(object2),
|
|
|
|
metabase.RawObject(object3),
|
|
|
|
},
|
|
|
|
Segments: []metabase.RawSegment{
|
|
|
|
metabase.RawSegment(expectedObj1Segment),
|
|
|
|
metabase.RawSegment(expectedObj2Segment),
|
|
|
|
metabase.RawSegment(expectedObj3Segment),
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
})
|
2022-08-09 20:43:27 +01:00
|
|
|
|
|
|
|
// 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)
|
|
|
|
|
2023-10-02 14:14:52 +01:00
|
|
|
_, err := db.TestingBeginObjectExactVersion(ctx, metabase.BeginObjectExactVersion{
|
2022-08-09 20:43:27 +01:00
|
|
|
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)
|
|
|
|
})
|
2021-04-29 10:21:29 +01:00
|
|
|
})
|
|
|
|
}
|