Commit bdbe0182 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 686d0ff1
......@@ -22,10 +22,10 @@
It is used as helper for ΔBTree tests.
Treegen provides the following subcommands:
The following subcommands are provided:
- `trees` generates trees specified as arguments,
- `allstructs` generates subset of all possible tree changes in between to
- `allstructs` generates subset of all possible tree changes in between two
trees represented by two key->value dicts.
......@@ -89,10 +89,10 @@ from zodbtools.util import storageFromURL, ashex
from persistent import CHANGED
from persistent.mapping import PersistentMapping
# XXX hack: set LOBTree.LOBTree -> XLOTree so that nodes are split often
# (XLOTree is LOBTree with small .max_*_size). Do it this way so that generated
# database looks as if regular LOBTree was used. We use the hack because
# we cannot tune LOBTree directly.
# XXX hack: set LOBTree.LOBTree -> XLOTree so that nodes are split often for
# regular tree updates (XLOTree is LOBTree with small .max_*_size). Do it this
# way so that generated database looks as if regular LOBTree was used. We use
# the hack because we cannot tune LOBTree directly.
XLOTree = xbtree_test.XLOTree
XLOTree.__module__ = 'BTrees.LOBTree'
XLOTree.__name__ = 'LOBTree'
......@@ -113,7 +113,7 @@ class ZCtx(object):
zctx.zconn = zctx.db.open()
zctx.root = zctx.zconn.root()
# root['treegen/values'] = {} v -> ZBlk(v)
# init root['treegen/values'] = {} v -> ZBlk(v)
# TODO don't generate if already there
zctx.valdict = zctx.root['treegen/values'] = PersistentMapping()
valv = b'abcdefghi'
......@@ -123,6 +123,7 @@ class ZCtx(object):
zctx.valdict[v] = zblk
commit('treegen/values -> %r' % valv)
# close release resources associated with zctx.
def close(zctx):
zctx.zconn.close()
zctx.db.close()
......@@ -140,8 +141,36 @@ class ZCtx(object):
# XXX doc
@func
def Trees(zstor, r):
for l in r.readlines():
1/0
zctx = ZCtx(zstor)
defer(zctx.close)
trees = zctx.root.get('treegen/trees')
if trees is None:
trees = zctx.root['treegen/trees'] = PersistentMapping()
commit('mk treegen/trees')
for treetxt in r.readlines():
tree = zctx.TopoDecode(treetxt)
ztree = trees[treetxt] = LOBTree()
# tree[k]=v for all k
# do tree.keys() via walkBFS
for level in xbtree._walkBFS(tree):
for node in level:
if isinstance(node, xbtree.Bucket):
assert node.valuev is not None
assert len(node.keyv) == len(node.valuev)
for (k,v) in zip(node.keyv, node.valuev):
ztree[k] = v
# restructure to requested topology
xbtree.Restructure(ztree, tree)
tid = commit(treetxt)
# XXX print more details
print("txn %s -> tree(%s) %s" % (ashex(tid), ashex(ztree._p_oid), treetxt))
# AllStructs generates subset of all possible tree changes in
......@@ -171,7 +200,7 @@ def AllStructs(zstor, kv1txt, kv2txt, n, seed=None):
t2AllStructs = list(xbtree.AllStructs(kv2.keys(), maxdepth, maxsplit))
# create the tree
ztree = zctx.root['treegen/tree'] = XLOTree()
ztree = zctx.root['treegen/tree'] = XLOTree() # XXX -> treegen/allstructs ?
commit('treegen/tree')
# XXX print something?
......
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