Commit e7eb277f authored by Kirill Smelkov's avatar Kirill Smelkov

.

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