frostfs-node/pkg/local_object_storage/shard/shard_test.go
Aleksey Savchuk e2a6663ef6
All checks were successful
Vulncheck / Vulncheck (pull_request) Successful in 3m0s
Pre-commit hooks / Pre-commit (pull_request) Successful in 3m33s
Tests and linters / gopls check (pull_request) Successful in 4m29s
Tests and linters / Tests with -race (pull_request) Successful in 6m11s
Tests and linters / Run gofumpt (pull_request) Successful in 7m7s
DCO action / DCO (pull_request) Successful in 7m34s
Tests and linters / Staticcheck (pull_request) Successful in 9m23s
Tests and linters / Tests (pull_request) Successful in 9m30s
Build / Build Components (pull_request) Successful in 10m10s
Tests and linters / Lint (pull_request) Successful in 10m23s
[#1445] shard/gc: Make handler and callback names more descriptive
Consider the following methods:
- `(*Shard).collectExpiredTombstones`
- `(*StorageEngines).processExpiredTombstones`
- `(*Shard).HandleExpiredTombstones`

All of them handle not tombstones but graves. `HandleExpiredTombstones`
in fact deletes tombstones but it does it based on graves it received.
So, rename all `...Tombstones` methods to `...Graves` method. It'll make
future changes in the garbage collector behavior simpler.

Also, rename all `...Locks` methods to `...LockObjects` because they
handle not locks but lock objects.

Signed-off-by: Aleksey Savchuk <a.savchuk@yadro.com>
2024-12-17 13:40:37 +03:00

113 lines
3.3 KiB
Go

package shard
import (
"context"
"path/filepath"
"testing"
"time"
"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/writecache"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger/test"
objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
"github.com/panjf2000/ants/v2"
"github.com/stretchr/testify/require"
)
type epochState struct {
Value uint64
}
func (s epochState) CurrentEpoch() uint64 {
return s.Value
}
type shardOptions struct {
rootPath string
wcOpts []writecache.Option
bsOpts []blobstor.Option
metaOptions []meta.Option
additionalShardOptions []Option
}
func newShard(t testing.TB, enableWriteCache bool) *Shard {
return newCustomShard(t, enableWriteCache, shardOptions{})
}
func newCustomShard(t testing.TB, enableWriteCache bool, o shardOptions) *Shard {
if o.rootPath == "" {
o.rootPath = t.TempDir()
}
var sh *Shard
if enableWriteCache {
o.wcOpts = append(
[]writecache.Option{writecache.WithPath(filepath.Join(o.rootPath, "wcache"))},
o.wcOpts...)
}
if o.bsOpts == nil {
o.bsOpts = []blobstor.Option{
blobstor.WithLogger(test.NewLogger(t)),
blobstor.WithStorages([]blobstor.SubStorage{
{
Storage: blobovniczatree.NewBlobovniczaTree(
context.Background(),
blobovniczatree.WithLogger(test.NewLogger(t)),
blobovniczatree.WithRootPath(filepath.Join(o.rootPath, "blob", "blobovnicza")),
blobovniczatree.WithBlobovniczaShallowDepth(1),
blobovniczatree.WithBlobovniczaShallowWidth(1)),
Policy: func(_ *objectSDK.Object, data []byte) bool {
return len(data) <= 1<<20
},
},
{
Storage: fstree.New(
fstree.WithPath(filepath.Join(o.rootPath, "blob"))),
},
}),
}
}
opts := []Option{
WithID(NewIDFromBytes([]byte{})),
WithLogger(test.NewLogger(t)),
WithBlobStorOptions(o.bsOpts...),
WithMetaBaseOptions(
append([]meta.Option{
meta.WithPath(filepath.Join(o.rootPath, "meta")), meta.WithEpochState(epochState{}),
},
o.metaOptions...)...,
),
WithPiloramaOptions(pilorama.WithPath(filepath.Join(o.rootPath, "pilorama"))),
WithWriteCache(enableWriteCache),
WithWriteCacheOptions(o.wcOpts),
WithDeletedLockCallback(func(ctx context.Context, addresses []oid.Address) {
sh.HandleDeletedLocks(ctx, addresses)
}),
WithExpiredLocksCallback(func(ctx context.Context, epoch uint64, a []oid.Address) {
sh.HandleExpiredLockObjects(ctx, epoch, a)
}),
WithGCWorkerPoolInitializer(func(sz int) util.WorkerPool {
pool, err := ants.NewPool(sz)
require.NoError(t, err)
return pool
}),
WithGCRemoverSleepInterval(100 * time.Millisecond),
}
opts = append(opts, o.additionalShardOptions...)
sh = New(opts...)
require.NoError(t, sh.Open(context.Background()))
require.NoError(t, sh.Init(context.Background()))
return sh
}