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"
|
|
|
|
|
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
|
|
|
)
|
|
|
|
|
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-05-06 12:42:20 +01:00
|
|
|
zombieDeadline := now.Add(24 * time.Hour)
|
2020-10-28 15:28:06 +00:00
|
|
|
|
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,
|
|
|
|
},
|
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.DeleteObjectExactVersion{
|
2020-10-28 15:28:06 +00:00
|
|
|
Opts: metabase.DeleteObjectExactVersion{
|
|
|
|
ObjectLocation: location,
|
|
|
|
Version: 33,
|
|
|
|
},
|
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.DeleteObjectExactVersion{
|
2020-10-28 15:28:06 +00:00
|
|
|
Opts: metabase.DeleteObjectExactVersion{
|
|
|
|
ObjectLocation: location,
|
|
|
|
Version: 1,
|
|
|
|
},
|
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{
|
2020-10-28 15:28:06 +00:00
|
|
|
Objects: []metabase.RawObject{
|
|
|
|
{
|
|
|
|
ObjectStream: obj,
|
|
|
|
CreatedAt: now,
|
|
|
|
Status: metabase.Pending,
|
2020-10-29 13:49:53 +00:00
|
|
|
|
2021-05-06 12:42:20 +01:00
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
|
|
|
ZombieDeletionDeadline: &zombieDeadline,
|
2020-10-28 15:28:06 +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-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) {
|
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.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) {
|
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-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))
|
|
|
|
|
|
|
|
copyObj, copySegments := metabasetest.CreateObjectCopy{
|
|
|
|
OriginalObject: originalObj,
|
|
|
|
}.Run(ctx, t, db)
|
|
|
|
|
|
|
|
// check that copy went OK
|
|
|
|
metabasetest.Verify{
|
|
|
|
Objects: []metabase.RawObject{
|
|
|
|
metabase.RawObject(originalObj),
|
|
|
|
metabase.RawObject(copyObj),
|
|
|
|
},
|
|
|
|
Segments: append(metabasetest.SegmentsToRaw(originalSegments), copySegments...),
|
|
|
|
Copies: []metabase.RawCopy{
|
|
|
|
{
|
|
|
|
StreamID: copyObj.StreamID,
|
|
|
|
AncestorStreamID: originalObj.StreamID,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}.Normalize().Check(ctx, t, db)
|
|
|
|
|
|
|
|
_, err := db.DeleteObjectExactVersion(ctx, metabase.DeleteObjectExactVersion{
|
|
|
|
Version: copyObj.Version,
|
|
|
|
ObjectLocation: copyObj.Location(),
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// Verify that we are back at the original single object
|
|
|
|
metabasetest.Verify{
|
|
|
|
Objects: []metabase.RawObject{
|
|
|
|
metabase.RawObject(originalObj),
|
|
|
|
},
|
|
|
|
Segments: metabasetest.SegmentsToRaw(originalSegments),
|
|
|
|
}.Normalize().Check(ctx, t, db)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("delete one of two copies", func(t *testing.T) {
|
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
|
|
|
numberOfSegments := 0
|
|
|
|
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))
|
|
|
|
|
|
|
|
copyObject1, _ := metabasetest.CreateObjectCopy{
|
|
|
|
OriginalObject: originalObj,
|
|
|
|
}.Run(ctx, t, db)
|
|
|
|
copyObject2, copySegments2 := metabasetest.CreateObjectCopy{
|
|
|
|
OriginalObject: originalObj,
|
|
|
|
}.Run(ctx, t, db)
|
|
|
|
|
|
|
|
_, err := db.DeleteObjectExactVersion(ctx, metabase.DeleteObjectExactVersion{
|
|
|
|
Version: copyObject1.Version,
|
|
|
|
ObjectLocation: copyObject1.Location(),
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// 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...),
|
|
|
|
Copies: []metabase.RawCopy{
|
|
|
|
{
|
|
|
|
StreamID: copyObject2.StreamID,
|
|
|
|
AncestorStreamID: originalObj.StreamID,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}.Normalize().Check(ctx, t, db)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("delete original", func(t *testing.T) {
|
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
|
|
|
numberOfSegments := 0
|
|
|
|
originalObjectStream := metabasetest.RandObjectStream()
|
|
|
|
|
|
|
|
originalObj, _ := 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))
|
|
|
|
|
|
|
|
copyObject, copySegments := metabasetest.CreateObjectCopy{
|
|
|
|
OriginalObject: originalObj,
|
|
|
|
}.Run(ctx, t, db)
|
|
|
|
|
|
|
|
_, err := db.DeleteObjectExactVersion(ctx, metabase.DeleteObjectExactVersion{
|
|
|
|
Version: originalObj.Version,
|
|
|
|
ObjectLocation: originalObj.Location(),
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// verify that the copy is left
|
|
|
|
metabasetest.Verify{
|
|
|
|
Objects: []metabase.RawObject{
|
|
|
|
metabase.RawObject(copyObject),
|
|
|
|
},
|
|
|
|
Segments: copySegments,
|
|
|
|
}.Normalize().Check(ctx, t, db)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("delete original and leave two copies", func(t *testing.T) {
|
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
|
|
|
numberOfSegments := 0
|
|
|
|
originalObjectStream := metabasetest.RandObjectStream()
|
|
|
|
|
|
|
|
originalObj, _ := 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))
|
|
|
|
|
|
|
|
copyObject1, copySegments1 := metabasetest.CreateObjectCopy{
|
|
|
|
OriginalObject: originalObj,
|
|
|
|
}.Run(ctx, t, db)
|
|
|
|
copyObject2, copySegments2 := metabasetest.CreateObjectCopy{
|
|
|
|
OriginalObject: originalObj,
|
|
|
|
}.Run(ctx, t, db)
|
|
|
|
|
|
|
|
_, err := db.DeleteObjectExactVersion(ctx, metabase.DeleteObjectExactVersion{
|
|
|
|
Version: originalObj.Version,
|
|
|
|
ObjectLocation: originalObj.Location(),
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
remainingStreamIDs := []uuid.UUID{copyObject1.StreamID, copyObject2.StreamID}
|
|
|
|
uuid.SortAscending(remainingStreamIDs)
|
|
|
|
|
|
|
|
// 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...),
|
|
|
|
Copies: []metabase.RawCopy{
|
|
|
|
{
|
|
|
|
StreamID: remainingStreamIDs[1],
|
|
|
|
AncestorStreamID: remainingStreamIDs[0],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}.Normalize().Check(ctx, t, db)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|