binary format for WAL

This commit is contained in:
Anton Kaliaev
2017-10-09 23:10:58 +04:00
parent 31030c6514
commit 3115c23762
16 changed files with 451 additions and 143 deletions

View File

@ -0,0 +1,53 @@
package main
import (
"fmt"
"io"
"os"
"strconv"
cs "github.com/tendermint/tendermint/consensus"
)
func main() {
var heightToStop uint64
var err error
if heightToStop, err = strconv.ParseUint(os.Args[2], 10, 64); err != nil {
panic(fmt.Errorf("failed to parse height: %v (format: cutWALUntil in heightToStop out)", err))
}
in, err := os.Open(os.Args[1])
if err != nil {
panic(fmt.Errorf("failed to open WAL file: %v (format: cutWALUntil in heightToStop out)", err))
}
defer in.Close()
out, err := os.Create(os.Args[3])
if err != nil {
panic(fmt.Errorf("failed to open WAL file: %v (format: cutWALUntil in heightToStop out)", err))
}
defer out.Close()
enc := cs.NewWALEncoder(out)
dec := cs.NewWALDecoder(in)
for {
msg, err := dec.Decode()
if err == io.EOF {
break
} else if err != nil {
panic(fmt.Errorf("failed to decode msg: %v", err))
}
if m, ok := msg.Msg.(cs.EndHeightMessage); ok {
if m.Height == heightToStop {
break
}
}
err = enc.Encode(msg)
if err != nil {
panic(fmt.Errorf("failed to encode msg: %v", err))
}
}
}

36
scripts/wal2json/main.go Normal file
View File

@ -0,0 +1,36 @@
package main
import (
"encoding/json"
"fmt"
"io"
"os"
cs "github.com/tendermint/tendermint/consensus"
)
func main() {
f, err := os.Open(os.Args[1])
if err != nil {
panic(fmt.Errorf("failed to open WAL file: %v", err))
}
defer f.Close()
dec := cs.NewWALDecoder(f)
for {
msg, err := dec.Decode()
if err == io.EOF {
break
} else if err != nil {
panic(fmt.Errorf("failed to decode msg: %v", err))
}
json, err := json.Marshal(msg)
if err != nil {
panic(fmt.Errorf("failed to marshal msg: %v", err))
}
os.Stdout.Write(json)
os.Stdout.Write([]byte("\n"))
}
}

BIN
scripts/wal2json/wal2json Executable file

Binary file not shown.