Commit fdcec437 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent aecd4dfd
......@@ -96,7 +96,6 @@ def diff(d1, d2): # -> [] of (k,v) to change; DEL means del[k]
delta.append((k,v2))
return delta
# patch changes mapping d according to diff.
# diff = [] of (k,v) to change; DEL means del[k]
def patch(d, diff, verify):
......@@ -145,16 +144,15 @@ def treedeltaGenAllStructs(zstor, kv1txt, kv2txt, n):
zconn = db.open(); defer(zconn.close)
root = zconn.root()
# seed
seed = int(time.now())
print("# seed=%d" % seed)
random.seed(seed)
# root['treedelta/values'] = {} v -> ZBlk(v)
valdict = root['treedelta/values'] = PersistentMapping()
valv = b'abcdefghi'
for v in valv:
# XXX don't ovewrite if already set?
zblk = ZBlk()
zblk.setblkdata(v)
valdict[v] = zblk
......@@ -173,30 +171,40 @@ def treedeltaGenAllStructs(zstor, kv1txt, kv2txt, n):
kv1 = kvDecode(kv1txt, vdecode)
kv2 = kvDecode(kv2txt, vdecode)
# δ kv1 <-> kv2
diff12 = diff(kv1, kv2) # of (k,v) diff to go from kv1 to kv2
diff21 = diff(kv2, kv1) # of (k,v) diff to go from kv2 to kv1
# all topology structs 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))
# emit initial kv1 state prepared as ZODB would natively
ztree = root['treedelta/tree'] = BTrees.LOBTree.LOBTree() # XXX -> XLOTree (small nodes)
# create the tree
ztree = root['treedelta/tree'] = BTrees.LOBTree.LOBTree() # XXX -> XLOTree (small nodes)
commit('treedelta/tree')
for k in sorted(kv1):
ztree[k] = kv1[k]
ttxt = treetxt(ztree)
tid = commit(ttxt)
# XXX print txnδ
t1struct0 = xbtree.StructureOf(ztree)
# XXX print something?
# emit patches ztree with delta, adjusts tree structure and emits corresponding commit.
def emit(delta, verify, treeTopo):
ttxt_prev = treetxt(ztree)
patch(ztree, delta, verify)
if treeTopo is not None:
xbtree.Restructure(ztree, treeTopo)
ttxt = treetxt(ztree)
tid = commit('%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 = vencode(v)
print('\t%d:%s' % (k,vtxt)) # XXX print not only +, but also - (e.g. -1:a +1:b) ?
# emit initial kv2 state prepared as ZODB would natively
patch(ztree, diff12, verify=kv2)
ttxt_prev = ttxt
ttxt = treetxt(ztree)
tid = commit('%s -> %s' % (ttxt_prev, ttxt))
# XXX printδ
# emit initial kv1 and kv2 states prepared as ZODB would do natively
emit(diff({}, kv1), verify=kv1, treeTopo=None)
t1struct0 = xbtree.StructureOf(ztree)
emit(diff(kv1, kv2), verify=kv2, treeTopo=None)
t2struct0 = xbtree.StructureOf(ztree)
# all tree1 and tree2 topologies we are going to emit: native + n random ones
......@@ -218,19 +226,7 @@ def treedeltaGenAllStructs(zstor, kv1txt, kv2txt, n):
verify = kv2
assert tstruct in t2structv
patch(ztree, delta, verify)
xbtree.Restructure(ztree, tstruct)
ttxt_prev = ttxt
ttxt = treetxt(ztree)
tid = commit('%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 = vencode(v)
print('\t%d:%s' % (k,vtxt)) # XXX print not only +, but also - (e.g. -1:a +1:b) ?
emit(delta, verify, tstruct)
# bitravel2Way generates travel path through all A<->B edges such
......
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