Commit e7b5eab2 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent aeb11950
...@@ -46,7 +46,7 @@ import threading ...@@ -46,7 +46,7 @@ import threading
from persistent import Persistent from persistent import Persistent
from ZODB.FileStorage import FileStorage from ZODB.FileStorage import FileStorage
from ZODB.utils import z64, u64, p64 from ZODB.utils import z64, u64, p64
from zodbtools.util import ashex, fromhex from zodbtools.util import ashex as h, fromhex
from .internal import mm from .internal import mm
...@@ -193,13 +193,18 @@ def mmap(wconn, foid, blk_start, blk_len): # -> Mapping ...@@ -193,13 +193,18 @@ def mmap(wconn, foid, blk_start, blk_len): # -> Mapping
f = _File() f = _File()
f.wconn = wconn f.wconn = wconn
f.foid = foid f.foid = foid
f.headf = wconn._wc._open("head/bigfile/%s" % (ashex(foid),), "rb") f.headf = wconn._wc._open("head/bigfile/%s" % (h(foid),), "rb")
f.blksize = os.fstat(f.headf.fileno()).st_blksize f.blksize = os.fstat(f.headf.fileno()).st_blksize
f.pinned = {} f.pinned = {}
f.mmaps = [] f.mmaps = []
wconn._filetab[foid] = f wconn._filetab[foid] = f
# XXX start watching f # start watching f
_ = wconn._wlink.sendReq(context.background(), b"watch %s @%s" % (h(foid), h(wconn.at)))
if _ != "ok":
# XXX unregister f from _filetab
# XXX vvv -> errctx?
raise RuntimeError("mmap f<%s>[%d +%d): %s" % (h(foid), blk_start, blk_len, _))
# XXX relock wconn -> f ? # XXX relock wconn -> f ?
...@@ -231,7 +236,7 @@ def _remmapblk(mmap, blk, at): ...@@ -231,7 +236,7 @@ def _remmapblk(mmap, blk, at):
fsfile = f.headf fsfile = f.headf
else: else:
# TODO share @rev fd until wconn is resynced? # TODO share @rev fd until wconn is resynced?
fsfile = f.wconn._wc._open("@%s/bigfile/%s" % (ashex(at), ashex(f.foid)), "rb") fsfile = f.wconn._wc._open("@%s/bigfile/%s" % (h(at), h(f.foid)), "rb")
defer(fsfile.close) defer(fsfile.close)
assert os.fstat(fsfile.fileno()).st_blksize == f.blksize # FIXME assert assert os.fstat(fsfile.fileno()).st_blksize == f.blksize # FIXME assert
...@@ -515,8 +520,8 @@ def _path(wc, obj, at=None): ...@@ -515,8 +520,8 @@ def _path(wc, obj, at=None):
#assert type(obj) is ZBigFile XXX import cycle #assert type(obj) is ZBigFile XXX import cycle
objtypestr = type(obj).__module__ + "." + type(obj).__name__ objtypestr = type(obj).__module__ + "." + type(obj).__name__
assert objtypestr == "wendelin.bigfile.file_zodb.ZBigFile", objtypestr assert objtypestr == "wendelin.bigfile.file_zodb.ZBigFile", objtypestr
head = "head/" if at is None else ("@%s/" % ashex(at)) head = "head/" if at is None else ("@%s/" % h(at))
obj = "%s/bigfile/%s" % (head, ashex(obj._p_oid)) obj = "%s/bigfile/%s" % (head, h(obj._p_oid))
at = None at = None
assert isinstance(obj, str) assert isinstance(obj, str)
assert at is None # must not be used with str assert at is None # must not be used with str
...@@ -558,7 +563,7 @@ def _open(wc, obj, mode='rb', at=None): ...@@ -558,7 +563,7 @@ def _open(wc, obj, mode='rb', at=None):
zat = p64(u64(zconn._storage._start)-1) # before -> at zat = p64(u64(zconn._storage._start)-1) # before -> at
# XXX pinned to @revX/... for now -> TODO /head/bigfile/... # XXX pinned to @revX/... for now -> TODO /head/bigfile/...
path = '%s/@%s/bigfile/%s' % (self.mountpoint, ashex(zat), ashex(zfile._p_oid)) path = '%s/@%s/bigfile/%s' % (self.mountpoint, h(zat), h(zfile._p_oid))
fd = os.open(path, os.O_RDONLY) fd = os.open(path, os.O_RDONLY)
return FileH(fd) return FileH(fd)
......
...@@ -1736,16 +1736,16 @@ def test_wcfspy_virtmem(): ...@@ -1736,16 +1736,16 @@ def test_wcfspy_virtmem():
assert len(m1.mem) == 3*zf.blksize assert len(m1.mem) == 3*zf.blksize
f = m1.file f = m1.file
t1 = tMapping(m1) tm1 = tMapping(m1)
#assertCache(m1, [0,0,0]) #assertCache(m1, [0,0,0])
assert f.pinned == {} assert f.pinned == {}
t1.assertBlk(2, 'c1') tm1.assertBlk(2, 'c1')
assert f.pinned == {2:at1} assert f.pinned == {2:at1}
t1.assertBlk(3, 'd1') tm1.assertBlk(3, 'd1')
assert f.pinned == {2:at1} assert f.pinned == {2:at1}
t1.assertBlk(3, 'x') tm1.assertBlk(3, 'x')
assert f.pinned == {2:at1} assert f.pinned == {2:at1}
#assertData (m1, ['c1','d1','']) #assertData (m1, ['c1','d1',''])
......
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