2021-04-14 08:50:21 +00:00
|
|
|
package engine
|
|
|
|
|
|
|
|
import (
|
2023-03-23 14:59:14 +00:00
|
|
|
"context"
|
2022-02-02 13:28:08 +00:00
|
|
|
"path/filepath"
|
2021-04-14 08:50:21 +00:00
|
|
|
"testing"
|
|
|
|
|
2023-03-07 13:38:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/blobovniczatree"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/fstree"
|
2023-03-21 10:38:44 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/teststore"
|
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/local_object_storage/pilorama"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/shard"
|
2023-08-23 07:53:42 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger/test"
|
2023-07-06 12:36:41 +00:00
|
|
|
objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
|
2021-04-14 08:50:21 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
2022-07-27 18:34:25 +00:00
|
|
|
type epochState struct{}
|
|
|
|
|
|
|
|
func (s epochState) CurrentEpoch() uint64 {
|
2022-09-09 10:27:15 +00:00
|
|
|
return 0
|
2022-07-27 18:34:25 +00:00
|
|
|
}
|
|
|
|
|
2023-03-30 11:58:20 +00:00
|
|
|
type testEngineWrapper struct {
|
|
|
|
engine *StorageEngine
|
2024-11-13 10:30:16 +00:00
|
|
|
shards []*shard.Shard
|
2023-03-30 11:58:20 +00:00
|
|
|
shardIDs []*shard.ID
|
|
|
|
}
|
2021-04-14 08:50:21 +00:00
|
|
|
|
2023-03-30 11:58:20 +00:00
|
|
|
func testNewEngine(t testing.TB, opts ...Option) *testEngineWrapper {
|
2024-11-13 10:30:16 +00:00
|
|
|
opts = append(testGetDefaultEngineOptions(t), opts...)
|
|
|
|
return &testEngineWrapper{engine: New(opts...)}
|
2023-03-30 11:58:20 +00:00
|
|
|
}
|
|
|
|
|
2024-11-13 10:30:16 +00:00
|
|
|
func (te *testEngineWrapper) setShardsNum(t testing.TB, num int) *testEngineWrapper {
|
|
|
|
return te.setShardsNumOpts(t, num, func(_ int) []shard.Option {
|
|
|
|
return testGetDefaultShardOptions(t)
|
|
|
|
})
|
|
|
|
}
|
2021-10-08 13:26:24 +00:00
|
|
|
|
2024-11-13 10:30:16 +00:00
|
|
|
func (te *testEngineWrapper) setShardsNumOpts(
|
|
|
|
t testing.TB, num int, shardOpts func(id int) []shard.Option,
|
|
|
|
) *testEngineWrapper {
|
|
|
|
te.shards = make([]*shard.Shard, num)
|
|
|
|
te.shardIDs = make([]*shard.ID, num)
|
|
|
|
for i := range num {
|
|
|
|
shard, err := te.engine.createShard(context.Background(), shardOpts(i))
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NoError(t, te.engine.addShard(shard))
|
|
|
|
te.shards[i] = shard
|
|
|
|
te.shardIDs[i] = shard.ID()
|
2021-04-14 08:50:21 +00:00
|
|
|
}
|
2024-11-13 10:30:16 +00:00
|
|
|
require.Len(t, te.engine.shards, num)
|
|
|
|
require.Len(t, te.engine.shardPools, num)
|
2023-03-30 11:58:20 +00:00
|
|
|
return te
|
|
|
|
}
|
2021-04-14 08:50:21 +00:00
|
|
|
|
2024-11-13 10:30:16 +00:00
|
|
|
func (te *testEngineWrapper) setShardsNumAdditionalOpts(
|
|
|
|
t testing.TB, num int, shardOpts func(id int) []shard.Option,
|
|
|
|
) *testEngineWrapper {
|
|
|
|
return te.setShardsNumOpts(t, num, func(id int) []shard.Option {
|
|
|
|
return append(testGetDefaultShardOptions(t), shardOpts(id)...)
|
|
|
|
})
|
|
|
|
}
|
2023-03-30 11:58:20 +00:00
|
|
|
|
2024-11-13 10:30:16 +00:00
|
|
|
// prepare calls Open and Init on the created engine.
|
|
|
|
func (te *testEngineWrapper) prepare(t testing.TB) *testEngineWrapper {
|
|
|
|
require.NoError(t, te.engine.Open(context.Background()))
|
|
|
|
require.NoError(t, te.engine.Init(context.Background()))
|
|
|
|
return te
|
2023-03-30 11:58:20 +00:00
|
|
|
}
|
|
|
|
|
2024-11-13 10:30:16 +00:00
|
|
|
func testGetDefaultEngineOptions(t testing.TB) []Option {
|
|
|
|
return []Option{
|
|
|
|
WithLogger(test.NewLogger(t)),
|
2023-03-30 11:58:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-11-13 10:30:16 +00:00
|
|
|
func testGetDefaultShardOptions(t testing.TB) []shard.Option {
|
|
|
|
return []shard.Option{
|
|
|
|
shard.WithLogger(test.NewLogger(t)),
|
|
|
|
shard.WithBlobStorOptions(
|
|
|
|
blobstor.WithStorages(
|
|
|
|
newStorages(t, t.TempDir(), 1<<20)),
|
|
|
|
blobstor.WithLogger(test.NewLogger(t)),
|
|
|
|
),
|
|
|
|
shard.WithPiloramaOptions(pilorama.WithPath(filepath.Join(t.TempDir(), "pilorama"))),
|
|
|
|
shard.WithMetaBaseOptions(
|
|
|
|
meta.WithPath(filepath.Join(t.TempDir(), "metabase")),
|
|
|
|
meta.WithPermissions(0o700),
|
|
|
|
meta.WithEpochState(epochState{}),
|
|
|
|
meta.WithLogger(test.NewLogger(t)),
|
|
|
|
),
|
2023-03-30 11:58:20 +00:00
|
|
|
}
|
2021-04-14 08:50:21 +00:00
|
|
|
}
|
|
|
|
|
2024-01-09 14:27:54 +00:00
|
|
|
func newStorages(t testing.TB, root string, smallSize uint64) []blobstor.SubStorage {
|
2022-07-11 12:34:17 +00:00
|
|
|
return []blobstor.SubStorage{
|
|
|
|
{
|
|
|
|
Storage: blobovniczatree.NewBlobovniczaTree(
|
2024-03-01 11:43:26 +00:00
|
|
|
context.Background(),
|
2022-07-11 12:34:17 +00:00
|
|
|
blobovniczatree.WithRootPath(filepath.Join(root, "blobovnicza")),
|
|
|
|
blobovniczatree.WithBlobovniczaShallowDepth(1),
|
|
|
|
blobovniczatree.WithBlobovniczaShallowWidth(1),
|
2024-01-09 14:27:54 +00:00
|
|
|
blobovniczatree.WithPermissions(0o700),
|
|
|
|
blobovniczatree.WithLogger(test.NewLogger(t))),
|
2023-07-06 12:36:41 +00:00
|
|
|
Policy: func(_ *objectSDK.Object, data []byte) bool {
|
2022-07-11 12:34:17 +00:00
|
|
|
return uint64(len(data)) < smallSize
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Storage: fstree.New(
|
|
|
|
fstree.WithPath(root),
|
2024-01-09 14:27:54 +00:00
|
|
|
fstree.WithDepth(1),
|
|
|
|
fstree.WithLogger(test.NewLogger(t))),
|
2022-07-11 12:34:17 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-21 10:38:44 +00:00
|
|
|
func newTestStorages(root string, smallSize uint64) ([]blobstor.SubStorage, *teststore.TestStore, *teststore.TestStore) {
|
|
|
|
smallFileStorage := teststore.New(
|
|
|
|
teststore.WithSubstorage(blobovniczatree.NewBlobovniczaTree(
|
2024-03-01 11:43:26 +00:00
|
|
|
context.Background(),
|
2023-03-21 10:38:44 +00:00
|
|
|
blobovniczatree.WithRootPath(filepath.Join(root, "blobovnicza")),
|
|
|
|
blobovniczatree.WithBlobovniczaShallowDepth(1),
|
|
|
|
blobovniczatree.WithBlobovniczaShallowWidth(1),
|
2023-10-31 11:56:55 +00:00
|
|
|
blobovniczatree.WithPermissions(0o700)),
|
2023-03-21 10:38:44 +00:00
|
|
|
))
|
|
|
|
largeFileStorage := teststore.New(
|
|
|
|
teststore.WithSubstorage(fstree.New(
|
|
|
|
fstree.WithPath(root),
|
|
|
|
fstree.WithDepth(1)),
|
|
|
|
))
|
|
|
|
return []blobstor.SubStorage{
|
|
|
|
{
|
|
|
|
Storage: smallFileStorage,
|
2023-07-06 12:36:41 +00:00
|
|
|
Policy: func(_ *objectSDK.Object, data []byte) bool {
|
2023-03-21 10:38:44 +00:00
|
|
|
return uint64(len(data)) < smallSize
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Storage: largeFileStorage,
|
|
|
|
},
|
|
|
|
}, smallFileStorage, largeFileStorage
|
|
|
|
}
|