2024-08-28 15:32:30 +00:00
|
|
|
//go:build integration
|
|
|
|
|
|
|
|
package meta
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
"os"
|
|
|
|
"strconv"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2024-10-03 08:06:31 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/container"
|
2024-08-28 15:32:30 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/object"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/internal/testutil"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/shard/mode"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger/test"
|
2024-11-07 14:32:10 +00:00
|
|
|
objectV2 "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/api/object"
|
2024-08-28 15:32:30 +00:00
|
|
|
cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id"
|
|
|
|
cidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id/test"
|
|
|
|
objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
|
|
|
|
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"golang.org/x/sync/errgroup"
|
|
|
|
)
|
|
|
|
|
|
|
|
const upgradeFilePath = "/path/to/metabase.v2"
|
|
|
|
|
|
|
|
func TestUpgradeV2ToV3(t *testing.T) {
|
|
|
|
path := createTempCopy(t, upgradeFilePath)
|
|
|
|
defer func() {
|
|
|
|
require.NoError(t, os.Remove(path))
|
|
|
|
}()
|
|
|
|
db := New(WithPath(path), WithEpochState(epochState{e: 1000}), WithLogger(test.NewLogger(t)))
|
|
|
|
require.NoError(t, db.Open(context.Background(), mode.ReadWrite))
|
|
|
|
require.ErrorIs(t, db.Init(), ErrOutdatedVersion)
|
|
|
|
require.NoError(t, db.Close())
|
2024-10-03 08:06:31 +00:00
|
|
|
require.NoError(t, Upgrade(context.Background(), path, true, &testContainerInfoProvider{}, t.Log))
|
2024-08-28 15:32:30 +00:00
|
|
|
require.NoError(t, db.Open(context.Background(), mode.ReadWrite))
|
|
|
|
require.NoError(t, db.Init())
|
|
|
|
require.NoError(t, db.Close())
|
|
|
|
fmt.Println()
|
|
|
|
}
|
|
|
|
|
2024-10-03 08:06:31 +00:00
|
|
|
type testContainerInfoProvider struct{}
|
|
|
|
|
|
|
|
func (p *testContainerInfoProvider) Info(id cid.ID) (container.Info, error) {
|
|
|
|
return container.Info{}, nil
|
|
|
|
}
|
|
|
|
|
2024-08-28 15:32:30 +00:00
|
|
|
func createTempCopy(t *testing.T, path string) string {
|
|
|
|
src, err := os.Open(path)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
tmpPath := upgradeFilePath + time.Now().Format(time.RFC3339)
|
|
|
|
dest, err := os.Create(tmpPath)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
_, err = io.Copy(dest, src)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
require.NoError(t, src.Close())
|
|
|
|
require.NoError(t, dest.Close())
|
|
|
|
|
|
|
|
return tmpPath
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGenerateMetabaseFile(t *testing.T) {
|
|
|
|
t.Skip("for generating db")
|
|
|
|
const (
|
|
|
|
containersCount = 10_000
|
|
|
|
simpleObjectsCount = 500_000
|
|
|
|
complexObjectsCount = 500_000 // x2
|
|
|
|
deletedByGCMarksCount = 100_000
|
|
|
|
deletedByTombstoneCount = 100_000 // x2
|
|
|
|
lockedCount = 100_000 // x2
|
|
|
|
|
|
|
|
allocSize = 128 << 20
|
|
|
|
generateWorkersCount = 1_000
|
|
|
|
minEpoch = 1_000
|
|
|
|
maxFilename = 1_000
|
|
|
|
maxStorageID = 10_000
|
|
|
|
)
|
|
|
|
|
|
|
|
db := New(WithPath(upgradeFilePath), WithEpochState(epochState{e: minEpoch}), WithLogger(test.NewLogger(t)))
|
|
|
|
require.NoError(t, db.Open(context.Background(), mode.ReadWrite))
|
|
|
|
db.boltDB.AllocSize = allocSize
|
|
|
|
db.boltDB.NoSync = true
|
|
|
|
require.NoError(t, db.Init())
|
|
|
|
containers := make([]cid.ID, containersCount)
|
|
|
|
for i := range containers {
|
|
|
|
containers[i] = cidtest.ID()
|
|
|
|
}
|
|
|
|
oc, err := db.ObjectCounters()
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.True(t, oc.IsZero())
|
|
|
|
eg, ctx := errgroup.WithContext(context.Background())
|
|
|
|
eg.SetLimit(generateWorkersCount)
|
|
|
|
// simple objects
|
2024-08-30 16:20:55 +00:00
|
|
|
for i := range simpleObjectsCount {
|
2024-08-28 15:32:30 +00:00
|
|
|
i := i
|
|
|
|
eg.Go(func() error {
|
|
|
|
obj := testutil.GenerateObjectWithCID(containers[i%len(containers)])
|
2024-10-03 08:06:31 +00:00
|
|
|
testutil.AddAttribute(obj, objectSDK.AttributeFilePath, strconv.FormatInt(int64(i%maxFilename), 10))
|
2024-08-28 15:32:30 +00:00
|
|
|
testutil.AddAttribute(obj, objectV2.SysAttributeExpEpoch, strconv.FormatUint(uint64(i%minEpoch+minEpoch), 10))
|
|
|
|
_, err := db.Put(ctx, PutPrm{
|
|
|
|
obj: obj,
|
|
|
|
id: []byte(strconv.FormatInt(int64(i%maxStorageID), 10) + "/" + strconv.FormatInt(int64(i%maxStorageID), 10)),
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
}
|
|
|
|
require.NoError(t, eg.Wait())
|
2024-10-21 07:22:54 +00:00
|
|
|
db.log.Info(ctx, "simple objects generated")
|
2024-08-28 15:32:30 +00:00
|
|
|
eg, ctx = errgroup.WithContext(context.Background())
|
|
|
|
eg.SetLimit(generateWorkersCount)
|
|
|
|
// complex objects
|
2024-08-30 16:20:55 +00:00
|
|
|
for i := range complexObjectsCount {
|
2024-08-28 15:32:30 +00:00
|
|
|
i := i
|
|
|
|
eg.Go(func() error {
|
|
|
|
parent := testutil.GenerateObjectWithCID(containers[i%len(containers)])
|
|
|
|
child := testutil.GenerateObjectWithCID(containers[i%len(containers)])
|
|
|
|
child.SetParent(parent)
|
|
|
|
idParent, _ := parent.ID()
|
|
|
|
child.SetParentID(idParent)
|
2024-10-03 08:06:31 +00:00
|
|
|
testutil.AddAttribute(child, objectSDK.AttributeFilePath, strconv.FormatInt(int64(i%maxFilename), 10))
|
|
|
|
testutil.AddAttribute(parent, objectSDK.AttributeFilePath, strconv.FormatInt(int64(i%maxFilename), 10))
|
2024-08-28 15:32:30 +00:00
|
|
|
testutil.AddAttribute(child, objectV2.SysAttributeExpEpoch, strconv.FormatUint(uint64(i%minEpoch+minEpoch), 10))
|
|
|
|
testutil.AddAttribute(parent, objectV2.SysAttributeExpEpoch, strconv.FormatUint(uint64(i%minEpoch+minEpoch), 10))
|
|
|
|
_, err := db.Put(ctx, PutPrm{
|
|
|
|
obj: child,
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
}
|
|
|
|
require.NoError(t, eg.Wait())
|
2024-10-21 07:22:54 +00:00
|
|
|
db.log.Info(ctx, "complex objects generated")
|
2024-08-28 15:32:30 +00:00
|
|
|
eg, ctx = errgroup.WithContext(context.Background())
|
|
|
|
eg.SetLimit(generateWorkersCount)
|
|
|
|
// simple objects deleted by gc marks
|
2024-08-30 16:20:55 +00:00
|
|
|
for i := range deletedByGCMarksCount {
|
2024-08-28 15:32:30 +00:00
|
|
|
i := i
|
|
|
|
eg.Go(func() error {
|
|
|
|
obj := testutil.GenerateObjectWithCID(containers[i%len(containers)])
|
2024-10-03 08:06:31 +00:00
|
|
|
testutil.AddAttribute(obj, objectSDK.AttributeFilePath, strconv.FormatInt(int64(i%maxFilename), 10))
|
2024-08-28 15:32:30 +00:00
|
|
|
_, err := db.Put(ctx, PutPrm{
|
|
|
|
obj: obj,
|
|
|
|
id: []byte(strconv.FormatInt(int64(i%maxStorageID), 10) + "/" + strconv.FormatInt(int64(i%maxStorageID), 10)),
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
_, err = db.Inhume(ctx, InhumePrm{
|
|
|
|
target: []oid.Address{object.AddressOf(obj)},
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
}
|
|
|
|
require.NoError(t, eg.Wait())
|
2024-10-21 07:22:54 +00:00
|
|
|
db.log.Info(ctx, "simple objects deleted by gc marks generated")
|
2024-08-28 15:32:30 +00:00
|
|
|
eg, ctx = errgroup.WithContext(context.Background())
|
|
|
|
eg.SetLimit(10000)
|
|
|
|
// simple objects deleted by tombstones
|
2024-08-30 16:20:55 +00:00
|
|
|
for i := range deletedByTombstoneCount {
|
2024-08-28 15:32:30 +00:00
|
|
|
i := i
|
|
|
|
eg.Go(func() error {
|
|
|
|
obj := testutil.GenerateObjectWithCID(containers[i%len(containers)])
|
2024-10-03 08:06:31 +00:00
|
|
|
testutil.AddAttribute(obj, objectSDK.AttributeFilePath, strconv.FormatInt(int64(i%maxFilename), 10))
|
2024-08-28 15:32:30 +00:00
|
|
|
_, err := db.Put(ctx, PutPrm{
|
|
|
|
obj: obj,
|
|
|
|
id: []byte(strconv.FormatInt(int64(i%maxStorageID), 10) + "/" + strconv.FormatInt(int64(i%maxStorageID), 10)),
|
|
|
|
})
|
|
|
|
tomb := testutil.GenerateObjectWithCID(containers[i%len(containers)])
|
|
|
|
tomb.SetType(objectSDK.TypeTombstone)
|
|
|
|
_, err = db.Put(ctx, PutPrm{
|
|
|
|
obj: tomb,
|
|
|
|
id: []byte(strconv.FormatInt(int64(i%maxStorageID), 10) + "/" + strconv.FormatInt(int64(i%maxStorageID), 10)),
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
tombAddr := object.AddressOf(tomb)
|
|
|
|
_, err = db.Inhume(ctx, InhumePrm{
|
|
|
|
target: []oid.Address{object.AddressOf(obj)},
|
|
|
|
tomb: &tombAddr,
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
}
|
|
|
|
require.NoError(t, eg.Wait())
|
2024-10-21 07:22:54 +00:00
|
|
|
db.log.Info(ctx, "simple objects deleted by tombstones generated")
|
2024-08-28 15:32:30 +00:00
|
|
|
eg, ctx = errgroup.WithContext(context.Background())
|
|
|
|
eg.SetLimit(generateWorkersCount)
|
|
|
|
// simple objects locked by locks
|
2024-08-30 16:20:55 +00:00
|
|
|
for i := range lockedCount {
|
2024-08-28 15:32:30 +00:00
|
|
|
i := i
|
|
|
|
eg.Go(func() error {
|
|
|
|
obj := testutil.GenerateObjectWithCID(containers[i%len(containers)])
|
2024-10-03 08:06:31 +00:00
|
|
|
testutil.AddAttribute(obj, objectSDK.AttributeFilePath, strconv.FormatInt(int64(i%maxFilename), 10))
|
2024-08-28 15:32:30 +00:00
|
|
|
_, err := db.Put(ctx, PutPrm{
|
|
|
|
obj: obj,
|
|
|
|
id: []byte(strconv.FormatInt(int64(i%maxStorageID), 10) + "/" + strconv.FormatInt(int64(i%maxStorageID), 10)),
|
|
|
|
})
|
|
|
|
lock := testutil.GenerateObjectWithCID(containers[i%len(containers)])
|
|
|
|
lock.SetType(objectSDK.TypeLock)
|
|
|
|
testutil.AddAttribute(lock, objectV2.SysAttributeExpEpoch, strconv.FormatUint(uint64(i%minEpoch+minEpoch), 10))
|
|
|
|
_, err = db.Put(ctx, PutPrm{
|
|
|
|
obj: lock,
|
|
|
|
id: []byte(strconv.FormatInt(int64(i%maxStorageID), 10) + "/" + strconv.FormatInt(int64(i%maxStorageID), 10)),
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
err = db.Lock(ctx, containers[i%len(containers)], object.AddressOf(lock).Object(), []oid.ID{object.AddressOf(obj).Object()})
|
|
|
|
require.NoError(t, err)
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
}
|
|
|
|
require.NoError(t, eg.Wait())
|
2024-10-21 07:22:54 +00:00
|
|
|
db.log.Info(ctx, "simple objects locked by locks generated")
|
2024-08-28 15:32:30 +00:00
|
|
|
require.NoError(t, db.boltDB.Sync())
|
|
|
|
require.NoError(t, db.Close())
|
|
|
|
}
|