2020-12-08 07:51:34 +00:00
|
|
|
package meta_test
|
2020-10-30 13:42:24 +00:00
|
|
|
|
|
|
|
import (
|
2023-04-12 14:01:29 +00:00
|
|
|
"context"
|
2022-03-21 13:34:31 +00:00
|
|
|
"runtime"
|
|
|
|
"strconv"
|
2023-05-19 15:06:20 +00:00
|
|
|
"sync/atomic"
|
2020-10-30 13:42:24 +00:00
|
|
|
"testing"
|
2022-03-21 13:34:31 +00:00
|
|
|
"time"
|
2020-10-30 13:42:24 +00:00
|
|
|
|
2023-03-07 13:38:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/object"
|
2023-03-20 14:10:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/internal/testutil"
|
2023-03-07 13:38:26 +00:00
|
|
|
meta "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/metabase"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/rand"
|
|
|
|
cidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id/test"
|
|
|
|
objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
|
|
|
|
objecttest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id/test"
|
2020-10-30 13:42:24 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
2022-03-21 13:34:31 +00:00
|
|
|
func prepareObjects(t testing.TB, n int) []*objectSDK.Object {
|
2022-05-31 17:00:41 +00:00
|
|
|
cnr := cidtest.ID()
|
2022-03-21 13:34:31 +00:00
|
|
|
parentID := objecttest.ID()
|
|
|
|
objs := make([]*objectSDK.Object, n)
|
|
|
|
for i := range objs {
|
2023-03-20 14:10:26 +00:00
|
|
|
objs[i] = testutil.GenerateObjectWithCID(cnr)
|
2022-03-21 13:34:31 +00:00
|
|
|
|
|
|
|
// FKBT indices.
|
|
|
|
attrs := make([]objectSDK.Attribute, 20)
|
|
|
|
for j := range attrs {
|
|
|
|
attrs[j].SetKey("abc" + strconv.FormatUint(rand.Uint64()%4, 16))
|
|
|
|
attrs[j].SetValue("xyz" + strconv.FormatUint(rand.Uint64()%4, 16))
|
|
|
|
}
|
|
|
|
objs[i].SetAttributes(attrs...)
|
|
|
|
|
|
|
|
// List indices.
|
|
|
|
if i%2 == 0 {
|
|
|
|
objs[i].SetParentID(parentID)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return objs
|
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkPut(b *testing.B) {
|
|
|
|
b.Run("parallel", func(b *testing.B) {
|
|
|
|
db := newDB(b,
|
2022-06-15 06:59:51 +00:00
|
|
|
meta.WithMaxBatchDelay(time.Millisecond*10),
|
|
|
|
meta.WithMaxBatchSize(runtime.NumCPU()))
|
2022-03-21 13:34:31 +00:00
|
|
|
// Ensure the benchmark is bound by CPU and not waiting batch-delay time.
|
|
|
|
b.SetParallelism(1)
|
|
|
|
|
2023-05-19 15:06:20 +00:00
|
|
|
var index atomic.Int64
|
|
|
|
index.Store(-1)
|
|
|
|
|
2022-03-21 13:34:31 +00:00
|
|
|
objs := prepareObjects(b, b.N)
|
|
|
|
b.ResetTimer()
|
|
|
|
b.ReportAllocs()
|
|
|
|
b.RunParallel(func(pb *testing.PB) {
|
|
|
|
for pb.Next() {
|
2023-05-19 15:06:20 +00:00
|
|
|
if err := metaPut(db, objs[index.Add(1)], nil); err != nil {
|
2022-03-21 13:34:31 +00:00
|
|
|
b.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
b.Run("sequential", func(b *testing.B) {
|
|
|
|
db := newDB(b,
|
2022-06-15 06:59:51 +00:00
|
|
|
meta.WithMaxBatchDelay(time.Millisecond*10),
|
|
|
|
meta.WithMaxBatchSize(1))
|
2023-05-19 15:06:20 +00:00
|
|
|
var index atomic.Int64
|
|
|
|
index.Store(-1)
|
2022-03-21 13:34:31 +00:00
|
|
|
objs := prepareObjects(b, b.N)
|
|
|
|
b.ResetTimer()
|
|
|
|
b.ReportAllocs()
|
|
|
|
for i := 0; i < b.N; i++ {
|
2023-05-19 15:06:20 +00:00
|
|
|
if err := metaPut(db, objs[index.Add(1)], nil); err != nil {
|
2022-03-21 13:34:31 +00:00
|
|
|
b.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-12-08 07:51:34 +00:00
|
|
|
func TestDB_PutBlobovnicaUpdate(t *testing.T) {
|
|
|
|
db := newDB(t)
|
2020-10-30 13:42:24 +00:00
|
|
|
|
2023-03-20 14:10:26 +00:00
|
|
|
raw1 := testutil.GenerateObject()
|
2022-07-06 14:09:50 +00:00
|
|
|
storageID := []byte{1, 2, 3, 4}
|
2020-10-30 13:42:24 +00:00
|
|
|
|
2022-07-06 14:09:50 +00:00
|
|
|
// put one object with storageID
|
|
|
|
err := metaPut(db, raw1, storageID)
|
2020-10-30 13:42:24 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-07-06 14:09:50 +00:00
|
|
|
fetchedStorageID, err := metaStorageID(db, object.AddressOf(raw1))
|
2020-12-08 07:51:34 +00:00
|
|
|
require.NoError(t, err)
|
2022-07-06 14:09:50 +00:00
|
|
|
require.Equal(t, storageID, fetchedStorageID)
|
2020-10-30 13:42:24 +00:00
|
|
|
|
2022-07-06 14:09:50 +00:00
|
|
|
t.Run("update storageID", func(t *testing.T) {
|
|
|
|
newID := []byte{5, 6, 7, 8}
|
2020-10-30 13:42:24 +00:00
|
|
|
|
2022-07-06 14:09:50 +00:00
|
|
|
err := metaPut(db, raw1, newID)
|
2020-12-08 07:51:34 +00:00
|
|
|
require.NoError(t, err)
|
2020-10-30 13:42:24 +00:00
|
|
|
|
2022-07-06 14:09:50 +00:00
|
|
|
fetchedBlobovniczaID, err := metaStorageID(db, object.AddressOf(raw1))
|
2020-12-08 07:51:34 +00:00
|
|
|
require.NoError(t, err)
|
2022-07-06 14:09:50 +00:00
|
|
|
require.Equal(t, newID, fetchedBlobovniczaID)
|
2020-12-08 07:51:34 +00:00
|
|
|
})
|
2020-10-30 13:42:24 +00:00
|
|
|
|
2022-07-06 14:09:50 +00:00
|
|
|
t.Run("update storageID on bad object", func(t *testing.T) {
|
2023-03-20 14:10:26 +00:00
|
|
|
raw2 := testutil.GenerateObject()
|
2022-03-03 14:19:05 +00:00
|
|
|
err := putBig(db, raw2)
|
2020-12-08 07:51:34 +00:00
|
|
|
require.NoError(t, err)
|
2020-10-30 13:42:24 +00:00
|
|
|
|
2022-07-06 14:09:50 +00:00
|
|
|
fetchedBlobovniczaID, err := metaStorageID(db, object.AddressOf(raw2))
|
2020-12-08 07:51:34 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Nil(t, fetchedBlobovniczaID)
|
|
|
|
})
|
2020-10-30 13:42:24 +00:00
|
|
|
}
|
2022-07-12 14:42:55 +00:00
|
|
|
|
2022-07-06 14:09:50 +00:00
|
|
|
func metaPut(db *meta.DB, obj *objectSDK.Object, id []byte) error {
|
2022-07-12 14:42:55 +00:00
|
|
|
var putPrm meta.PutPrm
|
2022-07-12 14:59:37 +00:00
|
|
|
putPrm.SetObject(obj)
|
2022-07-06 14:09:50 +00:00
|
|
|
putPrm.SetStorageID(id)
|
2022-07-12 14:42:55 +00:00
|
|
|
|
2023-04-12 14:01:29 +00:00
|
|
|
_, err := db.Put(context.Background(), putPrm)
|
2022-07-12 14:42:55 +00:00
|
|
|
|
|
|
|
return err
|
|
|
|
}
|