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

.

parent 3470a1d5
......@@ -156,7 +156,7 @@ def close(wconn):
# close all files - both that have no mappings and that still have opened mappings.
# XXX after file is closed mappings continue to survive, but we can no
# longer maintin consisten view.
# longer maintain consistent view.
with wconn._filemu:
for f in wconn._filetab.values():
f.headf.close()
......@@ -249,17 +249,31 @@ def _pin1(wconn, req):
def resync(wconn, at):
# XXX locking
for foid in wconn._filetab:
for foid, f in wconn._filetab.items():
# XXX if file has no mappings and was not used during whole prev
# cycle - forget and stop watching it
# update f.headfsize and remmap to head/f zero regions that are now covered by head/f
_ = os.fstat(f.headf.fileno())
assert f.blksize == _.st_blksize # blksize must not change
headfsize = _.st_size
assert f.headfsize <= headfsize # head/file size ↑=
assert headfsize % f.blksize == 0
for mmap in f.mmaps:
memunzero = mmap.mem[f.headfsize - mmap.blk_start*f.blksize :
headfsize - mmap.blk_start*f.blksize]
if len(memunzero) > 0:
mm.map_into_ro(memunzero, f.headf.fileno(), f.headfsize)
f.headfsize = headfsize
_ = wconn._wlink.sendReq(context.background(), b"watch %s @%s" % (h(foid), h(at)))
if _ != "ok":
# XXX unregister f from _filetab
# XXX vvv -> errctx?
raise RuntimeError("resync @%s -> @%s: f<%s>: %s" % (h(wconn.at), h(at), h(foid), _))
# XXX update f.headfsize
# XXX remmap appended data after old f.headfsize
wconn.at = at
......@@ -282,6 +296,7 @@ def mmap(wconn, foid, blk_start, blk_len): # -> Mapping
_ = os.fstat(f.headf.fileno())
f.blksize = _.st_blksize
f.headfsize = _.st_size
assert f.headfsize % f.blksize == 0
wconn._filetab[foid] = f
......@@ -323,7 +338,13 @@ def mmap(wconn, foid, blk_start, blk_len): # -> Mapping
def _remmapblk(mmap, blk, at):
assert mmap.blk_start <= blk < mmap.blk_stop
f = mmap.file
blkmem = mmap.mem[(blk-mmap.blk_start)*f.blksize:][:f.blksize]
if at is None:
# head/file[blk >= size] -> Z
if blk*f.blksize >= f.headfsize:
mm.map_zero_into(blkmem)
return
# head/file[blk < size] -> use the file
fsfile = f.headf
else:
# TODO share @rev fd until wconn is resynced?
......@@ -331,9 +352,7 @@ def _remmapblk(mmap, blk, at):
defer(fsfile.close)
assert os.fstat(fsfile.fileno()).st_blksize == f.blksize # FIXME assert
mm.map_into_ro(
mmap.mem[(blk-mmap.blk_start)*f.blksize:][:f.blksize],
fsfile.fileno(), blk*f.blksize)
mm.map_into_ro(blkmem, fsfile.fileno(), blk*f.blksize)
# remmap_blk remmaps file[blk] in its place again.
......@@ -758,7 +777,7 @@ def join(zurl, autostart=_default_autostart()): # -> WCFS
# _start starts wcfs server for ZODB @ zurl.
#
# optv can be optionally given to pass flags to wcfs.
# called under _wcmu
# called under _wcmu.
def _start(zurl, *optv): # -> WCFS
mntpt = _mntpt_4zurl(zurl)
log.info("wcfs: starting for %s ...", zurl)
......
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