Commit e7eb277f authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 9f32a779
......@@ -92,7 +92,7 @@ public:
public:
error close();
_Mapping* mmap(zodb::Oid foid, int64_t blk_start, int64_t blk_len);
pair<_Mapping*, error> mmap(zodb::Oid foid, int64_t blk_start, int64_t blk_len);
error resync(zodb::Tid at);
private:
......
......@@ -254,7 +254,7 @@ void _Conn::_pin1(PinReq *req) {
}
// mmap creates file mapping representing file[blk_start +blk_len) data as of wconn.at database state.
_Mapping* _Conn::mmap(zodb::Oid foid, int64_t blk_start, int64_t blk_len) {
pair<_Mapping*, error> _Conn::mmap(zodb::Oid foid, int64_t blk_start, int64_t blk_len) {
_Conn& wconn = *this;
// XXX err ctx
// XXX (blk_start + blk_len) * blk_size overflow
......@@ -275,25 +275,24 @@ _Mapping* _Conn::mmap(zodb::Oid foid, int64_t blk_start, int64_t blk_len) {
_File* f; bool ok;
tie(f, ok) = wconn._filetab.get(foid);
if (f == nil) {
f = new _File();
f = new _File(); // XXX free f on error return (will be automatic if f = refptr)
f->wconn = newref(&wconn); // XXX newref -> simpler?
f->foid = foid;
tie(f->headf, err)
= wconn._wc->_open(fmt::sprintf("head/bigfile/%s", h_(foid)));
if (err != nil)
panic("TODO"); // XXX err
return make_pair(nil, err);
//f.pinned = {}
//f.mmaps = []
struct stat st;
err = f->headf->stat(&st);
if (err != nil)
panic("TODO"); // XXX
return make_pair(nil, err);
f->blksize = st.st_blksize;
f->headfsize = st.st_size;
if (!(f->headfsize % f->blksize == 0))
//return fmt::errorf("wcfs bug: head/file size %% blksize != 0");
panic("wcfs bug: head/file size %% blksize != 0"); // XXX -> err
return make_pair(nil, fmt::errorf("wcfs bug: head/file size %% blksize != 0"));
wconn._filetab[foid] = f;
......@@ -301,12 +300,11 @@ _Mapping* _Conn::mmap(zodb::Oid foid, int64_t blk_start, int64_t blk_len) {
string ack;
tie(ack, err) = wconn._wlink->sendReq(context::background(), fmt::sprintf("watch %s @%s", h_(foid), h_(wconn.at)));
if (err != nil)
panic("TODO"); // XXX
return make_pair(nil, err);
if (ack != "ok") {
// XXX unregister f from _filetab
// XXX vvv -> errctx?
/*return XXX*/ fmt::errorf("@%s: mmap f<%s>[%zd +%zd): %s", h_(wconn.at), h_(foid), blk_start, blk_len, ack.c_str());
panic("TODO ack != ok"); // XXX ^^^
return make_pair(nil, fmt::errorf("@%s: mmap f<%s>[%zd +%zd): %s", h_(wconn.at), h_(foid), blk_start, blk_len, ack.c_str()));
}
}
......@@ -318,7 +316,7 @@ _Mapping* _Conn::mmap(zodb::Oid foid, int64_t blk_start, int64_t blk_len) {
uint8_t *mem_start, *mem_stop;
tie(mem_start, err) = mmap_ro(f->headf, start, blk_len*f->blksize);
if (err != nil)
panic("TODO"); // XXX
return make_pair(nil, err);
mem_stop = mem_start + blk_len*f->blksize;
int64_t stop = blk_stop*f->blksize;
......@@ -326,7 +324,7 @@ _Mapping* _Conn::mmap(zodb::Oid foid, int64_t blk_start, int64_t blk_len) {
uint8_t *zmem_start = mem_start + (max(f->headfsize/*XXX -1 ?*/, start) - start);
err = mmap_zero_into_ro(zmem_start, mem_stop - zmem_start);
if (err != nil)
panic("TODO"); // XXX
return make_pair(nil, err);
}
_Mapping* mmap = new _Mapping();
......@@ -345,7 +343,7 @@ _Mapping* _Conn::mmap(zodb::Oid foid, int64_t blk_start, int64_t blk_len) {
f->mmaps.push_back(mmap); // XXX keep f.mmaps ↑blk_start
return mmap;
return make_pair(mmap, nil);
}
// resync resyncs connection and its mappings onto different database view.
......
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