2023-08-31 12:47:06 +00:00
|
|
|
package shard
|
2022-01-18 14:27:07 +00:00
|
|
|
|
|
|
|
import (
|
2023-03-13 11:37:35 +00:00
|
|
|
"context"
|
2023-08-09 13:01:44 +00:00
|
|
|
"crypto/rand"
|
2022-01-18 14:27:07 +00:00
|
|
|
"testing"
|
|
|
|
|
2023-03-07 13:38:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/object"
|
2023-03-20 14:10:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/internal/testutil"
|
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/writecachebbolt"
|
2023-03-07 13:38:26 +00:00
|
|
|
cidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id/test"
|
|
|
|
objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
|
2022-01-18 14:27:07 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
2023-05-05 11:07:11 +00:00
|
|
|
"golang.org/x/sync/errgroup"
|
2022-01-18 14:27:07 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestWriteCacheObjectLoss(t *testing.T) {
|
2023-05-05 11:08:10 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2022-01-18 14:27:07 +00:00
|
|
|
const (
|
|
|
|
smallSize = 1024
|
|
|
|
objCount = 100
|
|
|
|
)
|
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
objects := make([]*objectSDK.Object, objCount)
|
2022-01-18 14:27:07 +00:00
|
|
|
for i := range objects {
|
|
|
|
size := smallSize
|
2022-03-03 14:19:05 +00:00
|
|
|
// if i%2 == 0 {
|
2022-01-18 14:27:07 +00:00
|
|
|
size = smallSize / 2
|
2022-03-03 14:19:05 +00:00
|
|
|
// }
|
2022-01-18 14:27:07 +00:00
|
|
|
data := make([]byte, size)
|
|
|
|
rand.Read(data)
|
|
|
|
|
2023-03-20 14:10:26 +00:00
|
|
|
objects[i] = testutil.GenerateObjectWithCIDWithPayload(cidtest.ID(), data)
|
2022-01-18 14:27:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
dir := t.TempDir()
|
2023-06-22 11:55:30 +00:00
|
|
|
wcOpts := writecacheconfig.Options{
|
|
|
|
Type: writecacheconfig.TypeBBolt,
|
|
|
|
BBoltOptions: []writecachebbolt.Option{
|
|
|
|
writecachebbolt.WithMaxObjectSize(smallSize * 2),
|
|
|
|
},
|
|
|
|
}
|
2022-01-18 14:27:07 +00:00
|
|
|
|
2023-09-06 14:51:15 +00:00
|
|
|
sh := newCustomShard(t, true, shardOptions{dontRelease: true, rootPath: dir, wcOpts: wcOpts})
|
2022-01-18 14:27:07 +00:00
|
|
|
|
2023-05-05 11:07:11 +00:00
|
|
|
var errG errgroup.Group
|
2022-01-18 14:27:07 +00:00
|
|
|
for i := range objects {
|
2023-05-05 11:07:11 +00:00
|
|
|
obj := objects[i]
|
|
|
|
errG.Go(func() error {
|
2023-08-31 12:47:06 +00:00
|
|
|
var putPrm PutPrm
|
2023-05-05 11:07:11 +00:00
|
|
|
putPrm.SetObject(obj)
|
|
|
|
_, err := sh.Put(context.Background(), putPrm)
|
|
|
|
return err
|
|
|
|
})
|
2022-01-18 14:27:07 +00:00
|
|
|
}
|
2023-05-05 11:07:11 +00:00
|
|
|
require.NoError(t, errG.Wait())
|
2022-01-18 14:27:07 +00:00
|
|
|
require.NoError(t, sh.Close())
|
|
|
|
|
2023-09-06 14:32:14 +00:00
|
|
|
sh = newCustomShard(t, true, shardOptions{rootPath: dir, wcOpts: wcOpts})
|
2022-01-18 14:27:07 +00:00
|
|
|
|
2023-08-31 12:47:06 +00:00
|
|
|
var getPrm GetPrm
|
2022-05-20 18:08:59 +00:00
|
|
|
|
2022-01-18 14:27:07 +00:00
|
|
|
for i := range objects {
|
2022-07-13 12:43:04 +00:00
|
|
|
getPrm.SetAddress(object.AddressOf(objects[i]))
|
2022-05-20 18:08:59 +00:00
|
|
|
|
2023-03-13 11:37:35 +00:00
|
|
|
_, err := sh.Get(context.Background(), getPrm)
|
2022-01-18 14:27:07 +00:00
|
|
|
require.NoError(t, err, i)
|
|
|
|
}
|
|
|
|
}
|