Commit 6a52ac1a authored by Kirill Smelkov's avatar Kirill Smelkov

X zodbdump: use xfmt

parent b750d103
...@@ -38,7 +38,6 @@ import ( ...@@ -38,7 +38,6 @@ import (
"io" "io"
"log" "log"
"os" "os"
"strconv"
"../../../zodb" "../../../zodb"
"../../../storage/fs1" "../../../storage/fs1"
...@@ -53,7 +52,7 @@ type dumper struct { ...@@ -53,7 +52,7 @@ type dumper struct {
afterFirst bool // true after first transaction has been dumped afterFirst bool // true after first transaction has been dumped
workMem []byte // reusable data buffer for formatting xbuf xfmt.Buffer // reusable data buffer for formatting
} }
var _LF = []byte{'\n'} var _LF = []byte{'\n'}
...@@ -61,41 +60,36 @@ var _LF = []byte{'\n'} ...@@ -61,41 +60,36 @@ var _LF = []byte{'\n'}
// DumpData dumps one data record // DumpData dumps one data record
func (d *dumper) DumpData(datai *zodb.StorageRecordInformation) error { func (d *dumper) DumpData(datai *zodb.StorageRecordInformation) error {
buf := d.workMem[:0] xbuf := &d.xbuf
xbuf.Reset()
//entry := "obj " + datai.Oid.String() + " " //entry := "obj " + datai.Oid.String() + " "
buf = append(buf, "obj "...) xbuf .S("obj ") .V(&datai.Oid) .Cb(' ')
buf = xfmt.Append(buf, &datai.Oid)
buf = append(buf, ' ')
writeData := false writeData := false
switch { switch {
case datai.Data == nil: case datai.Data == nil:
//entry += "delete" //entry += "delete"
buf = append(buf, "delete"...) xbuf.S("delete")
case datai.Tid != datai.DataTid: case datai.Tid != datai.DataTid:
//entry += "from " + datai.DataTid.String() //entry += "from " + datai.DataTid.String()
buf = append(buf, "from "...) xbuf .S("from ") .V(&datai.DataTid)
buf = xfmt.Append(buf, &datai.DataTid)
default: default:
//entry += fmt.Sprintf("%d sha1:%x", len(datai.Data), sha1.Sum(datai.Data)) //entry += fmt.Sprintf("%d sha1:%x", len(datai.Data), sha1.Sum(datai.Data))
buf = strconv.AppendInt(buf, int64(len(datai.Data)), 10)
buf = append(buf, " sha1:"...)
dataSha1 := sha1.Sum(datai.Data) dataSha1 := sha1.Sum(datai.Data)
buf = xfmt.AppendHex(buf, dataSha1[:]) xbuf .D(len(datai.Data)) .S(" sha1:") .Xb(dataSha1[:])
writeData = true writeData = true
} }
//entry += "\n" //entry += "\n"
buf = append(buf, '\n') xbuf .Cb('\n')
// TODO use writev(data, "\n") via net.Buffers (it is already available) // TODO use writev(data, "\n") via net.Buffers (it is already available)
//_, err := d.W.Write(mem.Bytes(entry)) _, err := d.W.Write(xbuf.Bytes())
_, err := d.W.Write(buf)
if err != nil { if err != nil {
goto out goto out
} }
...@@ -106,6 +100,7 @@ func (d *dumper) DumpData(datai *zodb.StorageRecordInformation) error { ...@@ -106,6 +100,7 @@ func (d *dumper) DumpData(datai *zodb.StorageRecordInformation) error {
goto out goto out
} }
// XXX maybe better to merge with next record ?
_, err = d.W.Write(_LF) _, err = d.W.Write(_LF)
if err != nil { if err != nil {
goto out goto out
...@@ -113,8 +108,6 @@ func (d *dumper) DumpData(datai *zodb.StorageRecordInformation) error { ...@@ -113,8 +108,6 @@ func (d *dumper) DumpData(datai *zodb.StorageRecordInformation) error {
} }
out: out:
d.workMem = buf
// XXX do we need this context ? // XXX do we need this context ?
// see for rationale in similar place in DumpTxn // see for rationale in similar place in DumpTxn
if err != nil { if err != nil {
......
...@@ -27,11 +27,11 @@ func (oid Oid) String() string { ...@@ -27,11 +27,11 @@ func (oid Oid) String() string {
} }
func (tid Tid) XFmtString(b []byte) []byte { func (tid Tid) XFmtString(b []byte) []byte {
return xfmt.AppendHex64(b, uint64(tid)) return xfmt.AppendHex016(b, uint64(tid))
} }
func (oid Oid) XFmtString(b []byte) []byte { func (oid Oid) XFmtString(b []byte) []byte {
return xfmt.AppendHex64(b, uint64(oid)) return xfmt.AppendHex016(b, uint64(oid))
} }
// XXX move me out of here // XXX move me out of here
......
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