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

.

parent 8995af28
...@@ -34,6 +34,7 @@ using namespace golang; ...@@ -34,6 +34,7 @@ using namespace golang;
#include <wendelin/bigfile/ram.h> #include <wendelin/bigfile/ram.h>
#include <wendelin/bug.h> #include <wendelin/bug.h>
#include <algorithm>
#include <string> #include <string>
#include <vector> #include <vector>
...@@ -47,6 +48,7 @@ using namespace golang; ...@@ -47,6 +48,7 @@ using namespace golang;
#include "wcfs_misc.h" #include "wcfs_misc.h"
using std::min;
using std::vector; using std::vector;
typedef uint64_t Tid; typedef uint64_t Tid;
...@@ -129,9 +131,9 @@ private: ...@@ -129,9 +131,9 @@ private:
struct _File { struct _File {
Conn *wconn; Conn *wconn;
Oid foid; // hex of ZBigFile root object ID 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 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 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 vector<_Mapping*> mmaps; // []_Mapping ↑blk_start mappings of this file
...@@ -365,7 +367,6 @@ void Conn::_pin1(PinReq *req) { ...@@ -365,7 +367,6 @@ void Conn::_pin1(PinReq *req) {
// XXX Conn::mmap // XXX Conn::mmap
// resync resyncs connection and its mappings onto different database view. // resync resyncs connection and its mappings onto different database view.
#if 0
error Conn::resync(Tid at) { error Conn::resync(Tid at) {
Conn &wconn = *this; Conn &wconn = *this;
// XXX err ctx // XXX err ctx
...@@ -374,24 +375,38 @@ error Conn::resync(Tid at) { ...@@ -374,24 +375,38 @@ error Conn::resync(Tid at) {
for (auto fit : wconn._filetab) { for (auto fit : wconn._filetab) {
Oid foid = fit.first; 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 // XXX if file has no mappings and was not used during whole prev
// cycle - forget and stop watching it // cycle - forget and stop watching it
// update f.headfsize and remmap to head/f zero regions that are now covered by head/f // update f.headfsize and remmap to head/f zero regions that are now covered by head/f
struct stat st; struct stat st;
auto err = f->headf.stat(&st) // XXX err auto err = f.headf.stat(&st);
assert f.blksize == st.st_blksize // blksize must not change if (err != nil)
headfsize = st.st_size; return err;
assert f.headfsize <= headfsize // head/file size ↑=
assert headfsize % f.blksize == 0 if ((size_t)st.st_blksize != f.blksize) // blksize must not change
for mmap in f.mmaps: return fmt::errorf("wcfs bug: blksize changed: %zd -> %ld", f.blksize, st.st_blksize);
printf(" resync -> %s: unzero [%d:%d)" % (at, f.headfsize//f.blksize, headfsize//f.blksize)); auto headfsize = st.st_size;
memunzero = mmap.mem[f.headfsize - mmap.blk_start*f.blksize : if (!(f.headfsize <= headfsize)) // head/file size ↑=
headfsize - mmap.blk_start*f.blksize] return fmt::errorf("wcfs bug: head/file size not ↑=");
if len(memunzero) > 0: if (!(headfsize % f.blksize == 0))
mm.map_into_ro(memunzero, f.headf.fileno(), f.headfsize) 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; f.headfsize = headfsize;
...@@ -405,8 +420,8 @@ error Conn::resync(Tid at) { ...@@ -405,8 +420,8 @@ error Conn::resync(Tid at) {
} }
wconn.at = at; wconn.at = at;
return nil;
} }
#endif
// _remmapblk remmaps mapping memory for file[blk] to be viewing database as of @at state. // _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) { ...@@ -444,8 +459,7 @@ error _Mapping::_remmapblk(int64_t blk, Tid at) {
if (err != nil) if (err != nil)
return err; return err;
if ((size_t)st.st_blksize != f->blksize) if ((size_t)st.st_blksize != f->blksize)
return fmt::errorf("wcfs bug: blksize changed: expected %lu; got %ld", return fmt::errorf("wcfs bug: blksize changed: %zd -> %ld", f->blksize, st.st_blksize);
f->blksize, st.st_blksize);
// block is beyond file size - mmap with zeros - else access to memory // block is beyond file size - mmap with zeros - else access to memory
// after file.size will raise SIGBUS. (assumes head/f size ↑=) // 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