Commit 8a1d3f7c authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 1cd48172
......@@ -21,6 +21,7 @@ package main
import (
"bufio"
"context"
"fmt"
"io"
"io/ioutil"
......@@ -33,6 +34,7 @@ import (
"lab.nexedi.com/kirr/go123/exc"
"lab.nexedi.com/kirr/go123/xerr"
"lab.nexedi.com/kirr/neo/go/zodb"
"lab.nexedi.com/kirr/neo/go/zodb/btree"
)
// TreeGen represents connection to running `treegen trees` server.
......@@ -141,6 +143,59 @@ func (tg *TreeGen) Commit(tree string) (_ zodb.Tid, err error) {
return tid, nil
}
// GetTree loads LOBtree from zurl@at->obj<root>.
// Tree values must be ZBlk whose data is returned instead of references to ZBlk.
func XGetTree(zurl string, at zodb.Tid, root zodb.Oid) (_ map[int64]string, err error) {
defer xerr.Contextf(&err, "%s: @%s: get tree %s", zurl, at, root)
X := exc.Raiseif
ctx := context.Background()
// XXX pass IStorage to here instead of zurl?
zstor, err := zodb.Open(ctx, zurl, &zodb.OpenOptions{ReadOnly: true}); X(err)
defer zstor.Close() // XXX err
db := zodb.NewDB(zstor)
defer db.Close() // XXX err
// XXX +transaction
// XXX +defer txn.Abort()
zconn, err := db.Open(ctx, &zodb.ConnOptions{At: at}); X(err)
xztree, err := zconn.Get(ctx, root); X(err)
ztree, ok := xztree.(*btree.LOBTree)
if !ok {
return nil, fmt.Errorf("expected LOBTree, got %s", zodb.ClassOf(xztree))
}
err = ztree.PActivate(ctx); X(err)
defer ztree.PDeactivate()
zbucket := ztree.FirstBucket()
kv := make(map[int64]string)
for zbucket != nil {
err = zbucket.PActivate(ctx); X(err)
defer zbucket.PDeactivate()
for _, __ := range zbucket.Entryv() {
k := __.Key()
xv := __.Value()
zv, ok := xv.(zBlk)
if !ok {
return nil, fmt.Errorf("[%d] -> %s; want ZBlk", k, typeOf(xv))
}
data, _, err := zv.loadBlkData(ctx); X(err)
kv[k] = string(data)
}
zbucket = zbucket.Next()
}
return kv, nil
}
func TestΔBTail(t *testing.T) {
X := exc.Raiseif
......
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