forked from TrueCloudLab/frostfs-node
Aleksey Savchuk
7fc6101bec
- Remove `testNewShard` and `setInitializedShards` because they violated the default engine workflow. The correct workflow is: first use `New()`, followed by `Open()`, and then `Init()`. As a result, adding new logic to `(*StorageEngine).Init` caused several tests to fail with a panic when attempting to access uninitialized resources. Now, all engines created with the test utils must be initialized manually. The new helper method `prepare` can be used for that purpose. - Additionally, `setInitializedShards` hardcoded the shard worker pool size, which prevented it from being configured in tests and benchmarks. This has been fixed as well. - Ensure engine initialization is done wherever it was missing. - Refactor `setShardsNumOpts`, `setShardsNumAdditionalOpts`, and `setShardsNum`. Make them all depend on `setShardsNumOpts`. Signed-off-by: Aleksey Savchuk <a.savchuk@yadro.com>
51 lines
1.3 KiB
Go
51 lines
1.3 KiB
Go
package engine
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/internal/testutil"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/shard"
|
|
cidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id/test"
|
|
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
|
|
oidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id/test"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func BenchmarkExists(b *testing.B) {
|
|
b.Run("2 shards", func(b *testing.B) {
|
|
benchmarkExists(b, 2)
|
|
})
|
|
b.Run("4 shards", func(b *testing.B) {
|
|
benchmarkExists(b, 4)
|
|
})
|
|
b.Run("8 shards", func(b *testing.B) {
|
|
benchmarkExists(b, 8)
|
|
})
|
|
}
|
|
|
|
func benchmarkExists(b *testing.B, shardNum int) {
|
|
e := testNewEngine(b).setShardsNum(b, shardNum).prepare(b).engine
|
|
defer func() { require.NoError(b, e.Close(context.Background())) }()
|
|
|
|
addr := oidtest.Address()
|
|
for range 100 {
|
|
obj := testutil.GenerateObjectWithCID(cidtest.ID())
|
|
err := Put(context.Background(), e, obj, false)
|
|
if err != nil {
|
|
b.Fatal(err)
|
|
}
|
|
}
|
|
|
|
b.ReportAllocs()
|
|
b.ResetTimer()
|
|
for range b.N {
|
|
var shPrm shard.ExistsPrm
|
|
shPrm.Address = addr
|
|
shPrm.ParentAddress = oid.Address{}
|
|
ok, _, err := e.exists(context.Background(), shPrm)
|
|
if err != nil || ok {
|
|
b.Fatalf("%t %v", ok, err)
|
|
}
|
|
}
|
|
}
|