[#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")
|
||||
|
||||
// EvacuatePrm groups the parameters of Evacuate operation.
|
||||
type EvacuatePrm struct {
|
||||
// DumpPrm groups the parameters of Dump operation.
|
||||
type DumpPrm struct {
|
||||
path string
|
||||
stream io.Writer
|
||||
ignoreErrors bool
|
||||
}
|
||||
|
||||
// WithPath is an Evacuate option to set the destination path.
|
||||
func (p *EvacuatePrm) WithPath(path string) *EvacuatePrm {
|
||||
// WithPath is an Dump option to set the destination path.
|
||||
func (p *DumpPrm) WithPath(path string) *DumpPrm {
|
||||
p.path = path
|
||||
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.
|
||||
func (p *EvacuatePrm) WithStream(r io.Writer) *EvacuatePrm {
|
||||
func (p *DumpPrm) WithStream(r io.Writer) *DumpPrm {
|
||||
p.stream = r
|
||||
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.
|
||||
func (p *EvacuatePrm) WithIgnoreErrors(ignore bool) *EvacuatePrm {
|
||||
func (p *DumpPrm) WithIgnoreErrors(ignore bool) *DumpPrm {
|
||||
p.ignoreErrors = ignore
|
||||
return p
|
||||
}
|
||||
|
||||
// EvacuateRes groups the result fields of Evacuate operation.
|
||||
type EvacuateRes struct {
|
||||
// DumpRes groups the result fields of Dump operation.
|
||||
type DumpRes struct {
|
||||
count int
|
||||
}
|
||||
|
||||
// Count return amount of object written.
|
||||
func (r *EvacuateRes) Count() int {
|
||||
func (r *DumpRes) Count() int {
|
||||
return r.count
|
||||
}
|
||||
|
||||
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.
|
||||
func (s *Shard) Evacuate(prm *EvacuatePrm) (*EvacuateRes, error) {
|
||||
func (s *Shard) Dump(prm *DumpPrm) (*DumpRes, error) {
|
||||
s.m.RLock()
|
||||
defer s.m.RUnlock()
|
||||
|
||||
|
@ -126,5 +126,5 @@ func (s *Shard) Evacuate(prm *EvacuatePrm) (*EvacuateRes, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
return &EvacuateRes{count: count}, nil
|
||||
return &DumpRes{count: count}, nil
|
||||
}
|
|
@ -23,17 +23,17 @@ import (
|
|||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestEvacuate(t *testing.T) {
|
||||
func TestDump(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) {
|
||||
// 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 (
|
||||
wcSmallObjectSize = 1024 // 1 KiB, goes to write-cache memory
|
||||
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)
|
||||
|
||||
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) {
|
||||
_, err := sh.Evacuate(prm)
|
||||
_, err := sh.Dump(prm)
|
||||
require.True(t, errors.Is(err, shard.ErrMustBeReadOnly), "got: %v", err)
|
||||
})
|
||||
|
||||
require.NoError(t, sh.SetMode(shard.ModeReadOnly))
|
||||
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.Equal(t, 0, res.Count())
|
||||
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))
|
||||
|
||||
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)
|
||||
})
|
||||
|
||||
res, err = sh.Evacuate(prm)
|
||||
res, err = sh.Dump(prm)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, objCount, res.Count())
|
||||
|
||||
|
@ -209,7 +209,7 @@ func TestStream(t *testing.T) {
|
|||
finish := make(chan struct{})
|
||||
|
||||
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.Equal(t, objCount, res.Count())
|
||||
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 (
|
||||
wcSmallObjectSize = 512 // goes to write-cache memory
|
||||
wcBigObjectSize = wcSmallObjectSize << 1 // goes to write-cache FSTree
|
||||
|
@ -346,7 +346,7 @@ func TestEvacuateIgnoreErrors(t *testing.T) {
|
|||
}
|
||||
|
||||
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.Equal(t, objCount, res.Count())
|
||||
}
|
|
@ -56,7 +56,7 @@ func (r *RestoreRes) FailCount() int {
|
|||
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.
|
||||
func (s *Shard) Restore(prm *RestorePrm) (*RestoreRes, error) {
|
||||
|
|
Loading…
Reference in a new issue