forked from TrueCloudLab/frostfs-node
[#1085] writecache: persist in-memory objects before shutdown
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
parent
3215210d0c
commit
0ef3d5ab03
4 changed files with 58 additions and 4 deletions
|
@ -39,7 +39,7 @@ func testEvacuate(t *testing.T, objCount int, hasWriteCache bool) {
|
||||||
if !hasWriteCache {
|
if !hasWriteCache {
|
||||||
sh = newShard(t, false)
|
sh = newShard(t, false)
|
||||||
} else {
|
} else {
|
||||||
sh = newCustomShard(t, true,
|
sh = newCustomShard(t, t.TempDir(), true,
|
||||||
writecache.WithSmallObjectSize(wcSmallObjectSize),
|
writecache.WithSmallObjectSize(wcSmallObjectSize),
|
||||||
writecache.WithMaxObjectSize(wcBigObjectSize))
|
writecache.WithMaxObjectSize(wcBigObjectSize))
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,11 +27,10 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func newShard(t testing.TB, enableWriteCache bool) *shard.Shard {
|
func newShard(t testing.TB, enableWriteCache bool) *shard.Shard {
|
||||||
return newCustomShard(t, enableWriteCache, writecache.WithMaxMemSize(0))
|
return newCustomShard(t, t.TempDir(), enableWriteCache, writecache.WithMaxMemSize(0))
|
||||||
}
|
}
|
||||||
|
|
||||||
func newCustomShard(t testing.TB, enableWriteCache bool, wcOpts ...writecache.Option) *shard.Shard {
|
func newCustomShard(t testing.TB, rootPath string, enableWriteCache bool, wcOpts ...writecache.Option) *shard.Shard {
|
||||||
rootPath := t.Name()
|
|
||||||
if enableWriteCache {
|
if enableWriteCache {
|
||||||
rootPath = path.Join(rootPath, "wc")
|
rootPath = path.Join(rootPath, "wc")
|
||||||
} else {
|
} else {
|
||||||
|
|
52
pkg/local_object_storage/shard/shutdown_test.go
Normal file
52
pkg/local_object_storage/shard/shutdown_test.go
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
package shard_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"math/rand"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/nspcc-dev/neofs-node/pkg/core/object"
|
||||||
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard"
|
||||||
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/writecache"
|
||||||
|
cidtest "github.com/nspcc-dev/neofs-sdk-go/container/id/test"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestWriteCacheObjectLoss(t *testing.T) {
|
||||||
|
const (
|
||||||
|
smallSize = 1024
|
||||||
|
objCount = 100
|
||||||
|
)
|
||||||
|
|
||||||
|
objects := make([]*object.Object, objCount)
|
||||||
|
for i := range objects {
|
||||||
|
size := smallSize
|
||||||
|
//if i%2 == 0 {
|
||||||
|
size = smallSize / 2
|
||||||
|
//}
|
||||||
|
data := make([]byte, size)
|
||||||
|
rand.Read(data)
|
||||||
|
|
||||||
|
objects[i] = generateRawObjectWithPayload(cidtest.ID(), data).Object()
|
||||||
|
}
|
||||||
|
|
||||||
|
dir := t.TempDir()
|
||||||
|
wcOpts := []writecache.Option{
|
||||||
|
writecache.WithSmallObjectSize(smallSize),
|
||||||
|
writecache.WithMaxObjectSize(smallSize * 2)}
|
||||||
|
|
||||||
|
sh := newCustomShard(t, dir, true, wcOpts...)
|
||||||
|
|
||||||
|
for i := range objects {
|
||||||
|
_, err := sh.Put(new(shard.PutPrm).WithObject(objects[i]))
|
||||||
|
require.NoError(t, err)
|
||||||
|
}
|
||||||
|
require.NoError(t, sh.Close())
|
||||||
|
|
||||||
|
sh = newCustomShard(t, dir, true, wcOpts...)
|
||||||
|
defer releaseShard(sh, t)
|
||||||
|
|
||||||
|
for i := range objects {
|
||||||
|
_, err := sh.Get(new(shard.GetPrm).WithAddress(objects[i].Address()))
|
||||||
|
require.NoError(t, err, i)
|
||||||
|
}
|
||||||
|
}
|
|
@ -140,6 +140,9 @@ func (c *cache) Init() error {
|
||||||
|
|
||||||
// Close closes db connection and stops services. Executes ObjectCounters.FlushAndClose op.
|
// Close closes db connection and stops services. Executes ObjectCounters.FlushAndClose op.
|
||||||
func (c *cache) Close() error {
|
func (c *cache) Close() error {
|
||||||
|
// Finish all in-progress operations.
|
||||||
|
c.SetMode(ModeReadOnly)
|
||||||
|
|
||||||
close(c.closeCh)
|
close(c.closeCh)
|
||||||
c.objCounters.FlushAndClose()
|
c.objCounters.FlushAndClose()
|
||||||
return c.db.Close()
|
return c.db.Close()
|
||||||
|
|
Loading…
Reference in a new issue