2020-11-16 14:02:11 +00:00
|
|
|
// Copyright (C) 2020 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
2020-11-17 13:37:19 +00:00
|
|
|
package metabase_test
|
2020-11-16 14:02:11 +00:00
|
|
|
|
|
|
|
import (
|
2022-07-21 15:32:50 +01:00
|
|
|
"context"
|
2022-08-26 14:02:57 +01:00
|
|
|
"math/rand"
|
2020-11-17 13:37:19 +00:00
|
|
|
"sort"
|
2022-06-21 10:03:56 +01:00
|
|
|
"strconv"
|
2020-11-16 14:02:11 +00:00
|
|
|
"testing"
|
2020-11-17 13:37:19 +00:00
|
|
|
"time"
|
2020-11-16 14:02:11 +00:00
|
|
|
|
2021-02-28 18:27:38 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
2020-11-17 13:37:19 +00:00
|
|
|
"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-11-16 14:02:11 +00:00
|
|
|
)
|
|
|
|
|
2020-12-21 16:43:08 +00:00
|
|
|
func TestIterateObjectsWithStatus(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Run(t, func(ctx *testcontext.Context, t *testing.T, db *metabase.DB) {
|
2021-10-13 09:54:55 +01:00
|
|
|
t.Run("invalid arguments", func(t *testing.T) {
|
2020-11-17 13:37:19 +00:00
|
|
|
t.Run("ProjectID missing", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.IterateObjectsWithStatus{
|
2020-12-21 15:07:00 +00:00
|
|
|
Opts: metabase.IterateObjectsWithStatus{
|
2020-11-17 13:37:19 +00:00
|
|
|
ProjectID: uuid.UUID{},
|
|
|
|
BucketName: "sj://mybucket",
|
|
|
|
Recursive: true,
|
2023-10-13 17:13:18 +01:00
|
|
|
Status: metabase.CommittedUnversioned,
|
2020-11-17 13:37:19 +00:00
|
|
|
},
|
|
|
|
ErrClass: &metabase.ErrInvalidRequest,
|
|
|
|
ErrText: "ProjectID missing",
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
})
|
2021-10-13 09:54:55 +01:00
|
|
|
t.Run("BucketName missing", func(t *testing.T) {
|
|
|
|
metabasetest.IterateObjectsWithStatus{
|
|
|
|
Opts: metabase.IterateObjectsWithStatus{
|
|
|
|
ProjectID: uuid.UUID{1},
|
|
|
|
BucketName: "",
|
|
|
|
Recursive: true,
|
2023-10-13 17:13:18 +01:00
|
|
|
Status: metabase.CommittedUnversioned,
|
2021-10-13 09:54:55 +01:00
|
|
|
},
|
|
|
|
ErrClass: &metabase.ErrInvalidRequest,
|
|
|
|
ErrText: "BucketName missing",
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
})
|
|
|
|
t.Run("Limit is negative", func(t *testing.T) {
|
|
|
|
metabasetest.IterateObjectsWithStatus{
|
|
|
|
Opts: metabase.IterateObjectsWithStatus{
|
|
|
|
ProjectID: uuid.UUID{1},
|
|
|
|
BucketName: "mybucket",
|
|
|
|
BatchSize: -1,
|
|
|
|
Recursive: true,
|
2023-10-13 17:13:18 +01:00
|
|
|
Status: metabase.CommittedUnversioned,
|
2021-10-13 09:54:55 +01:00
|
|
|
},
|
|
|
|
ErrClass: &metabase.ErrInvalidRequest,
|
|
|
|
ErrText: "BatchSize is negative",
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
})
|
|
|
|
t.Run("Status is invalid", func(t *testing.T) {
|
|
|
|
metabasetest.IterateObjectsWithStatus{
|
|
|
|
Opts: metabase.IterateObjectsWithStatus{
|
|
|
|
ProjectID: uuid.UUID{1},
|
|
|
|
BucketName: "test",
|
|
|
|
Recursive: true,
|
|
|
|
Status: 255,
|
|
|
|
},
|
|
|
|
ErrClass: &metabase.ErrInvalidRequest,
|
|
|
|
ErrText: "Status 255 is not supported",
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
})
|
2020-11-17 13:37:19 +00:00
|
|
|
})
|
2020-11-16 14:02:11 +00:00
|
|
|
|
2020-11-17 13:37:19 +00:00
|
|
|
t.Run("empty bucket", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2020-11-17 13:37:19 +00:00
|
|
|
objects := createObjects(ctx, t, db, 2, uuid.UUID{1}, "mybucket")
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.IterateObjectsWithStatus{
|
2020-12-21 15:07:00 +00:00
|
|
|
Opts: metabase.IterateObjectsWithStatus{
|
2020-11-17 13:37:19 +00:00
|
|
|
ProjectID: uuid.UUID{1},
|
|
|
|
BucketName: "myemptybucket",
|
|
|
|
BatchSize: 10,
|
|
|
|
Recursive: true,
|
2023-10-13 17:13:18 +01:00
|
|
|
Status: metabase.CommittedUnversioned,
|
2020-11-17 13:37:19 +00:00
|
|
|
},
|
|
|
|
Result: nil,
|
|
|
|
}.Check(ctx, t, db)
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{Objects: objects}.Check(ctx, t, db)
|
2020-11-17 13:37:19 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("based on status", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2020-11-17 13:37:19 +00:00
|
|
|
|
|
|
|
now := time.Now()
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
pending := metabasetest.RandObjectStream()
|
|
|
|
committed := metabasetest.RandObjectStream()
|
2020-11-17 13:37:19 +00:00
|
|
|
committed.ProjectID = pending.ProjectID
|
|
|
|
committed.BucketName = pending.BucketName
|
|
|
|
|
|
|
|
projectID := pending.ProjectID
|
|
|
|
bucketName := pending.BucketName
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.BeginObjectExactVersion{
|
2020-11-17 13:37:19 +00:00
|
|
|
Opts: metabase.BeginObjectExactVersion{
|
|
|
|
ObjectStream: pending,
|
2021-04-26 10:35:44 +01:00
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
2020-11-17 13:37:19 +00:00
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
encryptedMetadata := testrand.Bytes(1024)
|
|
|
|
encryptedMetadataNonce := testrand.Nonce()
|
|
|
|
encryptedMetadataKey := testrand.Bytes(265)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.BeginObjectExactVersion{
|
2020-11-17 13:37:19 +00:00
|
|
|
Opts: metabase.BeginObjectExactVersion{
|
|
|
|
ObjectStream: committed,
|
2021-04-26 10:35:44 +01:00
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
2020-11-17 13:37:19 +00:00
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.CommitObject{
|
2020-11-17 13:37:19 +00:00
|
|
|
Opts: metabase.CommitObject{
|
|
|
|
ObjectStream: committed,
|
2022-04-14 12:20:18 +01:00
|
|
|
OverrideEncryptedMetadata: true,
|
2021-10-12 14:37:12 +01:00
|
|
|
EncryptedMetadataNonce: encryptedMetadataNonce[:],
|
2020-11-17 13:37:19 +00:00
|
|
|
EncryptedMetadata: encryptedMetadata,
|
|
|
|
EncryptedMetadataEncryptedKey: encryptedMetadataKey,
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.IterateObjectsWithStatus{
|
2020-12-21 15:07:00 +00:00
|
|
|
Opts: metabase.IterateObjectsWithStatus{
|
2021-09-28 13:36:10 +01:00
|
|
|
ProjectID: projectID,
|
|
|
|
BucketName: bucketName,
|
|
|
|
Recursive: true,
|
2023-10-13 17:13:18 +01:00
|
|
|
Status: metabase.CommittedUnversioned,
|
2021-09-28 13:36:10 +01:00
|
|
|
IncludeCustomMetadata: true,
|
|
|
|
IncludeSystemMetadata: true,
|
2020-11-17 13:37:19 +00:00
|
|
|
},
|
|
|
|
Result: []metabase.ObjectEntry{{
|
2020-11-17 14:05:41 +00:00
|
|
|
ObjectKey: committed.ObjectKey,
|
|
|
|
Version: committed.Version,
|
|
|
|
StreamID: committed.StreamID,
|
2020-11-17 13:37:19 +00:00
|
|
|
CreatedAt: now,
|
2023-10-13 17:13:18 +01:00
|
|
|
Status: metabase.CommittedUnversioned,
|
2021-04-26 10:35:44 +01:00
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
2021-10-12 14:37:12 +01:00
|
|
|
EncryptedMetadataNonce: encryptedMetadataNonce[:],
|
2020-11-17 13:37:19 +00:00
|
|
|
EncryptedMetadata: encryptedMetadata,
|
|
|
|
EncryptedMetadataEncryptedKey: encryptedMetadataKey,
|
|
|
|
}},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.IterateObjectsWithStatus{
|
2020-12-21 15:07:00 +00:00
|
|
|
Opts: metabase.IterateObjectsWithStatus{
|
2021-09-28 13:36:10 +01:00
|
|
|
ProjectID: projectID,
|
|
|
|
BucketName: bucketName,
|
|
|
|
Recursive: true,
|
|
|
|
Status: metabase.Pending,
|
|
|
|
IncludeCustomMetadata: true,
|
|
|
|
IncludeSystemMetadata: true,
|
2020-11-17 13:37:19 +00:00
|
|
|
},
|
|
|
|
Result: []metabase.ObjectEntry{{
|
2020-11-17 14:05:41 +00:00
|
|
|
ObjectKey: pending.ObjectKey,
|
|
|
|
Version: pending.Version,
|
|
|
|
StreamID: pending.StreamID,
|
|
|
|
CreatedAt: now,
|
|
|
|
Status: metabase.Pending,
|
2021-04-26 10:35:44 +01:00
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
2020-11-17 13:37:19 +00:00
|
|
|
}},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("less objects than limit", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2020-11-17 13:37:19 +00:00
|
|
|
numberOfObjects := 3
|
|
|
|
limit := 10
|
|
|
|
expected := make([]metabase.ObjectEntry, numberOfObjects)
|
|
|
|
objects := createObjects(ctx, t, db, numberOfObjects, uuid.UUID{1}, "mybucket")
|
|
|
|
for i, obj := range objects {
|
2020-11-17 14:05:41 +00:00
|
|
|
expected[i] = objectEntryFromRaw(obj)
|
2020-11-17 13:37:19 +00:00
|
|
|
}
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.IterateObjectsWithStatus{
|
2020-12-21 15:07:00 +00:00
|
|
|
Opts: metabase.IterateObjectsWithStatus{
|
2021-09-28 13:36:10 +01:00
|
|
|
ProjectID: uuid.UUID{1},
|
|
|
|
BucketName: "mybucket",
|
|
|
|
Recursive: true,
|
|
|
|
BatchSize: limit,
|
2023-10-13 17:13:18 +01:00
|
|
|
Status: metabase.CommittedUnversioned,
|
2021-09-28 13:36:10 +01:00
|
|
|
IncludeCustomMetadata: true,
|
|
|
|
IncludeSystemMetadata: true,
|
2020-11-17 13:37:19 +00:00
|
|
|
},
|
|
|
|
Result: expected,
|
|
|
|
}.Check(ctx, t, db)
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{Objects: objects}.Check(ctx, t, db)
|
2020-11-17 13:37:19 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("more objects than limit", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2020-11-17 13:37:19 +00:00
|
|
|
numberOfObjects := 10
|
|
|
|
limit := 3
|
|
|
|
expected := make([]metabase.ObjectEntry, numberOfObjects)
|
|
|
|
objects := createObjects(ctx, t, db, numberOfObjects, uuid.UUID{1}, "mybucket")
|
|
|
|
for i, obj := range objects {
|
2020-11-17 14:05:41 +00:00
|
|
|
expected[i] = objectEntryFromRaw(obj)
|
2020-11-17 13:37:19 +00:00
|
|
|
}
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.IterateObjectsWithStatus{
|
2020-12-21 15:07:00 +00:00
|
|
|
Opts: metabase.IterateObjectsWithStatus{
|
2021-09-28 13:36:10 +01:00
|
|
|
ProjectID: uuid.UUID{1},
|
|
|
|
BucketName: "mybucket",
|
|
|
|
Recursive: true,
|
|
|
|
BatchSize: limit,
|
2023-10-13 17:13:18 +01:00
|
|
|
Status: metabase.CommittedUnversioned,
|
2021-09-28 13:36:10 +01:00
|
|
|
IncludeCustomMetadata: true,
|
|
|
|
IncludeSystemMetadata: true,
|
2020-11-17 13:37:19 +00:00
|
|
|
},
|
|
|
|
Result: expected,
|
|
|
|
}.Check(ctx, t, db)
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{Objects: objects}.Check(ctx, t, db)
|
2020-11-17 13:37:19 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("objects in one bucket in project with 2 buckets", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2020-11-17 13:37:19 +00:00
|
|
|
numberOfObjectsPerBucket := 5
|
2021-06-25 15:01:12 +01:00
|
|
|
|
2020-11-17 13:37:19 +00:00
|
|
|
expected := make([]metabase.ObjectEntry, numberOfObjectsPerBucket)
|
2021-06-25 15:01:12 +01:00
|
|
|
|
2020-11-17 13:37:19 +00:00
|
|
|
objectsBucketA := createObjects(ctx, t, db, numberOfObjectsPerBucket, uuid.UUID{1}, "bucket-a")
|
|
|
|
objectsBucketB := createObjects(ctx, t, db, numberOfObjectsPerBucket, uuid.UUID{1}, "bucket-b")
|
2021-06-25 15:01:12 +01:00
|
|
|
|
2020-11-17 13:37:19 +00:00
|
|
|
for i, obj := range objectsBucketA {
|
2020-11-17 14:05:41 +00:00
|
|
|
expected[i] = objectEntryFromRaw(obj)
|
2020-11-17 13:37:19 +00:00
|
|
|
}
|
2021-06-25 15:01:12 +01:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.IterateObjectsWithStatus{
|
2020-12-21 15:07:00 +00:00
|
|
|
Opts: metabase.IterateObjectsWithStatus{
|
2021-09-28 13:36:10 +01:00
|
|
|
ProjectID: uuid.UUID{1},
|
|
|
|
BucketName: "bucket-a",
|
|
|
|
Recursive: true,
|
2023-10-13 17:13:18 +01:00
|
|
|
Status: metabase.CommittedUnversioned,
|
2021-09-28 13:36:10 +01:00
|
|
|
IncludeCustomMetadata: true,
|
|
|
|
IncludeSystemMetadata: true,
|
2020-11-17 13:37:19 +00:00
|
|
|
},
|
|
|
|
Result: expected,
|
|
|
|
}.Check(ctx, t, db)
|
2021-06-25 15:01:12 +01:00
|
|
|
|
|
|
|
metabasetest.Verify{
|
|
|
|
Objects: append(objectsBucketA, objectsBucketB...),
|
|
|
|
}.Check(ctx, t, db)
|
2020-11-17 13:37:19 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("objects in one bucket with same bucketName in another project", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2020-11-17 13:37:19 +00:00
|
|
|
numberOfObjectsPerBucket := 5
|
2021-06-25 15:01:12 +01:00
|
|
|
|
2020-11-17 13:37:19 +00:00
|
|
|
expected := make([]metabase.ObjectEntry, numberOfObjectsPerBucket)
|
2021-06-25 15:01:12 +01:00
|
|
|
|
2020-11-17 13:37:19 +00:00
|
|
|
objectsProject1 := createObjects(ctx, t, db, numberOfObjectsPerBucket, uuid.UUID{1}, "mybucket")
|
|
|
|
objectsProject2 := createObjects(ctx, t, db, numberOfObjectsPerBucket, uuid.UUID{2}, "mybucket")
|
|
|
|
for i, obj := range objectsProject1 {
|
2020-11-17 14:05:41 +00:00
|
|
|
expected[i] = objectEntryFromRaw(obj)
|
2020-11-17 13:37:19 +00:00
|
|
|
}
|
2021-06-25 15:01:12 +01:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.IterateObjectsWithStatus{
|
2020-12-21 15:07:00 +00:00
|
|
|
Opts: metabase.IterateObjectsWithStatus{
|
2021-09-28 13:36:10 +01:00
|
|
|
ProjectID: uuid.UUID{1},
|
|
|
|
BucketName: "mybucket",
|
|
|
|
Recursive: true,
|
2023-10-13 17:13:18 +01:00
|
|
|
Status: metabase.CommittedUnversioned,
|
2021-09-28 13:36:10 +01:00
|
|
|
IncludeCustomMetadata: true,
|
|
|
|
IncludeSystemMetadata: true,
|
2020-11-17 13:37:19 +00:00
|
|
|
},
|
|
|
|
Result: expected,
|
|
|
|
}.Check(ctx, t, db)
|
2021-06-25 15:01:12 +01:00
|
|
|
|
|
|
|
metabasetest.Verify{
|
|
|
|
Objects: append(objectsProject1, objectsProject2...),
|
|
|
|
}.Check(ctx, t, db)
|
2020-11-17 13:37:19 +00:00
|
|
|
})
|
|
|
|
|
2020-11-17 14:05:41 +00:00
|
|
|
t.Run("recursive", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2020-11-17 13:37:19 +00:00
|
|
|
projectID, bucketName := uuid.UUID{1}, "bucky"
|
|
|
|
|
|
|
|
objects := createObjectsWithKeys(ctx, t, db, projectID, bucketName, []metabase.ObjectKey{
|
|
|
|
"a",
|
|
|
|
"b/1",
|
|
|
|
"b/2",
|
|
|
|
"b/3",
|
|
|
|
"c",
|
|
|
|
"c/",
|
|
|
|
"c//",
|
|
|
|
"c/1",
|
|
|
|
"g",
|
|
|
|
})
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.IterateObjectsWithStatus{
|
2020-12-21 15:07:00 +00:00
|
|
|
Opts: metabase.IterateObjectsWithStatus{
|
2021-09-28 13:36:10 +01:00
|
|
|
ProjectID: projectID,
|
|
|
|
BucketName: bucketName,
|
|
|
|
Recursive: true,
|
2023-10-13 17:13:18 +01:00
|
|
|
Status: metabase.CommittedUnversioned,
|
2021-09-28 13:36:10 +01:00
|
|
|
IncludeCustomMetadata: true,
|
|
|
|
IncludeSystemMetadata: true,
|
2020-11-17 13:37:19 +00:00
|
|
|
},
|
|
|
|
Result: []metabase.ObjectEntry{
|
|
|
|
objects["a"],
|
|
|
|
objects["b/1"],
|
|
|
|
objects["b/2"],
|
|
|
|
objects["b/3"],
|
|
|
|
objects["c"],
|
|
|
|
objects["c/"],
|
|
|
|
objects["c//"],
|
|
|
|
objects["c/1"],
|
|
|
|
objects["g"],
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.IterateObjectsWithStatus{
|
2020-12-21 15:07:00 +00:00
|
|
|
Opts: metabase.IterateObjectsWithStatus{
|
2021-09-28 13:36:10 +01:00
|
|
|
ProjectID: projectID,
|
|
|
|
BucketName: bucketName,
|
|
|
|
Recursive: true,
|
2023-10-13 17:13:18 +01:00
|
|
|
Status: metabase.CommittedUnversioned,
|
2021-09-28 13:36:10 +01:00
|
|
|
IncludeCustomMetadata: true,
|
|
|
|
IncludeSystemMetadata: true,
|
2020-11-17 13:37:19 +00:00
|
|
|
|
2023-09-15 17:30:47 +01:00
|
|
|
Cursor: metabase.IterateCursor{Key: "a", Version: objects["a"].Version + 1},
|
2020-11-17 13:37:19 +00:00
|
|
|
},
|
|
|
|
Result: []metabase.ObjectEntry{
|
|
|
|
objects["b/1"],
|
|
|
|
objects["b/2"],
|
|
|
|
objects["b/3"],
|
|
|
|
objects["c"],
|
|
|
|
objects["c/"],
|
|
|
|
objects["c//"],
|
|
|
|
objects["c/1"],
|
|
|
|
objects["g"],
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.IterateObjectsWithStatus{
|
2020-12-21 15:07:00 +00:00
|
|
|
Opts: metabase.IterateObjectsWithStatus{
|
2021-09-28 13:36:10 +01:00
|
|
|
ProjectID: projectID,
|
|
|
|
BucketName: bucketName,
|
|
|
|
Recursive: true,
|
2023-10-13 17:13:18 +01:00
|
|
|
Status: metabase.CommittedUnversioned,
|
2021-09-28 13:36:10 +01:00
|
|
|
IncludeCustomMetadata: true,
|
|
|
|
IncludeSystemMetadata: true,
|
2020-11-17 13:37:19 +00:00
|
|
|
|
|
|
|
Cursor: metabase.IterateCursor{Key: "b", Version: 0},
|
|
|
|
},
|
|
|
|
Result: []metabase.ObjectEntry{
|
|
|
|
objects["b/1"],
|
|
|
|
objects["b/2"],
|
|
|
|
objects["b/3"],
|
|
|
|
objects["c"],
|
|
|
|
objects["c/"],
|
|
|
|
objects["c//"],
|
|
|
|
objects["c/1"],
|
|
|
|
objects["g"],
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.IterateObjectsWithStatus{
|
2020-12-21 15:07:00 +00:00
|
|
|
Opts: metabase.IterateObjectsWithStatus{
|
2021-09-28 13:36:10 +01:00
|
|
|
ProjectID: projectID,
|
|
|
|
BucketName: bucketName,
|
|
|
|
Recursive: true,
|
2023-10-13 17:13:18 +01:00
|
|
|
Status: metabase.CommittedUnversioned,
|
2021-09-28 13:36:10 +01:00
|
|
|
IncludeCustomMetadata: true,
|
|
|
|
IncludeSystemMetadata: true,
|
2020-11-17 13:37:19 +00:00
|
|
|
|
|
|
|
Prefix: "b/",
|
|
|
|
},
|
|
|
|
Result: withoutPrefix("b/",
|
|
|
|
objects["b/1"],
|
|
|
|
objects["b/2"],
|
|
|
|
objects["b/3"],
|
|
|
|
),
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.IterateObjectsWithStatus{
|
2020-12-21 15:07:00 +00:00
|
|
|
Opts: metabase.IterateObjectsWithStatus{
|
2021-09-28 13:36:10 +01:00
|
|
|
ProjectID: projectID,
|
|
|
|
BucketName: bucketName,
|
|
|
|
Recursive: true,
|
2023-10-13 17:13:18 +01:00
|
|
|
Status: metabase.CommittedUnversioned,
|
2021-09-28 13:36:10 +01:00
|
|
|
IncludeCustomMetadata: true,
|
|
|
|
IncludeSystemMetadata: true,
|
2020-11-17 13:37:19 +00:00
|
|
|
|
|
|
|
Prefix: "b/",
|
|
|
|
Cursor: metabase.IterateCursor{Key: "a"},
|
|
|
|
},
|
|
|
|
Result: withoutPrefix("b/",
|
|
|
|
objects["b/1"],
|
|
|
|
objects["b/2"],
|
|
|
|
objects["b/3"],
|
|
|
|
),
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.IterateObjectsWithStatus{
|
2020-12-21 15:07:00 +00:00
|
|
|
Opts: metabase.IterateObjectsWithStatus{
|
2021-09-28 13:36:10 +01:00
|
|
|
ProjectID: projectID,
|
|
|
|
BucketName: bucketName,
|
|
|
|
Recursive: true,
|
2023-10-13 17:13:18 +01:00
|
|
|
Status: metabase.CommittedUnversioned,
|
2021-09-28 13:36:10 +01:00
|
|
|
IncludeCustomMetadata: true,
|
|
|
|
IncludeSystemMetadata: true,
|
2020-11-17 13:37:19 +00:00
|
|
|
|
|
|
|
Prefix: "b/",
|
|
|
|
Cursor: metabase.IterateCursor{Key: "b/2", Version: -3},
|
|
|
|
},
|
|
|
|
Result: withoutPrefix("b/",
|
|
|
|
objects["b/2"],
|
|
|
|
objects["b/3"],
|
|
|
|
),
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.IterateObjectsWithStatus{
|
2020-12-21 15:07:00 +00:00
|
|
|
Opts: metabase.IterateObjectsWithStatus{
|
2021-09-28 13:36:10 +01:00
|
|
|
ProjectID: projectID,
|
|
|
|
BucketName: bucketName,
|
|
|
|
Recursive: true,
|
2023-10-13 17:13:18 +01:00
|
|
|
Status: metabase.CommittedUnversioned,
|
2021-09-28 13:36:10 +01:00
|
|
|
IncludeCustomMetadata: true,
|
|
|
|
IncludeSystemMetadata: true,
|
2020-11-17 13:37:19 +00:00
|
|
|
|
|
|
|
Prefix: "b/",
|
|
|
|
Cursor: metabase.IterateCursor{Key: "c/"},
|
|
|
|
},
|
|
|
|
Result: nil,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
})
|
2020-11-17 14:05:41 +00:00
|
|
|
|
|
|
|
t.Run("non-recursive", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2020-11-17 14:05:41 +00:00
|
|
|
projectID, bucketName := uuid.UUID{1}, "bucky"
|
|
|
|
|
|
|
|
objects := createObjectsWithKeys(ctx, t, db, projectID, bucketName, []metabase.ObjectKey{
|
|
|
|
"a",
|
|
|
|
"b/1",
|
|
|
|
"b/2",
|
|
|
|
"b/3",
|
|
|
|
"c",
|
|
|
|
"c/",
|
|
|
|
"c//",
|
|
|
|
"c/1",
|
|
|
|
"g",
|
|
|
|
})
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.IterateObjectsWithStatus{
|
2020-12-21 15:07:00 +00:00
|
|
|
Opts: metabase.IterateObjectsWithStatus{
|
2021-09-28 13:36:10 +01:00
|
|
|
ProjectID: projectID,
|
|
|
|
BucketName: bucketName,
|
2023-10-13 17:13:18 +01:00
|
|
|
Status: metabase.CommittedUnversioned,
|
2021-09-28 13:36:10 +01:00
|
|
|
IncludeCustomMetadata: true,
|
|
|
|
IncludeSystemMetadata: true,
|
2020-11-17 14:05:41 +00:00
|
|
|
},
|
|
|
|
Result: []metabase.ObjectEntry{
|
|
|
|
objects["a"],
|
2023-10-13 17:13:18 +01:00
|
|
|
prefixEntry("b/", metabase.CommittedUnversioned),
|
2020-11-17 14:05:41 +00:00
|
|
|
objects["c"],
|
2023-10-13 17:13:18 +01:00
|
|
|
prefixEntry("c/", metabase.CommittedUnversioned),
|
2020-11-17 14:05:41 +00:00
|
|
|
objects["g"],
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.IterateObjectsWithStatus{
|
2020-12-21 15:07:00 +00:00
|
|
|
Opts: metabase.IterateObjectsWithStatus{
|
2021-09-28 13:36:10 +01:00
|
|
|
ProjectID: projectID,
|
|
|
|
BucketName: bucketName,
|
2023-10-13 17:13:18 +01:00
|
|
|
Status: metabase.CommittedUnversioned,
|
2021-09-28 13:36:10 +01:00
|
|
|
IncludeCustomMetadata: true,
|
|
|
|
IncludeSystemMetadata: true,
|
2020-11-17 14:05:41 +00:00
|
|
|
|
2023-09-15 17:30:47 +01:00
|
|
|
Cursor: metabase.IterateCursor{Key: "a", Version: objects["a"].Version + 1},
|
2020-11-17 14:05:41 +00:00
|
|
|
},
|
|
|
|
Result: []metabase.ObjectEntry{
|
2023-10-13 17:13:18 +01:00
|
|
|
prefixEntry("b/", metabase.CommittedUnversioned),
|
2020-11-17 14:05:41 +00:00
|
|
|
objects["c"],
|
2023-10-13 17:13:18 +01:00
|
|
|
prefixEntry("c/", metabase.CommittedUnversioned),
|
2020-11-17 14:05:41 +00:00
|
|
|
objects["g"],
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.IterateObjectsWithStatus{
|
2020-12-21 15:07:00 +00:00
|
|
|
Opts: metabase.IterateObjectsWithStatus{
|
2021-09-28 13:36:10 +01:00
|
|
|
ProjectID: projectID,
|
|
|
|
BucketName: bucketName,
|
2023-10-13 17:13:18 +01:00
|
|
|
Status: metabase.CommittedUnversioned,
|
2021-09-28 13:36:10 +01:00
|
|
|
IncludeCustomMetadata: true,
|
|
|
|
IncludeSystemMetadata: true,
|
2020-11-17 14:05:41 +00:00
|
|
|
|
|
|
|
Cursor: metabase.IterateCursor{Key: "b", Version: 0},
|
|
|
|
},
|
|
|
|
Result: []metabase.ObjectEntry{
|
2023-10-13 17:13:18 +01:00
|
|
|
prefixEntry("b/", metabase.CommittedUnversioned),
|
2020-11-17 14:05:41 +00:00
|
|
|
objects["c"],
|
2023-10-13 17:13:18 +01:00
|
|
|
prefixEntry("c/", metabase.CommittedUnversioned),
|
2020-11-17 14:05:41 +00:00
|
|
|
objects["g"],
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.IterateObjectsWithStatus{
|
2020-12-21 15:07:00 +00:00
|
|
|
Opts: metabase.IterateObjectsWithStatus{
|
2021-09-28 13:36:10 +01:00
|
|
|
ProjectID: projectID,
|
|
|
|
BucketName: bucketName,
|
2023-10-13 17:13:18 +01:00
|
|
|
Status: metabase.CommittedUnversioned,
|
2021-09-28 13:36:10 +01:00
|
|
|
IncludeCustomMetadata: true,
|
|
|
|
IncludeSystemMetadata: true,
|
2020-11-17 14:05:41 +00:00
|
|
|
|
|
|
|
Prefix: "b/",
|
|
|
|
},
|
|
|
|
Result: withoutPrefix("b/",
|
|
|
|
objects["b/1"],
|
|
|
|
objects["b/2"],
|
|
|
|
objects["b/3"],
|
|
|
|
),
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.IterateObjectsWithStatus{
|
2020-12-21 15:07:00 +00:00
|
|
|
Opts: metabase.IterateObjectsWithStatus{
|
2021-09-28 13:36:10 +01:00
|
|
|
ProjectID: projectID,
|
|
|
|
BucketName: bucketName,
|
2023-10-13 17:13:18 +01:00
|
|
|
Status: metabase.CommittedUnversioned,
|
2021-09-28 13:36:10 +01:00
|
|
|
IncludeCustomMetadata: true,
|
|
|
|
IncludeSystemMetadata: true,
|
2020-11-17 14:05:41 +00:00
|
|
|
|
|
|
|
Prefix: "b/",
|
|
|
|
Cursor: metabase.IterateCursor{Key: "a"},
|
|
|
|
},
|
|
|
|
Result: withoutPrefix("b/",
|
|
|
|
objects["b/1"],
|
|
|
|
objects["b/2"],
|
|
|
|
objects["b/3"],
|
|
|
|
),
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.IterateObjectsWithStatus{
|
2020-12-21 15:07:00 +00:00
|
|
|
Opts: metabase.IterateObjectsWithStatus{
|
2021-09-28 13:36:10 +01:00
|
|
|
ProjectID: projectID,
|
|
|
|
BucketName: bucketName,
|
2023-10-13 17:13:18 +01:00
|
|
|
Status: metabase.CommittedUnversioned,
|
2021-09-28 13:36:10 +01:00
|
|
|
IncludeCustomMetadata: true,
|
|
|
|
IncludeSystemMetadata: true,
|
2020-11-17 14:05:41 +00:00
|
|
|
|
|
|
|
Prefix: "b/",
|
|
|
|
Cursor: metabase.IterateCursor{Key: "b/2", Version: -3},
|
|
|
|
},
|
|
|
|
Result: withoutPrefix("b/",
|
|
|
|
objects["b/2"],
|
|
|
|
objects["b/3"],
|
|
|
|
),
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.IterateObjectsWithStatus{
|
2020-12-21 15:07:00 +00:00
|
|
|
Opts: metabase.IterateObjectsWithStatus{
|
2021-09-28 13:36:10 +01:00
|
|
|
ProjectID: projectID,
|
|
|
|
BucketName: bucketName,
|
2023-10-13 17:13:18 +01:00
|
|
|
Status: metabase.CommittedUnversioned,
|
2021-09-28 13:36:10 +01:00
|
|
|
IncludeCustomMetadata: true,
|
|
|
|
IncludeSystemMetadata: true,
|
2020-11-17 14:05:41 +00:00
|
|
|
|
|
|
|
Prefix: "b/",
|
|
|
|
Cursor: metabase.IterateCursor{Key: "c/"},
|
|
|
|
},
|
|
|
|
Result: nil,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.IterateObjectsWithStatus{
|
2020-12-21 15:07:00 +00:00
|
|
|
Opts: metabase.IterateObjectsWithStatus{
|
2021-09-28 13:36:10 +01:00
|
|
|
ProjectID: projectID,
|
|
|
|
BucketName: bucketName,
|
2023-10-13 17:13:18 +01:00
|
|
|
Status: metabase.CommittedUnversioned,
|
2021-09-28 13:36:10 +01:00
|
|
|
IncludeCustomMetadata: true,
|
|
|
|
IncludeSystemMetadata: true,
|
2020-11-17 14:05:41 +00:00
|
|
|
|
|
|
|
Prefix: "c/",
|
|
|
|
Cursor: metabase.IterateCursor{Key: "c/"},
|
|
|
|
},
|
|
|
|
Result: withoutPrefix("c/",
|
|
|
|
objects["c/"],
|
2023-10-13 17:13:18 +01:00
|
|
|
prefixEntry("c//", metabase.CommittedUnversioned),
|
2020-11-17 14:05:41 +00:00
|
|
|
objects["c/1"],
|
|
|
|
),
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.IterateObjectsWithStatus{
|
2020-12-21 15:07:00 +00:00
|
|
|
Opts: metabase.IterateObjectsWithStatus{
|
2021-09-28 13:36:10 +01:00
|
|
|
ProjectID: projectID,
|
|
|
|
BucketName: bucketName,
|
2023-10-13 17:13:18 +01:00
|
|
|
Status: metabase.CommittedUnversioned,
|
2021-09-28 13:36:10 +01:00
|
|
|
IncludeCustomMetadata: true,
|
|
|
|
IncludeSystemMetadata: true,
|
2020-11-17 14:05:41 +00:00
|
|
|
|
|
|
|
Prefix: "c//",
|
|
|
|
},
|
|
|
|
Result: withoutPrefix("c//",
|
|
|
|
objects["c//"],
|
|
|
|
),
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
})
|
2021-02-28 18:27:38 +00:00
|
|
|
|
|
|
|
t.Run("boundaries", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2021-02-28 18:27:38 +00:00
|
|
|
projectID, bucketName := uuid.UUID{1}, "bucky"
|
|
|
|
|
|
|
|
queries := []metabase.ObjectKey{""}
|
|
|
|
for a := 0; a <= 0xFF; a++ {
|
2022-05-27 11:30:53 +01:00
|
|
|
if 3 < a && a < 252 {
|
2021-02-28 18:27:38 +00:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
queries = append(queries, metabase.ObjectKey([]byte{byte(a)}))
|
|
|
|
for b := 0; b <= 0xFF; b++ {
|
2021-10-13 09:54:55 +01:00
|
|
|
if 4 < b && b < 251 {
|
2021-02-28 18:27:38 +00:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
queries = append(queries, metabase.ObjectKey([]byte{byte(a), byte(b)}))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
createObjectsWithKeys(ctx, t, db, projectID, bucketName, queries[1:])
|
|
|
|
|
2022-05-27 11:30:53 +01:00
|
|
|
var collector metabasetest.IterateCollector
|
2021-02-28 18:27:38 +00:00
|
|
|
for _, cursor := range queries {
|
|
|
|
for _, prefix := range queries {
|
2022-05-27 11:30:53 +01:00
|
|
|
collector = collector[:0]
|
2021-02-28 18:27:38 +00:00
|
|
|
err := db.IterateObjectsAllVersionsWithStatus(ctx, metabase.IterateObjectsWithStatus{
|
|
|
|
ProjectID: projectID,
|
|
|
|
BucketName: bucketName,
|
|
|
|
Cursor: metabase.IterateCursor{
|
|
|
|
Key: cursor,
|
|
|
|
Version: -1,
|
|
|
|
},
|
2021-09-28 13:36:10 +01:00
|
|
|
Prefix: prefix,
|
2023-10-13 17:13:18 +01:00
|
|
|
Status: metabase.CommittedUnversioned,
|
2021-09-28 13:36:10 +01:00
|
|
|
IncludeCustomMetadata: true,
|
2021-02-28 18:27:38 +00:00
|
|
|
}, collector.Add)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-05-27 11:30:53 +01:00
|
|
|
collector = collector[:0]
|
2021-02-28 18:27:38 +00:00
|
|
|
err = db.IterateObjectsAllVersionsWithStatus(ctx, metabase.IterateObjectsWithStatus{
|
|
|
|
ProjectID: projectID,
|
|
|
|
BucketName: bucketName,
|
|
|
|
Cursor: metabase.IterateCursor{
|
|
|
|
Key: cursor,
|
|
|
|
Version: -1,
|
|
|
|
},
|
2021-09-28 13:36:10 +01:00
|
|
|
Prefix: prefix,
|
|
|
|
Recursive: true,
|
2023-10-13 17:13:18 +01:00
|
|
|
Status: metabase.CommittedUnversioned,
|
2021-09-28 13:36:10 +01:00
|
|
|
IncludeCustomMetadata: true,
|
2021-02-28 18:27:38 +00:00
|
|
|
}, collector.Add)
|
|
|
|
require.NoError(t, err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("verify-iterator-boundary", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2021-02-28 18:27:38 +00:00
|
|
|
projectID, bucketName := uuid.UUID{1}, "bucky"
|
|
|
|
queries := []metabase.ObjectKey{"\x00\xFF"}
|
|
|
|
createObjectsWithKeys(ctx, t, db, projectID, bucketName, queries)
|
2021-04-26 10:35:44 +01:00
|
|
|
var collector metabasetest.IterateCollector
|
2021-02-28 18:27:38 +00:00
|
|
|
err := db.IterateObjectsAllVersionsWithStatus(ctx, metabase.IterateObjectsWithStatus{
|
|
|
|
ProjectID: projectID,
|
|
|
|
BucketName: bucketName,
|
|
|
|
Cursor: metabase.IterateCursor{
|
|
|
|
Key: metabase.ObjectKey([]byte{}),
|
|
|
|
Version: -1,
|
|
|
|
},
|
2021-09-28 13:36:10 +01:00
|
|
|
Prefix: metabase.ObjectKey([]byte{1}),
|
2023-10-13 17:13:18 +01:00
|
|
|
Status: metabase.CommittedUnversioned,
|
2021-09-28 13:36:10 +01:00
|
|
|
IncludeCustomMetadata: true,
|
|
|
|
IncludeSystemMetadata: true,
|
2021-02-28 18:27:38 +00:00
|
|
|
}, collector.Add)
|
|
|
|
require.NoError(t, err)
|
|
|
|
})
|
2021-02-28 20:00:29 +00:00
|
|
|
|
|
|
|
t.Run("verify-cursor-continuation", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2021-02-28 20:00:29 +00:00
|
|
|
projectID, bucketName := uuid.UUID{1}, "bucky"
|
|
|
|
|
|
|
|
createObjectsWithKeys(ctx, t, db, projectID, bucketName, []metabase.ObjectKey{
|
|
|
|
"1",
|
|
|
|
"a/a",
|
|
|
|
"a/0",
|
|
|
|
})
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
var collector metabasetest.IterateCollector
|
2021-02-28 20:00:29 +00:00
|
|
|
err := db.IterateObjectsAllVersionsWithStatus(ctx, metabase.IterateObjectsWithStatus{
|
2021-09-28 13:36:10 +01:00
|
|
|
ProjectID: projectID,
|
|
|
|
BucketName: bucketName,
|
|
|
|
Prefix: metabase.ObjectKey("a/"),
|
|
|
|
BatchSize: 1,
|
2023-10-13 17:13:18 +01:00
|
|
|
Status: metabase.CommittedUnversioned,
|
2021-09-28 13:36:10 +01:00
|
|
|
IncludeCustomMetadata: true,
|
2021-02-28 20:00:29 +00:00
|
|
|
}, collector.Add)
|
|
|
|
require.NoError(t, err)
|
|
|
|
})
|
2021-08-03 02:26:19 +01:00
|
|
|
|
|
|
|
t.Run("include metadata", func(t *testing.T) {
|
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
obj1 := metabasetest.RandObjectStream()
|
|
|
|
metabasetest.CreateTestObject{
|
|
|
|
CommitObject: &metabase.CommitObject{
|
|
|
|
ObjectStream: obj1,
|
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
2022-04-14 12:20:18 +01:00
|
|
|
OverrideEncryptedMetadata: true,
|
2021-08-03 02:26:19 +01:00
|
|
|
EncryptedMetadata: []byte{3},
|
|
|
|
EncryptedMetadataEncryptedKey: []byte{4},
|
2021-10-12 14:37:12 +01:00
|
|
|
EncryptedMetadataNonce: []byte{5},
|
2021-08-03 02:26:19 +01:00
|
|
|
},
|
|
|
|
}.Run(ctx, t, db, obj1, 4)
|
|
|
|
|
|
|
|
var collector metabasetest.IterateCollector
|
|
|
|
err := db.IterateObjectsAllVersionsWithStatus(ctx, metabase.IterateObjectsWithStatus{
|
2021-09-28 13:36:10 +01:00
|
|
|
ProjectID: obj1.ProjectID,
|
|
|
|
BucketName: obj1.BucketName,
|
|
|
|
Recursive: true,
|
2023-10-13 17:13:18 +01:00
|
|
|
Status: metabase.CommittedUnversioned,
|
2021-09-28 13:36:10 +01:00
|
|
|
IncludeCustomMetadata: true,
|
|
|
|
IncludeSystemMetadata: true,
|
2021-08-03 02:26:19 +01:00
|
|
|
}, collector.Add)
|
|
|
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
for _, entry := range collector {
|
|
|
|
require.Equal(t, entry.EncryptedMetadata, []byte{3})
|
|
|
|
require.Equal(t, entry.EncryptedMetadataEncryptedKey, []byte{4})
|
2021-10-12 14:37:12 +01:00
|
|
|
require.Equal(t, entry.EncryptedMetadataNonce, []byte{5})
|
2021-08-03 02:26:19 +01:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2021-09-28 13:36:10 +01:00
|
|
|
t.Run("exclude custom metadata", func(t *testing.T) {
|
2021-08-03 02:26:19 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
obj1 := metabasetest.RandObjectStream()
|
|
|
|
metabasetest.CreateTestObject{
|
|
|
|
CommitObject: &metabase.CommitObject{
|
|
|
|
ObjectStream: obj1,
|
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
|
|
|
EncryptedMetadata: []byte{3},
|
|
|
|
EncryptedMetadataEncryptedKey: []byte{4},
|
2021-10-12 14:37:12 +01:00
|
|
|
EncryptedMetadataNonce: []byte{5},
|
2021-08-03 02:26:19 +01:00
|
|
|
},
|
|
|
|
}.Run(ctx, t, db, obj1, 4)
|
|
|
|
|
|
|
|
var collector metabasetest.IterateCollector
|
|
|
|
err := db.IterateObjectsAllVersionsWithStatus(ctx, metabase.IterateObjectsWithStatus{
|
2021-09-28 13:36:10 +01:00
|
|
|
ProjectID: obj1.ProjectID,
|
|
|
|
BucketName: obj1.BucketName,
|
|
|
|
Recursive: true,
|
2023-10-13 17:13:18 +01:00
|
|
|
Status: metabase.CommittedUnversioned,
|
2021-09-28 13:36:10 +01:00
|
|
|
IncludeCustomMetadata: false,
|
|
|
|
IncludeSystemMetadata: true,
|
2021-08-03 02:26:19 +01:00
|
|
|
}, collector.Add)
|
|
|
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
for _, entry := range collector {
|
2021-10-12 14:37:12 +01:00
|
|
|
require.Nil(t, entry.EncryptedMetadataNonce)
|
2021-08-03 02:26:19 +01:00
|
|
|
require.Nil(t, entry.EncryptedMetadata)
|
|
|
|
require.Nil(t, entry.EncryptedMetadataEncryptedKey)
|
|
|
|
}
|
|
|
|
})
|
2021-09-28 13:36:10 +01:00
|
|
|
|
|
|
|
t.Run("exclude system metadata", func(t *testing.T) {
|
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
obj1 := metabasetest.RandObjectStream()
|
|
|
|
metabasetest.CreateTestObject{
|
|
|
|
CommitObject: &metabase.CommitObject{
|
|
|
|
ObjectStream: obj1,
|
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
2022-04-14 12:20:18 +01:00
|
|
|
OverrideEncryptedMetadata: true,
|
2021-09-28 13:36:10 +01:00
|
|
|
EncryptedMetadata: []byte{3},
|
|
|
|
EncryptedMetadataEncryptedKey: []byte{4},
|
|
|
|
EncryptedMetadataNonce: []byte{5},
|
|
|
|
},
|
|
|
|
}.Run(ctx, t, db, obj1, 4)
|
|
|
|
|
|
|
|
var collector metabasetest.IterateCollector
|
|
|
|
err := db.IterateObjectsAllVersionsWithStatus(ctx, metabase.IterateObjectsWithStatus{
|
|
|
|
ProjectID: obj1.ProjectID,
|
|
|
|
BucketName: obj1.BucketName,
|
|
|
|
Recursive: true,
|
2023-10-13 17:13:18 +01:00
|
|
|
Status: metabase.CommittedUnversioned,
|
2021-09-28 13:36:10 +01:00
|
|
|
IncludeCustomMetadata: true,
|
|
|
|
IncludeSystemMetadata: false,
|
|
|
|
}, collector.Add)
|
|
|
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
for _, entry := range collector {
|
2021-11-10 10:46:11 +00:00
|
|
|
// fields that should always be set
|
|
|
|
require.NotEmpty(t, entry.ObjectKey)
|
|
|
|
require.NotEmpty(t, entry.StreamID)
|
|
|
|
require.NotZero(t, entry.Version)
|
2023-10-13 17:13:18 +01:00
|
|
|
require.Equal(t, metabase.CommittedUnversioned, entry.Status)
|
2021-11-10 10:46:11 +00:00
|
|
|
require.False(t, entry.Encryption.IsZero())
|
|
|
|
|
2021-09-28 13:36:10 +01:00
|
|
|
require.True(t, entry.CreatedAt.IsZero())
|
|
|
|
require.Nil(t, entry.ExpiresAt)
|
2022-11-09 10:26:18 +00:00
|
|
|
|
2021-09-28 13:36:10 +01:00
|
|
|
require.Zero(t, entry.SegmentCount)
|
|
|
|
require.Zero(t, entry.TotalPlainSize)
|
|
|
|
require.Zero(t, entry.TotalEncryptedSize)
|
|
|
|
require.Zero(t, entry.FixedSegmentSize)
|
|
|
|
|
|
|
|
require.NotNil(t, entry.EncryptedMetadataNonce)
|
|
|
|
require.NotNil(t, entry.EncryptedMetadata)
|
|
|
|
require.NotNil(t, entry.EncryptedMetadataEncryptedKey)
|
|
|
|
}
|
|
|
|
})
|
2022-06-21 10:03:56 +01:00
|
|
|
|
|
|
|
t.Run("verify-cursor-continuation", func(t *testing.T) {
|
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
|
|
|
projectID, bucketName := uuid.UUID{1}, "bucky"
|
|
|
|
createObjectsWithKeys(ctx, t, db, projectID, bucketName, []metabase.ObjectKey{
|
|
|
|
"1",
|
|
|
|
"a/a",
|
|
|
|
"a/0",
|
|
|
|
})
|
|
|
|
var collector metabasetest.IterateCollector
|
|
|
|
err := db.IterateObjectsAllVersionsWithStatus(ctx, metabase.IterateObjectsWithStatus{
|
|
|
|
ProjectID: projectID,
|
|
|
|
BucketName: bucketName,
|
|
|
|
Prefix: metabase.ObjectKey("a/"),
|
2023-10-13 17:13:18 +01:00
|
|
|
Status: metabase.CommittedUnversioned,
|
2022-06-21 10:03:56 +01:00
|
|
|
BatchSize: 1,
|
|
|
|
}, collector.Add)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, 2, len(collector))
|
|
|
|
})
|
|
|
|
t.Run("skip-expired-objects", func(t *testing.T) {
|
|
|
|
now := time.Now()
|
|
|
|
type test struct {
|
|
|
|
notExpired []metabase.ObjectKey
|
|
|
|
expired []metabase.ObjectKey
|
|
|
|
}
|
|
|
|
testCases := []test{
|
|
|
|
{
|
|
|
|
notExpired: []metabase.ObjectKey{"1"},
|
|
|
|
expired: []metabase.ObjectKey{"2"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
notExpired: []metabase.ObjectKey{"2"},
|
|
|
|
expired: []metabase.ObjectKey{"1"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
notExpired: []metabase.ObjectKey{"2"},
|
|
|
|
expired: []metabase.ObjectKey{"1", "3"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
notExpired: []metabase.ObjectKey{"2", "4"},
|
|
|
|
expired: []metabase.ObjectKey{"1", "3"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
expired: []metabase.ObjectKey{"1", "2", "3", "4"},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
stream := metabase.ObjectStream{
|
|
|
|
ProjectID: uuid.UUID{1},
|
|
|
|
BucketName: "bucket",
|
|
|
|
Version: 1,
|
|
|
|
StreamID: testrand.UUID(),
|
|
|
|
}
|
|
|
|
for i, tc := range testCases {
|
|
|
|
tc := tc
|
|
|
|
t.Run(strconv.Itoa(i), func(t *testing.T) {
|
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
|
|
|
expectedResult := []metabase.ObjectEntry{}
|
|
|
|
if len(tc.notExpired) == 0 {
|
|
|
|
expectedResult = nil
|
|
|
|
}
|
|
|
|
for _, key := range tc.notExpired {
|
|
|
|
stream.ObjectKey = key
|
|
|
|
object := metabasetest.CreateObject(ctx, t, db, stream, 0)
|
|
|
|
expectedResult = append(expectedResult, objectEntryFromRaw(metabase.RawObject(object)))
|
|
|
|
}
|
|
|
|
for _, key := range tc.expired {
|
|
|
|
stream.ObjectKey = key
|
|
|
|
metabasetest.CreateExpiredObject(ctx, t, db, stream, 0, now.Add(-2*time.Hour))
|
|
|
|
}
|
|
|
|
for _, batchSize := range []int{1, 2, 3} {
|
|
|
|
opts := metabase.IterateObjectsWithStatus{
|
|
|
|
ProjectID: stream.ProjectID,
|
|
|
|
BucketName: stream.BucketName,
|
|
|
|
BatchSize: batchSize,
|
|
|
|
Status: 3,
|
|
|
|
IncludeSystemMetadata: true,
|
|
|
|
}
|
|
|
|
metabasetest.IterateObjectsWithStatus{
|
|
|
|
Opts: opts,
|
|
|
|
Result: expectedResult,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
{
|
|
|
|
opts := opts
|
|
|
|
opts.Recursive = true
|
|
|
|
metabasetest.IterateObjectsWithStatus{
|
|
|
|
Opts: opts,
|
|
|
|
Result: expectedResult,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
2022-08-22 15:05:13 +01:00
|
|
|
|
|
|
|
t.Run("prefix longer than key", func(t *testing.T) {
|
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
projectID, bucketName := uuid.UUID{1}, "bucky"
|
|
|
|
objects := createObjectsWithKeys(ctx, t, db, projectID, bucketName, []metabase.ObjectKey{
|
|
|
|
"aaaa/a",
|
|
|
|
"aaaa/b",
|
|
|
|
"aaaa/c",
|
|
|
|
})
|
|
|
|
|
|
|
|
metabasetest.IterateObjectsWithStatus{
|
|
|
|
Opts: metabase.IterateObjectsWithStatus{
|
|
|
|
ProjectID: projectID,
|
|
|
|
BucketName: bucketName,
|
|
|
|
Recursive: false,
|
|
|
|
Prefix: "aaaa/",
|
2023-10-13 17:13:18 +01:00
|
|
|
Status: metabase.CommittedUnversioned,
|
2022-08-22 15:05:13 +01:00
|
|
|
BatchSize: 2,
|
|
|
|
IncludeSystemMetadata: true,
|
|
|
|
},
|
|
|
|
Result: withoutPrefix("aaaa/",
|
|
|
|
objects["aaaa/a"],
|
|
|
|
objects["aaaa/b"],
|
|
|
|
objects["aaaa/c"],
|
|
|
|
),
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
})
|
2022-08-26 14:02:57 +01:00
|
|
|
|
|
|
|
t.Run("version greater than one", func(t *testing.T) {
|
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
projectID, bucketName := uuid.UUID{2}, "bucky"
|
|
|
|
|
|
|
|
id1 := metabasetest.RandObjectStream()
|
|
|
|
id1.ProjectID = projectID
|
|
|
|
id1.BucketName = bucketName
|
|
|
|
id1.Version = metabase.Version(rand.Int31())
|
|
|
|
|
|
|
|
id2 := metabasetest.RandObjectStream()
|
|
|
|
id2.ProjectID = projectID
|
|
|
|
id2.BucketName = bucketName
|
|
|
|
id2.ObjectKey = id1.ObjectKey + "Z" // for deterministic ordering
|
|
|
|
id2.Version = 1
|
|
|
|
|
|
|
|
var objs []metabase.Object
|
|
|
|
for _, id := range []metabase.ObjectStream{id1, id2} {
|
|
|
|
obj, _ := metabasetest.CreateTestObject{
|
|
|
|
BeginObjectExactVersion: &metabase.BeginObjectExactVersion{
|
|
|
|
ObjectStream: id,
|
|
|
|
},
|
|
|
|
CommitObject: &metabase.CommitObject{
|
|
|
|
ObjectStream: id,
|
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
|
|
|
},
|
|
|
|
}.Run(ctx, t, db, id, 1)
|
|
|
|
objs = append(objs, obj)
|
|
|
|
}
|
|
|
|
|
|
|
|
metabasetest.IterateObjectsWithStatus{
|
|
|
|
Opts: metabase.IterateObjectsWithStatus{
|
|
|
|
ProjectID: projectID,
|
|
|
|
BucketName: bucketName,
|
|
|
|
Recursive: true,
|
2023-10-13 17:13:18 +01:00
|
|
|
Status: metabase.CommittedUnversioned,
|
2022-08-26 14:02:57 +01:00
|
|
|
BatchSize: 3,
|
|
|
|
IncludeSystemMetadata: true,
|
|
|
|
},
|
|
|
|
Result: []metabase.ObjectEntry{
|
|
|
|
objectEntryFromRaw(metabase.RawObject(objs[0])),
|
|
|
|
objectEntryFromRaw(metabase.RawObject(objs[1])),
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
})
|
2020-11-17 13:37:19 +00:00
|
|
|
})
|
|
|
|
}
|
2021-02-28 18:27:38 +00:00
|
|
|
|
2021-06-25 15:01:12 +01:00
|
|
|
func TestIterateObjectsSkipCursor(t *testing.T) {
|
|
|
|
metabasetest.Run(t, func(ctx *testcontext.Context, t *testing.T, db *metabase.DB) {
|
|
|
|
projectID, bucketName := uuid.UUID{1}, "bucky"
|
|
|
|
|
|
|
|
t.Run("no prefix", func(t *testing.T) {
|
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
createObjectsWithKeys(ctx, t, db, projectID, bucketName, []metabase.ObjectKey{
|
|
|
|
"08/test",
|
|
|
|
"09/test",
|
|
|
|
"10/test",
|
|
|
|
})
|
|
|
|
|
|
|
|
metabasetest.IterateObjectsWithStatus{
|
|
|
|
Opts: metabase.IterateObjectsWithStatus{
|
|
|
|
ProjectID: projectID,
|
|
|
|
BucketName: bucketName,
|
|
|
|
Recursive: false,
|
|
|
|
Prefix: "",
|
|
|
|
Cursor: metabase.IterateCursor{
|
|
|
|
Key: metabase.ObjectKey("08/"),
|
|
|
|
Version: 1,
|
|
|
|
},
|
2023-10-13 17:13:18 +01:00
|
|
|
Status: metabase.CommittedUnversioned,
|
2021-09-28 13:36:10 +01:00
|
|
|
IncludeCustomMetadata: true,
|
|
|
|
IncludeSystemMetadata: true,
|
2021-06-25 15:01:12 +01:00
|
|
|
},
|
|
|
|
Result: []metabase.ObjectEntry{
|
2023-10-13 17:13:18 +01:00
|
|
|
prefixEntry(metabase.ObjectKey("09/"), metabase.CommittedUnversioned),
|
|
|
|
prefixEntry(metabase.ObjectKey("10/"), metabase.CommittedUnversioned),
|
2021-06-25 15:01:12 +01:00
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
metabasetest.IterateObjectsWithStatus{
|
|
|
|
Opts: metabase.IterateObjectsWithStatus{
|
|
|
|
ProjectID: projectID,
|
|
|
|
BucketName: bucketName,
|
|
|
|
Recursive: false,
|
|
|
|
Prefix: "",
|
|
|
|
Cursor: metabase.IterateCursor{
|
|
|
|
Key: metabase.ObjectKey("08"),
|
|
|
|
Version: 1,
|
|
|
|
},
|
2023-10-13 17:13:18 +01:00
|
|
|
Status: metabase.CommittedUnversioned,
|
2021-09-28 13:36:10 +01:00
|
|
|
IncludeSystemMetadata: true,
|
2021-06-25 15:01:12 +01:00
|
|
|
},
|
|
|
|
Result: []metabase.ObjectEntry{
|
2023-10-13 17:13:18 +01:00
|
|
|
prefixEntry(metabase.ObjectKey("08/"), metabase.CommittedUnversioned),
|
|
|
|
prefixEntry(metabase.ObjectKey("09/"), metabase.CommittedUnversioned),
|
|
|
|
prefixEntry(metabase.ObjectKey("10/"), metabase.CommittedUnversioned),
|
2021-06-25 15:01:12 +01:00
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
metabasetest.IterateObjectsWithStatus{
|
|
|
|
Opts: metabase.IterateObjectsWithStatus{
|
|
|
|
ProjectID: projectID,
|
|
|
|
BucketName: bucketName,
|
|
|
|
Recursive: false,
|
|
|
|
Prefix: "",
|
|
|
|
Cursor: metabase.IterateCursor{
|
|
|
|
Key: metabase.ObjectKey("08/a/x"),
|
|
|
|
Version: 1,
|
|
|
|
},
|
2023-10-13 17:13:18 +01:00
|
|
|
Status: metabase.CommittedUnversioned,
|
2021-09-28 13:36:10 +01:00
|
|
|
IncludeSystemMetadata: true,
|
2021-06-25 15:01:12 +01:00
|
|
|
},
|
|
|
|
Result: []metabase.ObjectEntry{
|
2023-10-13 17:13:18 +01:00
|
|
|
prefixEntry(metabase.ObjectKey("09/"), metabase.CommittedUnversioned),
|
|
|
|
prefixEntry(metabase.ObjectKey("10/"), metabase.CommittedUnversioned),
|
2021-06-25 15:01:12 +01:00
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("prefix", func(t *testing.T) {
|
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
createObjectsWithKeys(ctx, t, db, projectID, bucketName, []metabase.ObjectKey{
|
|
|
|
"2017/05/08/test",
|
|
|
|
"2017/05/09/test",
|
|
|
|
"2017/05/10/test",
|
|
|
|
})
|
|
|
|
|
|
|
|
metabasetest.IterateObjectsWithStatus{
|
|
|
|
Opts: metabase.IterateObjectsWithStatus{
|
|
|
|
ProjectID: projectID,
|
|
|
|
BucketName: bucketName,
|
|
|
|
Recursive: false,
|
|
|
|
Prefix: metabase.ObjectKey("2017/05/"),
|
|
|
|
Cursor: metabase.IterateCursor{
|
|
|
|
Key: metabase.ObjectKey("2017/05/08"),
|
|
|
|
Version: 1,
|
|
|
|
},
|
2023-10-13 17:13:18 +01:00
|
|
|
Status: metabase.CommittedUnversioned,
|
2021-09-28 13:36:10 +01:00
|
|
|
IncludeSystemMetadata: true,
|
2021-06-25 15:01:12 +01:00
|
|
|
},
|
|
|
|
Result: []metabase.ObjectEntry{
|
2023-10-13 17:13:18 +01:00
|
|
|
prefixEntry(metabase.ObjectKey("08/"), metabase.CommittedUnversioned),
|
|
|
|
prefixEntry(metabase.ObjectKey("09/"), metabase.CommittedUnversioned),
|
|
|
|
prefixEntry(metabase.ObjectKey("10/"), metabase.CommittedUnversioned),
|
2021-06-25 15:01:12 +01:00
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
metabasetest.IterateObjectsWithStatus{
|
|
|
|
Opts: metabase.IterateObjectsWithStatus{
|
|
|
|
ProjectID: projectID,
|
|
|
|
BucketName: bucketName,
|
|
|
|
Recursive: false,
|
|
|
|
Prefix: metabase.ObjectKey("2017/05/"),
|
|
|
|
Cursor: metabase.IterateCursor{
|
|
|
|
Key: metabase.ObjectKey("2017/05/08/"),
|
|
|
|
Version: 1,
|
|
|
|
},
|
2023-10-13 17:13:18 +01:00
|
|
|
Status: metabase.CommittedUnversioned,
|
2021-09-28 13:36:10 +01:00
|
|
|
IncludeSystemMetadata: true,
|
2021-06-25 15:01:12 +01:00
|
|
|
},
|
|
|
|
Result: []metabase.ObjectEntry{
|
2023-10-13 17:13:18 +01:00
|
|
|
prefixEntry(metabase.ObjectKey("09/"), metabase.CommittedUnversioned),
|
|
|
|
prefixEntry(metabase.ObjectKey("10/"), metabase.CommittedUnversioned),
|
2021-06-25 15:01:12 +01:00
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
metabasetest.IterateObjectsWithStatus{
|
|
|
|
Opts: metabase.IterateObjectsWithStatus{
|
|
|
|
ProjectID: projectID,
|
|
|
|
BucketName: bucketName,
|
|
|
|
Recursive: false,
|
|
|
|
Prefix: metabase.ObjectKey("2017/05/"),
|
|
|
|
Cursor: metabase.IterateCursor{
|
|
|
|
Key: metabase.ObjectKey("2017/05/08/a/x"),
|
|
|
|
Version: 1,
|
|
|
|
},
|
2023-10-13 17:13:18 +01:00
|
|
|
Status: metabase.CommittedUnversioned,
|
2021-09-28 13:36:10 +01:00
|
|
|
IncludeSystemMetadata: true,
|
2021-06-25 15:01:12 +01:00
|
|
|
},
|
|
|
|
Result: []metabase.ObjectEntry{
|
2023-10-13 17:13:18 +01:00
|
|
|
prefixEntry(metabase.ObjectKey("09/"), metabase.CommittedUnversioned),
|
|
|
|
prefixEntry(metabase.ObjectKey("10/"), metabase.CommittedUnversioned),
|
2021-06-25 15:01:12 +01:00
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("batch-size", func(t *testing.T) {
|
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
afterDelimiter := metabase.ObjectKey(metabase.Delimiter + 1)
|
|
|
|
|
|
|
|
objects := createObjectsWithKeys(ctx, t, db, projectID, bucketName, []metabase.ObjectKey{
|
|
|
|
"2017/05/08",
|
|
|
|
"2017/05/08/a",
|
|
|
|
"2017/05/08/b",
|
|
|
|
"2017/05/08/c",
|
|
|
|
"2017/05/08/d",
|
|
|
|
"2017/05/08/e",
|
|
|
|
"2017/05/08" + afterDelimiter,
|
|
|
|
"2017/05/09/a",
|
|
|
|
"2017/05/09/b",
|
|
|
|
"2017/05/09/c",
|
|
|
|
"2017/05/09/d",
|
|
|
|
"2017/05/09/e",
|
|
|
|
"2017/05/10/a",
|
|
|
|
"2017/05/10/b",
|
|
|
|
"2017/05/10/c",
|
|
|
|
"2017/05/10/d",
|
|
|
|
"2017/05/10/e",
|
|
|
|
})
|
|
|
|
|
|
|
|
metabasetest.IterateObjectsWithStatus{
|
|
|
|
Opts: metabase.IterateObjectsWithStatus{
|
|
|
|
ProjectID: projectID,
|
|
|
|
BucketName: bucketName,
|
|
|
|
Recursive: false,
|
|
|
|
BatchSize: 3,
|
|
|
|
Prefix: metabase.ObjectKey("2017/05/"),
|
|
|
|
Cursor: metabase.IterateCursor{
|
|
|
|
Key: metabase.ObjectKey("2017/05/08"),
|
2023-09-15 17:30:47 +01:00
|
|
|
Version: objects["2017/05/08"].Version,
|
2021-06-25 15:01:12 +01:00
|
|
|
},
|
2023-10-13 17:13:18 +01:00
|
|
|
Status: metabase.CommittedUnversioned,
|
2021-09-28 13:36:10 +01:00
|
|
|
IncludeCustomMetadata: true,
|
|
|
|
IncludeSystemMetadata: true,
|
2021-06-25 15:01:12 +01:00
|
|
|
},
|
|
|
|
Result: []metabase.ObjectEntry{
|
2023-10-13 17:13:18 +01:00
|
|
|
prefixEntry(metabase.ObjectKey("08/"), metabase.CommittedUnversioned),
|
2021-06-25 15:01:12 +01:00
|
|
|
withoutPrefix1("2017/05/", objects["2017/05/08"+afterDelimiter]),
|
2023-10-13 17:13:18 +01:00
|
|
|
prefixEntry(metabase.ObjectKey("09/"), metabase.CommittedUnversioned),
|
|
|
|
prefixEntry(metabase.ObjectKey("10/"), metabase.CommittedUnversioned),
|
2021-06-25 15:01:12 +01:00
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
metabasetest.IterateObjectsWithStatus{
|
|
|
|
Opts: metabase.IterateObjectsWithStatus{
|
|
|
|
ProjectID: projectID,
|
|
|
|
BucketName: bucketName,
|
|
|
|
Recursive: false,
|
|
|
|
BatchSize: 3,
|
|
|
|
Prefix: metabase.ObjectKey("2017/05/"),
|
|
|
|
Cursor: metabase.IterateCursor{
|
|
|
|
Key: metabase.ObjectKey("2017/05/08/"),
|
|
|
|
Version: 1,
|
|
|
|
},
|
2023-10-13 17:13:18 +01:00
|
|
|
Status: metabase.CommittedUnversioned,
|
2021-09-28 13:36:10 +01:00
|
|
|
IncludeCustomMetadata: true,
|
|
|
|
IncludeSystemMetadata: true,
|
2021-06-25 15:01:12 +01:00
|
|
|
},
|
|
|
|
Result: []metabase.ObjectEntry{
|
|
|
|
withoutPrefix1("2017/05/", objects["2017/05/08"+afterDelimiter]),
|
2023-10-13 17:13:18 +01:00
|
|
|
prefixEntry(metabase.ObjectKey("09/"), metabase.CommittedUnversioned),
|
|
|
|
prefixEntry(metabase.ObjectKey("10/"), metabase.CommittedUnversioned),
|
2021-06-25 15:01:12 +01:00
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
metabasetest.IterateObjectsWithStatus{
|
|
|
|
Opts: metabase.IterateObjectsWithStatus{
|
|
|
|
ProjectID: projectID,
|
|
|
|
BucketName: bucketName,
|
|
|
|
Recursive: false,
|
|
|
|
Prefix: metabase.ObjectKey("2017/05/"),
|
|
|
|
Cursor: metabase.IterateCursor{
|
|
|
|
Key: metabase.ObjectKey("2017/05/08/a/x"),
|
|
|
|
Version: 1,
|
|
|
|
},
|
2023-10-13 17:13:18 +01:00
|
|
|
Status: metabase.CommittedUnversioned,
|
2021-09-28 13:36:10 +01:00
|
|
|
IncludeCustomMetadata: true,
|
|
|
|
IncludeSystemMetadata: true,
|
2021-06-25 15:01:12 +01:00
|
|
|
},
|
|
|
|
Result: []metabase.ObjectEntry{
|
|
|
|
withoutPrefix1("2017/05/", objects["2017/05/08"+afterDelimiter]),
|
2023-10-13 17:13:18 +01:00
|
|
|
prefixEntry(metabase.ObjectKey("09/"), metabase.CommittedUnversioned),
|
|
|
|
prefixEntry(metabase.ObjectKey("10/"), metabase.CommittedUnversioned),
|
2021-06-25 15:01:12 +01:00
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-01-11 12:06:04 +00:00
|
|
|
func TestIteratePendingObjectsWithObjectKey(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()
|
2021-01-11 12:06:04 +00:00
|
|
|
|
|
|
|
location := obj.Location()
|
|
|
|
|
|
|
|
now := time.Now()
|
2021-05-06 12:42:20 +01:00
|
|
|
zombieDeadline := now.Add(24 * time.Hour)
|
2021-01-11 12:06:04 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
for _, test := range metabasetest.InvalidObjectLocations(location) {
|
2021-01-11 12:06:04 +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.IteratePendingObjectsByKey{
|
2021-01-11 12:06:04 +00:00
|
|
|
Opts: metabase.IteratePendingObjectsByKey{
|
|
|
|
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)
|
2021-01-11 12:06:04 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Run("committed object", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2021-01-11 12:06:04 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
obj := metabasetest.RandObjectStream()
|
2021-01-11 12:06:04 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.CreateObject(ctx, t, db, obj, 0)
|
|
|
|
metabasetest.IteratePendingObjectsByKey{
|
2021-01-11 12:06:04 +00:00
|
|
|
Opts: metabase.IteratePendingObjectsByKey{
|
|
|
|
ObjectLocation: obj.Location(),
|
|
|
|
BatchSize: 10,
|
|
|
|
},
|
|
|
|
Result: nil,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
})
|
|
|
|
t.Run("non existing object", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
|
|
|
pending := metabasetest.RandObjectStream()
|
|
|
|
metabasetest.CreatePendingObject(ctx, t, db, pending, 0)
|
2021-01-11 12:06:04 +00:00
|
|
|
|
|
|
|
object := metabase.RawObject{
|
|
|
|
ObjectStream: pending,
|
|
|
|
CreatedAt: now,
|
|
|
|
Status: metabase.Pending,
|
|
|
|
|
2021-05-06 12:42:20 +01:00
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
|
|
|
ZombieDeletionDeadline: &zombieDeadline,
|
2021-01-11 12:06:04 +00:00
|
|
|
}
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.IteratePendingObjectsByKey{
|
2021-01-11 12:06:04 +00:00
|
|
|
Opts: metabase.IteratePendingObjectsByKey{
|
|
|
|
ObjectLocation: metabase.ObjectLocation{
|
|
|
|
ProjectID: pending.ProjectID,
|
|
|
|
BucketName: pending.BucketName,
|
|
|
|
ObjectKey: pending.Location().ObjectKey + "other",
|
|
|
|
},
|
|
|
|
BatchSize: 10,
|
|
|
|
},
|
|
|
|
Result: nil,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{Objects: []metabase.RawObject{object}}.Check(ctx, t, db)
|
2021-01-11 12:06:04 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("less and more objects than limit", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2021-01-11 12:06:04 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
pending := []metabase.ObjectStream{metabasetest.RandObjectStream(), metabasetest.RandObjectStream(), metabasetest.RandObjectStream()}
|
2021-01-11 12:06:04 +00:00
|
|
|
|
|
|
|
location := pending[0].Location()
|
|
|
|
objects := make([]metabase.RawObject, 3)
|
|
|
|
expected := make([]metabase.ObjectEntry, 3)
|
|
|
|
|
|
|
|
for i, obj := range pending {
|
|
|
|
obj.ProjectID = location.ProjectID
|
|
|
|
obj.BucketName = location.BucketName
|
|
|
|
obj.ObjectKey = location.ObjectKey
|
|
|
|
obj.Version = metabase.Version(i + 1)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.CreatePendingObject(ctx, t, db, obj, 0)
|
2021-01-11 12:06:04 +00:00
|
|
|
|
|
|
|
objects[i] = metabase.RawObject{
|
|
|
|
ObjectStream: obj,
|
|
|
|
CreatedAt: now,
|
|
|
|
Status: metabase.Pending,
|
|
|
|
|
2021-05-06 12:42:20 +01:00
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
|
|
|
ZombieDeletionDeadline: &zombieDeadline,
|
2021-01-11 12:06:04 +00:00
|
|
|
}
|
|
|
|
expected[i] = objectEntryFromRaw(objects[i])
|
|
|
|
}
|
|
|
|
|
|
|
|
sort.Slice(expected, func(i, j int) bool {
|
2021-04-26 10:35:44 +01:00
|
|
|
return expected[i].StreamID.Less(expected[j].StreamID)
|
2021-01-11 12:06:04 +00:00
|
|
|
})
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.IteratePendingObjectsByKey{
|
2021-01-11 12:06:04 +00:00
|
|
|
Opts: metabase.IteratePendingObjectsByKey{
|
|
|
|
ObjectLocation: location,
|
|
|
|
BatchSize: 10,
|
|
|
|
},
|
|
|
|
Result: expected,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.IteratePendingObjectsByKey{
|
2021-01-11 12:06:04 +00:00
|
|
|
Opts: metabase.IteratePendingObjectsByKey{
|
|
|
|
ObjectLocation: location,
|
|
|
|
BatchSize: 2,
|
|
|
|
},
|
|
|
|
Result: expected,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{Objects: objects}.Check(ctx, t, db)
|
2021-01-11 12:06:04 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("prefixed object key", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2021-01-11 12:06:04 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
pending := metabasetest.RandObjectStream()
|
2021-01-11 12:06:04 +00:00
|
|
|
pending.ObjectKey = metabase.ObjectKey("a/prefixed/" + string(location.ObjectKey))
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.CreatePendingObject(ctx, t, db, pending, 0)
|
2021-01-11 12:06:04 +00:00
|
|
|
|
|
|
|
object := metabase.RawObject{
|
|
|
|
ObjectStream: pending,
|
|
|
|
CreatedAt: now,
|
|
|
|
Status: metabase.Pending,
|
|
|
|
|
2021-05-06 12:42:20 +01:00
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
|
|
|
ZombieDeletionDeadline: &zombieDeadline,
|
2021-01-11 12:06:04 +00:00
|
|
|
}
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.IteratePendingObjectsByKey{
|
2021-01-11 12:06:04 +00:00
|
|
|
Opts: metabase.IteratePendingObjectsByKey{
|
|
|
|
ObjectLocation: pending.Location(),
|
|
|
|
},
|
|
|
|
Result: []metabase.ObjectEntry{objectEntryFromRaw(object)},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{Objects: []metabase.RawObject{object}}.Check(ctx, t, db)
|
2021-01-11 12:06:04 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("using streamID cursor", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
|
|
|
pending := []metabase.ObjectStream{metabasetest.RandObjectStream(), metabasetest.RandObjectStream(), metabasetest.RandObjectStream()}
|
2021-01-11 12:06:04 +00:00
|
|
|
|
|
|
|
location := pending[0].Location()
|
|
|
|
objects := make([]metabase.RawObject, 3)
|
|
|
|
expected := make([]metabase.ObjectEntry, 3)
|
|
|
|
|
|
|
|
for i, obj := range pending {
|
|
|
|
obj.ProjectID = location.ProjectID
|
|
|
|
obj.BucketName = location.BucketName
|
|
|
|
obj.ObjectKey = location.ObjectKey
|
|
|
|
obj.Version = metabase.Version(i + 1)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.CreatePendingObject(ctx, t, db, obj, 0)
|
2021-01-11 12:06:04 +00:00
|
|
|
|
|
|
|
objects[i] = metabase.RawObject{
|
|
|
|
ObjectStream: obj,
|
|
|
|
CreatedAt: now,
|
|
|
|
Status: metabase.Pending,
|
|
|
|
|
2021-05-06 12:42:20 +01:00
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
|
|
|
ZombieDeletionDeadline: &zombieDeadline,
|
2021-01-11 12:06:04 +00:00
|
|
|
}
|
|
|
|
expected[i] = objectEntryFromRaw(objects[i])
|
|
|
|
}
|
|
|
|
|
|
|
|
sort.Slice(expected, func(i, j int) bool {
|
2021-04-26 10:35:44 +01:00
|
|
|
return expected[i].StreamID.Less(expected[j].StreamID)
|
2021-01-11 12:06:04 +00:00
|
|
|
})
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.IteratePendingObjectsByKey{
|
2021-01-11 12:06:04 +00:00
|
|
|
Opts: metabase.IteratePendingObjectsByKey{
|
|
|
|
ObjectLocation: location,
|
|
|
|
BatchSize: 10,
|
|
|
|
Cursor: metabase.StreamIDCursor{
|
|
|
|
StreamID: expected[0].StreamID,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Result: expected[1:],
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{Objects: objects}.Check(ctx, t, db)
|
2021-01-11 12:06:04 +00:00
|
|
|
})
|
2022-08-26 21:44:06 +01:00
|
|
|
|
|
|
|
t.Run("same key different versions", func(t *testing.T) {
|
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
obj1 := metabasetest.RandObjectStream()
|
|
|
|
obj2 := obj1
|
|
|
|
obj2.StreamID = testrand.UUID()
|
|
|
|
obj2.Version = 2
|
|
|
|
|
|
|
|
pending := []metabase.ObjectStream{obj1, obj2}
|
|
|
|
|
|
|
|
location := pending[0].Location()
|
|
|
|
objects := make([]metabase.RawObject, 2)
|
|
|
|
expected := make([]metabase.ObjectEntry, 2)
|
|
|
|
|
|
|
|
for i, obj := range pending {
|
|
|
|
obj.ProjectID = location.ProjectID
|
|
|
|
obj.BucketName = location.BucketName
|
|
|
|
obj.ObjectKey = location.ObjectKey
|
|
|
|
obj.Version = metabase.Version(i + 1)
|
|
|
|
|
|
|
|
metabasetest.CreatePendingObject(ctx, t, db, obj, 0)
|
|
|
|
|
|
|
|
objects[i] = metabase.RawObject{
|
|
|
|
ObjectStream: obj,
|
|
|
|
CreatedAt: now,
|
|
|
|
Status: metabase.Pending,
|
|
|
|
|
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
|
|
|
ZombieDeletionDeadline: &zombieDeadline,
|
|
|
|
}
|
|
|
|
expected[i] = objectEntryFromRaw(objects[i])
|
|
|
|
}
|
|
|
|
|
|
|
|
sort.Slice(expected, func(i, j int) bool {
|
|
|
|
return expected[i].StreamID.Less(expected[j].StreamID)
|
|
|
|
})
|
|
|
|
|
|
|
|
metabasetest.IteratePendingObjectsByKey{
|
|
|
|
Opts: metabase.IteratePendingObjectsByKey{
|
|
|
|
ObjectLocation: location,
|
|
|
|
BatchSize: 1,
|
|
|
|
},
|
|
|
|
Result: expected,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
metabasetest.IteratePendingObjectsByKey{
|
|
|
|
Opts: metabase.IteratePendingObjectsByKey{
|
|
|
|
ObjectLocation: location,
|
|
|
|
BatchSize: 3,
|
|
|
|
},
|
|
|
|
Result: expected,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
metabasetest.Verify{Objects: objects}.Check(ctx, t, db)
|
|
|
|
})
|
2021-01-11 12:06:04 +00:00
|
|
|
})
|
|
|
|
}
|
2020-11-17 13:37:19 +00:00
|
|
|
|
|
|
|
func createObjects(ctx *testcontext.Context, t *testing.T, db *metabase.DB, numberOfObjects int, projectID uuid.UUID, bucketName string) []metabase.RawObject {
|
|
|
|
objects := make([]metabase.RawObject, numberOfObjects)
|
|
|
|
for i := 0; i < numberOfObjects; i++ {
|
2021-04-26 10:35:44 +01:00
|
|
|
obj := metabasetest.RandObjectStream()
|
2020-11-17 13:37:19 +00:00
|
|
|
obj.ProjectID = projectID
|
|
|
|
obj.BucketName = bucketName
|
|
|
|
now := time.Now()
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.CreateObject(ctx, t, db, obj, 0)
|
2020-11-17 13:37:19 +00:00
|
|
|
|
|
|
|
objects[i] = metabase.RawObject{
|
|
|
|
ObjectStream: obj,
|
|
|
|
CreatedAt: now,
|
2023-10-13 17:13:18 +01:00
|
|
|
Status: metabase.CommittedUnversioned,
|
2021-04-26 10:35:44 +01:00
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
2020-11-16 14:02:11 +00:00
|
|
|
}
|
|
|
|
}
|
2020-11-17 13:37:19 +00:00
|
|
|
sort.SliceStable(objects, func(i, j int) bool {
|
|
|
|
return objects[i].ObjectKey < objects[j].ObjectKey
|
|
|
|
})
|
|
|
|
return objects
|
2020-11-16 14:02:11 +00:00
|
|
|
}
|
|
|
|
|
2020-11-17 13:37:19 +00:00
|
|
|
func createObjectsWithKeys(ctx *testcontext.Context, t *testing.T, db *metabase.DB, projectID uuid.UUID, bucketName string, keys []metabase.ObjectKey) map[metabase.ObjectKey]metabase.ObjectEntry {
|
|
|
|
objects := make(map[metabase.ObjectKey]metabase.ObjectEntry, len(keys))
|
|
|
|
for _, key := range keys {
|
2021-04-26 10:35:44 +01:00
|
|
|
obj := metabasetest.RandObjectStream()
|
2020-11-17 13:37:19 +00:00
|
|
|
obj.ProjectID = projectID
|
|
|
|
obj.BucketName = bucketName
|
|
|
|
obj.ObjectKey = key
|
|
|
|
now := time.Now()
|
2020-11-16 14:02:11 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.CreateObject(ctx, t, db, obj, 0)
|
2020-11-17 13:37:19 +00:00
|
|
|
|
|
|
|
objects[key] = metabase.ObjectEntry{
|
2020-11-17 14:05:41 +00:00
|
|
|
ObjectKey: obj.ObjectKey,
|
|
|
|
Version: obj.Version,
|
|
|
|
StreamID: obj.StreamID,
|
|
|
|
CreatedAt: now,
|
2023-10-13 17:13:18 +01:00
|
|
|
Status: metabase.CommittedUnversioned,
|
2021-04-26 10:35:44 +01:00
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
2020-11-16 14:02:11 +00:00
|
|
|
}
|
|
|
|
}
|
2020-11-17 13:37:19 +00:00
|
|
|
|
|
|
|
return objects
|
|
|
|
}
|
|
|
|
|
|
|
|
func withoutPrefix(prefix metabase.ObjectKey, entries ...metabase.ObjectEntry) []metabase.ObjectEntry {
|
|
|
|
xs := make([]metabase.ObjectEntry, len(entries))
|
|
|
|
for i, e := range entries {
|
|
|
|
xs[i] = e
|
|
|
|
xs[i].ObjectKey = entries[i].ObjectKey[len(prefix):]
|
|
|
|
}
|
|
|
|
return xs
|
2020-11-16 14:02:11 +00:00
|
|
|
}
|
2020-11-17 14:05:41 +00:00
|
|
|
|
2021-06-25 15:01:12 +01:00
|
|
|
func withoutPrefix1(prefix metabase.ObjectKey, entry metabase.ObjectEntry) metabase.ObjectEntry {
|
|
|
|
entry.ObjectKey = entry.ObjectKey[len(prefix):]
|
|
|
|
return entry
|
|
|
|
}
|
|
|
|
|
2020-11-17 14:05:41 +00:00
|
|
|
func prefixEntry(key metabase.ObjectKey, status metabase.ObjectStatus) metabase.ObjectEntry {
|
|
|
|
return metabase.ObjectEntry{
|
|
|
|
IsPrefix: true,
|
|
|
|
ObjectKey: key,
|
|
|
|
Status: status,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func objectEntryFromRaw(m metabase.RawObject) metabase.ObjectEntry {
|
|
|
|
return metabase.ObjectEntry{
|
|
|
|
IsPrefix: false,
|
|
|
|
ObjectKey: m.ObjectKey,
|
|
|
|
Version: m.Version,
|
|
|
|
StreamID: m.StreamID,
|
|
|
|
CreatedAt: m.CreatedAt,
|
|
|
|
ExpiresAt: m.ExpiresAt,
|
|
|
|
Status: m.Status,
|
|
|
|
SegmentCount: m.SegmentCount,
|
|
|
|
EncryptedMetadataNonce: m.EncryptedMetadataNonce,
|
|
|
|
EncryptedMetadata: m.EncryptedMetadata,
|
|
|
|
EncryptedMetadataEncryptedKey: m.EncryptedMetadataEncryptedKey,
|
|
|
|
TotalEncryptedSize: m.TotalEncryptedSize,
|
2022-08-26 14:02:57 +01:00
|
|
|
TotalPlainSize: m.TotalPlainSize,
|
2020-11-17 14:05:41 +00:00
|
|
|
FixedSegmentSize: m.FixedSegmentSize,
|
|
|
|
Encryption: m.Encryption,
|
|
|
|
}
|
|
|
|
}
|
2022-07-21 15:32:50 +01:00
|
|
|
|
|
|
|
func BenchmarkNonRecursiveListing(b *testing.B) {
|
|
|
|
metabasetest.Bench(b, func(ctx *testcontext.Context, b *testing.B, db *metabase.DB) {
|
|
|
|
baseObj := metabasetest.RandObjectStream()
|
|
|
|
|
|
|
|
for i := 0; i < 10; i++ {
|
|
|
|
baseObj.ObjectKey = metabase.ObjectKey("foo/" + strconv.Itoa(i))
|
2022-08-01 10:50:46 +01:00
|
|
|
metabasetest.CreateObject(ctx, b, db, baseObj, 0)
|
|
|
|
|
2022-07-21 15:32:50 +01:00
|
|
|
baseObj.ObjectKey = metabase.ObjectKey("foo/prefixA/" + strconv.Itoa(i))
|
2022-08-01 10:50:46 +01:00
|
|
|
metabasetest.CreateObject(ctx, b, db, baseObj, 0)
|
|
|
|
|
2022-07-21 15:32:50 +01:00
|
|
|
baseObj.ObjectKey = metabase.ObjectKey("foo/prefixB/" + strconv.Itoa(i))
|
2022-08-01 10:50:46 +01:00
|
|
|
metabasetest.CreateObject(ctx, b, db, baseObj, 0)
|
2022-07-21 15:32:50 +01:00
|
|
|
}
|
|
|
|
|
2022-08-22 15:05:13 +01:00
|
|
|
for i := 0; i < 50; i++ {
|
|
|
|
baseObj.ObjectKey = metabase.ObjectKey("boo/foo" + strconv.Itoa(i) + "/object")
|
|
|
|
metabasetest.CreateObject(ctx, b, db, baseObj, 0)
|
|
|
|
}
|
|
|
|
|
2022-07-21 15:32:50 +01:00
|
|
|
b.Run("listing no prefix", func(b *testing.B) {
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
err := db.IterateObjectsAllVersionsWithStatus(ctx, metabase.IterateObjectsWithStatus{
|
|
|
|
ProjectID: baseObj.ProjectID,
|
|
|
|
BucketName: baseObj.BucketName,
|
|
|
|
BatchSize: 5,
|
2023-10-13 17:13:18 +01:00
|
|
|
Status: metabase.CommittedUnversioned,
|
2022-07-21 15:32:50 +01:00
|
|
|
}, func(ctx context.Context, oi metabase.ObjectsIterator) error {
|
|
|
|
entry := metabase.ObjectEntry{}
|
|
|
|
for oi.Next(ctx, &entry) {
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
require.NoError(b, err)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
b.Run("listing with prefix", func(b *testing.B) {
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
err := db.IterateObjectsAllVersionsWithStatus(ctx, metabase.IterateObjectsWithStatus{
|
|
|
|
ProjectID: baseObj.ProjectID,
|
|
|
|
BucketName: baseObj.BucketName,
|
|
|
|
Prefix: "foo/",
|
|
|
|
BatchSize: 5,
|
2023-10-13 17:13:18 +01:00
|
|
|
Status: metabase.CommittedUnversioned,
|
2022-07-21 15:32:50 +01:00
|
|
|
}, func(ctx context.Context, oi metabase.ObjectsIterator) error {
|
|
|
|
entry := metabase.ObjectEntry{}
|
|
|
|
for oi.Next(ctx, &entry) {
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
require.NoError(b, err)
|
|
|
|
}
|
|
|
|
})
|
2022-08-22 15:05:13 +01:00
|
|
|
|
|
|
|
b.Run("listing only prefix", func(b *testing.B) {
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
err := db.IterateObjectsAllVersionsWithStatus(ctx, metabase.IterateObjectsWithStatus{
|
|
|
|
ProjectID: baseObj.ProjectID,
|
|
|
|
BucketName: baseObj.BucketName,
|
|
|
|
Prefix: "boo/",
|
|
|
|
BatchSize: 5,
|
2023-10-13 17:13:18 +01:00
|
|
|
Status: metabase.CommittedUnversioned,
|
2022-08-22 15:05:13 +01:00
|
|
|
}, func(ctx context.Context, oi metabase.ObjectsIterator) error {
|
|
|
|
entry := metabase.ObjectEntry{}
|
|
|
|
for oi.Next(ctx, &entry) {
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
require.NoError(b, err)
|
|
|
|
}
|
|
|
|
})
|
2022-07-21 15:32:50 +01:00
|
|
|
})
|
|
|
|
}
|