Commit 56aad370 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 2de41552
...@@ -283,7 +283,7 @@ class tDB: ...@@ -283,7 +283,7 @@ class tDB:
t.root['_last'] = last = Persistent() t.root['_last'] = last = Persistent()
last._p_changed = 1 last._p_changed = 1
transaction.commit() transaction.commit()
head = last._p_serial head = tAt(t, last._p_serial)
dF.rev = head dF.rev = head
for dfile in dF.byfile.values(): for dfile in dF.byfile.values():
...@@ -291,7 +291,7 @@ class tDB: ...@@ -291,7 +291,7 @@ class tDB:
t.dFtail.append(dF) t.dFtail.append(dF)
assert t.head == head # self-check assert t.head == head # self-check
print('\nM: commit -> %s' % t.hat(head)) print('\nM: commit -> %s' % head)
for zf, zfDelta in t._changed.items(): for zf, zfDelta in t._changed.items():
print('M: f<%s>\t%s' % (h(zf._p_oid), sorted(zfDelta.keys()))) print('M: f<%s>\t%s' % (h(zf._p_oid), sorted(zfDelta.keys())))
t._changed = {} t._changed = {}
...@@ -306,10 +306,10 @@ class tDB: ...@@ -306,10 +306,10 @@ class tDB:
l = t._wc_zheadfh.readline() l = t._wc_zheadfh.readline()
#print('> zhead read: %r' % l) #print('> zhead read: %r' % l)
l = l.rstrip('\n') l = l.rstrip('\n')
wchead = fromhex(l) wchead = tAt(t, fromhex(l))
i = len(t._wc_zheadv) i = len(t._wc_zheadv)
if wchead != t.dFtail[i].rev: if wchead != t.dFtail[i].rev:
raise RuntimeError("wcsync #%d: wczhead (%s) != zhead (%s)" % (i, h(wchead), h(t.dFtail[i].rev))) raise RuntimeError("wcsync #%d: wczhead (%s) != zhead (%s)" % (i, wchead, t.dFtail[i].rev))
t._wc_zheadv.append(wchead) t._wc_zheadv.append(wchead)
# head/at = last txn of whole db # head/at = last txn of whole db
...@@ -864,7 +864,7 @@ class tSrvReq: ...@@ -864,7 +864,7 @@ class tSrvReq:
if at == "head": if at == "head":
at = None at = None
else: else:
at = fromhex(at) at = tAt(req.twlink.tdb, fromhex(at))
return foid, blk, at return foid, blk, at
...@@ -899,15 +899,15 @@ def watch(twlink, zf, at, pinok=None): # -> tWatch ...@@ -899,15 +899,15 @@ def watch(twlink, zf, at, pinok=None): # -> tWatch
at_from = '' at_from = ''
if at_prev is not None: if at_prev is not None:
at_from = '(%s ->) ' % t.hat(at_prev) at_from = '(%s ->) ' % at_prev
print('\nC: setup watch f<%s> %s%s' % (h(zf._p_oid), at_from, t.hat(at))) print('\nC: setup watch f<%s> %s%s' % (h(zf._p_oid), at_from, at))
accessed = t._blkaccessed(zf) accessed = t._blkaccessed(zf)
lastRevOf = lambda blk: t._blkRevAt(zf, blk, t.head) lastRevOf = lambda blk: t._blkRevAt(zf, blk, t.head)
pin_prev = {} pin_prev = {}
if at_prev is not None: if at_prev is not None:
assert at_prev <= at, 'TODO %s -> %s' % (t.hat(at_prev), t.hat(at)) assert at_prev <= at, 'TODO %s -> %s' % (at_prev, at)
pin_prev = t._pinnedAt(zf, at_prev) pin_prev = t._pinnedAt(zf, at_prev)
assert w.pinned == pin_prev assert w.pinned == pin_prev
...@@ -923,7 +923,7 @@ def watch(twlink, zf, at, pinok=None): # -> tWatch ...@@ -923,7 +923,7 @@ def watch(twlink, zf, at, pinok=None): # -> tWatch
# blk ∉ pin_prev, blk ∈ pin -> cannot happen, except on first start # blk ∉ pin_prev, blk ∈ pin -> cannot happen, except on first start
if blk not in pin_prev and blk in pin: if blk not in pin_prev and blk in pin:
if at_prev is not None: if at_prev is not None:
fail('#%d pinned %s; not pinned %s' % (t.hat(at_prev), t.hat(at))) fail('#%d pinned %s; not pinned %s' % (at_prev, at))
# blk ∈ pin -> blk is tracked; has rev > at # blk ∈ pin -> blk is tracked; has rev > at
# (see criteria in _pinnedAt) # (see criteria in _pinnedAt)
...@@ -1179,13 +1179,13 @@ def _pinnedAt(t, zf, at): # -> pin = {} blk -> rev ...@@ -1179,13 +1179,13 @@ def _pinnedAt(t, zf, at): # -> pin = {} blk -> rev
@func(tDB) @func(tDB)
def iter_revv(t, start=z64, level=0): def iter_revv(t, start=z64, level=0):
dFtail = [_ for _ in t.dFtail if _.rev > start] dFtail = [_ for _ in t.dFtail if _.rev > start]
#print(' '*level, 'iter_revv', t.hat(start), [t.hat(_.rev) for _ in dFtail]) #print(' '*level, 'iter_revv', start, [_.rev for _ in dFtail])
if len(dFtail) == 0: if len(dFtail) == 0:
yield [] yield []
return return
for dF in dFtail: for dF in dFtail:
#print(' '*level, 'QQQ', t.hat(dF.rev)) #print(' '*level, 'QQQ', dF.rev)
for tail in t.iter_revv(start=dF.rev, level=level+1): for tail in t.iter_revv(start=dF.rev, level=level+1):
#print(' '*level, 'zzz', tail) #print(' '*level, 'zzz', tail)
yield ([dF.rev] + tail) yield ([dF.rev] + tail)
...@@ -1452,7 +1452,7 @@ def test_wcfs_watch_setup(): ...@@ -1452,7 +1452,7 @@ def test_wcfs_watch_setup():
for zf in t.zfiles(): for zf in t.zfiles():
for revv in t.iter_revv(): for revv in t.iter_revv():
print('\n--------') print('\n--------')
print(' -> '.join([t.hat(_) for _ in revv])) print(' -> '.join(revv))
wl = t.openwatch() wl = t.openwatch()
wl.watch(zf, revv[0]) wl.watch(zf, revv[0])
wl.watch(zf, revv[0]) # verify at_i -> at_i wl.watch(zf, revv[0]) # verify at_i -> at_i
...@@ -1724,16 +1724,27 @@ def test_tidtime_notrough(): ...@@ -1724,16 +1724,27 @@ def test_tidtime_notrough():
assert tidtime(at) > tidtime(atprev) assert tidtime(at) > tidtime(atprev)
# hat returns string for at. # tAt is bytes whose repr returns human readable string considering it as `at` under tDB.
# it gives both symbolic version and raw hex for at, for example: #
# It gives both symbolic version and raw hex forms, for example:
# @at2 (03cf7850500b5f66) # @at2 (03cf7850500b5f66)
@func(tDB) #
def hat(t, at): # tAt is used everywhere with the idea that e.g. if an assert comparing at, or
for i, dF in enumerate(t.dFtail): # e.g. dicts containing at, fails, everything is printed in human readable
if dF.rev == at: # form instead of raw hex that is hard to visibly map to logical transaction.
return "@at%d (%s)" % (i, h(at)) class tAt(bytes):
return "@" + h(at) def __new__(cls, tdb, at):
tat = bytes.__new__(cls, at)
tat.tdb = tdb
return tat
def __repr__(at):
t = at.tdb
for i, dF in enumerate(t.dFtail):
if dF.rev == at:
return "@at%d (%s)" % (i, h(at))
return "@" + h(at)
__str__ = __repr__
# hpin returns human-readable representation for {}blk->rev. # hpin returns human-readable representation for {}blk->rev.
@func(tDB) @func(tDB)
...@@ -1743,7 +1754,7 @@ def hpin(t, pin): ...@@ -1743,7 +1754,7 @@ def hpin(t, pin):
if pin[blk] is None: if pin[blk] is None:
s = '@head' s = '@head'
else: else:
s = t.hat(pin[blk]) s = '%s' % pin[blk]
pinv.append('%d: %s' % (blk, s)) pinv.append('%d: %s' % (blk, s))
return '{%s}' % ', '.join(pinv) return '{%s}' % ', '.join(pinv)
...@@ -1768,7 +1779,7 @@ def dump_history(t): ...@@ -1768,7 +1779,7 @@ def dump_history(t):
print('>>> Change history by file:\n') print('>>> Change history by file:\n')
for zf in t.zfiles(): for zf in t.zfiles():
print('f<%s>:' % h(zf._p_oid)) print('f<%s>:' % h(zf._p_oid))
indent = '\t%s\t' % (' '*len(t.hat(t.head)),) indent = '\t%s\t' % (' '*len('%s' % t.head),)
print('%s%s' % (indent, ' '.join('01234567'))) print('%s%s' % (indent, ' '.join('01234567')))
print('%s%s' % (indent, ' '.join('abcdefgh'))) print('%s%s' % (indent, ' '.join('abcdefgh')))
for dF in t.dFtail: for dF in t.dFtail:
...@@ -1782,7 +1793,7 @@ def dump_history(t): ...@@ -1782,7 +1793,7 @@ def dump_history(t):
else: else:
emitv.append(' ') emitv.append(' ')
print('\t%s\t%s' % (t.hat(dF.rev), ' '.join(emitv))) print('\t%s\t%s' % (dF.rev, ' '.join(emitv)))
print() print()
......
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