Commit 622e0a43 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 6adf799c
......@@ -178,7 +178,7 @@ class DF:
# it is is similar to ΔFile in wcfs.go .
class DFile:
# .rev tid
# .ddata {} blk -> data XXX name
# .ddata {} blk -> data
def __init__(dfile):
# rev set from outside
dfile.ddata = {}
......@@ -370,6 +370,32 @@ class tDB:
#print(' '*level, 'zzz', tail)
yield ([dF.rev] + tail)
# _blkData returns expected blk data and revision for @at database view.
def _blkData(t, zf, blk, at=None): # -> (data, rev)
if at is None:
at = t.head
# XXX dup wrt _pinAt
# all changes to zf
vdf = [_.byfile[zf] for _ in t.dFtail if zf in _.byfile]
# changes to zf[blk] <= at
blkhistoryat = [_ for _ in vdf if blk in _.ddata and _.rev <= at]
if len(blkhistoryat) == 0:
# blk did not existed @at # XXX verify whether file was existing at all
data = b''
rev = None
else:
_ = blkhistoryat[-1]
data = _.ddata[blk]
rev = _.rev
assert rev <= at
return data, rev
# tFile provides testing environment for one bigfile on wcfs.
......@@ -385,6 +411,8 @@ class tFile:
def __init__(t, tdb, zf, at=None):
assert isinstance(zf, ZBigFile)
t.tdb = tdb
t.zf = zf
t.at = at
t.f = tdb._open(zf, at=at)
t.blksize = zf.blksize
......@@ -447,6 +475,8 @@ class tFile:
if not isinstance(data, bytes):
data = data.encode('utf-8')
assert len(data) <= t.blksize
dataOk, _ = t.tdb._blkData(t.zf, blk, t.at)
assert data == dataOk, "explicit vs computed data"
data += b'\0'*(t.blksize - len(data)) # tailing zeros
assert blk < t._sizeinblk()
......@@ -724,7 +754,7 @@ def _pinAt(twlink, zf, at): # -> pin = {} blk -> rev
if len(blkhistoryat) == 0:
pinrev = t._headv[0] # was hole - at0 XXX -> pin to @00?
else:
pinrev = max(blkhistoryat)
pinrev = blkhistoryat[-1]
assert pinrev <= at
pin[blk] = pinrev
......@@ -1032,6 +1062,7 @@ def test_wcfs():
at4 = t.commit()
f.assertCache([1,1,0,1,0,0]) # FIXME a must be invalidated - see δbtree ^^^
# XXX -> f.assertBlk(2, '4c', {wl: {2: at3}})
blk = 2
pinok = {2: at3} # XXX at3 -> at <= wl.at for zf
......
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