2020-12-01 16:58:34 +03:00
|
|
|
package shard_test
|
|
|
|
|
|
|
|
import (
|
2023-03-23 17:59:14 +03:00
|
|
|
"context"
|
2022-02-02 16:28:08 +03:00
|
|
|
"path/filepath"
|
2020-12-01 16:58:34 +03:00
|
|
|
"testing"
|
|
|
|
|
2023-03-07 16:38:26 +03: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"
|
|
|
|
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"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/writecache"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
|
2020-12-01 16:58:34 +03:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"go.uber.org/zap"
|
2022-07-11 15:34:17 +03:00
|
|
|
"go.uber.org/zap/zaptest"
|
2020-12-01 16:58:34 +03:00
|
|
|
)
|
|
|
|
|
2023-03-17 10:56:37 +03:00
|
|
|
type epochState struct {
|
|
|
|
Value uint64
|
|
|
|
}
|
2022-07-27 21:34:25 +03:00
|
|
|
|
|
|
|
func (s epochState) CurrentEpoch() uint64 {
|
2023-03-17 10:56:37 +03:00
|
|
|
return s.Value
|
2022-07-27 21:34:25 +03:00
|
|
|
}
|
|
|
|
|
2020-12-01 16:58:34 +03:00
|
|
|
func newShard(t testing.TB, enableWriteCache bool) *shard.Shard {
|
2022-01-20 19:56:07 +03:00
|
|
|
return newCustomShard(t, t.TempDir(), enableWriteCache,
|
2022-09-01 09:03:01 +03:00
|
|
|
nil,
|
2022-01-20 19:56:07 +03:00
|
|
|
nil)
|
2022-01-18 16:40:11 +03:00
|
|
|
}
|
|
|
|
|
2022-01-20 19:56:07 +03:00
|
|
|
func newCustomShard(t testing.TB, rootPath string, enableWriteCache bool, wcOpts []writecache.Option, bsOpts []blobstor.Option) *shard.Shard {
|
2020-12-01 16:58:34 +03:00
|
|
|
if enableWriteCache {
|
2022-02-02 16:28:08 +03:00
|
|
|
rootPath = filepath.Join(rootPath, "wc")
|
2020-12-01 16:58:34 +03:00
|
|
|
} else {
|
2022-02-02 16:28:08 +03:00
|
|
|
rootPath = filepath.Join(rootPath, "nowc")
|
2020-12-01 16:58:34 +03:00
|
|
|
}
|
|
|
|
|
2022-07-11 15:34:17 +03:00
|
|
|
if bsOpts == nil {
|
|
|
|
bsOpts = []blobstor.Option{
|
2022-09-28 10:41:01 +03:00
|
|
|
blobstor.WithLogger(&logger.Logger{Logger: zaptest.NewLogger(t)}),
|
2022-07-11 15:34:17 +03:00
|
|
|
blobstor.WithStorages([]blobstor.SubStorage{
|
|
|
|
{
|
|
|
|
Storage: blobovniczatree.NewBlobovniczaTree(
|
2022-09-28 10:41:01 +03:00
|
|
|
blobovniczatree.WithLogger(&logger.Logger{Logger: zaptest.NewLogger(t)}),
|
2022-07-11 15:34:17 +03:00
|
|
|
blobovniczatree.WithRootPath(filepath.Join(rootPath, "blob", "blobovnicza")),
|
|
|
|
blobovniczatree.WithBlobovniczaShallowDepth(1),
|
|
|
|
blobovniczatree.WithBlobovniczaShallowWidth(1)),
|
|
|
|
Policy: func(_ *object.Object, data []byte) bool {
|
|
|
|
return len(data) <= 1<<20
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Storage: fstree.New(
|
|
|
|
fstree.WithPath(filepath.Join(rootPath, "blob"))),
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-01 16:58:34 +03:00
|
|
|
opts := []shard.Option{
|
2022-09-28 10:41:01 +03:00
|
|
|
shard.WithLogger(&logger.Logger{Logger: zap.L()}),
|
2022-07-11 15:34:17 +03:00
|
|
|
shard.WithBlobStorOptions(bsOpts...),
|
2020-12-01 16:58:34 +03:00
|
|
|
shard.WithMetaBaseOptions(
|
2022-02-02 16:28:08 +03:00
|
|
|
meta.WithPath(filepath.Join(rootPath, "meta")),
|
2022-07-27 21:34:25 +03:00
|
|
|
meta.WithEpochState(epochState{}),
|
2020-12-01 16:58:34 +03:00
|
|
|
),
|
2022-06-09 11:09:18 +03:00
|
|
|
shard.WithPiloramaOptions(pilorama.WithPath(filepath.Join(rootPath, "pilorama"))),
|
2020-12-01 16:58:34 +03:00
|
|
|
shard.WithWriteCache(enableWriteCache),
|
|
|
|
shard.WithWriteCacheOptions(
|
2022-01-20 19:56:07 +03:00
|
|
|
append(
|
2022-02-02 16:28:08 +03:00
|
|
|
[]writecache.Option{writecache.WithPath(filepath.Join(rootPath, "wcache"))},
|
2022-01-20 19:56:07 +03:00
|
|
|
wcOpts...)...,
|
2020-12-01 16:58:34 +03:00
|
|
|
),
|
|
|
|
}
|
|
|
|
|
|
|
|
sh := shard.New(opts...)
|
|
|
|
|
|
|
|
require.NoError(t, sh.Open())
|
2023-03-23 17:59:14 +03:00
|
|
|
require.NoError(t, sh.Init(context.Background()))
|
2020-12-01 16:58:34 +03:00
|
|
|
|
|
|
|
return sh
|
|
|
|
}
|
|
|
|
|
|
|
|
func releaseShard(s *shard.Shard, t testing.TB) {
|
2022-07-11 15:34:17 +03:00
|
|
|
require.NoError(t, s.Close())
|
2020-12-01 16:58:34 +03:00
|
|
|
}
|