Commit e9c16aec authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 4d006d3c
......@@ -260,6 +260,7 @@ def resync(wconn, at):
assert f.headfsize <= headfsize # head/file size ↑=
assert headfsize % f.blksize == 0
for mmap in f.mmaps:
print(' resync -> %s: unzero [%d:%d)' % (at, f.headfsize//f.blksize, headfsize//f.blksize))
memunzero = mmap.mem[f.headfsize - mmap.blk_start*f.blksize :
headfsize - mmap.blk_start*f.blksize]
if len(memunzero) > 0:
......@@ -340,18 +341,20 @@ def _remmapblk(mmap, blk, at):
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?
fsfile = f.wconn._wc._open("@%s/bigfile/%s" % (h(at), h(f.foid)), "rb")
defer(fsfile.close)
assert os.fstat(fsfile.fileno()).st_blksize == f.blksize # FIXME assert
_ = os.fstat(fsfile.fileno())
assert _.st_blksize == f.blksize # FIXME assert
# block is beyond file size - mmap with zeros (assumes head/f size ↑=)
if (blk+1)*f.blksize > _.st_size:
mm.map_zero_into_ro(blkmem)
# block is inside file - mmap file data
else:
mm.map_into_ro(blkmem, fsfile.fileno(), blk*f.blksize)
......
......@@ -1765,12 +1765,12 @@ def test_wcfspy_virtmem():
tm1.assertBlk(4, '')
assert f.pinned == {2:at1, 3:at1}
# resync at1 -> at2: #2 must unpin to @head
# resync at1 -> at2: #2 must unpin to @head; #4 must stay as zero
wconn.resync(at2)
assert f.pinned == {3:at1}
tm1.assertBlk(2, 'c2')
tm1.assertBlk(3, 'd1')
tm1.assertBlk(3, '')
tm1.assertBlk(4, '')
# resync at2 -> at3: #3 must unpin to @head; #4 - start to read with data
wconn.resync(at3)
......
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