Commit 7cbb1b4a authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent e7eb277f
......@@ -88,57 +88,6 @@ class WCFS(_WCFS):
pass
"""
# mmap creates file mapping representing file[blk_start +blk_len) data as of wconn.at database state.
@func(Conn)
def mmap(wconn, foid, blk_start, blk_len): # -> Mapping
assert blk_len >= 0
blk_stop = blk_start + blk_len
with wconn._filemu:
f = wconn._filetab.get(foid)
if f is None:
f = _File()
f.wconn = wconn
f.foid = foid
f.headf = wconn._wc._open("head/bigfile/%s" % (h(foid),), "rb")
f.pinned = {}
f.mmaps = []
_ = os.fstat(f.headf.fileno())
f.blksize = _.st_blksize
f.headfsize = _.st_size
assert f.headfsize % f.blksize == 0
wconn._filetab[foid] = 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("@%s: mmap f<%s>[%d +%d): %s" % (h(wconn.at), h(foid), blk_start, blk_len, _))
# XXX relock wconn -> f ?
# create memory with head/f mapping and applied pins
# mmap-in zeros after f.size (else access to memory after file.size will raise SIGBUS)
start = blk_start*f.blksize
mem = mm.map_ro(f.headf.fileno(), start, blk_len*f.blksize)
zmemtail = mem[max(f.headfsize, start) - start:]
if len(zmemtail) != 0:
mm.map_zero_into_ro(zmemtail)
mmap = _Mapping()
mmap.file = f
mmap.blk_start = blk_start
mmap.mem = mem
for blk, rev in f.pinned.items(): # XXX keep f.pinned ↑blk and use binary search?
if not (blk_start <= blk < blk_stop):
continue # blk out of this mapping
mmap._remmapblk(blk, rev)
f.mmaps.append(mmap) # XXX keep f.mmaps ↑blk_start
return mmap
# resync resyncs connection and its mappings onto different database view.
@func(Conn)
def resync(wconn, at):
......
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