2020-10-28 15:28:06 +00:00
|
|
|
// Copyright (C) 2020 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package metabase_test
|
|
|
|
|
|
|
|
import (
|
2022-02-11 21:10:10 +00:00
|
|
|
"fmt"
|
2020-10-28 15:28:06 +00:00
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2022-02-11 21:10:10 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
2022-03-16 18:44:21 +00:00
|
|
|
"storj.io/common/memory"
|
2020-10-28 15:28:06 +00:00
|
|
|
"storj.io/common/storj"
|
|
|
|
"storj.io/common/testcontext"
|
|
|
|
"storj.io/common/testrand"
|
|
|
|
"storj.io/common/uuid"
|
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-10-28 15:28:06 +00:00
|
|
|
)
|
|
|
|
|
2022-03-16 18:44:21 +00:00
|
|
|
var noServerSideCopyConfig = metabase.Config{
|
|
|
|
ApplicationName: "satellite-test",
|
|
|
|
MinPartSize: 5 * memory.MiB,
|
|
|
|
MaxNumberOfParts: 1000,
|
|
|
|
ServerSideCopy: false,
|
|
|
|
}
|
|
|
|
|
2020-12-01 23:17:05 +00:00
|
|
|
func TestDeletePendingObject(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Run(t, func(ctx *testcontext.Context, t *testing.T, db *metabase.DB) {
|
|
|
|
obj := metabasetest.RandObjectStream()
|
2020-12-01 23:17:05 +00:00
|
|
|
now := time.Now()
|
2021-05-06 12:42:20 +01:00
|
|
|
zombieDeadline := now.Add(24 * time.Hour)
|
2020-12-01 23:17:05 +00:00
|
|
|
|
2021-05-04 14:51:40 +01:00
|
|
|
for _, test := range metabasetest.InvalidObjectStreams(obj) {
|
2020-12-01 23:17:05 +00:00
|
|
|
test := test
|
|
|
|
t.Run(test.Name, func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
|
|
|
metabasetest.DeletePendingObject{
|
2020-12-01 23:17:05 +00:00
|
|
|
Opts: metabase.DeletePendingObject{
|
2021-05-04 14:51:40 +01:00
|
|
|
ObjectStream: test.ObjectStream,
|
2020-12-01 23:17:05 +00:00
|
|
|
},
|
|
|
|
ErrClass: test.ErrClass,
|
|
|
|
ErrText: test.ErrText,
|
|
|
|
}.Check(ctx, t, db)
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{}.Check(ctx, t, db)
|
2020-12-01 23:17:05 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-05-04 14:51:40 +01:00
|
|
|
t.Run("object missing", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2020-12-01 23:17:05 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.DeletePendingObject{
|
2020-12-01 23:17:05 +00:00
|
|
|
Opts: metabase.DeletePendingObject{
|
2021-05-04 14:51:40 +01:00
|
|
|
ObjectStream: obj,
|
2020-12-01 23:17:05 +00:00
|
|
|
},
|
|
|
|
ErrClass: &storj.ErrObjectNotFound,
|
|
|
|
ErrText: "metabase: no rows deleted",
|
|
|
|
}.Check(ctx, t, db)
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{}.Check(ctx, t, db)
|
2020-12-01 23:17:05 +00:00
|
|
|
})
|
|
|
|
|
2021-05-04 14:51:40 +01:00
|
|
|
t.Run("non existing object version", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2020-12-01 23:17:05 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.BeginObjectExactVersion{
|
2020-12-01 23:17:05 +00:00
|
|
|
Opts: metabase.BeginObjectExactVersion{
|
|
|
|
ObjectStream: obj,
|
2021-04-26 10:35:44 +01:00
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
2020-12-01 23:17:05 +00:00
|
|
|
},
|
|
|
|
Version: 1,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.DeletePendingObject{
|
2020-12-01 23:17:05 +00:00
|
|
|
Opts: metabase.DeletePendingObject{
|
2021-05-04 14:51:40 +01:00
|
|
|
ObjectStream: metabase.ObjectStream{
|
|
|
|
ProjectID: obj.ProjectID,
|
|
|
|
BucketName: obj.BucketName,
|
|
|
|
ObjectKey: obj.ObjectKey,
|
|
|
|
Version: 33,
|
|
|
|
StreamID: obj.StreamID,
|
|
|
|
},
|
2020-12-01 23:17:05 +00:00
|
|
|
},
|
|
|
|
ErrClass: &storj.ErrObjectNotFound,
|
|
|
|
ErrText: "metabase: no rows deleted",
|
|
|
|
}.Check(ctx, t, db)
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{
|
2020-12-01 23:17:05 +00:00
|
|
|
Objects: []metabase.RawObject{
|
|
|
|
{
|
|
|
|
ObjectStream: obj,
|
|
|
|
CreatedAt: now,
|
|
|
|
Status: metabase.Pending,
|
|
|
|
|
2021-05-06 12:42:20 +01:00
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
|
|
|
ZombieDeletionDeadline: &zombieDeadline,
|
2020-12-01 23:17:05 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
})
|
|
|
|
|
2021-05-04 14:51:40 +01:00
|
|
|
t.Run("delete committed object", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2020-12-01 23:17:05 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
object := metabasetest.CreateObject(ctx, t, db, obj, 0)
|
2020-12-01 23:17:05 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.DeletePendingObject{
|
2020-12-01 23:17:05 +00:00
|
|
|
Opts: metabase.DeletePendingObject{
|
2021-05-04 14:51:40 +01:00
|
|
|
ObjectStream: object.ObjectStream,
|
2020-12-01 23:17:05 +00:00
|
|
|
},
|
|
|
|
ErrClass: &storj.ErrObjectNotFound,
|
|
|
|
ErrText: "metabase: no rows deleted",
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{
|
2020-12-01 23:17:05 +00:00
|
|
|
Objects: []metabase.RawObject{
|
|
|
|
{
|
|
|
|
ObjectStream: obj,
|
|
|
|
CreatedAt: now,
|
|
|
|
Status: metabase.Committed,
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
2020-12-01 23:17:05 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
})
|
|
|
|
|
2021-05-04 14:51:40 +01:00
|
|
|
t.Run("without segments with wrong StreamID", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2020-12-01 23:17:05 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.BeginObjectExactVersion{
|
2020-12-01 23:17:05 +00:00
|
|
|
Opts: metabase.BeginObjectExactVersion{
|
|
|
|
ObjectStream: obj,
|
2021-04-26 10:35:44 +01:00
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
2020-12-01 23:17:05 +00:00
|
|
|
},
|
|
|
|
Version: 1,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.DeletePendingObject{
|
2020-12-01 23:17:05 +00:00
|
|
|
Opts: metabase.DeletePendingObject{
|
2021-05-04 14:51:40 +01:00
|
|
|
ObjectStream: metabase.ObjectStream{
|
|
|
|
ProjectID: obj.ProjectID,
|
|
|
|
BucketName: obj.BucketName,
|
|
|
|
ObjectKey: obj.ObjectKey,
|
|
|
|
Version: obj.Version,
|
|
|
|
StreamID: uuid.UUID{33},
|
|
|
|
},
|
2020-12-01 23:17:05 +00:00
|
|
|
},
|
|
|
|
Result: metabase.DeleteObjectResult{},
|
|
|
|
ErrClass: &storj.ErrObjectNotFound,
|
|
|
|
ErrText: "metabase: no rows deleted",
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{
|
2020-12-01 23:17:05 +00:00
|
|
|
Objects: []metabase.RawObject{
|
|
|
|
{
|
|
|
|
ObjectStream: obj,
|
|
|
|
CreatedAt: now,
|
|
|
|
Status: metabase.Pending,
|
|
|
|
|
2021-05-06 12:42:20 +01:00
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
|
|
|
ZombieDeletionDeadline: &zombieDeadline,
|
2020-12-01 23:17:05 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
})
|
|
|
|
|
2021-05-04 14:51:40 +01:00
|
|
|
t.Run("without segments", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2020-12-01 23:17:05 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.BeginObjectExactVersion{
|
2020-12-01 23:17:05 +00:00
|
|
|
Opts: metabase.BeginObjectExactVersion{
|
|
|
|
ObjectStream: obj,
|
2021-04-26 10:35:44 +01:00
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
2020-12-01 23:17:05 +00:00
|
|
|
},
|
|
|
|
Version: 1,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
object := metabase.RawObject{
|
|
|
|
ObjectStream: obj,
|
|
|
|
CreatedAt: now,
|
|
|
|
Status: metabase.Pending,
|
2021-04-26 10:35:44 +01:00
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
2020-12-01 23:17:05 +00:00
|
|
|
}
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.DeletePendingObject{
|
2020-12-01 23:17:05 +00:00
|
|
|
Opts: metabase.DeletePendingObject{
|
2021-05-04 14:51:40 +01:00
|
|
|
ObjectStream: obj,
|
2020-12-01 23:17:05 +00:00
|
|
|
},
|
|
|
|
Result: metabase.DeleteObjectResult{
|
|
|
|
Objects: []metabase.Object{metabase.Object(object)},
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{}.Check(ctx, t, db)
|
2020-12-01 23:17:05 +00:00
|
|
|
})
|
|
|
|
|
2021-05-04 14:51:40 +01:00
|
|
|
t.Run("with segments", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2020-12-01 23:17:05 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.CreatePendingObject(ctx, t, db, obj, 2)
|
2020-12-01 23:17:05 +00:00
|
|
|
|
|
|
|
expectedSegmentInfo := metabase.DeletedSegmentInfo{
|
|
|
|
RootPieceID: storj.PieceID{1},
|
|
|
|
Pieces: metabase.Pieces{{Number: 0, StorageNode: storj.NodeID{2}}},
|
|
|
|
}
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.DeletePendingObject{
|
2020-12-01 23:17:05 +00:00
|
|
|
Opts: metabase.DeletePendingObject{
|
2021-05-04 14:51:40 +01:00
|
|
|
ObjectStream: obj,
|
2020-12-01 23:17:05 +00:00
|
|
|
},
|
|
|
|
Result: metabase.DeleteObjectResult{
|
|
|
|
Objects: []metabase.Object{
|
|
|
|
{
|
|
|
|
ObjectStream: obj,
|
|
|
|
CreatedAt: now,
|
|
|
|
Status: metabase.Pending,
|
2021-04-26 10:35:44 +01:00
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
2020-12-01 23:17:05 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
Segments: []metabase.DeletedSegmentInfo{expectedSegmentInfo, expectedSegmentInfo},
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{}.Check(ctx, t, db)
|
2020-12-01 23:17:05 +00:00
|
|
|
})
|
|
|
|
|
2021-05-04 14:51:40 +01:00
|
|
|
t.Run("with inline segment", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2020-12-01 23:17:05 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.BeginObjectExactVersion{
|
2020-12-01 23:17:05 +00:00
|
|
|
Opts: metabase.BeginObjectExactVersion{
|
|
|
|
ObjectStream: obj,
|
2021-04-26 10:35:44 +01:00
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
2020-12-01 23:17:05 +00:00
|
|
|
},
|
|
|
|
Version: obj.Version,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.CommitInlineSegment{
|
2020-12-01 23:17:05 +00:00
|
|
|
Opts: metabase.CommitInlineSegment{
|
|
|
|
ObjectStream: obj,
|
|
|
|
Position: metabase.SegmentPosition{Part: 0, Index: 0},
|
|
|
|
|
|
|
|
EncryptedKey: testrand.Bytes(32),
|
2021-10-12 14:37:12 +01:00
|
|
|
EncryptedKeyNonce: testrand.Bytes(32),
|
2020-12-01 23:17:05 +00:00
|
|
|
|
|
|
|
InlineData: testrand.Bytes(1024),
|
|
|
|
|
|
|
|
PlainSize: 512,
|
|
|
|
PlainOffset: 0,
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.DeletePendingObject{
|
2020-12-01 23:17:05 +00:00
|
|
|
Opts: metabase.DeletePendingObject{
|
2021-05-04 14:51:40 +01:00
|
|
|
ObjectStream: obj,
|
2020-12-01 23:17:05 +00:00
|
|
|
},
|
|
|
|
Result: metabase.DeleteObjectResult{
|
|
|
|
Objects: []metabase.Object{
|
|
|
|
{
|
|
|
|
ObjectStream: obj,
|
|
|
|
CreatedAt: now,
|
|
|
|
Status: metabase.Pending,
|
2021-04-26 10:35:44 +01:00
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
2020-12-01 23:17:05 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{}.Check(ctx, t, db)
|
2020-12-01 23:17:05 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
2020-10-28 15:28:06 +00:00
|
|
|
|
|
|
|
func TestDeleteObjectExactVersion(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Run(t, func(ctx *testcontext.Context, t *testing.T, db *metabase.DB) {
|
|
|
|
obj := metabasetest.RandObjectStream()
|
2020-10-28 15:28:06 +00:00
|
|
|
|
|
|
|
location := obj.Location()
|
|
|
|
|
|
|
|
now := time.Now()
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
for _, test := range metabasetest.InvalidObjectLocations(location) {
|
2020-10-28 15:28:06 +00:00
|
|
|
test := test
|
|
|
|
t.Run(test.Name, func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
|
|
|
metabasetest.DeleteObjectExactVersion{
|
2020-10-28 15:28:06 +00:00
|
|
|
Opts: metabase.DeleteObjectExactVersion{
|
|
|
|
ObjectLocation: test.ObjectLocation,
|
|
|
|
},
|
|
|
|
ErrClass: test.ErrClass,
|
|
|
|
ErrText: test.ErrText,
|
|
|
|
}.Check(ctx, t, db)
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{}.Check(ctx, t, db)
|
2020-10-28 15:28:06 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Run("Version invalid", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2020-10-28 15:28:06 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.DeleteObjectExactVersion{
|
2020-10-28 15:28:06 +00:00
|
|
|
Opts: metabase.DeleteObjectExactVersion{
|
|
|
|
ObjectLocation: location,
|
|
|
|
Version: 0,
|
|
|
|
},
|
|
|
|
ErrClass: &metabase.ErrInvalidRequest,
|
|
|
|
ErrText: "Version invalid: 0",
|
|
|
|
}.Check(ctx, t, db)
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{}.Check(ctx, t, db)
|
2020-10-28 15:28:06 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Object missing", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2020-10-28 15:28:06 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.DeleteObjectExactVersion{
|
2020-10-28 15:28:06 +00:00
|
|
|
Opts: metabase.DeleteObjectExactVersion{
|
|
|
|
ObjectLocation: location,
|
|
|
|
Version: 1,
|
|
|
|
},
|
2022-03-14 15:53:00 +00:00
|
|
|
Result: metabase.DeleteObjectResult{
|
|
|
|
Objects: []metabase.Object{},
|
|
|
|
},
|
2020-10-28 15:28:06 +00:00
|
|
|
}.Check(ctx, t, db)
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{}.Check(ctx, t, db)
|
2020-10-28 15:28:06 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Delete non existing object version", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2020-10-28 15:28:06 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.DeleteObjectExactVersion{
|
2020-10-28 15:28:06 +00:00
|
|
|
Opts: metabase.DeleteObjectExactVersion{
|
|
|
|
ObjectLocation: location,
|
|
|
|
Version: 33,
|
|
|
|
},
|
2022-03-14 15:53:00 +00:00
|
|
|
Result: metabase.DeleteObjectResult{
|
|
|
|
Objects: []metabase.Object{},
|
|
|
|
},
|
2020-10-28 15:28:06 +00:00
|
|
|
}.Check(ctx, t, db)
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{}.Check(ctx, t, db)
|
2020-10-28 15:28:06 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Delete partial object", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2020-10-28 15:28:06 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.BeginObjectExactVersion{
|
2020-10-28 15:28:06 +00:00
|
|
|
Opts: metabase.BeginObjectExactVersion{
|
|
|
|
ObjectStream: obj,
|
2021-04-26 10:35:44 +01:00
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
2020-10-28 15:28:06 +00:00
|
|
|
},
|
|
|
|
Version: 1,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.DeleteObjectExactVersion{
|
2020-10-28 15:28:06 +00:00
|
|
|
Opts: metabase.DeleteObjectExactVersion{
|
|
|
|
ObjectLocation: location,
|
|
|
|
Version: 1,
|
|
|
|
},
|
2022-03-14 15:53:00 +00:00
|
|
|
Result: metabase.DeleteObjectResult{
|
|
|
|
Objects: []metabase.Object{{
|
2020-10-28 15:28:06 +00:00
|
|
|
ObjectStream: obj,
|
|
|
|
CreatedAt: now,
|
2022-03-14 15:53:00 +00:00
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
2020-10-28 15:28:06 +00:00
|
|
|
Status: metabase.Pending,
|
2022-03-14 15:53:00 +00:00
|
|
|
}},
|
2020-10-28 15:28:06 +00:00
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
2022-03-14 15:53:00 +00:00
|
|
|
|
|
|
|
metabasetest.Verify{}.Check(ctx, t, db)
|
2020-10-28 15:28:06 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Delete object without segments", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2020-10-28 15:28:06 +00:00
|
|
|
|
2020-11-16 16:46:47 +00:00
|
|
|
encryptedMetadata := testrand.Bytes(1024)
|
|
|
|
encryptedMetadataNonce := testrand.Nonce()
|
|
|
|
encryptedMetadataKey := testrand.Bytes(265)
|
|
|
|
|
2022-02-24 14:26:05 +00:00
|
|
|
object, _ := metabasetest.CreateTestObject{
|
2020-11-16 16:46:47 +00:00
|
|
|
CommitObject: &metabase.CommitObject{
|
|
|
|
ObjectStream: obj,
|
2021-10-12 14:37:12 +01:00
|
|
|
EncryptedMetadataNonce: encryptedMetadataNonce[:],
|
2020-11-16 16:46:47 +00:00
|
|
|
EncryptedMetadata: encryptedMetadata,
|
|
|
|
EncryptedMetadataEncryptedKey: encryptedMetadataKey,
|
|
|
|
},
|
|
|
|
}.Run(ctx, t, db, obj, 0)
|
2020-10-28 15:28:06 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.DeleteObjectExactVersion{
|
2020-10-28 15:28:06 +00:00
|
|
|
Opts: metabase.DeleteObjectExactVersion{
|
|
|
|
ObjectLocation: location,
|
|
|
|
Version: 1,
|
|
|
|
},
|
2020-11-03 10:45:49 +00:00
|
|
|
Result: metabase.DeleteObjectResult{
|
|
|
|
Objects: []metabase.Object{object},
|
|
|
|
},
|
2020-10-28 15:28:06 +00:00
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{}.Check(ctx, t, db)
|
2020-10-28 15:28:06 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Delete object with segments", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2020-10-28 15:28:06 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
object := metabasetest.CreateObject(ctx, t, db, obj, 2)
|
2020-10-28 15:28:06 +00:00
|
|
|
|
|
|
|
expectedSegmentInfo := metabase.DeletedSegmentInfo{
|
|
|
|
RootPieceID: storj.PieceID{1},
|
|
|
|
Pieces: metabase.Pieces{{Number: 0, StorageNode: storj.NodeID{2}}},
|
|
|
|
}
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.DeleteObjectExactVersion{
|
2020-10-28 15:28:06 +00:00
|
|
|
Opts: metabase.DeleteObjectExactVersion{
|
|
|
|
ObjectLocation: location,
|
|
|
|
Version: 1,
|
|
|
|
},
|
|
|
|
Result: metabase.DeleteObjectResult{
|
2020-11-03 10:45:49 +00:00
|
|
|
Objects: []metabase.Object{object},
|
2020-10-28 15:28:06 +00:00
|
|
|
Segments: []metabase.DeletedSegmentInfo{expectedSegmentInfo, expectedSegmentInfo},
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{}.Check(ctx, t, db)
|
2020-10-28 15:28:06 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Delete object with inline segment", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2020-10-28 15:28:06 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.BeginObjectExactVersion{
|
2020-10-28 15:28:06 +00:00
|
|
|
Opts: metabase.BeginObjectExactVersion{
|
|
|
|
ObjectStream: obj,
|
2021-04-26 10:35:44 +01:00
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
2020-10-28 15:28:06 +00:00
|
|
|
},
|
|
|
|
Version: obj.Version,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.CommitInlineSegment{
|
2020-10-28 15:28:06 +00:00
|
|
|
Opts: metabase.CommitInlineSegment{
|
|
|
|
ObjectStream: obj,
|
|
|
|
Position: metabase.SegmentPosition{Part: 0, Index: 0},
|
|
|
|
|
|
|
|
EncryptedKey: testrand.Bytes(32),
|
2021-10-12 14:37:12 +01:00
|
|
|
EncryptedKeyNonce: testrand.Bytes(32),
|
2020-10-28 15:28:06 +00:00
|
|
|
|
|
|
|
InlineData: testrand.Bytes(1024),
|
|
|
|
|
2020-11-11 10:54:10 +00:00
|
|
|
PlainSize: 512,
|
|
|
|
PlainOffset: 0,
|
2020-10-28 15:28:06 +00:00
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
object := metabasetest.CommitObject{
|
2020-10-28 15:28:06 +00:00
|
|
|
Opts: metabase.CommitObject{
|
|
|
|
ObjectStream: obj,
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.DeleteObjectExactVersion{
|
2020-10-28 15:28:06 +00:00
|
|
|
Opts: metabase.DeleteObjectExactVersion{
|
|
|
|
ObjectLocation: location,
|
|
|
|
Version: 1,
|
|
|
|
},
|
2020-11-03 10:45:49 +00:00
|
|
|
Result: metabase.DeleteObjectResult{
|
|
|
|
Objects: []metabase.Object{object},
|
|
|
|
},
|
2020-10-28 15:28:06 +00:00
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{}.Check(ctx, t, db)
|
2020-10-28 15:28:06 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-01-11 10:08:18 +00:00
|
|
|
func TestDeleteObjectAnyStatusAllVersions(t *testing.T) {
|
2022-03-16 18:44:21 +00:00
|
|
|
metabasetest.RunWithConfig(t, noServerSideCopyConfig, func(ctx *testcontext.Context, t *testing.T, db *metabase.DB) {
|
2021-04-26 10:35:44 +01:00
|
|
|
obj := metabasetest.RandObjectStream()
|
2020-10-28 15:28:06 +00:00
|
|
|
|
|
|
|
location := obj.Location()
|
|
|
|
|
|
|
|
now := time.Now()
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
for _, test := range metabasetest.InvalidObjectLocations(location) {
|
2020-10-28 15:28:06 +00:00
|
|
|
test := test
|
|
|
|
t.Run(test.Name, func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
|
|
|
metabasetest.DeleteObjectAnyStatusAllVersions{
|
2021-01-11 10:08:18 +00:00
|
|
|
Opts: metabase.DeleteObjectAnyStatusAllVersions{ObjectLocation: test.ObjectLocation},
|
2020-10-28 15:28:06 +00:00
|
|
|
ErrClass: test.ErrClass,
|
|
|
|
ErrText: test.ErrText,
|
|
|
|
}.Check(ctx, t, db)
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{}.Check(ctx, t, db)
|
2020-10-28 15:28:06 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Run("Object missing", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2020-10-28 15:28:06 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.DeleteObjectAnyStatusAllVersions{
|
2021-01-11 10:08:18 +00:00
|
|
|
Opts: metabase.DeleteObjectAnyStatusAllVersions{ObjectLocation: obj.Location()},
|
2020-11-02 10:51:36 +00:00
|
|
|
ErrClass: &storj.ErrObjectNotFound,
|
|
|
|
ErrText: "metabase: no rows deleted",
|
2020-10-28 15:28:06 +00:00
|
|
|
}.Check(ctx, t, db)
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{}.Check(ctx, t, db)
|
2020-10-28 15:28:06 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Delete non existing object version", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2020-10-28 15:28:06 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.DeleteObjectAnyStatusAllVersions{
|
2021-01-11 10:08:18 +00:00
|
|
|
Opts: metabase.DeleteObjectAnyStatusAllVersions{ObjectLocation: obj.Location()},
|
2020-11-02 10:51:36 +00:00
|
|
|
ErrClass: &storj.ErrObjectNotFound,
|
|
|
|
ErrText: "metabase: no rows deleted",
|
2020-10-28 15:28:06 +00:00
|
|
|
}.Check(ctx, t, db)
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{}.Check(ctx, t, db)
|
2020-10-28 15:28:06 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Delete partial object", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2020-10-28 15:28:06 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.BeginObjectExactVersion{
|
2020-10-28 15:28:06 +00:00
|
|
|
Opts: metabase.BeginObjectExactVersion{
|
|
|
|
ObjectStream: obj,
|
2021-04-26 10:35:44 +01:00
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
2020-10-28 15:28:06 +00:00
|
|
|
},
|
|
|
|
Version: 1,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.DeleteObjectAnyStatusAllVersions{
|
2021-01-11 10:08:18 +00:00
|
|
|
Opts: metabase.DeleteObjectAnyStatusAllVersions{ObjectLocation: obj.Location()},
|
|
|
|
Result: metabase.DeleteObjectResult{
|
|
|
|
Objects: []metabase.Object{{
|
2020-10-28 15:28:06 +00:00
|
|
|
ObjectStream: obj,
|
|
|
|
CreatedAt: now,
|
|
|
|
Status: metabase.Pending,
|
2020-10-29 13:49:53 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
2021-01-11 10:08:18 +00:00
|
|
|
}},
|
2020-10-28 15:28:06 +00:00
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
2021-01-11 10:08:18 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{}.Check(ctx, t, db)
|
2020-10-28 15:28:06 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Delete object without segments", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2020-10-28 15:28:06 +00:00
|
|
|
|
2020-11-16 16:46:47 +00:00
|
|
|
encryptedMetadata := testrand.Bytes(1024)
|
|
|
|
encryptedMetadataNonce := testrand.Nonce()
|
|
|
|
encryptedMetadataKey := testrand.Bytes(265)
|
|
|
|
|
2022-02-24 14:26:05 +00:00
|
|
|
object, _ := metabasetest.CreateTestObject{
|
2020-11-16 16:46:47 +00:00
|
|
|
CommitObject: &metabase.CommitObject{
|
|
|
|
ObjectStream: obj,
|
2021-10-12 14:37:12 +01:00
|
|
|
EncryptedMetadataNonce: encryptedMetadataNonce[:],
|
2020-11-16 16:46:47 +00:00
|
|
|
EncryptedMetadata: encryptedMetadata,
|
|
|
|
EncryptedMetadataEncryptedKey: encryptedMetadataKey,
|
|
|
|
},
|
|
|
|
}.Run(ctx, t, db, obj, 0)
|
2020-10-28 15:28:06 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.DeleteObjectAnyStatusAllVersions{
|
2021-01-11 10:08:18 +00:00
|
|
|
Opts: metabase.DeleteObjectAnyStatusAllVersions{ObjectLocation: obj.Location()},
|
2020-11-03 10:45:49 +00:00
|
|
|
Result: metabase.DeleteObjectResult{
|
|
|
|
Objects: []metabase.Object{object},
|
|
|
|
},
|
2020-10-28 15:28:06 +00:00
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{}.Check(ctx, t, db)
|
2020-10-28 15:28:06 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Delete object with segments", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2020-10-28 15:28:06 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
object := metabasetest.CreateObject(ctx, t, db, obj, 2)
|
2020-10-28 15:28:06 +00:00
|
|
|
|
|
|
|
expectedSegmentInfo := metabase.DeletedSegmentInfo{
|
|
|
|
RootPieceID: storj.PieceID{1},
|
|
|
|
Pieces: metabase.Pieces{{Number: 0, StorageNode: storj.NodeID{2}}},
|
|
|
|
}
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.DeleteObjectAnyStatusAllVersions{
|
2021-01-11 10:08:18 +00:00
|
|
|
Opts: metabase.DeleteObjectAnyStatusAllVersions{
|
2020-10-28 15:28:06 +00:00
|
|
|
ObjectLocation: location,
|
|
|
|
},
|
|
|
|
Result: metabase.DeleteObjectResult{
|
2020-11-03 10:45:49 +00:00
|
|
|
Objects: []metabase.Object{object},
|
2020-10-28 15:28:06 +00:00
|
|
|
Segments: []metabase.DeletedSegmentInfo{expectedSegmentInfo, expectedSegmentInfo},
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{}.Check(ctx, t, db)
|
2020-10-28 15:28:06 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Delete object with inline segment", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2020-10-28 15:28:06 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.BeginObjectExactVersion{
|
2020-10-28 15:28:06 +00:00
|
|
|
Opts: metabase.BeginObjectExactVersion{
|
|
|
|
ObjectStream: obj,
|
2021-04-26 10:35:44 +01:00
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
2020-10-28 15:28:06 +00:00
|
|
|
},
|
|
|
|
Version: obj.Version,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.CommitInlineSegment{
|
2020-10-28 15:28:06 +00:00
|
|
|
Opts: metabase.CommitInlineSegment{
|
|
|
|
ObjectStream: obj,
|
|
|
|
Position: metabase.SegmentPosition{Part: 0, Index: 0},
|
|
|
|
|
|
|
|
EncryptedKey: testrand.Bytes(32),
|
2021-10-12 14:37:12 +01:00
|
|
|
EncryptedKeyNonce: testrand.Bytes(32),
|
2020-10-28 15:28:06 +00:00
|
|
|
|
|
|
|
InlineData: testrand.Bytes(1024),
|
|
|
|
|
2020-11-11 10:54:10 +00:00
|
|
|
PlainSize: 512,
|
|
|
|
PlainOffset: 0,
|
2020-10-28 15:28:06 +00:00
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
object := metabasetest.CommitObject{
|
2020-10-28 15:28:06 +00:00
|
|
|
Opts: metabase.CommitObject{
|
|
|
|
ObjectStream: obj,
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.DeleteObjectAnyStatusAllVersions{
|
2021-01-11 10:08:18 +00:00
|
|
|
Opts: metabase.DeleteObjectAnyStatusAllVersions{ObjectLocation: obj.Location()},
|
2020-11-03 10:45:49 +00:00
|
|
|
Result: metabase.DeleteObjectResult{
|
|
|
|
Objects: []metabase.Object{object},
|
|
|
|
},
|
2020-10-28 15:28:06 +00:00
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{}.Check(ctx, t, db)
|
2020-10-28 15:28:06 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Delete multiple versions of the same object at once", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2020-10-28 15:28:06 +00:00
|
|
|
|
|
|
|
expected := metabase.DeleteObjectResult{}
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
obj := metabasetest.RandObjectStream()
|
2020-10-28 15:28:06 +00:00
|
|
|
for i := 1; i <= 10; i++ {
|
|
|
|
obj.StreamID = testrand.UUID()
|
|
|
|
obj.Version = metabase.Version(i)
|
2021-04-26 10:35:44 +01:00
|
|
|
expected.Objects = append(expected.Objects, metabasetest.CreateObject(ctx, t, db, obj, 1))
|
2020-10-28 15:28:06 +00:00
|
|
|
expected.Segments = append(expected.Segments, metabase.DeletedSegmentInfo{
|
|
|
|
RootPieceID: storj.PieceID{1},
|
|
|
|
Pieces: metabase.Pieces{{Number: 0, StorageNode: storj.NodeID{2}}},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.DeleteObjectAnyStatusAllVersions{
|
2021-01-11 10:08:18 +00:00
|
|
|
Opts: metabase.DeleteObjectAnyStatusAllVersions{ObjectLocation: obj.Location()},
|
2020-10-28 15:28:06 +00:00
|
|
|
Result: expected,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{}.Check(ctx, t, db)
|
2020-10-28 15:28:06 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-11-03 15:51:03 +00:00
|
|
|
func TestDeleteObjectsAllVersions(t *testing.T) {
|
2022-03-16 18:44:21 +00:00
|
|
|
metabasetest.RunWithConfig(t, noServerSideCopyConfig, func(ctx *testcontext.Context, t *testing.T, db *metabase.DB) {
|
2021-04-26 10:35:44 +01:00
|
|
|
obj := metabasetest.RandObjectStream()
|
2020-11-03 15:51:03 +00:00
|
|
|
|
|
|
|
location := obj.Location()
|
|
|
|
|
|
|
|
now := time.Now()
|
2021-05-06 12:42:20 +01:00
|
|
|
zombieDeadline := now.Add(24 * time.Hour)
|
2020-11-03 15:51:03 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
for _, test := range metabasetest.InvalidObjectLocations(location) {
|
2020-11-03 15:51:03 +00:00
|
|
|
test := test
|
|
|
|
t.Run(test.Name, func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
|
|
|
metabasetest.DeleteObjectsAllVersions{
|
2020-11-03 15:51:03 +00:00
|
|
|
Opts: metabase.DeleteObjectsAllVersions{
|
|
|
|
Locations: []metabase.ObjectLocation{test.ObjectLocation},
|
|
|
|
},
|
|
|
|
ErrClass: test.ErrClass,
|
|
|
|
ErrText: test.ErrText,
|
|
|
|
}.Check(ctx, t, db)
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{}.Check(ctx, t, db)
|
2020-11-03 15:51:03 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Run("Delete two objects from different projects", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2020-11-03 15:51:03 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
obj2 := metabasetest.RandObjectStream()
|
2020-11-03 15:51:03 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.DeleteObjectsAllVersions{
|
2020-11-03 15:51:03 +00:00
|
|
|
Opts: metabase.DeleteObjectsAllVersions{
|
|
|
|
Locations: []metabase.ObjectLocation{location, obj2.Location()},
|
|
|
|
},
|
|
|
|
ErrClass: &metabase.ErrInvalidRequest,
|
|
|
|
ErrText: "all objects must be in the same bucket",
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{}.Check(ctx, t, db)
|
2020-11-03 15:51:03 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Delete two objects from same project, but different buckets", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2020-11-03 15:51:03 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
obj2 := metabasetest.RandObjectStream()
|
2020-11-03 15:51:03 +00:00
|
|
|
obj2.ProjectID = obj.ProjectID
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.DeleteObjectsAllVersions{
|
2020-11-03 15:51:03 +00:00
|
|
|
Opts: metabase.DeleteObjectsAllVersions{
|
|
|
|
Locations: []metabase.ObjectLocation{location, obj2.Location()},
|
|
|
|
},
|
|
|
|
ErrClass: &metabase.ErrInvalidRequest,
|
|
|
|
ErrText: "all objects must be in the same bucket",
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{}.Check(ctx, t, db)
|
2020-11-03 15:51:03 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Delete empty list of objects", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2020-11-03 15:51:03 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.DeleteObjectsAllVersions{}.Check(ctx, t, db)
|
|
|
|
metabasetest.Verify{}.Check(ctx, t, db)
|
2020-11-03 15:51:03 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Object missing", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2020-11-03 15:51:03 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.DeleteObjectsAllVersions{
|
2020-11-03 15:51:03 +00:00
|
|
|
Opts: metabase.DeleteObjectsAllVersions{
|
|
|
|
Locations: []metabase.ObjectLocation{location},
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{}.Check(ctx, t, db)
|
2020-11-03 15:51:03 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Delete partial object", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2020-11-03 15:51:03 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.BeginObjectExactVersion{
|
2020-11-03 15:51:03 +00:00
|
|
|
Opts: metabase.BeginObjectExactVersion{
|
|
|
|
ObjectStream: obj,
|
2021-04-26 10:35:44 +01:00
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
2020-11-03 15:51:03 +00:00
|
|
|
},
|
|
|
|
Version: 1,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.DeleteObjectsAllVersions{
|
2020-11-03 15:51:03 +00:00
|
|
|
Opts: metabase.DeleteObjectsAllVersions{
|
|
|
|
Locations: []metabase.ObjectLocation{location},
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{
|
2020-11-03 15:51:03 +00:00
|
|
|
Objects: []metabase.RawObject{
|
|
|
|
{
|
|
|
|
ObjectStream: obj,
|
|
|
|
CreatedAt: now,
|
|
|
|
Status: metabase.Pending,
|
|
|
|
|
2021-05-06 12:42:20 +01:00
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
|
|
|
ZombieDeletionDeadline: &zombieDeadline,
|
2020-11-03 15:51:03 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Delete object without segments", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2020-11-03 15:51:03 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
object := metabasetest.CreateObject(ctx, t, db, obj, 0)
|
2020-11-03 15:51:03 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.DeleteObjectsAllVersions{
|
2020-11-03 15:51:03 +00:00
|
|
|
Opts: metabase.DeleteObjectsAllVersions{
|
|
|
|
Locations: []metabase.ObjectLocation{location},
|
|
|
|
},
|
|
|
|
Result: metabase.DeleteObjectResult{
|
|
|
|
Objects: []metabase.Object{object},
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{}.Check(ctx, t, db)
|
2020-11-03 15:51:03 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Delete object with segments", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2020-11-03 15:51:03 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
object := metabasetest.CreateObject(ctx, t, db, obj, 2)
|
2020-11-03 15:51:03 +00:00
|
|
|
|
|
|
|
expectedSegmentInfo := metabase.DeletedSegmentInfo{
|
|
|
|
RootPieceID: storj.PieceID{1},
|
|
|
|
Pieces: metabase.Pieces{{Number: 0, StorageNode: storj.NodeID{2}}},
|
|
|
|
}
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.DeleteObjectsAllVersions{
|
2020-11-03 15:51:03 +00:00
|
|
|
Opts: metabase.DeleteObjectsAllVersions{
|
|
|
|
Locations: []metabase.ObjectLocation{location},
|
|
|
|
},
|
|
|
|
Result: metabase.DeleteObjectResult{
|
|
|
|
Objects: []metabase.Object{object},
|
|
|
|
Segments: []metabase.DeletedSegmentInfo{expectedSegmentInfo, expectedSegmentInfo},
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{}.Check(ctx, t, db)
|
2020-11-03 15:51:03 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Delete two objects with segments from same bucket", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2020-11-03 15:51:03 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
obj2 := metabasetest.RandObjectStream()
|
2020-11-03 15:51:03 +00:00
|
|
|
obj2.ProjectID = obj.ProjectID
|
|
|
|
obj2.BucketName = obj.BucketName
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
object1 := metabasetest.CreateObject(ctx, t, db, obj, 1)
|
|
|
|
object2 := metabasetest.CreateObject(ctx, t, db, obj2, 2)
|
2020-11-03 15:51:03 +00:00
|
|
|
|
|
|
|
expectedSegmentInfo := metabase.DeletedSegmentInfo{
|
|
|
|
RootPieceID: storj.PieceID{1},
|
|
|
|
Pieces: metabase.Pieces{{Number: 0, StorageNode: storj.NodeID{2}}},
|
|
|
|
}
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.DeleteObjectsAllVersions{
|
2020-11-03 15:51:03 +00:00
|
|
|
Opts: metabase.DeleteObjectsAllVersions{
|
|
|
|
Locations: []metabase.ObjectLocation{location, obj2.Location()},
|
|
|
|
},
|
|
|
|
Result: metabase.DeleteObjectResult{
|
|
|
|
Objects: []metabase.Object{object1, object2},
|
|
|
|
Segments: []metabase.DeletedSegmentInfo{expectedSegmentInfo, expectedSegmentInfo, expectedSegmentInfo},
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{}.Check(ctx, t, db)
|
2020-11-03 15:51:03 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Delete object with inline segment", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2020-11-03 15:51:03 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.BeginObjectExactVersion{
|
2020-11-03 15:51:03 +00:00
|
|
|
Opts: metabase.BeginObjectExactVersion{
|
|
|
|
ObjectStream: obj,
|
2021-04-26 10:35:44 +01:00
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
2020-11-03 15:51:03 +00:00
|
|
|
},
|
|
|
|
Version: obj.Version,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.CommitInlineSegment{
|
2020-11-03 15:51:03 +00:00
|
|
|
Opts: metabase.CommitInlineSegment{
|
|
|
|
ObjectStream: obj,
|
|
|
|
Position: metabase.SegmentPosition{Part: 0, Index: 0},
|
|
|
|
|
|
|
|
EncryptedKey: testrand.Bytes(32),
|
2021-10-12 14:37:12 +01:00
|
|
|
EncryptedKeyNonce: testrand.Bytes(32),
|
2020-11-03 15:51:03 +00:00
|
|
|
|
|
|
|
InlineData: testrand.Bytes(1024),
|
|
|
|
|
2020-11-11 10:54:10 +00:00
|
|
|
PlainSize: 512,
|
|
|
|
PlainOffset: 0,
|
2020-11-03 15:51:03 +00:00
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
object := metabasetest.CommitObject{
|
2020-11-03 15:51:03 +00:00
|
|
|
Opts: metabase.CommitObject{
|
|
|
|
ObjectStream: obj,
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.DeleteObjectsAllVersions{
|
2020-11-03 15:51:03 +00:00
|
|
|
Opts: metabase.DeleteObjectsAllVersions{
|
|
|
|
Locations: []metabase.ObjectLocation{location},
|
|
|
|
},
|
|
|
|
Result: metabase.DeleteObjectResult{
|
|
|
|
Objects: []metabase.Object{object},
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{}.Check(ctx, t, db)
|
2020-11-03 15:51:03 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Delete object with inline segment and object with remote segments", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2020-11-03 15:51:03 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.BeginObjectExactVersion{
|
2020-11-03 15:51:03 +00:00
|
|
|
Opts: metabase.BeginObjectExactVersion{
|
|
|
|
ObjectStream: obj,
|
2021-04-26 10:35:44 +01:00
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
2020-11-03 15:51:03 +00:00
|
|
|
},
|
|
|
|
Version: obj.Version,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.CommitInlineSegment{
|
2020-11-03 15:51:03 +00:00
|
|
|
Opts: metabase.CommitInlineSegment{
|
|
|
|
ObjectStream: obj,
|
|
|
|
Position: metabase.SegmentPosition{Part: 0, Index: 0},
|
|
|
|
|
|
|
|
EncryptedKey: testrand.Bytes(32),
|
2021-10-12 14:37:12 +01:00
|
|
|
EncryptedKeyNonce: testrand.Bytes(32),
|
2020-11-03 15:51:03 +00:00
|
|
|
|
|
|
|
InlineData: testrand.Bytes(1024),
|
|
|
|
|
2020-11-11 10:54:10 +00:00
|
|
|
PlainSize: 512,
|
|
|
|
PlainOffset: 0,
|
2020-11-03 15:51:03 +00:00
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
object1 := metabasetest.CommitObject{
|
2020-11-03 15:51:03 +00:00
|
|
|
Opts: metabase.CommitObject{
|
|
|
|
ObjectStream: obj,
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
obj2 := metabasetest.RandObjectStream()
|
2020-11-03 15:51:03 +00:00
|
|
|
obj2.ProjectID = obj.ProjectID
|
|
|
|
obj2.BucketName = obj.BucketName
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
object2 := metabasetest.CreateObject(ctx, t, db, obj2, 2)
|
2020-11-03 15:51:03 +00:00
|
|
|
|
|
|
|
expectedSegmentInfo := metabase.DeletedSegmentInfo{
|
|
|
|
RootPieceID: storj.PieceID{1},
|
|
|
|
Pieces: metabase.Pieces{{Number: 0, StorageNode: storj.NodeID{2}}},
|
|
|
|
}
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.DeleteObjectsAllVersions{
|
2020-11-03 15:51:03 +00:00
|
|
|
Opts: metabase.DeleteObjectsAllVersions{
|
|
|
|
Locations: []metabase.ObjectLocation{location, object2.Location()},
|
|
|
|
},
|
|
|
|
Result: metabase.DeleteObjectResult{
|
|
|
|
Objects: []metabase.Object{object1, object2},
|
|
|
|
Segments: []metabase.DeletedSegmentInfo{expectedSegmentInfo, expectedSegmentInfo},
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{}.Check(ctx, t, db)
|
2020-11-03 15:51:03 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Delete multiple versions of the same object at once", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2020-11-03 15:51:03 +00:00
|
|
|
|
|
|
|
expected := metabase.DeleteObjectResult{}
|
|
|
|
|
|
|
|
for i := 1; i <= 10; i++ {
|
|
|
|
obj.StreamID = testrand.UUID()
|
|
|
|
obj.Version = metabase.Version(i)
|
2021-04-26 10:35:44 +01:00
|
|
|
expected.Objects = append(expected.Objects, metabasetest.CreateObject(ctx, t, db, obj, 1))
|
2020-11-03 15:51:03 +00:00
|
|
|
expected.Segments = append(expected.Segments, metabase.DeletedSegmentInfo{
|
|
|
|
RootPieceID: storj.PieceID{1},
|
|
|
|
Pieces: metabase.Pieces{{Number: 0, StorageNode: storj.NodeID{2}}},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.DeleteObjectsAllVersions{
|
2020-11-03 15:51:03 +00:00
|
|
|
Opts: metabase.DeleteObjectsAllVersions{
|
|
|
|
Locations: []metabase.ObjectLocation{location},
|
|
|
|
},
|
|
|
|
Result: expected,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{}.Check(ctx, t, db)
|
2020-11-03 15:51:03 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
2022-02-11 21:10:10 +00:00
|
|
|
|
|
|
|
func TestDeleteCopy(t *testing.T) {
|
|
|
|
metabasetest.Run(t, func(ctx *testcontext.Context, t *testing.T, db *metabase.DB) {
|
|
|
|
for _, numberOfSegments := range []int{0, 1, 3} {
|
|
|
|
t.Run(fmt.Sprintf("%d segments", numberOfSegments), func(t *testing.T) {
|
|
|
|
t.Run("delete copy", func(t *testing.T) {
|
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
|
|
|
originalObjStream := metabasetest.RandObjectStream()
|
|
|
|
|
|
|
|
originalObj, originalSegments := metabasetest.CreateTestObject{
|
|
|
|
CommitObject: &metabase.CommitObject{
|
|
|
|
ObjectStream: originalObjStream,
|
|
|
|
EncryptedMetadata: testrand.Bytes(64),
|
|
|
|
EncryptedMetadataNonce: testrand.Nonce().Bytes(),
|
|
|
|
EncryptedMetadataEncryptedKey: testrand.Bytes(265),
|
|
|
|
},
|
|
|
|
}.Run(ctx, t, db, originalObjStream, byte(numberOfSegments))
|
|
|
|
|
2022-02-18 00:03:50 +00:00
|
|
|
copyObj, _, copySegments := metabasetest.CreateObjectCopy{
|
2022-02-11 21:10:10 +00:00
|
|
|
OriginalObject: originalObj,
|
|
|
|
}.Run(ctx, t, db)
|
|
|
|
|
2022-02-24 00:17:35 +00:00
|
|
|
var copies []metabase.RawCopy
|
|
|
|
if numberOfSegments > 0 {
|
|
|
|
copies = []metabase.RawCopy{
|
|
|
|
{
|
|
|
|
StreamID: copyObj.StreamID,
|
|
|
|
AncestorStreamID: originalObj.StreamID,
|
|
|
|
}}
|
|
|
|
}
|
2022-02-11 21:10:10 +00:00
|
|
|
// check that copy went OK
|
|
|
|
metabasetest.Verify{
|
|
|
|
Objects: []metabase.RawObject{
|
|
|
|
metabase.RawObject(originalObj),
|
|
|
|
metabase.RawObject(copyObj),
|
|
|
|
},
|
|
|
|
Segments: append(metabasetest.SegmentsToRaw(originalSegments), copySegments...),
|
2022-02-24 00:17:35 +00:00
|
|
|
Copies: copies,
|
2022-03-22 12:03:02 +00:00
|
|
|
}.Check(ctx, t, db)
|
2022-02-11 21:10:10 +00:00
|
|
|
|
2022-03-16 18:44:21 +00:00
|
|
|
metabasetest.DeleteObjectExactVersion{
|
|
|
|
Opts: metabase.DeleteObjectExactVersion{
|
|
|
|
ObjectLocation: copyObj.Location(),
|
|
|
|
Version: copyObj.Version,
|
|
|
|
},
|
|
|
|
Result: metabase.DeleteObjectResult{
|
|
|
|
Objects: []metabase.Object{copyObj},
|
|
|
|
// no segments returned as we deleted copy
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
2022-02-11 21:10:10 +00:00
|
|
|
|
|
|
|
// Verify that we are back at the original single object
|
|
|
|
metabasetest.Verify{
|
|
|
|
Objects: []metabase.RawObject{
|
|
|
|
metabase.RawObject(originalObj),
|
|
|
|
},
|
|
|
|
Segments: metabasetest.SegmentsToRaw(originalSegments),
|
2022-03-22 12:03:02 +00:00
|
|
|
}.Check(ctx, t, db)
|
2022-02-11 21:10:10 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("delete one of two copies", func(t *testing.T) {
|
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
|
|
|
originalObjectStream := metabasetest.RandObjectStream()
|
|
|
|
|
|
|
|
originalObj, originalSegments := metabasetest.CreateTestObject{
|
|
|
|
CommitObject: &metabase.CommitObject{
|
|
|
|
ObjectStream: originalObjectStream,
|
|
|
|
EncryptedMetadata: testrand.Bytes(64),
|
|
|
|
EncryptedMetadataNonce: testrand.Nonce().Bytes(),
|
|
|
|
EncryptedMetadataEncryptedKey: testrand.Bytes(265),
|
|
|
|
},
|
|
|
|
}.Run(ctx, t, db, originalObjectStream, byte(numberOfSegments))
|
|
|
|
|
2022-02-18 00:03:50 +00:00
|
|
|
copyObject1, _, _ := metabasetest.CreateObjectCopy{
|
2022-02-11 21:10:10 +00:00
|
|
|
OriginalObject: originalObj,
|
|
|
|
}.Run(ctx, t, db)
|
2022-02-18 00:03:50 +00:00
|
|
|
copyObject2, _, copySegments2 := metabasetest.CreateObjectCopy{
|
2022-02-11 21:10:10 +00:00
|
|
|
OriginalObject: originalObj,
|
|
|
|
}.Run(ctx, t, db)
|
|
|
|
|
2022-03-16 18:44:21 +00:00
|
|
|
metabasetest.DeleteObjectExactVersion{
|
|
|
|
Opts: metabase.DeleteObjectExactVersion{
|
|
|
|
ObjectLocation: copyObject1.Location(),
|
|
|
|
Version: copyObject1.Version,
|
|
|
|
},
|
|
|
|
Result: metabase.DeleteObjectResult{
|
|
|
|
Objects: []metabase.Object{copyObject1},
|
|
|
|
// no segments returned as we deleted copy
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
2022-02-11 21:10:10 +00:00
|
|
|
|
2022-02-24 00:17:35 +00:00
|
|
|
var copies []metabase.RawCopy
|
|
|
|
if numberOfSegments > 0 {
|
|
|
|
copies = []metabase.RawCopy{
|
|
|
|
{
|
|
|
|
StreamID: copyObject2.StreamID,
|
|
|
|
AncestorStreamID: originalObj.StreamID,
|
|
|
|
}}
|
|
|
|
}
|
2022-02-11 21:10:10 +00:00
|
|
|
// Verify that only one of the copies is deleted
|
|
|
|
metabasetest.Verify{
|
|
|
|
Objects: []metabase.RawObject{
|
|
|
|
metabase.RawObject(originalObj),
|
|
|
|
metabase.RawObject(copyObject2),
|
|
|
|
},
|
|
|
|
Segments: append(metabasetest.SegmentsToRaw(originalSegments), copySegments2...),
|
2022-02-24 00:17:35 +00:00
|
|
|
Copies: copies,
|
2022-03-22 12:03:02 +00:00
|
|
|
}.Check(ctx, t, db)
|
2022-02-11 21:10:10 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("delete original", func(t *testing.T) {
|
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
|
|
|
originalObjectStream := metabasetest.RandObjectStream()
|
|
|
|
|
2022-03-23 13:16:46 +00:00
|
|
|
originalObj, originalSegments := metabasetest.CreateTestObject{
|
2022-02-11 21:10:10 +00:00
|
|
|
CommitObject: &metabase.CommitObject{
|
|
|
|
ObjectStream: originalObjectStream,
|
|
|
|
EncryptedMetadata: testrand.Bytes(64),
|
|
|
|
EncryptedMetadataNonce: testrand.Nonce().Bytes(),
|
|
|
|
EncryptedMetadataEncryptedKey: testrand.Bytes(265),
|
|
|
|
},
|
|
|
|
}.Run(ctx, t, db, originalObjectStream, byte(numberOfSegments))
|
|
|
|
|
2022-02-18 00:03:50 +00:00
|
|
|
copyObject, _, copySegments := metabasetest.CreateObjectCopy{
|
2022-02-11 21:10:10 +00:00
|
|
|
OriginalObject: originalObj,
|
|
|
|
}.Run(ctx, t, db)
|
|
|
|
|
2022-03-16 18:44:21 +00:00
|
|
|
metabasetest.DeleteObjectExactVersion{
|
|
|
|
Opts: metabase.DeleteObjectExactVersion{
|
|
|
|
ObjectLocation: originalObj.Location(),
|
|
|
|
Version: originalObj.Version,
|
|
|
|
},
|
|
|
|
Result: metabase.DeleteObjectResult{
|
|
|
|
Objects: []metabase.Object{originalObj},
|
|
|
|
// no segments returned as we deleted ancestor
|
|
|
|
// and we moved pieces to one of copies
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
2022-02-11 21:10:10 +00:00
|
|
|
|
2022-03-23 13:16:46 +00:00
|
|
|
for i := range copySegments {
|
|
|
|
copySegments[i].Pieces = originalSegments[i].Pieces
|
|
|
|
}
|
|
|
|
|
2022-02-11 21:10:10 +00:00
|
|
|
// verify that the copy is left
|
|
|
|
metabasetest.Verify{
|
|
|
|
Objects: []metabase.RawObject{
|
|
|
|
metabase.RawObject(copyObject),
|
|
|
|
},
|
|
|
|
Segments: copySegments,
|
2022-03-22 12:03:02 +00:00
|
|
|
}.Check(ctx, t, db)
|
2022-02-11 21:10:10 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("delete original and leave two copies", func(t *testing.T) {
|
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
|
|
|
originalObjectStream := metabasetest.RandObjectStream()
|
|
|
|
|
2022-03-23 13:16:46 +00:00
|
|
|
originalObj, originalSegments := metabasetest.CreateTestObject{
|
2022-02-11 21:10:10 +00:00
|
|
|
CommitObject: &metabase.CommitObject{
|
|
|
|
ObjectStream: originalObjectStream,
|
|
|
|
EncryptedMetadata: testrand.Bytes(64),
|
|
|
|
EncryptedMetadataNonce: testrand.Nonce().Bytes(),
|
|
|
|
EncryptedMetadataEncryptedKey: testrand.Bytes(265),
|
|
|
|
},
|
|
|
|
}.Run(ctx, t, db, originalObjectStream, byte(numberOfSegments))
|
|
|
|
|
2022-02-18 00:03:50 +00:00
|
|
|
copyObject1, _, copySegments1 := metabasetest.CreateObjectCopy{
|
2022-02-11 21:10:10 +00:00
|
|
|
OriginalObject: originalObj,
|
|
|
|
}.Run(ctx, t, db)
|
2022-02-18 00:03:50 +00:00
|
|
|
copyObject2, _, copySegments2 := metabasetest.CreateObjectCopy{
|
2022-02-11 21:10:10 +00:00
|
|
|
OriginalObject: originalObj,
|
|
|
|
}.Run(ctx, t, db)
|
|
|
|
|
|
|
|
_, err := db.DeleteObjectExactVersion(ctx, metabase.DeleteObjectExactVersion{
|
|
|
|
Version: originalObj.Version,
|
|
|
|
ObjectLocation: originalObj.Location(),
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-05-17 09:53:45 +01:00
|
|
|
var expectedAncestorStreamID uuid.UUID
|
|
|
|
var expectedCopyStreamID uuid.UUID
|
2022-02-11 21:10:10 +00:00
|
|
|
|
2022-02-24 00:17:35 +00:00
|
|
|
var copies []metabase.RawCopy
|
2022-05-17 09:53:45 +01:00
|
|
|
|
2022-02-24 00:17:35 +00:00
|
|
|
if numberOfSegments > 0 {
|
2022-05-17 09:53:45 +01:00
|
|
|
segments, err := db.TestingAllSegments(ctx)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NotEmpty(t, segments)
|
|
|
|
|
|
|
|
if segments[0].PiecesInAncestorSegment() {
|
|
|
|
if segments[0].StreamID == copyObject1.StreamID {
|
|
|
|
expectedCopyStreamID = copyObject1.StreamID
|
|
|
|
expectedAncestorStreamID = copyObject2.StreamID
|
|
|
|
} else {
|
|
|
|
expectedCopyStreamID = copyObject2.StreamID
|
|
|
|
expectedAncestorStreamID = copyObject1.StreamID
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
if segments[0].StreamID == copyObject1.StreamID {
|
|
|
|
expectedCopyStreamID = copyObject2.StreamID
|
|
|
|
expectedAncestorStreamID = copyObject1.StreamID
|
|
|
|
} else {
|
|
|
|
expectedCopyStreamID = copyObject1.StreamID
|
|
|
|
expectedAncestorStreamID = copyObject2.StreamID
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-24 00:17:35 +00:00
|
|
|
copies = []metabase.RawCopy{
|
|
|
|
{
|
2022-05-17 09:53:45 +01:00
|
|
|
StreamID: expectedCopyStreamID,
|
|
|
|
AncestorStreamID: expectedAncestorStreamID,
|
2022-02-24 00:17:35 +00:00
|
|
|
}}
|
|
|
|
}
|
2022-03-04 15:08:46 +00:00
|
|
|
|
2022-03-23 13:16:46 +00:00
|
|
|
// set pieces in expected ancestor for verifcation
|
|
|
|
for _, segments := range [][]metabase.RawSegment{copySegments1, copySegments2} {
|
|
|
|
for i := range segments {
|
|
|
|
if segments[i].StreamID == expectedAncestorStreamID {
|
|
|
|
segments[i].Pieces = originalSegments[i].Pieces
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-11 21:10:10 +00:00
|
|
|
// verify that two functioning copies are left and the original object is gone
|
|
|
|
metabasetest.Verify{
|
|
|
|
Objects: []metabase.RawObject{
|
|
|
|
metabase.RawObject(copyObject1),
|
|
|
|
metabase.RawObject(copyObject2),
|
|
|
|
},
|
|
|
|
Segments: append(copySegments1, copySegments2...),
|
2022-02-24 00:17:35 +00:00
|
|
|
Copies: copies,
|
2022-03-22 12:03:02 +00:00
|
|
|
}.Check(ctx, t, db)
|
2022-02-11 21:10:10 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|