2020-12-01 13:58:34 +00:00
|
|
|
package shard_test
|
|
|
|
|
|
|
|
import (
|
2023-03-23 14:59:14 +00:00
|
|
|
"context"
|
2022-02-02 13:28:08 +00:00
|
|
|
"path/filepath"
|
2020-12-01 13:58:34 +00:00
|
|
|
"testing"
|
2023-05-15 09:06:38 +00:00
|
|
|
"time"
|
2020-12-01 13:58:34 +00:00
|
|
|
|
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"
|
|
|
|
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-06-22 11:55:30 +00:00
|
|
|
writecacheconfig "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/writecache/config"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/writecache/writecachebadger"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/writecache/writecachebbolt"
|
2023-05-15 09:06:38 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util"
|
2023-03-07 13:38:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger"
|
2023-07-06 12:36:41 +00:00
|
|
|
objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
|
2023-05-15 09:06:38 +00:00
|
|
|
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
|
|
|
|
"github.com/panjf2000/ants/v2"
|
2020-12-01 13:58:34 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"go.uber.org/zap"
|
2022-07-11 12:34:17 +00:00
|
|
|
"go.uber.org/zap/zaptest"
|
2020-12-01 13:58:34 +00:00
|
|
|
)
|
|
|
|
|
2023-03-17 07:56:37 +00:00
|
|
|
type epochState struct {
|
|
|
|
Value uint64
|
|
|
|
}
|
2022-07-27 18:34:25 +00:00
|
|
|
|
|
|
|
func (s epochState) CurrentEpoch() uint64 {
|
2023-03-17 07:56:37 +00:00
|
|
|
return s.Value
|
2022-07-27 18:34:25 +00:00
|
|
|
}
|
|
|
|
|
2020-12-01 13:58:34 +00:00
|
|
|
func newShard(t testing.TB, enableWriteCache bool) *shard.Shard {
|
2022-01-20 16:56:07 +00:00
|
|
|
return newCustomShard(t, t.TempDir(), enableWriteCache,
|
2023-06-22 11:55:30 +00:00
|
|
|
writecacheconfig.Options{Type: writecacheconfig.TypeBBolt},
|
2022-09-01 06:03:01 +00:00
|
|
|
nil,
|
2022-01-20 16:56:07 +00:00
|
|
|
nil)
|
2022-01-18 13:40:11 +00:00
|
|
|
}
|
|
|
|
|
2023-06-22 11:55:30 +00:00
|
|
|
func newCustomShard(t testing.TB, rootPath string, enableWriteCache bool, wcOpts writecacheconfig.Options, bsOpts []blobstor.Option, metaOptions []meta.Option) *shard.Shard {
|
2023-05-15 09:06:38 +00:00
|
|
|
var sh *shard.Shard
|
2020-12-01 13:58:34 +00:00
|
|
|
if enableWriteCache {
|
2022-02-02 13:28:08 +00:00
|
|
|
rootPath = filepath.Join(rootPath, "wc")
|
2023-06-22 11:55:30 +00:00
|
|
|
switch wcOpts.Type {
|
|
|
|
case writecacheconfig.TypeBBolt:
|
|
|
|
wcOpts.BBoltOptions = append(
|
|
|
|
[]writecachebbolt.Option{writecachebbolt.WithPath(filepath.Join(rootPath, "wcache"))},
|
|
|
|
wcOpts.BBoltOptions...)
|
|
|
|
case writecacheconfig.TypeBadger:
|
|
|
|
wcOpts.BadgerOptions = append(
|
|
|
|
[]writecachebadger.Option{writecachebadger.WithPath(filepath.Join(rootPath, "wcache"))},
|
|
|
|
wcOpts.BadgerOptions...)
|
|
|
|
}
|
2020-12-01 13:58:34 +00:00
|
|
|
} else {
|
2022-02-02 13:28:08 +00:00
|
|
|
rootPath = filepath.Join(rootPath, "nowc")
|
2020-12-01 13:58:34 +00:00
|
|
|
}
|
|
|
|
|
2022-07-11 12:34:17 +00:00
|
|
|
if bsOpts == nil {
|
|
|
|
bsOpts = []blobstor.Option{
|
2022-09-28 07:41:01 +00:00
|
|
|
blobstor.WithLogger(&logger.Logger{Logger: zaptest.NewLogger(t)}),
|
2022-07-11 12:34:17 +00:00
|
|
|
blobstor.WithStorages([]blobstor.SubStorage{
|
|
|
|
{
|
|
|
|
Storage: blobovniczatree.NewBlobovniczaTree(
|
2022-09-28 07:41:01 +00:00
|
|
|
blobovniczatree.WithLogger(&logger.Logger{Logger: zaptest.NewLogger(t)}),
|
2022-07-11 12:34:17 +00:00
|
|
|
blobovniczatree.WithRootPath(filepath.Join(rootPath, "blob", "blobovnicza")),
|
|
|
|
blobovniczatree.WithBlobovniczaShallowDepth(1),
|
|
|
|
blobovniczatree.WithBlobovniczaShallowWidth(1)),
|
2023-07-06 12:36:41 +00:00
|
|
|
Policy: func(_ *objectSDK.Object, data []byte) bool {
|
2022-07-11 12:34:17 +00:00
|
|
|
return len(data) <= 1<<20
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Storage: fstree.New(
|
|
|
|
fstree.WithPath(filepath.Join(rootPath, "blob"))),
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-01 13:58:34 +00:00
|
|
|
opts := []shard.Option{
|
2023-03-13 11:37:35 +00:00
|
|
|
shard.WithID(shard.NewIDFromBytes([]byte{})),
|
2022-09-28 07:41:01 +00:00
|
|
|
shard.WithLogger(&logger.Logger{Logger: zap.L()}),
|
2022-07-11 12:34:17 +00:00
|
|
|
shard.WithBlobStorOptions(bsOpts...),
|
2020-12-01 13:58:34 +00:00
|
|
|
shard.WithMetaBaseOptions(
|
2023-05-15 09:06:38 +00:00
|
|
|
append([]meta.Option{
|
|
|
|
meta.WithPath(filepath.Join(rootPath, "meta")), meta.WithEpochState(epochState{})},
|
|
|
|
metaOptions...)...,
|
2020-12-01 13:58:34 +00:00
|
|
|
),
|
2022-06-09 08:09:18 +00:00
|
|
|
shard.WithPiloramaOptions(pilorama.WithPath(filepath.Join(rootPath, "pilorama"))),
|
2020-12-01 13:58:34 +00:00
|
|
|
shard.WithWriteCache(enableWriteCache),
|
2023-06-22 11:55:30 +00:00
|
|
|
shard.WithWriteCacheOptions(wcOpts),
|
2023-05-15 09:06:38 +00:00
|
|
|
shard.WithDeletedLockCallback(func(_ context.Context, addresses []oid.Address) {
|
|
|
|
sh.HandleDeletedLocks(addresses)
|
|
|
|
}),
|
|
|
|
shard.WithExpiredLocksCallback(func(ctx context.Context, epoch uint64, a []oid.Address) {
|
|
|
|
sh.HandleExpiredLocks(ctx, epoch, a)
|
|
|
|
}),
|
|
|
|
shard.WithGCWorkerPoolInitializer(func(sz int) util.WorkerPool {
|
|
|
|
pool, err := ants.NewPool(sz)
|
|
|
|
require.NoError(t, err)
|
|
|
|
return pool
|
|
|
|
}),
|
|
|
|
shard.WithGCRemoverSleepInterval(1 * time.Millisecond),
|
2020-12-01 13:58:34 +00:00
|
|
|
}
|
|
|
|
|
2023-05-15 09:06:38 +00:00
|
|
|
sh = shard.New(opts...)
|
2020-12-01 13:58:34 +00:00
|
|
|
|
|
|
|
require.NoError(t, sh.Open())
|
2023-03-23 14:59:14 +00:00
|
|
|
require.NoError(t, sh.Init(context.Background()))
|
2020-12-01 13:58:34 +00:00
|
|
|
|
|
|
|
return sh
|
|
|
|
}
|
|
|
|
|
|
|
|
func releaseShard(s *shard.Shard, t testing.TB) {
|
2022-07-11 12:34:17 +00:00
|
|
|
require.NoError(t, s.Close())
|
2020-12-01 13:58:34 +00:00
|
|
|
}
|