Commit c864ec80 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 24ab091c
......@@ -53,7 +53,7 @@ type Dumper interface {
DumpTxn(buf *xfmt.Buffer, it *fs1.Iter) error
// DumpEndOK is called at the end of successfull dump.
DumpEndOK(buf *xfmt.Buffer)
DumpEndOK(buf *xfmt.Buffer) error
}
// Dump dumps content of a FileStorage file @ path.
......@@ -123,7 +123,10 @@ func Dump(w io.Writer, path string, dir fs1.IterDir, d Dumper) (err error) {
}
}
d.DumpEndOK(buf)
err = d.DumpEndOK(buf)
if err != nil {
return err
}
return nil
}
......@@ -204,7 +207,8 @@ func (d *DumperFsDump) DumpTxn(buf *xfmt.Buffer, it *fs1.Iter) error {
}
}
func (d *DumperFsDump) DumpEndOK(buf *xfmt.Buffer) {
func (d *DumperFsDump) DumpEndOK(buf *xfmt.Buffer) error {
return nil
}
// DumperFsDumpVerbose implements a very verbose dumper with output identical
......@@ -290,7 +294,8 @@ func (d *DumperFsDumpVerbose) dumpData(buf *xfmt.Buffer, it *fs1.Iter) error {
return nil
}
func (d *DumperFsDumpVerbose) DumpEndOK(buf *xfmt.Buffer) {
func (d *DumperFsDumpVerbose) DumpEndOK(buf *xfmt.Buffer) error {
return nil
}
const dumpSummary = "dump database transactions"
......@@ -395,7 +400,8 @@ func (d *DumperFsTail) DumpTxn(buf *xfmt.Buffer, it *fs1.Iter) error {
return nil
}
func (d *DumperFsTail) DumpEndOK(buf *xfmt.Buffer) {
func (d *DumperFsTail) DumpEndOK(buf *xfmt.Buffer) error {
return nil
}
const tailSummary = "dump last few transactions of a database"
......
......@@ -57,18 +57,25 @@ func Verify(w io.Writer, path string, verbose int, progress bool) (err error) {
tick := time.NewTicker(time.Second / 4)
defer tick.Stop()
v.progress = func(pos int64) error {
select {
case <-tick.C:
default:
return nil
xcr := ""
if verbose > 0 {
xcr = "\n"
}
v.progress = func(force bool) error {
if !force {
select {
case <-tick.C:
default:
return nil
}
}
_, err := fmt.Fprintf(w,
"\rVerified data bytes: %.1f%% (%d/%d); #txn: %d",
100 * float64(pos) / float64(fsize),
pos, fsize,
v.ntxn)
"\rVerified data bytes: %.1f%% (%d/%d); #txn: %d%s",
100 * float64(v.donePos) / float64(fsize),
v.donePos, fsize,
v.ntxn,
xcr)
return err
}
}
......@@ -84,7 +91,8 @@ type Verifier struct {
// for loading data
dhLoading fs1.DataHeader
progress func(pos int64) error
donePos int64 // done verifying till this position
progress func(force bool) error
}
func (v *Verifier) DumperName() string {
......@@ -130,7 +138,8 @@ func (v *Verifier) DumpTxn(buf *xfmt.Buffer, it *fs1.Iter) error {
v.ntxn++
if v.progress != nil {
err := v.progress(txnh.Pos)
v.donePos = txnh.Pos + txnh.Len
err := v.progress(/*force=*/false)
if err != nil {
return err
}
......@@ -139,10 +148,17 @@ func (v *Verifier) DumpTxn(buf *xfmt.Buffer, it *fs1.Iter) error {
return nil
}
func (v *Verifier) DumpEndOK(buf *xfmt.Buffer) {
func (v *Verifier) DumpEndOK(buf *xfmt.Buffer) error {
if v.progress != nil {
err := v.progress(/*force=*/true)
if err != nil {
return err
}
}
if v.verbose >= 1 {
buf .S("no errors detected\n")
}
return nil
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment