2022-01-18 11:39:55 +00:00
|
|
|
package shard_test
|
|
|
|
|
|
|
|
import (
|
2022-01-20 16:56:07 +00:00
|
|
|
"bytes"
|
2022-01-18 11:39:55 +00:00
|
|
|
"io"
|
2022-01-18 14:07:30 +00:00
|
|
|
"math/rand"
|
2022-01-18 11:39:55 +00:00
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2022-01-20 16:56:07 +00:00
|
|
|
"github.com/klauspost/compress/zstd"
|
2022-01-18 11:39:55 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/core/object"
|
2022-01-20 16:56:07 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobovnicza"
|
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor"
|
2022-01-18 11:39:55 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard"
|
2022-06-28 14:05:08 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard/mode"
|
2022-01-18 13:40:11 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/writecache"
|
2022-01-18 11:39:55 +00:00
|
|
|
cidtest "github.com/nspcc-dev/neofs-sdk-go/container/id/test"
|
2022-03-03 14:19:05 +00:00
|
|
|
objectSDK "github.com/nspcc-dev/neofs-sdk-go/object"
|
2022-05-31 17:00:41 +00:00
|
|
|
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
2022-01-26 12:11:13 +00:00
|
|
|
objecttest "github.com/nspcc-dev/neofs-sdk-go/object/id/test"
|
2022-01-18 11:39:55 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
2022-01-24 12:40:42 +00:00
|
|
|
func TestDump(t *testing.T) {
|
2022-01-18 13:40:11 +00:00
|
|
|
t.Run("without write-cache", func(t *testing.T) {
|
2022-01-24 12:40:42 +00:00
|
|
|
testDump(t, 10, false)
|
2022-01-18 13:40:11 +00:00
|
|
|
})
|
|
|
|
t.Run("with write-cache", func(t *testing.T) {
|
|
|
|
// Put a bit more objects to write-cache to facilitate race-conditions.
|
2022-01-24 12:40:42 +00:00
|
|
|
testDump(t, 100, true)
|
2022-01-18 13:40:11 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-01-24 12:40:42 +00:00
|
|
|
func testDump(t *testing.T, objCount int, hasWriteCache bool) {
|
2022-01-18 13:40:11 +00:00
|
|
|
const (
|
|
|
|
wcSmallObjectSize = 1024 // 1 KiB, goes to write-cache memory
|
|
|
|
wcBigObjectSize = 4 * 1024 // 4 KiB, goes to write-cache FSTree
|
|
|
|
bsSmallObjectSize = 10 * 1024 // 10 KiB, goes to blobovnicza DB
|
|
|
|
bsBigObjectSize = 1024*1024 + 1 // > 1 MiB, goes to blobovnicza FSTree
|
|
|
|
)
|
|
|
|
|
|
|
|
var sh *shard.Shard
|
|
|
|
if !hasWriteCache {
|
|
|
|
sh = newShard(t, false)
|
|
|
|
} else {
|
2022-01-18 14:27:07 +00:00
|
|
|
sh = newCustomShard(t, t.TempDir(), true,
|
2022-01-20 16:56:07 +00:00
|
|
|
[]writecache.Option{
|
|
|
|
writecache.WithSmallObjectSize(wcSmallObjectSize),
|
|
|
|
writecache.WithMaxObjectSize(wcBigObjectSize),
|
|
|
|
},
|
|
|
|
nil)
|
2022-01-18 13:40:11 +00:00
|
|
|
}
|
2022-01-18 11:39:55 +00:00
|
|
|
defer releaseShard(sh, t)
|
|
|
|
|
|
|
|
out := filepath.Join(t.TempDir(), "dump")
|
2022-05-20 18:08:59 +00:00
|
|
|
var prm shard.DumpPrm
|
|
|
|
prm.WithPath(out)
|
2022-01-18 11:39:55 +00:00
|
|
|
|
|
|
|
t.Run("must be read-only", func(t *testing.T) {
|
2022-01-24 12:40:42 +00:00
|
|
|
_, err := sh.Dump(prm)
|
2022-04-29 10:22:29 +00:00
|
|
|
require.ErrorIs(t, err, shard.ErrMustBeReadOnly)
|
2022-01-18 11:39:55 +00:00
|
|
|
})
|
|
|
|
|
2022-06-28 14:05:08 +00:00
|
|
|
require.NoError(t, sh.SetMode(mode.ReadOnly))
|
2022-01-18 11:39:55 +00:00
|
|
|
outEmpty := out + ".empty"
|
2022-05-20 18:08:59 +00:00
|
|
|
var dumpPrm shard.DumpPrm
|
|
|
|
dumpPrm.WithPath(outEmpty)
|
|
|
|
|
|
|
|
res, err := sh.Dump(dumpPrm)
|
2022-01-18 11:39:55 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, 0, res.Count())
|
2022-06-28 14:05:08 +00:00
|
|
|
require.NoError(t, sh.SetMode(mode.ReadWrite))
|
2022-01-18 11:39:55 +00:00
|
|
|
|
2022-01-18 13:40:11 +00:00
|
|
|
// Approximate object header size.
|
|
|
|
const headerSize = 400
|
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
objects := make([]*objectSDK.Object, objCount)
|
2022-01-18 11:39:55 +00:00
|
|
|
for i := 0; i < objCount; i++ {
|
2022-05-31 17:00:41 +00:00
|
|
|
cnr := cidtest.ID()
|
2022-01-18 13:40:11 +00:00
|
|
|
var size int
|
|
|
|
switch i % 6 {
|
|
|
|
case 0, 1:
|
|
|
|
size = wcSmallObjectSize - headerSize
|
|
|
|
case 2, 3:
|
|
|
|
size = bsSmallObjectSize - headerSize
|
|
|
|
case 4:
|
|
|
|
size = wcBigObjectSize - headerSize
|
|
|
|
default:
|
|
|
|
size = bsBigObjectSize - headerSize
|
|
|
|
}
|
|
|
|
data := make([]byte, size)
|
2022-01-18 14:07:30 +00:00
|
|
|
rand.Read(data)
|
2022-05-31 17:00:41 +00:00
|
|
|
obj := generateObjectWithPayload(cnr, data)
|
2022-03-03 14:19:05 +00:00
|
|
|
objects[i] = obj
|
2022-01-18 11:39:55 +00:00
|
|
|
|
2022-05-20 18:08:59 +00:00
|
|
|
var prm shard.PutPrm
|
2022-07-13 12:43:04 +00:00
|
|
|
prm.SetObject(objects[i])
|
2022-01-18 11:39:55 +00:00
|
|
|
_, err := sh.Put(prm)
|
|
|
|
require.NoError(t, err)
|
|
|
|
}
|
|
|
|
|
2022-06-28 14:05:08 +00:00
|
|
|
require.NoError(t, sh.SetMode(mode.ReadOnly))
|
2022-01-18 11:39:55 +00:00
|
|
|
|
|
|
|
t.Run("invalid path", func(t *testing.T) {
|
2022-05-20 18:08:59 +00:00
|
|
|
var dumpPrm shard.DumpPrm
|
|
|
|
dumpPrm.WithPath("\x00")
|
|
|
|
|
|
|
|
_, err := sh.Dump(dumpPrm)
|
2022-01-18 11:39:55 +00:00
|
|
|
require.Error(t, err)
|
|
|
|
})
|
|
|
|
|
2022-01-24 12:40:42 +00:00
|
|
|
res, err = sh.Dump(prm)
|
2022-01-18 11:39:55 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, objCount, res.Count())
|
|
|
|
|
|
|
|
t.Run("restore", func(t *testing.T) {
|
|
|
|
sh := newShard(t, false)
|
|
|
|
defer releaseShard(sh, t)
|
|
|
|
|
|
|
|
t.Run("empty dump", func(t *testing.T) {
|
2022-05-20 18:08:59 +00:00
|
|
|
var restorePrm shard.RestorePrm
|
|
|
|
restorePrm.WithPath(outEmpty)
|
|
|
|
res, err := sh.Restore(restorePrm)
|
2022-01-18 11:39:55 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, 0, res.Count())
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("invalid path", func(t *testing.T) {
|
2022-05-20 18:08:59 +00:00
|
|
|
_, err := sh.Restore(*new(shard.RestorePrm))
|
2022-04-29 10:22:29 +00:00
|
|
|
require.ErrorIs(t, err, os.ErrNotExist)
|
2022-01-18 11:39:55 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("invalid file", func(t *testing.T) {
|
|
|
|
t.Run("invalid magic", func(t *testing.T) {
|
|
|
|
out := out + ".wrongmagic"
|
2022-03-18 11:12:58 +00:00
|
|
|
require.NoError(t, os.WriteFile(out, []byte{0, 0, 0, 0}, os.ModePerm))
|
2022-01-18 11:39:55 +00:00
|
|
|
|
2022-05-20 18:08:59 +00:00
|
|
|
var restorePrm shard.RestorePrm
|
|
|
|
restorePrm.WithPath(out)
|
|
|
|
|
|
|
|
_, err := sh.Restore(restorePrm)
|
2022-04-29 10:22:29 +00:00
|
|
|
require.ErrorIs(t, err, shard.ErrInvalidMagic)
|
2022-01-18 11:39:55 +00:00
|
|
|
})
|
|
|
|
|
2022-03-18 11:12:58 +00:00
|
|
|
fileData, err := os.ReadFile(out)
|
2022-01-18 11:39:55 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
t.Run("incomplete size", func(t *testing.T) {
|
|
|
|
out := out + ".wrongsize"
|
|
|
|
fileData := append(fileData, 1)
|
2022-03-18 11:12:58 +00:00
|
|
|
require.NoError(t, os.WriteFile(out, fileData, os.ModePerm))
|
2022-01-18 11:39:55 +00:00
|
|
|
|
2022-05-20 18:08:59 +00:00
|
|
|
var restorePrm shard.RestorePrm
|
|
|
|
restorePrm.WithPath(out)
|
|
|
|
|
|
|
|
_, err := sh.Restore(restorePrm)
|
2022-04-29 10:22:29 +00:00
|
|
|
require.ErrorIs(t, err, io.ErrUnexpectedEOF)
|
2022-01-18 11:39:55 +00:00
|
|
|
})
|
|
|
|
t.Run("incomplete object data", func(t *testing.T) {
|
|
|
|
out := out + ".wrongsize"
|
|
|
|
fileData := append(fileData, 1, 0, 0, 0)
|
2022-03-18 11:12:58 +00:00
|
|
|
require.NoError(t, os.WriteFile(out, fileData, os.ModePerm))
|
2022-01-18 11:39:55 +00:00
|
|
|
|
2022-05-20 18:08:59 +00:00
|
|
|
var restorePrm shard.RestorePrm
|
|
|
|
restorePrm.WithPath(out)
|
|
|
|
|
|
|
|
_, err := sh.Restore(restorePrm)
|
2022-04-29 10:22:29 +00:00
|
|
|
require.ErrorIs(t, err, io.EOF)
|
2022-01-18 11:39:55 +00:00
|
|
|
})
|
|
|
|
t.Run("invalid object", func(t *testing.T) {
|
|
|
|
out := out + ".wrongobj"
|
2022-01-20 10:45:29 +00:00
|
|
|
fileData := append(fileData, 1, 0, 0, 0, 0xFF, 4, 0, 0, 0, 1, 2, 3, 4)
|
2022-03-18 11:12:58 +00:00
|
|
|
require.NoError(t, os.WriteFile(out, fileData, os.ModePerm))
|
2022-01-18 11:39:55 +00:00
|
|
|
|
2022-05-20 18:08:59 +00:00
|
|
|
var restorePrm shard.RestorePrm
|
|
|
|
restorePrm.WithPath(out)
|
|
|
|
|
|
|
|
_, err := sh.Restore(restorePrm)
|
2022-01-18 11:39:55 +00:00
|
|
|
require.Error(t, err)
|
2022-01-20 10:45:29 +00:00
|
|
|
|
|
|
|
t.Run("skip errors", func(t *testing.T) {
|
2022-01-20 16:56:07 +00:00
|
|
|
sh := newCustomShard(t, filepath.Join(t.TempDir(), "ignore"), false, nil, nil)
|
2022-01-20 10:45:29 +00:00
|
|
|
defer releaseShard(sh, t)
|
|
|
|
|
2022-05-20 18:08:59 +00:00
|
|
|
var restorePrm shard.RestorePrm
|
|
|
|
restorePrm.WithPath(out)
|
|
|
|
restorePrm.WithIgnoreErrors(true)
|
|
|
|
|
|
|
|
res, err := sh.Restore(restorePrm)
|
2022-01-20 10:45:29 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, objCount, res.Count())
|
|
|
|
require.Equal(t, 2, res.FailCount())
|
|
|
|
})
|
2022-01-18 11:39:55 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2022-05-20 18:08:59 +00:00
|
|
|
var prm shard.RestorePrm
|
|
|
|
prm.WithPath(out)
|
2022-01-18 11:39:55 +00:00
|
|
|
t.Run("must allow write", func(t *testing.T) {
|
2022-06-28 14:05:08 +00:00
|
|
|
require.NoError(t, sh.SetMode(mode.ReadOnly))
|
2022-01-18 11:39:55 +00:00
|
|
|
|
|
|
|
_, err := sh.Restore(prm)
|
2022-04-29 10:22:29 +00:00
|
|
|
require.ErrorIs(t, err, shard.ErrReadOnlyMode)
|
2022-01-18 11:39:55 +00:00
|
|
|
})
|
|
|
|
|
2022-06-28 14:05:08 +00:00
|
|
|
require.NoError(t, sh.SetMode(mode.ReadWrite))
|
2022-01-18 11:39:55 +00:00
|
|
|
|
|
|
|
checkRestore(t, sh, prm, objects)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestStream(t *testing.T) {
|
|
|
|
sh1 := newCustomShard(t, filepath.Join(t.TempDir(), "shard1"), false, nil, nil)
|
|
|
|
defer releaseShard(sh1, t)
|
|
|
|
|
|
|
|
sh2 := newCustomShard(t, filepath.Join(t.TempDir(), "shard2"), false, nil, nil)
|
|
|
|
defer releaseShard(sh2, t)
|
|
|
|
|
|
|
|
const objCount = 5
|
2022-03-03 14:19:05 +00:00
|
|
|
objects := make([]*objectSDK.Object, objCount)
|
2022-01-18 11:39:55 +00:00
|
|
|
for i := 0; i < objCount; i++ {
|
2022-05-31 17:00:41 +00:00
|
|
|
cnr := cidtest.ID()
|
|
|
|
obj := generateObjectWithCID(t, cnr)
|
2022-03-03 14:19:05 +00:00
|
|
|
objects[i] = obj
|
2022-01-18 11:39:55 +00:00
|
|
|
|
2022-05-20 18:08:59 +00:00
|
|
|
var prm shard.PutPrm
|
2022-07-13 12:43:04 +00:00
|
|
|
prm.SetObject(objects[i])
|
2022-01-18 11:39:55 +00:00
|
|
|
_, err := sh1.Put(prm)
|
|
|
|
require.NoError(t, err)
|
|
|
|
}
|
|
|
|
|
2022-06-28 14:05:08 +00:00
|
|
|
require.NoError(t, sh1.SetMode(mode.ReadOnly))
|
2022-01-18 11:39:55 +00:00
|
|
|
|
|
|
|
r, w := io.Pipe()
|
|
|
|
finish := make(chan struct{})
|
|
|
|
|
|
|
|
go func() {
|
2022-05-20 18:08:59 +00:00
|
|
|
var dumpPrm shard.DumpPrm
|
|
|
|
dumpPrm.WithStream(w)
|
|
|
|
|
|
|
|
res, err := sh1.Dump(dumpPrm)
|
2022-01-18 11:39:55 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, objCount, res.Count())
|
|
|
|
require.NoError(t, w.Close())
|
|
|
|
close(finish)
|
|
|
|
}()
|
|
|
|
|
2022-05-20 18:08:59 +00:00
|
|
|
var restorePrm shard.RestorePrm
|
|
|
|
restorePrm.WithStream(r)
|
|
|
|
|
|
|
|
checkRestore(t, sh2, restorePrm, objects)
|
2022-01-18 11:39:55 +00:00
|
|
|
require.Eventually(t, func() bool {
|
|
|
|
select {
|
|
|
|
case <-finish:
|
|
|
|
return true
|
|
|
|
default:
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}, time.Second, time.Millisecond)
|
|
|
|
}
|
|
|
|
|
2022-05-20 18:08:59 +00:00
|
|
|
func checkRestore(t *testing.T, sh *shard.Shard, prm shard.RestorePrm, objects []*objectSDK.Object) {
|
2022-01-18 11:39:55 +00:00
|
|
|
res, err := sh.Restore(prm)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, len(objects), res.Count())
|
|
|
|
|
2022-05-20 18:08:59 +00:00
|
|
|
var getPrm shard.GetPrm
|
|
|
|
|
2022-01-18 11:39:55 +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
|
|
|
res, err := sh.Get(getPrm)
|
2022-01-18 11:39:55 +00:00
|
|
|
require.NoError(t, err)
|
2022-01-18 14:07:30 +00:00
|
|
|
require.Equal(t, objects[i], res.Object())
|
2022-01-18 11:39:55 +00:00
|
|
|
}
|
|
|
|
}
|
2022-01-20 16:56:07 +00:00
|
|
|
|
2022-01-24 12:40:42 +00:00
|
|
|
func TestDumpIgnoreErrors(t *testing.T) {
|
2022-01-20 16:56:07 +00:00
|
|
|
const (
|
|
|
|
wcSmallObjectSize = 512 // goes to write-cache memory
|
|
|
|
wcBigObjectSize = wcSmallObjectSize << 1 // goes to write-cache FSTree
|
|
|
|
bsSmallObjectSize = wcSmallObjectSize << 2 // goes to blobovnicza DB
|
|
|
|
|
|
|
|
objCount = 10
|
|
|
|
headerSize = 400
|
|
|
|
)
|
|
|
|
|
|
|
|
dir := t.TempDir()
|
|
|
|
bsPath := filepath.Join(dir, "blob")
|
|
|
|
bsOpts := []blobstor.Option{
|
|
|
|
blobstor.WithSmallSizeLimit(bsSmallObjectSize),
|
|
|
|
blobstor.WithRootPath(bsPath),
|
|
|
|
blobstor.WithCompressObjects(true),
|
|
|
|
blobstor.WithShallowDepth(1),
|
|
|
|
blobstor.WithBlobovniczaShallowDepth(1),
|
|
|
|
blobstor.WithBlobovniczaShallowWidth(2),
|
|
|
|
blobstor.WithBlobovniczaOpenedCacheSize(1),
|
|
|
|
}
|
|
|
|
wcPath := filepath.Join(dir, "writecache")
|
|
|
|
wcOpts := []writecache.Option{
|
|
|
|
writecache.WithPath(wcPath),
|
|
|
|
writecache.WithSmallObjectSize(wcSmallObjectSize),
|
|
|
|
writecache.WithMaxObjectSize(wcBigObjectSize),
|
|
|
|
}
|
|
|
|
sh := newCustomShard(t, dir, true, wcOpts, bsOpts)
|
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
objects := make([]*objectSDK.Object, objCount)
|
2022-01-20 16:56:07 +00:00
|
|
|
for i := 0; i < objCount; i++ {
|
|
|
|
size := (wcSmallObjectSize << (i % 4)) - headerSize
|
2022-03-03 14:19:05 +00:00
|
|
|
obj := generateObjectWithPayload(cidtest.ID(), make([]byte, size))
|
|
|
|
objects[i] = obj
|
2022-01-20 16:56:07 +00:00
|
|
|
|
2022-05-20 18:08:59 +00:00
|
|
|
var prm shard.PutPrm
|
2022-07-13 12:43:04 +00:00
|
|
|
prm.SetObject(objects[i])
|
2022-01-20 16:56:07 +00:00
|
|
|
_, err := sh.Put(prm)
|
|
|
|
require.NoError(t, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
releaseShard(sh, t)
|
|
|
|
|
|
|
|
b := bytes.NewBuffer(nil)
|
|
|
|
badObject := make([]byte, 1000)
|
|
|
|
enc, err := zstd.NewWriter(b)
|
|
|
|
require.NoError(t, err)
|
|
|
|
corruptedData := enc.EncodeAll(badObject, nil)
|
|
|
|
for i := 4; i < len(corruptedData); i++ {
|
|
|
|
corruptedData[i] ^= 0xFF
|
|
|
|
}
|
|
|
|
|
|
|
|
// There are 3 different types of errors to consider.
|
|
|
|
// To setup envirionment we use implementation details so this test must be updated
|
|
|
|
// if any of them are changed.
|
|
|
|
{
|
|
|
|
// 1. Invalid object in fs tree.
|
|
|
|
// 1.1. Invalid compressed data.
|
2022-05-12 16:37:46 +00:00
|
|
|
addr := cidtest.ID().EncodeToString() + "." + objecttest.ID().EncodeToString()
|
2022-01-20 16:56:07 +00:00
|
|
|
dirName := filepath.Join(bsPath, addr[:2])
|
|
|
|
require.NoError(t, os.MkdirAll(dirName, os.ModePerm))
|
2022-03-18 11:12:58 +00:00
|
|
|
require.NoError(t, os.WriteFile(filepath.Join(dirName, addr[2:]), corruptedData, os.ModePerm))
|
2022-01-20 16:56:07 +00:00
|
|
|
|
|
|
|
// 1.2. Unreadable file.
|
2022-05-31 17:00:41 +00:00
|
|
|
addr = cidtest.ID().EncodeToString() + "." + objecttest.ID().EncodeToString()
|
2022-01-20 16:56:07 +00:00
|
|
|
dirName = filepath.Join(bsPath, addr[:2])
|
|
|
|
require.NoError(t, os.MkdirAll(dirName, os.ModePerm))
|
|
|
|
|
|
|
|
fname := filepath.Join(dirName, addr[2:])
|
2022-03-18 11:12:58 +00:00
|
|
|
require.NoError(t, os.WriteFile(fname, []byte{}, 0))
|
2022-01-20 16:56:07 +00:00
|
|
|
|
|
|
|
// 1.3. Unreadable dir.
|
|
|
|
require.NoError(t, os.MkdirAll(filepath.Join(bsPath, "ZZ"), 0))
|
|
|
|
}
|
|
|
|
|
|
|
|
bsOpts = append(bsOpts, blobstor.WithBlobovniczaShallowWidth(3))
|
|
|
|
sh = newCustomShard(t, dir, true, wcOpts, bsOpts)
|
2022-06-28 14:05:08 +00:00
|
|
|
require.NoError(t, sh.SetMode(mode.ReadOnly))
|
2022-01-20 16:56:07 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
// 2. Invalid object in blobovnicza.
|
|
|
|
// 2.1. Invalid blobovnicza.
|
|
|
|
bTree := filepath.Join(bsPath, "blobovnicza")
|
|
|
|
data := make([]byte, 1024)
|
|
|
|
rand.Read(data)
|
2022-03-18 11:12:58 +00:00
|
|
|
require.NoError(t, os.WriteFile(filepath.Join(bTree, "0", "2"), data, 0))
|
2022-01-20 16:56:07 +00:00
|
|
|
|
|
|
|
// 2.2. Invalid object in valid blobovnicza.
|
2022-05-23 14:21:14 +00:00
|
|
|
var prm blobovnicza.PutPrm
|
2022-05-31 17:00:41 +00:00
|
|
|
prm.SetAddress(oid.Address{})
|
2022-01-20 16:56:07 +00:00
|
|
|
prm.SetMarshaledObject(corruptedData)
|
|
|
|
b := blobovnicza.New(blobovnicza.WithPath(filepath.Join(bTree, "1", "2")))
|
|
|
|
require.NoError(t, b.Open())
|
|
|
|
_, err := b.Put(prm)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NoError(t, b.Close())
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
// 3. Invalid object in write-cache. Note that because shard is read-only
|
|
|
|
// the object won't be flushed.
|
2022-05-31 17:00:41 +00:00
|
|
|
addr := cidtest.ID().EncodeToString() + "." + objecttest.ID().EncodeToString()
|
2022-01-20 16:56:07 +00:00
|
|
|
dir := filepath.Join(wcPath, addr[:1])
|
|
|
|
require.NoError(t, os.MkdirAll(dir, os.ModePerm))
|
2022-03-18 11:12:58 +00:00
|
|
|
require.NoError(t, os.WriteFile(filepath.Join(dir, addr[1:]), nil, 0))
|
2022-01-20 16:56:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
out := filepath.Join(t.TempDir(), "out.dump")
|
2022-05-20 18:08:59 +00:00
|
|
|
var dumpPrm shard.DumpPrm
|
|
|
|
dumpPrm.WithPath(out)
|
|
|
|
dumpPrm.WithIgnoreErrors(true)
|
|
|
|
res, err := sh.Dump(dumpPrm)
|
2022-01-20 16:56:07 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, objCount, res.Count())
|
|
|
|
}
|