Commit 4a4c1998 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 5c299054
...@@ -55,8 +55,8 @@ testdb = None ...@@ -55,8 +55,8 @@ testdb = None
testzurl = None # URL of testdb testzurl = None # URL of testdb
testmntpt = None # wcfs is mounted here testmntpt = None # wcfs is mounted here
def setup_module(): def setup_module():
# if wcfs.py receives SIGBUS because wcfs.go panics, we want to see # if wcfs.py receives SIGBUS because wcfs.go panics while serving mmap'ed
# python-level traceback instead of being killed. # read, we want to see python-level traceback instead of being killed.
install_sigbus_trap() install_sigbus_trap()
global testdb, testzurl, testmntpt global testdb, testzurl, testmntpt
...@@ -214,7 +214,7 @@ class tDB: ...@@ -214,7 +214,7 @@ class tDB:
# check the thread is the same when .root is used ) # check the thread is the same when .root is used )
t._maintid = gettid() t._maintid = gettid()
# prepare initail objects for test: zfile, nonzfile # prepare initial objects for test: zfile, nonzfile
t.root['!file'] = t.nonzfile = Persistent() t.root['!file'] = t.nonzfile = Persistent()
t.root['zfile'] = t.zfile = ZBigFile(blksize) t.root['zfile'] = t.zfile = ZBigFile(blksize)
t.at0 = t.commit() t.at0 = t.commit()
...@@ -248,7 +248,7 @@ class tDB: ...@@ -248,7 +248,7 @@ class tDB:
def openwatch(t): # -> tWatchLink def openwatch(t): # -> tWatchLink
return tWatchLink(t) return tWatchLink(t)
# change schedules zf to be changed according changeDelta at commit. # change schedules zf to be changed according to changeDelta at commit.
# #
# changeDelta: {} blk -> data. # changeDelta: {} blk -> data.
# data can be both bytes and unicode. # data can be both bytes and unicode.
...@@ -267,17 +267,15 @@ class tDB: ...@@ -267,17 +267,15 @@ class tDB:
# #
# zf and changeDelta can be optionally provided, in which case .change(zf, # zf and changeDelta can be optionally provided, in which case .change(zf,
# changeDelta) call is made before actually committing. # changeDelta) call is made before actually committing.
def commit(t, zf=None, changeDelta=None): def commit(t, zf=None, changeDelta=None): # -> tAt
if zf is not None: if zf is not None:
assert changeDelta is not None assert changeDelta is not None
t.change(zf, changeDelta) t.change(zf, changeDelta)
# we'll verify that all changed objects come from the same ZODB connection
zconns = set()
# perform modifications scheduled by change. # perform modifications scheduled by change.
# use !wcfs mode so that we prepare data independently of wcfs code paths. # use !wcfs mode so that we prepare data independently of wcfs code paths.
dF = DF() dF = DF()
zconns = set()
for zf, zfDelta in t._changed.items(): for zf, zfDelta in t._changed.items():
dfile = DFile() dfile = DFile()
zconns.add(zf._p_jar) zconns.add(zf._p_jar)
...@@ -289,6 +287,7 @@ class tDB: ...@@ -289,6 +287,7 @@ class tDB:
memcpy(vma, data) memcpy(vma, data)
dF.byfile[zf] = dfile dF.byfile[zf] = dfile
# verify that all changed objects come from the same ZODB connection
assert len(zconns) in (0, 1) # either nothing to commit or all from the same zconn assert len(zconns) in (0, 1) # either nothing to commit or all from the same zconn
if len(zconns) == 1: if len(zconns) == 1:
zconn = zconns.pop() zconn = zconns.pop()
...@@ -504,7 +503,6 @@ class tFile: ...@@ -504,7 +503,6 @@ class tFile:
# provided pinokByWLink when it is present. # provided pinokByWLink when it is present.
@func @func
def assertBlk(t, blk, dataok, pinokByWLink=None): def assertBlk(t, blk, dataok, pinokByWLink=None):
#print('assertBlk #%d' % blk)
# XXX -> assertCtx('blk #%d' % blk) # XXX -> assertCtx('blk #%d' % blk)
def _(): def _():
assertCtx = 'blk #%d' % blk assertCtx = 'blk #%d' % blk
...@@ -555,7 +553,6 @@ class tFile: ...@@ -555,7 +553,6 @@ class tFile:
assert cached == 0 assert cached == 0
# even if @head[blk] is uncached, the block could be # even if @head[blk] is uncached, the block could be
# already pinned by setup watch # already pinned by setup watch
# XXX assert blkaccessed.rev > w.at => w.pinned
if blk not in w.pinned: if blk not in w.pinned:
pinok = {blk: t.tdb._blkRevAt(t.zf, blk, w.at)} pinok = {blk: t.tdb._blkRevAt(t.zf, blk, w.at)}
shouldPin = True shouldPin = True
...@@ -569,7 +566,7 @@ class tFile: ...@@ -569,7 +566,7 @@ class tFile:
for wlink, pinok in pinokByWLink.items(): for wlink, pinok in pinokByWLink.items():
pinokByWLink[wlink] = (t.zf, pinok) pinokByWLink[wlink] = (t.zf, pinok)
# access 1 bye on the block and verify that wcfs sends us correct pins # access 1 byte on the block and verify that wcfs sends us correct pins
blkview = t._blk(blk) blkview = t._blk(blk)
assert t.cached()[blk] == cached assert t.cached()[blk] == cached
...@@ -625,9 +622,9 @@ class tFile: ...@@ -625,9 +622,9 @@ class tFile:
# #
# Expected blocks may be given with size < zf.blksize. In such case they # Expected blocks may be given with size < zf.blksize. In such case they
# are implicitly appended with trailing zeros. If a block is specified as # are implicitly appended with trailing zeros. If a block is specified as
# 'x' - this particular block is not checked. # 'x' - this particular block is not accessed and is not checked.
# #
# It also checks file size and optionally mtime. # The file size and optionally mtime are also verified.
def assertData(t, dataokv, mtime=None): def assertData(t, dataokv, mtime=None):
st = os.fstat(t.f.fileno()) st = os.fstat(t.f.fileno())
assert st.st_size == len(dataokv)*t.blksize assert st.st_size == len(dataokv)*t.blksize
...@@ -823,7 +820,7 @@ class tWatchLink: ...@@ -823,7 +820,7 @@ class tWatchLink:
return _rx return _rx
def _sendReq(t, ctx, req): # -> rxq def _sendReq(t, ctx, req): # -> rxq
stream = 1 stream = 1 # XXX -> dynamic
rxq = chan() rxq = chan()
with t._rxmu: with t._rxmu:
...@@ -1032,7 +1029,7 @@ def _watch(twlink, zf, at, pinok, replyok): ...@@ -1032,7 +1029,7 @@ def _watch(twlink, zf, at, pinok, replyok):
# #
# f(ctx, eventv) # f(ctx, eventv)
# pinokByWLink: {} tWatchLink -> (zf, {} blk -> at). # pinokByWLink: {} tWatchLink -> (zf, {} blk -> at).
# pinfunc(wlink, foid, blk, at) | None. XXX foid -> ZBigFile? # pinfunc(wlink, foid, blk, at) | None.
# #
# pinfunc is called after pin request is received from wcfs, but before pin ack # pinfunc is called after pin request is received from wcfs, but before pin ack
# is replied back. Pinfunc must not block. # is replied back. Pinfunc must not block.
...@@ -1135,8 +1132,6 @@ def _blkDataAt(t, zf, blk, at): # -> (data, rev) ...@@ -1135,8 +1132,6 @@ def _blkDataAt(t, zf, blk, at): # -> (data, rev)
if at is None: if at is None:
at = t.head at = t.head
# XXX dup wrt _pinnedAt
# all changes to zf # all changes to zf
vdf = [_.byfile[zf] for _ in t.dFtail if zf in _.byfile] vdf = [_.byfile[zf] for _ in t.dFtail if zf in _.byfile]
...@@ -1150,8 +1145,8 @@ def _blkDataAt(t, zf, blk, at): # -> (data, rev) ...@@ -1150,8 +1145,8 @@ def _blkDataAt(t, zf, blk, at): # -> (data, rev)
_ = blkhistoryat[-1] _ = blkhistoryat[-1]
data = _.ddata[blk] data = _.ddata[blk]
rev = _.rev rev = _.rev
assert rev <= at
assert rev <= at
return data, rev return data, rev
# _blkRevAt returns expected zf[blk] revision as of @at database state. # _blkRevAt returns expected zf[blk] revision as of @at database state.
...@@ -1171,8 +1166,6 @@ def _blkRevAt(t, zf, blk, at): # -> rev ...@@ -1171,8 +1166,6 @@ def _blkRevAt(t, zf, blk, at): # -> rev
# ; (and so is tracked by wcfs) # ; (and so is tracked by wcfs)
@func(tDB) @func(tDB)
def _pinnedAt(t, zf, at): # -> pin = {} blk -> rev def _pinnedAt(t, zf, at): # -> pin = {} blk -> rev
# XXX dup in _blkDataAt
# all changes to zf # all changes to zf
vdf = [_.byfile[zf] for _ in t.dFtail if zf in _.byfile] vdf = [_.byfile[zf] for _ in t.dFtail if zf in _.byfile]
...@@ -1182,15 +1175,8 @@ def _pinnedAt(t, zf, at): # -> pin = {} blk -> rev ...@@ -1182,15 +1175,8 @@ def _pinnedAt(t, zf, at): # -> pin = {} blk -> rev
for blk in df.ddata: for blk in df.ddata:
if blk in pin: if blk in pin:
continue continue
# history of blk changes <= at
blkhistoryat = [_.rev for _ in vdf if blk in _.ddata and _.rev <= at]
if len(blkhistoryat) == 0:
pinrev = t.dFtail[0].rev # was hole - at0 XXX -> pin to z64?
else:
pinrev = blkhistoryat[-1]
assert pinrev <= at
if blk in t._blkaccessed(zf): if blk in t._blkaccessed(zf):
pin[blk] = pinrev pin[blk] = t._blkRevAt(zf, blk, at)
return pin return pin
...@@ -1817,7 +1803,7 @@ def tidtime(tid): ...@@ -1817,7 +1803,7 @@ def tidtime(tid):
# NOTE pytest.approx supports only ==, not e.g. <, so we use plain round. # NOTE pytest.approx supports only ==, not e.g. <, so we use plain round.
return round(t, 6) return round(t, 6)
# tidfromtime converts time into corresponding transacton ID. # tidfromtime converts time into corresponding transaction ID.
def tidfromtime(t): def tidfromtime(t):
f = t - int(t) # fraction of seconds f = t - int(t) # fraction of seconds
t = int(t) t = int(t)
...@@ -1955,7 +1941,7 @@ defer = xdefer ...@@ -1955,7 +1941,7 @@ defer = xdefer
del xdefer del xdefer
# ready reports whether chan ch is ready # ready reports whether chan ch is ready.
def ready(ch): def ready(ch):
_, _rx = select( _, _rx = select(
default, # 0 default, # 0
......
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