Commit 8d046f41 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent f818193e
...@@ -134,8 +134,9 @@ class tDB: ...@@ -134,8 +134,9 @@ class tDB:
t.tracked = set() t.tracked = set()
def close(t): def close(t):
for tf in t.tracked: for tf in t.tracked.copy():
tf.close() tf.close()
assert len(t.tracked) == 0
t._wc_zheadfh.close() t._wc_zheadfh.close()
t.wc.close() t.wc.close()
dbclose(t.root) dbclose(t.root)
...@@ -194,19 +195,15 @@ class tDB: ...@@ -194,19 +195,15 @@ class tDB:
path = t.path(obj, at=at) path = t.path(obj, at=at)
return os.stat(path) return os.stat(path)
# open opens file corresponding to obj on wcfs. # _open opens file corresponding to obj on wcfs.
def open(t, obj, at=None): def _open(t, obj, at=None):
path = t.path(obj, at=at) path = t.path(obj, at=at)
return open(path, 'rb', 0) # unbuffered return open(path, 'rb', 0) # unbuffered
# track starts to track wcfs file corresponding to zf@at. # open opens wcfs file corresponding to zf@at and starts to track it.
# see returned tFile for details. # see returned tFile for details.
# def open(t, zf, at=None):
# XXX -> openfile? testopen? return tFile(t, zf, at=at)
def track(t, zf, at=None):
tf = tFile(t, zf, at=at)
t.tracked.add(tf)
return tf
# tFile is testing environment for one bigfile on wcfs. # tFile is testing environment for one bigfile on wcfs.
class tFile: class tFile:
...@@ -217,7 +214,7 @@ class tFile: ...@@ -217,7 +214,7 @@ class tFile:
def __init__(t, tdb, zf, at=None): def __init__(t, tdb, zf, at=None):
assert isinstance(zf, ZBigFile) assert isinstance(zf, ZBigFile)
t.tdb = tdb t.tdb = tdb
t.f = tdb.open(zf, at=at) t.f = tdb._open(zf, at=at)
t.blksize = zf.blksize t.blksize = zf.blksize
# mmap the file past the end up to XXX pages and lock the pages with # mmap the file past the end up to XXX pages and lock the pages with
...@@ -228,8 +225,10 @@ class tFile: ...@@ -228,8 +225,10 @@ class tFile:
t.fmmap = mm.map_ro(t.f.fileno(), 0, t._max_tracked*t.blksize) t.fmmap = mm.map_ro(t.f.fileno(), 0, t._max_tracked*t.blksize)
mm.lock(t.fmmap, mm.MLOCK_ONFAULT) mm.lock(t.fmmap, mm.MLOCK_ONFAULT)
tdb.tracked.add(t)
def close(t): def close(t):
# XXX remove from t.tdb.tracked t.tdb.tracked.remove(t)
mm.unmap(t.fmmap) mm.unmap(t.fmmap)
t.f.close() t.f.close()
...@@ -247,7 +246,7 @@ class tFile: ...@@ -247,7 +246,7 @@ class tFile:
@func @func
def readblk(t, zf, blk, at=None): def readblk(t, zf, blk, at=None):
assert isinstance(zf, ZBigFile) assert isinstance(zf, ZBigFile)
f = t.open(zf, at=at) # XXX binary, !buffered f = t._open(zf, at=at) # XXX binary, !buffered
defer(f.close) defer(f.close)
blksize = zf.blksize blksize = zf.blksize
...@@ -351,29 +350,27 @@ def test_wcfs(): ...@@ -351,29 +350,27 @@ def test_wcfs():
t.stat(nonfile) t.stat(nonfile)
assert exc.value.errno == EINVAL assert exc.value.errno == EINVAL
f = t.track(zf) # XXX -> testopen, fileopen? f = t.open(zf)
# file initially empty # file initially empty
f.assertCache([]) f.assertCache([])
f.assertData ([], mtime=tid1) f.assertData ([], mtime=tid1)
# commit data to zf and make sure we can see it on wcfs # commit data to zf -> verify we can see it on wcfs
# 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)
zfh = zf.fileh_open(_use_wcfs=False) zfh = zf.fileh_open(_use_wcfs=False)
vma = zfh.mmap(2, 1) # 1 page at offset=2 vma = zfh.mmap(2, 1) # 1 page at offset=2
s = b"hello world" s = b"hello world"
memcpy(vma, s) memcpy(vma, s)
t.commit() t.commit()
t.wcsync() # sync wcfs to ZODB
t.wcsync()
f.assertCache([0,0,0]) # initially not cached f.assertCache([0,0,0]) # initially not cached
f.assertData ([b'',b'',s], mtime=t.head) f.assertData ([b'',b'',s], mtime=t.head)
# XXX assertCache all present?
# commit data again and make sure we can see both latest and snapshotted states. # commit data again -> verify we can see both latest and snapshotted states.
tcommit1 = t.head at1 = t.head
zfh = zf.fileh_open(_use_wcfs=False) zfh = zf.fileh_open(_use_wcfs=False)
vma1 = zfh.mmap(2, 1) vma1 = zfh.mmap(2, 1)
...@@ -382,18 +379,26 @@ def test_wcfs(): ...@@ -382,18 +379,26 @@ def test_wcfs():
s2 = b"alpha" s2 = b"alpha"
memcpy(vma1,s1) memcpy(vma1,s1)
memcpy(vma2,s2) memcpy(vma2,s2)
t.commit() t.commit()
t.wcsync() t.wcsync()
# f @head # f @head
f.assertCache([1,1,0,0]) # XXX fails here (.size changed) f.assertCache([1,1,0,0])
f.assertData ([b'',b'', s1+b'ld', s2], mtime=t.head) f.assertData ([b'',b'', s1+b'ld', s2], mtime=t.head)
# f @tcommit1 # f @at1
f1 = t.track(zf, at=tcommit1) f1 = t.open(zf, at=at1)
f1.assertCache([0,0,1]) f1.assertCache([0,0,1])
f1.assertData ([b'',b'',s]) # XXX + mtime=tcommit1? f1.assertData ([b'',b'',s]) # XXX + mtime=at1?
# f @head is opened again -> cache must not be lost
f.assertCache([1,1,1,1])
f_ = t.open(zf)
f_.assertCache([1,1,1,1])
f_.close()
f.assertCache([1,1,1,1])
def test_wcfs_invproto(): def test_wcfs_invproto():
......
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