2023-08-31 12:47:06 +00:00
|
|
|
package shard
|
2020-12-01 13:58:34 +00:00
|
|
|
|
|
|
|
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"
|
2023-12-22 09:58:20 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/writecache"
|
2023-05-15 09:06:38 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util"
|
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"
|
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"
|
|
|
|
)
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2023-09-06 14:32:14 +00:00
|
|
|
type shardOptions struct {
|
|
|
|
rootPath string
|
2023-12-22 09:58:20 +00:00
|
|
|
wcOpts []writecache.Option
|
2023-09-06 14:32:14 +00:00
|
|
|
bsOpts []blobstor.Option
|
|
|
|
metaOptions []meta.Option
|
2023-09-06 15:03:04 +00:00
|
|
|
|
|
|
|
additionalShardOptions []Option
|
2023-09-06 14:32:14 +00:00
|
|
|
}
|
|
|
|
|
2023-08-31 12:47:06 +00:00
|
|
|
func newShard(t testing.TB, enableWriteCache bool) *Shard {
|
2023-09-06 14:51:15 +00:00
|
|
|
return newCustomShard(t, enableWriteCache, shardOptions{})
|
2022-01-18 13:40:11 +00:00
|
|
|
}
|
|
|
|
|
2023-09-06 14:32:14 +00:00
|
|
|
func newCustomShard(t testing.TB, enableWriteCache bool, o shardOptions) *Shard {
|
2023-09-06 14:48:00 +00:00
|
|
|
if o.rootPath == "" {
|
|
|
|
o.rootPath = t.TempDir()
|
|
|
|
}
|
|
|
|
|
2023-08-31 12:47:06 +00:00
|
|
|
var sh *Shard
|
2020-12-01 13:58:34 +00:00
|
|
|
if enableWriteCache {
|
2023-12-22 09:58:20 +00:00
|
|
|
o.wcOpts = append(
|
|
|
|
[]writecache.Option{writecache.WithPath(filepath.Join(o.rootPath, "wcache"))},
|
|
|
|
o.wcOpts...)
|
2020-12-01 13:58:34 +00:00
|
|
|
}
|
|
|
|
|
2023-09-06 14:32:14 +00:00
|
|
|
if o.bsOpts == nil {
|
|
|
|
o.bsOpts = []blobstor.Option{
|
2024-01-09 08:37:41 +00:00
|
|
|
blobstor.WithLogger(test.NewLogger(t)),
|
2022-07-11 12:34:17 +00:00
|
|
|
blobstor.WithStorages([]blobstor.SubStorage{
|
|
|
|
{
|
|
|
|
Storage: blobovniczatree.NewBlobovniczaTree(
|
2024-01-09 08:37:41 +00:00
|
|
|
blobovniczatree.WithLogger(test.NewLogger(t)),
|
2023-09-06 14:32:14 +00:00
|
|
|
blobovniczatree.WithRootPath(filepath.Join(o.rootPath, "blob", "blobovnicza")),
|
2022-07-11 12:34:17 +00:00
|
|
|
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(
|
2023-09-06 14:32:14 +00:00
|
|
|
fstree.WithPath(filepath.Join(o.rootPath, "blob"))),
|
2022-07-11 12:34:17 +00:00
|
|
|
},
|
|
|
|
}),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-31 12:47:06 +00:00
|
|
|
opts := []Option{
|
|
|
|
WithID(NewIDFromBytes([]byte{})),
|
2024-01-09 08:37:41 +00:00
|
|
|
WithLogger(test.NewLogger(t)),
|
2023-09-06 14:32:14 +00:00
|
|
|
WithBlobStorOptions(o.bsOpts...),
|
2023-08-31 12:47:06 +00:00
|
|
|
WithMetaBaseOptions(
|
2023-05-15 09:06:38 +00:00
|
|
|
append([]meta.Option{
|
2023-10-31 11:56:55 +00:00
|
|
|
meta.WithPath(filepath.Join(o.rootPath, "meta")), meta.WithEpochState(epochState{}),
|
|
|
|
},
|
2023-09-06 14:32:14 +00:00
|
|
|
o.metaOptions...)...,
|
2020-12-01 13:58:34 +00:00
|
|
|
),
|
2023-09-06 14:32:14 +00:00
|
|
|
WithPiloramaOptions(pilorama.WithPath(filepath.Join(o.rootPath, "pilorama"))),
|
2023-08-31 12:47:06 +00:00
|
|
|
WithWriteCache(enableWriteCache),
|
2023-09-06 14:32:14 +00:00
|
|
|
WithWriteCacheOptions(o.wcOpts),
|
2023-08-31 12:47:06 +00:00
|
|
|
WithDeletedLockCallback(func(_ context.Context, addresses []oid.Address) {
|
2023-05-15 09:06:38 +00:00
|
|
|
sh.HandleDeletedLocks(addresses)
|
|
|
|
}),
|
2023-08-31 12:47:06 +00:00
|
|
|
WithExpiredLocksCallback(func(ctx context.Context, epoch uint64, a []oid.Address) {
|
2023-05-15 09:06:38 +00:00
|
|
|
sh.HandleExpiredLocks(ctx, epoch, a)
|
|
|
|
}),
|
2023-08-31 12:47:06 +00:00
|
|
|
WithGCWorkerPoolInitializer(func(sz int) util.WorkerPool {
|
2023-05-15 09:06:38 +00:00
|
|
|
pool, err := ants.NewPool(sz)
|
|
|
|
require.NoError(t, err)
|
|
|
|
return pool
|
|
|
|
}),
|
2023-08-31 12:47:06 +00:00
|
|
|
WithGCRemoverSleepInterval(100 * time.Millisecond),
|
2020-12-01 13:58:34 +00:00
|
|
|
}
|
2023-09-06 15:03:04 +00:00
|
|
|
opts = append(opts, o.additionalShardOptions...)
|
2020-12-01 13:58:34 +00:00
|
|
|
|
2023-08-31 12:47:06 +00:00
|
|
|
sh = New(opts...)
|
2020-12-01 13:58:34 +00:00
|
|
|
|
2023-08-31 16:26:47 +00:00
|
|
|
require.NoError(t, sh.Open(context.Background()))
|
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
|
|
|
|
}
|