forked from TrueCloudLab/frostfs-node
[#1085] shard: rename Evacuate
to Dump
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
parent
d06425c852
commit
adb80bebb2
3 changed files with 27 additions and 27 deletions
|
@ -12,49 +12,49 @@ import (
|
||||||
|
|
||||||
var dumpMagic = []byte("NEOF")
|
var dumpMagic = []byte("NEOF")
|
||||||
|
|
||||||
// EvacuatePrm groups the parameters of Evacuate operation.
|
// DumpPrm groups the parameters of Dump operation.
|
||||||
type EvacuatePrm struct {
|
type DumpPrm struct {
|
||||||
path string
|
path string
|
||||||
stream io.Writer
|
stream io.Writer
|
||||||
ignoreErrors bool
|
ignoreErrors bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// WithPath is an Evacuate option to set the destination path.
|
// WithPath is an Dump option to set the destination path.
|
||||||
func (p *EvacuatePrm) WithPath(path string) *EvacuatePrm {
|
func (p *DumpPrm) WithPath(path string) *DumpPrm {
|
||||||
p.path = path
|
p.path = path
|
||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
|
|
||||||
// WithStream is an Evacuate option to set the destination stream.
|
// WithStream is an Dump option to set the destination stream.
|
||||||
// It takes priority over `path` option.
|
// It takes priority over `path` option.
|
||||||
func (p *EvacuatePrm) WithStream(r io.Writer) *EvacuatePrm {
|
func (p *DumpPrm) WithStream(r io.Writer) *DumpPrm {
|
||||||
p.stream = r
|
p.stream = r
|
||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
|
|
||||||
// WithIgnoreErrors is an Evacuate option to allow ignore all errors during iteration.
|
// WithIgnoreErrors is an Dump option to allow ignore all errors during iteration.
|
||||||
// This includes invalid blobovniczas as well as corrupted objects.
|
// This includes invalid blobovniczas as well as corrupted objects.
|
||||||
func (p *EvacuatePrm) WithIgnoreErrors(ignore bool) *EvacuatePrm {
|
func (p *DumpPrm) WithIgnoreErrors(ignore bool) *DumpPrm {
|
||||||
p.ignoreErrors = ignore
|
p.ignoreErrors = ignore
|
||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
|
|
||||||
// EvacuateRes groups the result fields of Evacuate operation.
|
// DumpRes groups the result fields of Dump operation.
|
||||||
type EvacuateRes struct {
|
type DumpRes struct {
|
||||||
count int
|
count int
|
||||||
}
|
}
|
||||||
|
|
||||||
// Count return amount of object written.
|
// Count return amount of object written.
|
||||||
func (r *EvacuateRes) Count() int {
|
func (r *DumpRes) Count() int {
|
||||||
return r.count
|
return r.count
|
||||||
}
|
}
|
||||||
|
|
||||||
var ErrMustBeReadOnly = errors.New("shard must be in read-only mode")
|
var ErrMustBeReadOnly = errors.New("shard must be in read-only mode")
|
||||||
|
|
||||||
// Evacuate dumps all objects from the shard to a file or stream.
|
// Dump dumps all objects from the shard to a file or stream.
|
||||||
//
|
//
|
||||||
// Returns any error encountered.
|
// Returns any error encountered.
|
||||||
func (s *Shard) Evacuate(prm *EvacuatePrm) (*EvacuateRes, error) {
|
func (s *Shard) Dump(prm *DumpPrm) (*DumpRes, error) {
|
||||||
s.m.RLock()
|
s.m.RLock()
|
||||||
defer s.m.RUnlock()
|
defer s.m.RUnlock()
|
||||||
|
|
||||||
|
@ -126,5 +126,5 @@ func (s *Shard) Evacuate(prm *EvacuatePrm) (*EvacuateRes, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return &EvacuateRes{count: count}, nil
|
return &DumpRes{count: count}, nil
|
||||||
}
|
}
|
|
@ -23,17 +23,17 @@ import (
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestEvacuate(t *testing.T) {
|
func TestDump(t *testing.T) {
|
||||||
t.Run("without write-cache", func(t *testing.T) {
|
t.Run("without write-cache", func(t *testing.T) {
|
||||||
testEvacuate(t, 10, false)
|
testDump(t, 10, false)
|
||||||
})
|
})
|
||||||
t.Run("with write-cache", func(t *testing.T) {
|
t.Run("with write-cache", func(t *testing.T) {
|
||||||
// Put a bit more objects to write-cache to facilitate race-conditions.
|
// Put a bit more objects to write-cache to facilitate race-conditions.
|
||||||
testEvacuate(t, 100, true)
|
testDump(t, 100, true)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func testEvacuate(t *testing.T, objCount int, hasWriteCache bool) {
|
func testDump(t *testing.T, objCount int, hasWriteCache bool) {
|
||||||
const (
|
const (
|
||||||
wcSmallObjectSize = 1024 // 1 KiB, goes to write-cache memory
|
wcSmallObjectSize = 1024 // 1 KiB, goes to write-cache memory
|
||||||
wcBigObjectSize = 4 * 1024 // 4 KiB, goes to write-cache FSTree
|
wcBigObjectSize = 4 * 1024 // 4 KiB, goes to write-cache FSTree
|
||||||
|
@ -55,16 +55,16 @@ func testEvacuate(t *testing.T, objCount int, hasWriteCache bool) {
|
||||||
defer releaseShard(sh, t)
|
defer releaseShard(sh, t)
|
||||||
|
|
||||||
out := filepath.Join(t.TempDir(), "dump")
|
out := filepath.Join(t.TempDir(), "dump")
|
||||||
prm := new(shard.EvacuatePrm).WithPath(out)
|
prm := new(shard.DumpPrm).WithPath(out)
|
||||||
|
|
||||||
t.Run("must be read-only", func(t *testing.T) {
|
t.Run("must be read-only", func(t *testing.T) {
|
||||||
_, err := sh.Evacuate(prm)
|
_, err := sh.Dump(prm)
|
||||||
require.True(t, errors.Is(err, shard.ErrMustBeReadOnly), "got: %v", err)
|
require.True(t, errors.Is(err, shard.ErrMustBeReadOnly), "got: %v", err)
|
||||||
})
|
})
|
||||||
|
|
||||||
require.NoError(t, sh.SetMode(shard.ModeReadOnly))
|
require.NoError(t, sh.SetMode(shard.ModeReadOnly))
|
||||||
outEmpty := out + ".empty"
|
outEmpty := out + ".empty"
|
||||||
res, err := sh.Evacuate(new(shard.EvacuatePrm).WithPath(outEmpty))
|
res, err := sh.Dump(new(shard.DumpPrm).WithPath(outEmpty))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, 0, res.Count())
|
require.Equal(t, 0, res.Count())
|
||||||
require.NoError(t, sh.SetMode(shard.ModeReadWrite))
|
require.NoError(t, sh.SetMode(shard.ModeReadWrite))
|
||||||
|
@ -99,11 +99,11 @@ func testEvacuate(t *testing.T, objCount int, hasWriteCache bool) {
|
||||||
require.NoError(t, sh.SetMode(shard.ModeReadOnly))
|
require.NoError(t, sh.SetMode(shard.ModeReadOnly))
|
||||||
|
|
||||||
t.Run("invalid path", func(t *testing.T) {
|
t.Run("invalid path", func(t *testing.T) {
|
||||||
_, err := sh.Evacuate(new(shard.EvacuatePrm).WithPath("\x00"))
|
_, err := sh.Dump(new(shard.DumpPrm).WithPath("\x00"))
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
})
|
})
|
||||||
|
|
||||||
res, err = sh.Evacuate(prm)
|
res, err = sh.Dump(prm)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, objCount, res.Count())
|
require.Equal(t, objCount, res.Count())
|
||||||
|
|
||||||
|
@ -209,7 +209,7 @@ func TestStream(t *testing.T) {
|
||||||
finish := make(chan struct{})
|
finish := make(chan struct{})
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
res, err := sh1.Evacuate(new(shard.EvacuatePrm).WithStream(w))
|
res, err := sh1.Dump(new(shard.DumpPrm).WithStream(w))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, objCount, res.Count())
|
require.Equal(t, objCount, res.Count())
|
||||||
require.NoError(t, w.Close())
|
require.NoError(t, w.Close())
|
||||||
|
@ -239,7 +239,7 @@ func checkRestore(t *testing.T, sh *shard.Shard, prm *shard.RestorePrm, objects
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEvacuateIgnoreErrors(t *testing.T) {
|
func TestDumpIgnoreErrors(t *testing.T) {
|
||||||
const (
|
const (
|
||||||
wcSmallObjectSize = 512 // goes to write-cache memory
|
wcSmallObjectSize = 512 // goes to write-cache memory
|
||||||
wcBigObjectSize = wcSmallObjectSize << 1 // goes to write-cache FSTree
|
wcBigObjectSize = wcSmallObjectSize << 1 // goes to write-cache FSTree
|
||||||
|
@ -346,7 +346,7 @@ func TestEvacuateIgnoreErrors(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
out := filepath.Join(t.TempDir(), "out.dump")
|
out := filepath.Join(t.TempDir(), "out.dump")
|
||||||
res, err := sh.Evacuate(new(shard.EvacuatePrm).WithPath(out).WithIgnoreErrors(true))
|
res, err := sh.Dump(new(shard.DumpPrm).WithPath(out).WithIgnoreErrors(true))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, objCount, res.Count())
|
require.Equal(t, objCount, res.Count())
|
||||||
}
|
}
|
|
@ -56,7 +56,7 @@ func (r *RestoreRes) FailCount() int {
|
||||||
return r.failed
|
return r.failed
|
||||||
}
|
}
|
||||||
|
|
||||||
// Restore restores objects from the dump prepared by Evacuate.
|
// Restore restores objects from the dump prepared by Dump.
|
||||||
//
|
//
|
||||||
// Returns any error encountered.
|
// Returns any error encountered.
|
||||||
func (s *Shard) Restore(prm *RestorePrm) (*RestoreRes, error) {
|
func (s *Shard) Restore(prm *RestorePrm) (*RestoreRes, error) {
|
||||||
|
|
Loading…
Reference in a new issue