Commit 24ab091c authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 48b8fcaf
......@@ -28,6 +28,7 @@ import (
"fmt"
"io"
"os"
"time"
"lab.nexedi.com/kirr/neo/go/zodb/storage/fs1"
......@@ -40,10 +41,38 @@ import (
//
// Only data part of the data base is verified (the *.fs file). Use
// VerifyIndexFor to verify the index part (*.fs.index).
func Verify(w io.Writer, path string, verbose int) (err error) {
func Verify(w io.Writer, path string, verbose int, progress bool) (err error) {
// just iterate through the file and emit progress.
// the FileStorage driver implements all consistency checks by itself.
fi, err := os.Stat(path)
if err != nil {
return fmt.Errorf("verify: %s: %s", path, err)
}
fsize := fi.Size()
v := &Verifier{verbose: verbose}
// display progress updates once per tick
if progress {
tick := time.NewTicker(time.Second / 4)
defer tick.Stop()
v.progress = func(pos int64) error {
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)
return err
}
}
return Dump(w, path, fs1.IterForward, v)
}
......@@ -54,6 +83,8 @@ type Verifier struct {
// for loading data
dhLoading fs1.DataHeader
progress func(pos int64) error
}
func (v *Verifier) DumperName() string {
......@@ -86,17 +117,25 @@ func (v *Verifier) DumpTxn(buf *xfmt.Buffer, it *fs1.Iter) error {
}
if v.verbose >= 2 {
buf .S(fmt.Sprintf("%10d: object oid %s #%d\n", dh.Pos, dh.Oid, i))
buf .S(fmt.Sprintf("%10d: object oid 0x%s #%d\n", dh.Pos, dh.Oid, i))
}
dbuf.Release()
}
if v.verbose >= 1 {
buf .S(fmt.Sprintf("%10d: transaction tid %s #%d \n", txnh.Pos, txnh.Tid, v.ntxn))
buf .S(fmt.Sprintf("%10d: transaction tid 0x%s #%d \n", txnh.Pos, txnh.Tid, v.ntxn))
}
v.ntxn++
if v.progress != nil {
err := v.progress(txnh.Pos)
if err != nil {
return err
}
}
return nil
}
......@@ -122,14 +161,17 @@ Dump transactions from a FileStorage XXX
-h --help this help text.
-v increase verbosity.
-p display total progress.
`)
}
func verifyMain(argv []string) {
verbose := 0
var progress bool
flags := flag.FlagSet{Usage: func() { verifyUsage(os.Stderr) }}
flags.Init("", flag.ExitOnError)
flags.Var((*xflag.Count)(&verbose), "v", "verbosity level")
flags.BoolVar(&progress, "p", false, "display total progress")
flags.Parse(argv[1:])
argv = flags.Args()
......@@ -139,7 +181,7 @@ func verifyMain(argv []string) {
}
storPath := argv[0]
err := Verify(os.Stdout, storPath, verbose)
err := Verify(os.Stdout, storPath, verbose, progress)
if err != nil {
prog.Fatal(err)
}
......
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