Commit 4f8b5511 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 18ad4bdd
...@@ -33,8 +33,8 @@ using std::pair; ...@@ -33,8 +33,8 @@ using std::pair;
#include "wcfs_misc.h" #include "wcfs_misc.h"
struct Conn; class _Conn;
struct _WatchLink; class _WatchLink;
// WCFS represents filesystem-level connection to wcfs server. // WCFS represents filesystem-level connection to wcfs server.
...@@ -42,7 +42,7 @@ struct _WatchLink; ...@@ -42,7 +42,7 @@ struct _WatchLink;
struct WCFS { struct WCFS {
string mountpoint; string mountpoint;
tuple<Conn*, error> connect(zodb::Tid at); tuple<refptr<_Conn>, error> connect(zodb::Tid at);
string _path(const string &obj); string _path(const string &obj);
tuple<os::File, error> _open(const string &path, int flags=O_RDONLY); tuple<os::File, error> _open(const string &path, int flags=O_RDONLY);
pair<refptr<_WatchLink>, error> _openwatch(); pair<refptr<_WatchLink>, error> _openwatch();
......
...@@ -50,7 +50,6 @@ static string h(uint64_t v); // v -> 016x hex representation ...@@ -50,7 +50,6 @@ static string h(uint64_t v); // v -> 016x hex representation
static error mmap_zero_into_ro(void *addr, size_t size); static error mmap_zero_into_ro(void *addr, size_t size);
static error mmap_into_ro(void *addr, size_t size, const os::File &f, off_t offset); static error mmap_into_ro(void *addr, size_t size, const os::File &f, off_t offset);
struct Conn;
struct _File; struct _File;
struct _Mapping; struct _Mapping;
struct PinReq; struct PinReq;
...@@ -58,15 +57,34 @@ struct PinReq; ...@@ -58,15 +57,34 @@ struct PinReq;
// Conn represents logical connection that provides view of data on wcfs // Conn represents logical connection that provides view of data on wcfs
// filesystem as of particular database state. // filesystem as of particular database state.
// //
// XXX doc // It uses /head/bigfile/* and notifications received from /head/watch to
struct Conn { // maintain isolated database view while at the same time sharing most of data
// cache in OS pagecache of /head/bigfile/*.
//
// Use WCFS.connect(at) to create Conn.
// Use .mmap to create new Mappings.
// Use .resync to resync Conn onto different database view.
//
// Conn logically mirrors ZODB.Connection .
typedef refptr<class _Conn> Conn;
class _Conn {
WCFS *_wc; WCFS *_wc;
zodb::Tid at; zodb::Tid at;
WatchLink _wlink; WatchLink _wlink; // watch/receive pins for created mappings
sync::Mutex _filemu; sync::Mutex _filemu;
dict<zodb::Oid, _File*> _filetab; // {} foid -> _file dict<zodb::Oid, _File*> _filetab; // {} foid -> _file
// XXX ._pinWG, ._pinCancel
// don't new - create via WCFS.connect
private:
_Conn();
~_Conn();
friend tuple<Conn, error> WCFS::connect(zodb::Tid at);
public:
void decref();
public: public:
error close(); error close();
error resync(zodb::Tid at); error resync(zodb::Tid at);
...@@ -79,9 +97,10 @@ private: ...@@ -79,9 +97,10 @@ private:
// _File represent isolated file view under Conn. // _File represent isolated file view under Conn.
// //
// XXX doc XXX naming -> _FileView ? // XXX doc XXX naming -> _FileView ?
// XXX -> refptr ?
struct _File { struct _File {
Conn *wconn; Conn wconn;
zodb::Oid foid; // hex of ZBigFile root object ID zodb::Oid foid; // ZBigFile root object ID
size_t blksize; // block size of this file XXX -> off_t ? 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
off_t 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 ↑=)
...@@ -91,6 +110,7 @@ struct _File { ...@@ -91,6 +110,7 @@ struct _File {
}; };
// _Mapping represents one mapping of _File. // _Mapping represents one mapping of _File.
// XXX -> refptr ?
struct _Mapping { struct _Mapping {
_File *file; _File *file;
int blk_start; // offset of this mapping in file int blk_start; // offset of this mapping in file
...@@ -110,29 +130,27 @@ struct _Mapping { ...@@ -110,29 +130,27 @@ struct _Mapping {
// connect creates new Conn viewing WCFS state as of @at. // connect creates new Conn viewing WCFS state as of @at.
tuple<Conn*, error> WCFS::connect(zodb::Tid at) { tuple<Conn, error> WCFS::connect(zodb::Tid at) {
WCFS *wc = this; WCFS *wc = this;
// XXX err ctx // XXX err ctx
// TODO support !isolated mode
WatchLink wlink; WatchLink wlink;
error err; error err;
tie(wlink, err) = wc->_openwatch(); tie(wlink, err) = wc->_openwatch();
if (err != nil) if (err != nil)
return make_tuple((Conn *)NULL, err); return make_tuple(nil, err);
Conn *wconn = new Conn(); Conn wconn = adoptref(new _Conn());
// TODO support !isolated mode
wconn->_wc = wc; wconn->_wc = wc;
wconn->at = at; wconn->at = at;
wconn->_wlink = wlink; wconn->_wlink = wlink;
// XXX reenable
#if 0
pinCtx, wconn._pinCancel = context.with_cancel(context.background()) pinCtx, wconn._pinCancel = context.with_cancel(context.background())
wconn._pinWG = sync.WorkGroup(pinCtx) wconn._pinWG = sync.WorkGroup(pinCtx)
wconn._pinWG.go(wconn._pinner) wconn._pinWG.go(wconn._pinner)
#endif
return make_tuple(wconn, nil); return make_tuple(wconn, nil);
} }
...@@ -163,7 +181,7 @@ error Conn::close() { // XXX error -> void? ...@@ -163,7 +181,7 @@ error Conn::close() { // XXX error -> void?
for (auto _ : wconn._filetab) { for (auto _ : wconn._filetab) {
auto f = _.second; auto f = _.second;
f->headf->close(); // XXX err f->headf->close(); // XXX err
//f->headf = None f->headf = nil;
// XXX stop watching f // XXX stop watching f
} }
......
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