-
Notifications
You must be signed in to change notification settings - Fork 1
/
debug.go
54 lines (49 loc) · 1.21 KB
/
debug.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package chotki
import (
"fmt"
"github.com/cockroachdb/pebble"
"github.com/drpcorg/chotki/rdx"
"io"
)
func ChotkiKVString(key, value []byte) string {
if len(key) != LidLKeyLen {
return ""
}
line := make([]byte, 0, 128)
//line = append(line, key[0], '.')
id, rdt := OKeyIdRdt(key)
line = append(line, id.String()...)
line = append(line, '.', byte(rdt), ':', '\t')
line = append(line, rdx.Xstring(rdt, value)...)
return string(line)
}
func (cho *Chotki) DumpAll(writer io.Writer) {
cho.DumpObjects(writer)
fmt.Fprintln(writer, "")
cho.DumpVV(writer)
}
func (cho *Chotki) DumpObjects(writer io.Writer) {
io := pebble.IterOptions{
LowerBound: []byte{'O'},
UpperBound: []byte{'P'},
}
i := cho.db.NewIter(&io)
defer i.Close()
for i.SeekGE([]byte{'O'}); i.Valid(); i.Next() {
fmt.Fprintln(writer, ChotkiKVString(i.Key(), i.Value()))
}
}
func (cho *Chotki) DumpVV(writer io.Writer) {
io := pebble.IterOptions{
LowerBound: []byte{'V'},
UpperBound: []byte{'W'},
}
i := cho.db.NewIter(&io)
defer i.Close()
for i.SeekGE(VKey(rdx.ID0)); i.Valid(); i.Next() {
id := rdx.IDFromBytes(i.Key()[1:])
vv := make(rdx.VV)
_ = vv.PutTLV(i.Value())
fmt.Fprintln(writer, id.String(), " -> ", vv.String())
}
}