[#668] shard/test: Move tests to the main package
Semantic patch (also, duplicate definitions are removed): ``` @@ var e identifier @@ -import "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/shard" -shard.e +e ``` Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
parent
aa23c6a83a
commit
bdecfbc1be
12 changed files with 79 additions and 99 deletions
|
@ -32,12 +32,6 @@ import (
|
||||||
"go.etcd.io/bbolt"
|
"go.etcd.io/bbolt"
|
||||||
)
|
)
|
||||||
|
|
||||||
type epochState struct{}
|
|
||||||
|
|
||||||
func (s epochState) CurrentEpoch() uint64 {
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
type objAddr struct {
|
type objAddr struct {
|
||||||
obj *objectSDK.Object
|
obj *objectSDK.Object
|
||||||
addr oid.Address
|
addr oid.Address
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package shard_test
|
package shard
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
@ -7,7 +7,6 @@ import (
|
||||||
|
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/object"
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/object"
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/internal/testutil"
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/internal/testutil"
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/shard"
|
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client"
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client"
|
||||||
cidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id/test"
|
cidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id/test"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
@ -36,8 +35,8 @@ func testShardDelete(t *testing.T, hasWriteCache bool) {
|
||||||
obj := testutil.GenerateObjectWithCID(cnr)
|
obj := testutil.GenerateObjectWithCID(cnr)
|
||||||
testutil.AddAttribute(obj, "foo", "bar")
|
testutil.AddAttribute(obj, "foo", "bar")
|
||||||
|
|
||||||
var putPrm shard.PutPrm
|
var putPrm PutPrm
|
||||||
var getPrm shard.GetPrm
|
var getPrm GetPrm
|
||||||
|
|
||||||
t.Run("big object", func(t *testing.T) {
|
t.Run("big object", func(t *testing.T) {
|
||||||
testutil.AddPayload(obj, 1<<20)
|
testutil.AddPayload(obj, 1<<20)
|
||||||
|
@ -45,7 +44,7 @@ func testShardDelete(t *testing.T, hasWriteCache bool) {
|
||||||
putPrm.SetObject(obj)
|
putPrm.SetObject(obj)
|
||||||
getPrm.SetAddress(object.AddressOf(obj))
|
getPrm.SetAddress(object.AddressOf(obj))
|
||||||
|
|
||||||
var delPrm shard.DeletePrm
|
var delPrm DeletePrm
|
||||||
delPrm.SetAddresses(object.AddressOf(obj))
|
delPrm.SetAddresses(object.AddressOf(obj))
|
||||||
|
|
||||||
_, err := sh.Put(context.Background(), putPrm)
|
_, err := sh.Put(context.Background(), putPrm)
|
||||||
|
@ -71,7 +70,7 @@ func testShardDelete(t *testing.T, hasWriteCache bool) {
|
||||||
putPrm.SetObject(obj)
|
putPrm.SetObject(obj)
|
||||||
getPrm.SetAddress(object.AddressOf(obj))
|
getPrm.SetAddress(object.AddressOf(obj))
|
||||||
|
|
||||||
var delPrm shard.DeletePrm
|
var delPrm DeletePrm
|
||||||
delPrm.SetAddresses(object.AddressOf(obj))
|
delPrm.SetAddresses(object.AddressOf(obj))
|
||||||
|
|
||||||
_, err := sh.Put(context.Background(), putPrm)
|
_, err := sh.Put(context.Background(), putPrm)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package shard_test
|
package shard
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
@ -10,7 +10,6 @@ import (
|
||||||
objectCore "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/object"
|
objectCore "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/object"
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/internal/testutil"
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/internal/testutil"
|
||||||
meta "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/metabase"
|
meta "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/metabase"
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/shard"
|
|
||||||
writecacheconfig "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/writecache/config"
|
writecacheconfig "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/writecache/config"
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client"
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client"
|
||||||
cidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id/test"
|
cidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id/test"
|
||||||
|
@ -55,7 +54,7 @@ func Test_GCDropsLockedExpiredSimpleObject(t *testing.T) {
|
||||||
lock.SetAttributes(lockExpirationAttr)
|
lock.SetAttributes(lockExpirationAttr)
|
||||||
lockID, _ := lock.ID()
|
lockID, _ := lock.ID()
|
||||||
|
|
||||||
var putPrm shard.PutPrm
|
var putPrm PutPrm
|
||||||
putPrm.SetObject(obj)
|
putPrm.SetObject(obj)
|
||||||
|
|
||||||
_, err := sh.Put(context.Background(), putPrm)
|
_, err := sh.Put(context.Background(), putPrm)
|
||||||
|
@ -69,9 +68,9 @@ func Test_GCDropsLockedExpiredSimpleObject(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
epoch.Value = 105
|
epoch.Value = 105
|
||||||
sh.NotificationChannel() <- shard.EventNewEpoch(epoch.Value)
|
sh.NotificationChannel() <- EventNewEpoch(epoch.Value)
|
||||||
|
|
||||||
var getPrm shard.GetPrm
|
var getPrm GetPrm
|
||||||
getPrm.SetAddress(objectCore.AddressOf(obj))
|
getPrm.SetAddress(objectCore.AddressOf(obj))
|
||||||
require.Eventually(t, func() bool {
|
require.Eventually(t, func() bool {
|
||||||
_, err = sh.Get(context.Background(), getPrm)
|
_, err = sh.Get(context.Background(), getPrm)
|
||||||
|
@ -141,7 +140,7 @@ func Test_GCDropsLockedExpiredComplexObject(t *testing.T) {
|
||||||
lock.SetAttributes(lockExpirationAttr)
|
lock.SetAttributes(lockExpirationAttr)
|
||||||
lockID, _ := lock.ID()
|
lockID, _ := lock.ID()
|
||||||
|
|
||||||
var putPrm shard.PutPrm
|
var putPrm PutPrm
|
||||||
|
|
||||||
for _, child := range children {
|
for _, child := range children {
|
||||||
putPrm.SetObject(child)
|
putPrm.SetObject(child)
|
||||||
|
@ -160,7 +159,7 @@ func Test_GCDropsLockedExpiredComplexObject(t *testing.T) {
|
||||||
_, err = sh.Put(context.Background(), putPrm)
|
_, err = sh.Put(context.Background(), putPrm)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
var getPrm shard.GetPrm
|
var getPrm GetPrm
|
||||||
getPrm.SetAddress(objectCore.AddressOf(parent))
|
getPrm.SetAddress(objectCore.AddressOf(parent))
|
||||||
|
|
||||||
_, err = sh.Get(context.Background(), getPrm)
|
_, err = sh.Get(context.Background(), getPrm)
|
||||||
|
@ -168,7 +167,7 @@ func Test_GCDropsLockedExpiredComplexObject(t *testing.T) {
|
||||||
require.True(t, errors.As(err, &splitInfoError), "split info must be provided")
|
require.True(t, errors.As(err, &splitInfoError), "split info must be provided")
|
||||||
|
|
||||||
epoch.Value = 105
|
epoch.Value = 105
|
||||||
sh.NotificationChannel() <- shard.EventNewEpoch(epoch.Value)
|
sh.NotificationChannel() <- EventNewEpoch(epoch.Value)
|
||||||
|
|
||||||
require.Eventually(t, func() bool {
|
require.Eventually(t, func() bool {
|
||||||
_, err = sh.Get(context.Background(), getPrm)
|
_, err = sh.Get(context.Background(), getPrm)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package shard_test
|
package shard
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
@ -9,7 +9,6 @@ import (
|
||||||
|
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/object"
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/object"
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/internal/testutil"
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/internal/testutil"
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/shard"
|
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client"
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client"
|
||||||
cidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id/test"
|
cidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id/test"
|
||||||
objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
|
objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
|
||||||
|
@ -35,8 +34,8 @@ func testShardGet(t *testing.T, hasWriteCache bool) {
|
||||||
sh := newShard(t, hasWriteCache)
|
sh := newShard(t, hasWriteCache)
|
||||||
defer releaseShard(sh, t)
|
defer releaseShard(sh, t)
|
||||||
|
|
||||||
var putPrm shard.PutPrm
|
var putPrm PutPrm
|
||||||
var getPrm shard.GetPrm
|
var getPrm GetPrm
|
||||||
|
|
||||||
t.Run("small object", func(t *testing.T) {
|
t.Run("small object", func(t *testing.T) {
|
||||||
obj := testutil.GenerateObject()
|
obj := testutil.GenerateObject()
|
||||||
|
@ -116,7 +115,7 @@ func testShardGet(t *testing.T, hasWriteCache bool) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func testGet(t *testing.T, sh *shard.Shard, getPrm shard.GetPrm, hasWriteCache bool) (shard.GetRes, error) {
|
func testGet(t *testing.T, sh *Shard, getPrm GetPrm, hasWriteCache bool) (GetRes, error) {
|
||||||
res, err := sh.Get(context.Background(), getPrm)
|
res, err := sh.Get(context.Background(), getPrm)
|
||||||
if hasWriteCache {
|
if hasWriteCache {
|
||||||
require.Eventually(t, func() bool {
|
require.Eventually(t, func() bool {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package shard_test
|
package shard
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
@ -8,7 +8,6 @@ import (
|
||||||
|
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/object"
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/object"
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/internal/testutil"
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/internal/testutil"
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/shard"
|
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client"
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client"
|
||||||
cidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id/test"
|
cidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id/test"
|
||||||
objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
|
objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
|
||||||
|
@ -33,8 +32,8 @@ func testShardHead(t *testing.T, hasWriteCache bool) {
|
||||||
sh := newShard(t, hasWriteCache)
|
sh := newShard(t, hasWriteCache)
|
||||||
defer releaseShard(sh, t)
|
defer releaseShard(sh, t)
|
||||||
|
|
||||||
var putPrm shard.PutPrm
|
var putPrm PutPrm
|
||||||
var headPrm shard.HeadPrm
|
var headPrm HeadPrm
|
||||||
|
|
||||||
t.Run("regular object", func(t *testing.T) {
|
t.Run("regular object", func(t *testing.T) {
|
||||||
obj := testutil.GenerateObject()
|
obj := testutil.GenerateObject()
|
||||||
|
@ -87,7 +86,7 @@ func testShardHead(t *testing.T, hasWriteCache bool) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func testHead(t *testing.T, sh *shard.Shard, headPrm shard.HeadPrm, hasWriteCache bool) (shard.HeadRes, error) {
|
func testHead(t *testing.T, sh *Shard, headPrm HeadPrm, hasWriteCache bool) (HeadRes, error) {
|
||||||
res, err := sh.Head(context.Background(), headPrm)
|
res, err := sh.Head(context.Background(), headPrm)
|
||||||
if hasWriteCache {
|
if hasWriteCache {
|
||||||
require.Eventually(t, func() bool {
|
require.Eventually(t, func() bool {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package shard_test
|
package shard
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
@ -6,7 +6,6 @@ import (
|
||||||
|
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/object"
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/object"
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/internal/testutil"
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/internal/testutil"
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/shard"
|
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client"
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client"
|
||||||
cidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id/test"
|
cidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id/test"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
@ -37,13 +36,13 @@ func testShardInhume(t *testing.T, hasWriteCache bool) {
|
||||||
|
|
||||||
ts := testutil.GenerateObjectWithCID(cnr)
|
ts := testutil.GenerateObjectWithCID(cnr)
|
||||||
|
|
||||||
var putPrm shard.PutPrm
|
var putPrm PutPrm
|
||||||
putPrm.SetObject(obj)
|
putPrm.SetObject(obj)
|
||||||
|
|
||||||
var inhPrm shard.InhumePrm
|
var inhPrm InhumePrm
|
||||||
inhPrm.SetTarget(object.AddressOf(ts), object.AddressOf(obj))
|
inhPrm.SetTarget(object.AddressOf(ts), object.AddressOf(obj))
|
||||||
|
|
||||||
var getPrm shard.GetPrm
|
var getPrm GetPrm
|
||||||
getPrm.SetAddress(object.AddressOf(obj))
|
getPrm.SetAddress(object.AddressOf(obj))
|
||||||
|
|
||||||
_, err := sh.Put(context.Background(), putPrm)
|
_, err := sh.Put(context.Background(), putPrm)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package shard_test
|
package shard
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
@ -7,7 +7,6 @@ import (
|
||||||
|
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/object"
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/object"
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/internal/testutil"
|
"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"
|
cidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id/test"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"golang.org/x/sync/errgroup"
|
"golang.org/x/sync/errgroup"
|
||||||
|
@ -31,7 +30,7 @@ func TestShard_List(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func testShardList(t *testing.T, sh *shard.Shard) {
|
func testShardList(t *testing.T, sh *Shard) {
|
||||||
const C = 10
|
const C = 10
|
||||||
const N = 5
|
const N = 5
|
||||||
|
|
||||||
|
@ -59,7 +58,7 @@ func testShardList(t *testing.T, sh *shard.Shard) {
|
||||||
objs[object.AddressOf(obj).EncodeToString()] = 0
|
objs[object.AddressOf(obj).EncodeToString()] = 0
|
||||||
mtx.Unlock()
|
mtx.Unlock()
|
||||||
|
|
||||||
var putPrm shard.PutPrm
|
var putPrm PutPrm
|
||||||
putPrm.SetObject(obj)
|
putPrm.SetObject(obj)
|
||||||
|
|
||||||
_, err := sh.Put(context.Background(), putPrm)
|
_, err := sh.Put(context.Background(), putPrm)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package shard_test
|
package shard
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
@ -11,7 +11,6 @@ import (
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/fstree"
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/fstree"
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/internal/testutil"
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/internal/testutil"
|
||||||
meta "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/metabase"
|
meta "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/metabase"
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/shard"
|
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger"
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger"
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client"
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client"
|
||||||
apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status"
|
apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status"
|
||||||
|
@ -26,13 +25,13 @@ import (
|
||||||
func TestShard_Lock(t *testing.T) {
|
func TestShard_Lock(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
var sh *shard.Shard
|
var sh *Shard
|
||||||
|
|
||||||
rootPath := t.TempDir()
|
rootPath := t.TempDir()
|
||||||
opts := []shard.Option{
|
opts := []Option{
|
||||||
shard.WithID(shard.NewIDFromBytes([]byte{})),
|
WithID(NewIDFromBytes([]byte{})),
|
||||||
shard.WithLogger(&logger.Logger{Logger: zap.NewNop()}),
|
WithLogger(&logger.Logger{Logger: zap.NewNop()}),
|
||||||
shard.WithBlobStorOptions(
|
WithBlobStorOptions(
|
||||||
blobstor.WithStorages([]blobstor.SubStorage{
|
blobstor.WithStorages([]blobstor.SubStorage{
|
||||||
{
|
{
|
||||||
Storage: blobovniczatree.NewBlobovniczaTree(
|
Storage: blobovniczatree.NewBlobovniczaTree(
|
||||||
|
@ -49,16 +48,16 @@ func TestShard_Lock(t *testing.T) {
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
shard.WithMetaBaseOptions(
|
WithMetaBaseOptions(
|
||||||
meta.WithPath(filepath.Join(rootPath, "meta")),
|
meta.WithPath(filepath.Join(rootPath, "meta")),
|
||||||
meta.WithEpochState(epochState{}),
|
meta.WithEpochState(epochState{}),
|
||||||
),
|
),
|
||||||
shard.WithDeletedLockCallback(func(_ context.Context, addresses []oid.Address) {
|
WithDeletedLockCallback(func(_ context.Context, addresses []oid.Address) {
|
||||||
sh.HandleDeletedLocks(addresses)
|
sh.HandleDeletedLocks(addresses)
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
|
|
||||||
sh = shard.New(opts...)
|
sh = New(opts...)
|
||||||
require.NoError(t, sh.Open())
|
require.NoError(t, sh.Open())
|
||||||
require.NoError(t, sh.Init(context.Background()))
|
require.NoError(t, sh.Init(context.Background()))
|
||||||
|
|
||||||
|
@ -76,7 +75,7 @@ func TestShard_Lock(t *testing.T) {
|
||||||
|
|
||||||
// put the object
|
// put the object
|
||||||
|
|
||||||
var putPrm shard.PutPrm
|
var putPrm PutPrm
|
||||||
putPrm.SetObject(obj)
|
putPrm.SetObject(obj)
|
||||||
|
|
||||||
_, err := sh.Put(context.Background(), putPrm)
|
_, err := sh.Put(context.Background(), putPrm)
|
||||||
|
@ -94,7 +93,7 @@ func TestShard_Lock(t *testing.T) {
|
||||||
t.Run("inhuming locked objects", func(t *testing.T) {
|
t.Run("inhuming locked objects", func(t *testing.T) {
|
||||||
ts := testutil.GenerateObjectWithCID(cnr)
|
ts := testutil.GenerateObjectWithCID(cnr)
|
||||||
|
|
||||||
var inhumePrm shard.InhumePrm
|
var inhumePrm InhumePrm
|
||||||
inhumePrm.SetTarget(objectcore.AddressOf(ts), objectcore.AddressOf(obj))
|
inhumePrm.SetTarget(objectcore.AddressOf(ts), objectcore.AddressOf(obj))
|
||||||
|
|
||||||
var objLockedErr *apistatus.ObjectLocked
|
var objLockedErr *apistatus.ObjectLocked
|
||||||
|
@ -110,7 +109,7 @@ func TestShard_Lock(t *testing.T) {
|
||||||
t.Run("inhuming lock objects", func(t *testing.T) {
|
t.Run("inhuming lock objects", func(t *testing.T) {
|
||||||
ts := testutil.GenerateObjectWithCID(cnr)
|
ts := testutil.GenerateObjectWithCID(cnr)
|
||||||
|
|
||||||
var inhumePrm shard.InhumePrm
|
var inhumePrm InhumePrm
|
||||||
inhumePrm.SetTarget(objectcore.AddressOf(ts), objectcore.AddressOf(lock))
|
inhumePrm.SetTarget(objectcore.AddressOf(ts), objectcore.AddressOf(lock))
|
||||||
|
|
||||||
_, err = sh.Inhume(context.Background(), inhumePrm)
|
_, err = sh.Inhume(context.Background(), inhumePrm)
|
||||||
|
@ -122,7 +121,7 @@ func TestShard_Lock(t *testing.T) {
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("force objects inhuming", func(t *testing.T) {
|
t.Run("force objects inhuming", func(t *testing.T) {
|
||||||
var inhumePrm shard.InhumePrm
|
var inhumePrm InhumePrm
|
||||||
inhumePrm.MarkAsGarbage(objectcore.AddressOf(lock))
|
inhumePrm.MarkAsGarbage(objectcore.AddressOf(lock))
|
||||||
inhumePrm.ForceRemoval()
|
inhumePrm.ForceRemoval()
|
||||||
|
|
||||||
|
@ -132,7 +131,7 @@ func TestShard_Lock(t *testing.T) {
|
||||||
// it should be possible to remove
|
// it should be possible to remove
|
||||||
// lock object now
|
// lock object now
|
||||||
|
|
||||||
inhumePrm = shard.InhumePrm{}
|
inhumePrm = InhumePrm{}
|
||||||
inhumePrm.MarkAsGarbage(objectcore.AddressOf(obj))
|
inhumePrm.MarkAsGarbage(objectcore.AddressOf(obj))
|
||||||
|
|
||||||
_, err = sh.Inhume(context.Background(), inhumePrm)
|
_, err = sh.Inhume(context.Background(), inhumePrm)
|
||||||
|
@ -140,7 +139,7 @@ func TestShard_Lock(t *testing.T) {
|
||||||
|
|
||||||
// check that object has been removed
|
// check that object has been removed
|
||||||
|
|
||||||
var getPrm shard.GetPrm
|
var getPrm GetPrm
|
||||||
getPrm.SetAddress(objectcore.AddressOf(obj))
|
getPrm.SetAddress(objectcore.AddressOf(obj))
|
||||||
|
|
||||||
_, err = sh.Get(context.Background(), getPrm)
|
_, err = sh.Get(context.Background(), getPrm)
|
||||||
|
@ -160,7 +159,7 @@ func TestShard_IsLocked(t *testing.T) {
|
||||||
|
|
||||||
// put the object
|
// put the object
|
||||||
|
|
||||||
var putPrm shard.PutPrm
|
var putPrm PutPrm
|
||||||
putPrm.SetObject(obj)
|
putPrm.SetObject(obj)
|
||||||
|
|
||||||
_, err := sh.Put(context.Background(), putPrm)
|
_, err := sh.Put(context.Background(), putPrm)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package shard_test
|
package shard
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
@ -12,7 +12,6 @@ import (
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/internal/testutil"
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/internal/testutil"
|
||||||
meta "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/metabase"
|
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/pilorama"
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/shard"
|
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/shard/mode"
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/shard/mode"
|
||||||
objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
|
objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
|
||||||
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
|
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
|
||||||
|
@ -126,9 +125,6 @@ func (m *metricsStore) DeleteShardMetrics() {
|
||||||
m.errCounter = 0
|
m.errCounter = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
const physical = "phy"
|
|
||||||
const logical = "logic"
|
|
||||||
|
|
||||||
func TestCounters(t *testing.T) {
|
func TestCounters(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
|
@ -163,7 +159,7 @@ func TestCounters(t *testing.T) {
|
||||||
totalPayload += oSize
|
totalPayload += oSize
|
||||||
}
|
}
|
||||||
|
|
||||||
var prm shard.PutPrm
|
var prm PutPrm
|
||||||
|
|
||||||
for i := 0; i < objNumber; i++ {
|
for i := 0; i < objNumber; i++ {
|
||||||
prm.SetObject(oo[i])
|
prm.SetObject(oo[i])
|
||||||
|
@ -178,7 +174,7 @@ func TestCounters(t *testing.T) {
|
||||||
require.Equal(t, totalPayload, mm.payloadSize())
|
require.Equal(t, totalPayload, mm.payloadSize())
|
||||||
|
|
||||||
t.Run("inhume_GC", func(t *testing.T) {
|
t.Run("inhume_GC", func(t *testing.T) {
|
||||||
var prm shard.InhumePrm
|
var prm InhumePrm
|
||||||
inhumedNumber := objNumber / 4
|
inhumedNumber := objNumber / 4
|
||||||
|
|
||||||
for i := 0; i < inhumedNumber; i++ {
|
for i := 0; i < inhumedNumber; i++ {
|
||||||
|
@ -197,7 +193,7 @@ func TestCounters(t *testing.T) {
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("inhume_TS", func(t *testing.T) {
|
t.Run("inhume_TS", func(t *testing.T) {
|
||||||
var prm shard.InhumePrm
|
var prm InhumePrm
|
||||||
ts := objectcore.AddressOf(testutil.GenerateObject())
|
ts := objectcore.AddressOf(testutil.GenerateObject())
|
||||||
|
|
||||||
phy := mm.getObjectCounter(physical)
|
phy := mm.getObjectCounter(physical)
|
||||||
|
@ -218,7 +214,7 @@ func TestCounters(t *testing.T) {
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("Delete", func(t *testing.T) {
|
t.Run("Delete", func(t *testing.T) {
|
||||||
var prm shard.DeletePrm
|
var prm DeletePrm
|
||||||
|
|
||||||
phy := mm.getObjectCounter(physical)
|
phy := mm.getObjectCounter(physical)
|
||||||
logic := mm.getObjectCounter(logical)
|
logic := mm.getObjectCounter(logical)
|
||||||
|
@ -244,7 +240,7 @@ func TestCounters(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func shardWithMetrics(t *testing.T, path string) (*shard.Shard, *metricsStore) {
|
func shardWithMetrics(t *testing.T, path string) (*Shard, *metricsStore) {
|
||||||
blobOpts := []blobstor.Option{
|
blobOpts := []blobstor.Option{
|
||||||
blobstor.WithStorages([]blobstor.SubStorage{
|
blobstor.WithStorages([]blobstor.SubStorage{
|
||||||
{
|
{
|
||||||
|
@ -264,14 +260,14 @@ func shardWithMetrics(t *testing.T, path string) (*shard.Shard, *metricsStore) {
|
||||||
cnrSize: make(map[string]int64),
|
cnrSize: make(map[string]int64),
|
||||||
}
|
}
|
||||||
|
|
||||||
sh := shard.New(
|
sh := New(
|
||||||
shard.WithID(shard.NewIDFromBytes([]byte{})),
|
WithID(NewIDFromBytes([]byte{})),
|
||||||
shard.WithBlobStorOptions(blobOpts...),
|
WithBlobStorOptions(blobOpts...),
|
||||||
shard.WithPiloramaOptions(pilorama.WithPath(filepath.Join(path, "pilorama"))),
|
WithPiloramaOptions(pilorama.WithPath(filepath.Join(path, "pilorama"))),
|
||||||
shard.WithMetaBaseOptions(
|
WithMetaBaseOptions(
|
||||||
meta.WithPath(filepath.Join(path, "meta")),
|
meta.WithPath(filepath.Join(path, "meta")),
|
||||||
meta.WithEpochState(epochState{})),
|
meta.WithEpochState(epochState{})),
|
||||||
shard.WithMetricsWriter(mm),
|
WithMetricsWriter(mm),
|
||||||
)
|
)
|
||||||
require.NoError(t, sh.Open())
|
require.NoError(t, sh.Open())
|
||||||
require.NoError(t, sh.Init(context.Background()))
|
require.NoError(t, sh.Init(context.Background()))
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package shard_test
|
package shard
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
@ -11,7 +11,6 @@ import (
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/blobovniczatree"
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/blobovniczatree"
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/fstree"
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/fstree"
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/internal/testutil"
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/internal/testutil"
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/shard"
|
|
||||||
writecacheconfig "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/writecache/config"
|
writecacheconfig "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/writecache/config"
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/writecache/writecachebbolt"
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/writecache/writecachebbolt"
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger/test"
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger/test"
|
||||||
|
@ -106,13 +105,13 @@ func testShardGetRange(t *testing.T, hasWriteCache bool) {
|
||||||
addr := object.AddressOf(obj)
|
addr := object.AddressOf(obj)
|
||||||
payload := slice.Copy(obj.Payload())
|
payload := slice.Copy(obj.Payload())
|
||||||
|
|
||||||
var putPrm shard.PutPrm
|
var putPrm PutPrm
|
||||||
putPrm.SetObject(obj)
|
putPrm.SetObject(obj)
|
||||||
|
|
||||||
_, err := sh.Put(context.Background(), putPrm)
|
_, err := sh.Put(context.Background(), putPrm)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
var rngPrm shard.RngPrm
|
var rngPrm RngPrm
|
||||||
rngPrm.SetAddress(addr)
|
rngPrm.SetAddress(addr)
|
||||||
rngPrm.SetRange(tc.rng.GetOffset(), tc.rng.GetLength())
|
rngPrm.SetRange(tc.rng.GetOffset(), tc.rng.GetLength())
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package shard_test
|
package shard
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
@ -11,7 +11,6 @@ import (
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/fstree"
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/fstree"
|
||||||
meta "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/metabase"
|
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/pilorama"
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/shard"
|
|
||||||
writecacheconfig "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/writecache/config"
|
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/writecachebadger"
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/writecache/writecachebbolt"
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/writecache/writecachebbolt"
|
||||||
|
@ -31,15 +30,15 @@ func (s epochState) CurrentEpoch() uint64 {
|
||||||
return s.Value
|
return s.Value
|
||||||
}
|
}
|
||||||
|
|
||||||
func newShard(t testing.TB, enableWriteCache bool) *shard.Shard {
|
func newShard(t testing.TB, enableWriteCache bool) *Shard {
|
||||||
return newCustomShard(t, t.TempDir(), enableWriteCache,
|
return newCustomShard(t, t.TempDir(), enableWriteCache,
|
||||||
writecacheconfig.Options{Type: writecacheconfig.TypeBBolt},
|
writecacheconfig.Options{Type: writecacheconfig.TypeBBolt},
|
||||||
nil,
|
nil,
|
||||||
nil)
|
nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func newCustomShard(t testing.TB, rootPath string, enableWriteCache bool, wcOpts writecacheconfig.Options, bsOpts []blobstor.Option, metaOptions []meta.Option) *shard.Shard {
|
func newCustomShard(t testing.TB, rootPath string, enableWriteCache bool, wcOpts writecacheconfig.Options, bsOpts []blobstor.Option, metaOptions []meta.Option) *Shard {
|
||||||
var sh *shard.Shard
|
var sh *Shard
|
||||||
if enableWriteCache {
|
if enableWriteCache {
|
||||||
rootPath = filepath.Join(rootPath, "wc")
|
rootPath = filepath.Join(rootPath, "wc")
|
||||||
switch wcOpts.Type {
|
switch wcOpts.Type {
|
||||||
|
@ -78,33 +77,33 @@ func newCustomShard(t testing.TB, rootPath string, enableWriteCache bool, wcOpts
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
opts := []shard.Option{
|
opts := []Option{
|
||||||
shard.WithID(shard.NewIDFromBytes([]byte{})),
|
WithID(NewIDFromBytes([]byte{})),
|
||||||
shard.WithLogger(test.NewLogger(t, true)),
|
WithLogger(test.NewLogger(t, true)),
|
||||||
shard.WithBlobStorOptions(bsOpts...),
|
WithBlobStorOptions(bsOpts...),
|
||||||
shard.WithMetaBaseOptions(
|
WithMetaBaseOptions(
|
||||||
append([]meta.Option{
|
append([]meta.Option{
|
||||||
meta.WithPath(filepath.Join(rootPath, "meta")), meta.WithEpochState(epochState{})},
|
meta.WithPath(filepath.Join(rootPath, "meta")), meta.WithEpochState(epochState{})},
|
||||||
metaOptions...)...,
|
metaOptions...)...,
|
||||||
),
|
),
|
||||||
shard.WithPiloramaOptions(pilorama.WithPath(filepath.Join(rootPath, "pilorama"))),
|
WithPiloramaOptions(pilorama.WithPath(filepath.Join(rootPath, "pilorama"))),
|
||||||
shard.WithWriteCache(enableWriteCache),
|
WithWriteCache(enableWriteCache),
|
||||||
shard.WithWriteCacheOptions(wcOpts),
|
WithWriteCacheOptions(wcOpts),
|
||||||
shard.WithDeletedLockCallback(func(_ context.Context, addresses []oid.Address) {
|
WithDeletedLockCallback(func(_ context.Context, addresses []oid.Address) {
|
||||||
sh.HandleDeletedLocks(addresses)
|
sh.HandleDeletedLocks(addresses)
|
||||||
}),
|
}),
|
||||||
shard.WithExpiredLocksCallback(func(ctx context.Context, epoch uint64, a []oid.Address) {
|
WithExpiredLocksCallback(func(ctx context.Context, epoch uint64, a []oid.Address) {
|
||||||
sh.HandleExpiredLocks(ctx, epoch, a)
|
sh.HandleExpiredLocks(ctx, epoch, a)
|
||||||
}),
|
}),
|
||||||
shard.WithGCWorkerPoolInitializer(func(sz int) util.WorkerPool {
|
WithGCWorkerPoolInitializer(func(sz int) util.WorkerPool {
|
||||||
pool, err := ants.NewPool(sz)
|
pool, err := ants.NewPool(sz)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
return pool
|
return pool
|
||||||
}),
|
}),
|
||||||
shard.WithGCRemoverSleepInterval(100 * time.Millisecond),
|
WithGCRemoverSleepInterval(100 * time.Millisecond),
|
||||||
}
|
}
|
||||||
|
|
||||||
sh = shard.New(opts...)
|
sh = New(opts...)
|
||||||
|
|
||||||
require.NoError(t, sh.Open())
|
require.NoError(t, sh.Open())
|
||||||
require.NoError(t, sh.Init(context.Background()))
|
require.NoError(t, sh.Init(context.Background()))
|
||||||
|
@ -112,6 +111,6 @@ func newCustomShard(t testing.TB, rootPath string, enableWriteCache bool, wcOpts
|
||||||
return sh
|
return sh
|
||||||
}
|
}
|
||||||
|
|
||||||
func releaseShard(s *shard.Shard, t testing.TB) {
|
func releaseShard(s *Shard, t testing.TB) {
|
||||||
require.NoError(t, s.Close())
|
require.NoError(t, s.Close())
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package shard_test
|
package shard
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
@ -7,7 +7,6 @@ import (
|
||||||
|
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/object"
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/object"
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/internal/testutil"
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/internal/testutil"
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/shard"
|
|
||||||
writecacheconfig "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/writecache/config"
|
writecacheconfig "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/writecache/config"
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/writecache/writecachebbolt"
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/writecache/writecachebbolt"
|
||||||
cidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id/test"
|
cidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id/test"
|
||||||
|
@ -50,7 +49,7 @@ func TestWriteCacheObjectLoss(t *testing.T) {
|
||||||
for i := range objects {
|
for i := range objects {
|
||||||
obj := objects[i]
|
obj := objects[i]
|
||||||
errG.Go(func() error {
|
errG.Go(func() error {
|
||||||
var putPrm shard.PutPrm
|
var putPrm PutPrm
|
||||||
putPrm.SetObject(obj)
|
putPrm.SetObject(obj)
|
||||||
_, err := sh.Put(context.Background(), putPrm)
|
_, err := sh.Put(context.Background(), putPrm)
|
||||||
return err
|
return err
|
||||||
|
@ -62,7 +61,7 @@ func TestWriteCacheObjectLoss(t *testing.T) {
|
||||||
sh = newCustomShard(t, dir, true, wcOpts, nil, nil)
|
sh = newCustomShard(t, dir, true, wcOpts, nil, nil)
|
||||||
defer releaseShard(sh, t)
|
defer releaseShard(sh, t)
|
||||||
|
|
||||||
var getPrm shard.GetPrm
|
var getPrm GetPrm
|
||||||
|
|
||||||
for i := range objects {
|
for i := range objects {
|
||||||
getPrm.SetAddress(object.AddressOf(objects[i]))
|
getPrm.SetAddress(object.AddressOf(objects[i]))
|
||||||
|
|
Loading…
Reference in a new issue