Commit 987fdf4b authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 8995af28
......@@ -34,6 +34,7 @@ using namespace golang;
#include <wendelin/bigfile/ram.h>
#include <wendelin/bug.h>
#include <algorithm>
#include <string>
#include <vector>
......@@ -47,6 +48,7 @@ using namespace golang;
#include "wcfs_misc.h"
using std::min;
using std::vector;
typedef uint64_t Tid;
......@@ -129,9 +131,9 @@ private:
struct _File {
Conn *wconn;
Oid foid; // hex of ZBigFile root object ID
size_t blksize; // block size of this file
size_t blksize; // block size of this file XXX -> off_t ?
os::File headf; // file object of head/file
// .headfsize head/file size is known to be at least headfsize (size ↑=)
off_t headfsize; // head/file size is known to be at least headfsize (size ↑=)
dict<int64_t, Tid> pinned; // {} blk -> rev that wcfs already sent us for this file
vector<_Mapping*> mmaps; // []_Mapping ↑blk_start mappings of this file
......@@ -365,7 +367,6 @@ void Conn::_pin1(PinReq *req) {
// XXX Conn::mmap
// resync resyncs connection and its mappings onto different database view.
#if 0
error Conn::resync(Tid at) {
Conn &wconn = *this;
// XXX err ctx
......@@ -374,24 +375,38 @@ error Conn::resync(Tid at) {
for (auto fit : wconn._filetab) {
Oid foid = fit.first;
_File *f = fit.second;
_File &f = *fit.second;
// 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
struct stat st;
auto err = f->headf.stat(&st) // XXX err
assert f.blksize == st.st_blksize // blksize must not change
headfsize = st.st_size;
assert f.headfsize <= headfsize // head/file size ↑=
assert headfsize % f.blksize == 0
for mmap in f.mmaps:
printf(" 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:
mm.map_into_ro(memunzero, f.headf.fileno(), f.headfsize)
auto err = f.headf.stat(&st);
if (err != nil)
return err;
if ((size_t)st.st_blksize != f.blksize) // blksize must not change
return fmt::errorf("wcfs bug: blksize changed: %zd -> %ld", f.blksize, st.st_blksize);
auto headfsize = st.st_size;
if (!(f.headfsize <= headfsize)) // head/file size ↑=
return fmt::errorf("wcfs bug: head/file size not ↑=");
if (!(headfsize % f.blksize == 0))
return fmt::errorf("wcfs bug: head/file size %% blksize != 0");
for (auto mmap : f.mmaps) {
printf(" resync -> %s: unzero [%lu:%lu)", h_(at), f.headfsize/f.blksize, headfsize/f.blksize);
uint8_t *mem_unzero_start = min(mmap->mem_stop,
mmap->mem_start + (f.headfsize - mmap->blk_start*f.blksize));
uint8_t *mem_unzero_stop = min(mmap->mem_stop,
mmap->mem_start + (headfsize - mmap->blk_start*f.blksize));
if (mem_unzero_stop - mem_unzero_start > 0) {
err = mm::map_into(mem_unzero_start, mem_unzero_stop-mem_unzero_start, PROT_READ, MAP_SHARED, f.headf, f.headfsize);
if (err != nil)
return err;
}
}
f.headfsize = headfsize;
......@@ -405,8 +420,8 @@ error Conn::resync(Tid at) {
}
wconn.at = at;
return nil;
}
#endif
// _remmapblk remmaps mapping memory for file[blk] to be viewing database as of @at state.
//
......@@ -444,8 +459,7 @@ error _Mapping::_remmapblk(int64_t blk, Tid at) {
if (err != nil)
return err;
if ((size_t)st.st_blksize != f->blksize)
return fmt::errorf("wcfs bug: blksize changed: expected %lu; got %ld",
f->blksize, st.st_blksize);
return fmt::errorf("wcfs bug: blksize changed: %zd -> %ld", f->blksize, st.st_blksize);
// block is beyond file size - mmap with zeros - else access to memory
// after file.size will raise SIGBUS. (assumes head/f size ↑=)
......
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