Commit c82e7c58 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 3f165269
......@@ -154,7 +154,7 @@ def Trees(zstor, r):
ztree = zctx.root['treegen/tree'] = XLOTree()
head = commit('treegen/tree: init')
xprint("start @%s root=%s" % (ashex(head), ashex(ztree._p_oid)))
xprint("tree.srv start @%s root=%s" % (ashex(head), ashex(ztree._p_oid)))
treetxtPrev = zctx.ztreetxt(ztree)
# XXX dup wrt AllStructsSrv
......@@ -197,86 +197,11 @@ def Trees(zstor, r):
xprint("%s" % ashex(head))
"""
# AllStructs generates subset of all possible tree changes in
# between kv1 and kv2. See top-level documentation for details.
@func
def AllStructs(zstor, kv1txt, kv2txt, n, seed=None):
zctx = ZCtx(zstor)
defer(zctx.close)
# seed
if seed is None:
seed = int(time.now())
print("# seed=%d" % seed)
random.seed(seed)
kv1 = kvDecode(kv1txt, zctx.vdecode)
kv2 = kvDecode(kv2txt, zctx.vdecode)
# δ kv1 <-> kv2
diff12 = diff(kv1, kv2)
diff21 = diff(kv2, kv1)
# all tree topologies that can represent kv1 and kv2
maxdepth=2 # XXX -> 3?
maxsplit=1 # XXX -> 2?
t1AllStructs = list(xbtree.AllStructs(kv1.keys(), maxdepth, maxsplit))
t2AllStructs = list(xbtree.AllStructs(kv2.keys(), maxdepth, maxsplit))
# create the tree
ztree = zctx.root['treegen/allstructs/tree'] = XLOTree() # XXX -> treegen/allstructs ?
commit('treegen/allstructs: init tree')
# XXX print something?
# emit patches ztree with delta, adjusts tree structure and emits corresponding commit.
def emit(delta, verify, treeTopo):
ttxt_prev = zctx.ztreetxt(ztree)
patch(ztree, delta, verify)
if treeTopo is not None:
xbtree.Restructure(ztree, treeTopo)
ttxt = zctx.ztreetxt(ztree)
tid = commit('treegen/allstructs: %s -> %s' % (ttxt_prev, ttxt))
print('txn %s # %s -> %s' % (ashex(tid), ttxt_prev, ttxt))
for (k,v) in delta:
vtxt = 'ø'
if v is not DEL:
vtxt = zctx.vencode(v)
# XXX print not only +, but also - (e.g. -1:a +1:b) ?
print('\t%d:%s' % (k,vtxt))
# emit initial kv1 and kv2 states prepared as ZODB would do natively
emit(diff({}, kv1), verify=kv1, treeTopo=None)
t1struct0 = xbtree.StructureOf(ztree, onlyKeys=True)
emit(diff(kv1, kv2), verify=kv2, treeTopo=None)
t2struct0 = xbtree.StructureOf(ztree, onlyKeys=True)
# all tree1 and tree2 topologies jumps in between we are going to emit:
# native + n random ones.
t1structv = [t1struct0] + random.sample(t1AllStructs, min(n, len(t1AllStructs)))
t2structv = [t2struct0] + random.sample(t2AllStructs, min(n, len(t2AllStructs)))
# emit tree1->tree2 and tree1<-tree2 transitions for all combinations of tree1 and tree2.
# tree1₀->tree2₀ was already done.
t12travel = list(bitravel2Way(t1structv, t2structv))
assert t12travel[0] is t1struct0
assert t12travel[1] is t2struct0
for i,tstruct in enumerate(t12travel[2:]):
if i%2 == 0:
delta = diff21
verify = kv1
assert tstruct in t1structv
else:
delta = diff12
verify = kv2
assert tstruct in t2structv
emit(delta, verify, tstruct)
"""
# XXX
# AllStructsSrv is server version of AllStructs.
@func
def AllStructsSrv(r):
xprint('# allstructs.srv start')
# XXX dup wrt Trees
while 1:
req = r.readline()
......@@ -286,6 +211,21 @@ def AllStructsSrv(r):
if req.startswith('#'):
continue # skip comments
# maxdepth maxsplit n(/seed) kv1 kv2
maxdepth, maxsplit, n, kv1txt, kv2txt = req.split()
maxdepth = int(maxdepth)
maxsplit = int(maxsplit)
seed = None
if '/' in n:
n, seeds = n.split('/')
seed = int(seeds)
n = int(n)
if kv1txt == 'ø': kv1txt = ''
if kv2txt == 'ø': kv2txt = ''
AllStructs(kv1txt, kv2txt, maxdepth, maxsplit, n, seed)
xprint('# ----')
# AllStructs generates topologies for subset of all possible tree changes in
# between kv1 and kv2. See top-level documentation for details.
@func
......@@ -305,10 +245,12 @@ def AllStructs(kv1txt, kv2txt, maxdepth, maxsplit, n, seed=None):
# initial kv1 and kv2 states with topologies prepared as ZODB would do natively
patch(ztree, diff({}, kv1), verify=kv1)
if kv1 == {}: ztree._p_changed = True # to avoid empty commit - see Trees
commit('kv1')
t1struct0 = xbtree.StructureOf(ztree)
patch(ztree, diff(kv1, kv2), verify=kv2)
if kv2 == kv1: ztree._p_changed = True
commit('kv2')
t2struct0 = xbtree.StructureOf(ztree)
......@@ -339,8 +281,6 @@ def AllStructs(kv1txt, kv2txt, maxdepth, maxsplit, n, seed=None):
print(zctx.TopoEncode(tstruct))
print("# ----")
# bitravel2Way generates travel path through all A<->B edges such
# that all edges a->b and a<-b are traveled and exactly once.
......@@ -474,7 +414,7 @@ def cmd_allstructs(argv):
@func
def cmd_allstructs_srv(argv):
if len(argv) != 1:
if len(argv) != 0:
print("Usage: cat requests |treegen allstructs.srv", file=sys.stderr)
sys.exit(1)
AllStructsSrv(sys.stdin)
......@@ -499,7 +439,7 @@ def xprint(msg):
cmdRegistry = {
'allstructs': cmd_allstructs,
'allstructs_srv': cmd_allstructs_srv,
'allstructs.srv': cmd_allstructs_srv,
'trees': cmd_trees,
}
......
......@@ -509,7 +509,7 @@ func TestΔBTreeAllStructs(t *testing.T) {
// given (kv1, kv2) test on automatically generated (tree1 -> tree2)
fmt.Printf("%s -> %s\n", kvtxt(kv1), kvtxt(kv2))
testq <- ...
//testq <- ...
}
}()
......
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