Remoto - VFS
|
A VFS_datastore subclass for accessing data in Mongo. More...
#include <VFS_mongo.h>
Public Member Functions | |
Q_INVOKABLE | VFS_mongo (QString uri, QString db, QString collection, quint64 size=VFS_datastore_cache::DEFAULT_DATACACHE_SIZE, bool debug=false, int flushInterval=5000, int expireInterval=60000, bool createCollection=false) |
Create a VFS_Mongo node. More... | |
virtual | ~VFS_mongo () |
virtual QString | reportDetails () |
Report the current cache usage. More... | |
Public Member Functions inherited from VFS_datastore | |
VFS_datastore (quint64 size, bool debug=false) | |
virtual | ~VFS_datastore () |
virtual VFS_node * | find (VFS_request *r) |
virtual bool | isContainer () |
All datastore subclasses are containers. More... | |
Public Member Functions inherited from VFS_node | |
Q_INVOKABLE | VFS_node () |
The VFS_node constructor will add its instance to the VFS_node::__allNodes global node registry, observing thread safety rules. More... | |
virtual | ~VFS_node () |
VFS_node destructor. More... | |
virtual VFS_node * | append (QString name, VFS_node *node, bool containerCheck=true, QString user="server") |
Append a VFS_node as a child of this node. More... | |
QString | className () |
Return the class name of a node. More... | |
virtual VFS_request * | createRequest (VFS_request::requestType type, QString path, QString user="unknown", QJsonDocument data=QJsonDocument(), QJsonObject metadata=QJsonObject(), bool dontDelete=false) |
Create a new VFS_request with this object as _origin. More... | |
VFS_node * | find (QString path) |
Find a node by string path. More... | |
VFS_node * | findChildWithName (QString name) |
Check if a child with a given name exists. More... | |
virtual VFS_node * | mount () |
Mount this node. More... | |
QString | uniqueChildName (QString name) |
Generate a unique child name. More... | |
virtual VFS_node * | unmount () |
Unmount this node. More... | |
virtual bool | validChildName (QString name) |
Check if a node name is valid. More... | |
Protected Member Functions | |
bool | createCollection (QString name) |
Create a collection. More... | |
bool | createDocument (QString path, QJsonObject o, quint64 &size, bool container=false) |
Create a new document in the database if it doesn't exist. More... | |
virtual QByteArray | icon () |
The "disk" icon found in the VFS_icons library. More... | |
virtual void | ls (VFS_request *r) |
List the contents of a collection using a Mongo find() on the path. More... | |
virtual void | metadata (VFS_request *r) |
Fetch the metadata for a database document. More... | |
virtual void | read (VFS_request *r) |
Read the contents of a database document. More... | |
QJsonObject | readDocument (QString path, quint64 &size, bool &container) |
Search for a document by "_path" in the database. More... | |
bool | removeDocument (QString path) |
Remove a document from the database. More... | |
virtual void | rm (VFS_request *r) |
Attempt to delete a file. More... | |
virtual void | submit (VFS_request *r) |
Submit data to a file, applying the data as a diff. More... | |
virtual void | subscribe (VFS_request *r) |
Subscribe to changes on a database document. More... | |
virtual void | write (VFS_request *r) |
Write data to a database document. More... | |
quint64 | writeDocument (QString path, QJsonObject o, bool container=false) |
Update a document in the database. More... | |
Protected Member Functions inherited from VFS_node | |
virtual void | aclDefaults (VFS_request *r) |
Return default values and features associated wth this node. More... | |
void | addACLDefault (QJsonObject &acl, bool value, QString description="") |
Add a default value to the acl object. More... | |
void | addACLFeature (QJsonObject &acl, QString feature, bool value, QString description="") |
Add a feature to the acl object. More... | |
void | addACLFeatureGroup (QJsonObject &acl, QString feature, QString group, bool value) |
Add a feature group to the acl object. More... | |
void | addACLFeatureUser (QJsonObject &acl, QString feature, QString user, bool value) |
Add a feature user to the acl object. More... | |
void | addACLGroup (QJsonObject &acl, QString group, bool value) |
Add a group to the acl object. More... | |
void | addACLUser (QJsonObject &acl, QString user, bool value) |
Add a user to the acl object. More... | |
virtual void | issueRequest (VFS_node *target, VFS_request *t) |
Issue a VFS_request to its target. More... | |
virtual void | issueRequest (VFS_request *t) |
A convenience function. More... | |
virtual void | issueResponse (VFS_request *t) |
Once a request has been completed, issue a response. More... | |
virtual void | releaseLock (VFS_request *r) |
Release a lock on this node. More... | |
virtual void | report (VFS_request *r) |
Report debugging information about the current state of this node. More... | |
virtual void | requestLock (VFS_request *r) |
Request a lock on this node. More... | |
virtual void | unsubscribe (VFS_request *r) |
Remove an entry from this node's _subscription list. More... | |
virtual void | unsubscribePath (QString path) |
Unsubscribe all references to a subpath. More... | |
Protected Attributes | |
int | _expireInterval |
Interval for cache entries to expire, in milliseconds. More... | |
int | _flushInterval |
Interval for cache entries to flush, in milliseconds. More... | |
Protected Attributes inherited from VFS_datastore | |
VFS_datastore_cache | _cache |
The data cache. More... | |
bool | _debug |
Debug mode. More... | |
Protected Attributes inherited from VFS_node | |
VFS_children | _children |
This node's children. More... | |
QMutex | _lock |
A recursive mutex that is local to this node. More... | |
VFS_subscriptionType | _subscribers |
This node's subscribers. These subscribers will receive diff notifications. More... | |
Private Attributes | |
client | _client |
The Mongo (mongocxx) client object. More... | |
QString | _collection |
The collection to use. More... | |
bool | _createCollection |
If a reference is made to a non-existent collection, create it, or throw an error. More... | |
database | _database |
The Mongo (mongocxx) database object. More... | |
QString | _databaseName |
The name of the database to use. More... | |
QString | _url |
The database url for this node to connect to, for instance mongodb://localhost:27017. More... | |
Static Private Attributes | |
static instance | _instance = std::move(mongocxx::instance::current()) |
The global mongocxx instance. There should only ever be one of these. More... | |
Friends | |
class | VFS_mongo_cache_entry |
Additional Inherited Members | |
Public Slots inherited from VFS_node | |
virtual void | applyDiff (VFS_request *r) |
Apply a diff received via subscription. More... | |
virtual void | executeRequest (VFS_request *t) |
Based on the VFS_request::requestType, execute the function associated with an operation. More... | |
void | notifySubscribers (VFS_node *origin, VFS_request *t) |
Propagate a diff to subscribers. More... | |
virtual void | receiveResponse (VFS_request *t) |
Once a VFS_request has been completed, a response will be issued back to its _origin. More... | |
void | remove (bool andDelete) |
Remove a child node. More... | |
virtual void | remove (VFS_node *node=nullptr, QString *name=nullptr, QString user="server") |
Remove a child node from this node. More... | |
virtual void | subtreeRequest (VFS_request *t) |
find() the target of a VFS_request, and execute the request More... | |
virtual void | unsubscribeAll (VFS_node *n) |
Remove all references to a subscriber from this node. More... | |
Signals inherited from VFS_node | |
void | diff (VFS_node *origin, VFS_request *t) |
Emit a diff, which will trigger notifySubscribers() for a mounted node. More... | |
void | finished (bool andDelete=false) |
Emitted if a thread fails to create its node, or a node is rm()'d, or any other reason a node has completed its lifecycle. It is deleted if andDelete==true . More... | |
void | mounted () |
Emitted when a node is mount()ed. More... | |
void | unmounted (VFS_node *self) |
Emitted when a node is unmount()ed. More... | |
Static Public Member Functions inherited from VFS_datastore | |
static QString | applyDeltaDiff (QString data, QJsonObject delta, QString trace="", QString user="server") |
Apply a delta diff to a json object. More... | |
static QJsonObject | applyJsonDiff (QJsonObject obj, QJsonObject diff, QString trace="", QString user="server") |
Apply a json diff to a json object. More... | |
Static Public Member Functions inherited from VFS_node | |
static bool | __isNode (VFS_node *) |
Check to see if a node is in the global registry. More... | |
static QString | code (QString nodename, QString libname, QString &error) |
Fetch code or any other resource from a node. More... | |
A VFS_datastore subclass for accessing data in Mongo.
This plugin requires the mongocxx driver.
This plugin is a drop-in replacement for VFS_HD. It will append a _path
field to documents and use that field to emulate a filesystem. Basically _id
fields are ignored, and a regex is performed on path values to create listable directories.
The _path
field will not be visible in returned documents, but it will appear if a mongo query happens outside of the VFS.
It is recommended to create an index on the _path
field. The first time the node is used on a collection, if the collection does not exist it will create the collection and the index if the createCollection
flag is set.
More complex queries are possible using the VFS_mongoRDBM plugin, which is in a different repository.
Definition at line 42 of file VFS_mongo.h.
|
explicit |
Create a VFS_Mongo node.
url | The Mongo database uri, for instance "mongodb://localhost:27017" |
db | The database name |
collection | The collection to use |
size | The cache size |
debug | Verbose debugging |
flushInterval | Interval to flush to the database, in milliseconds. |
expireInterval | Interval to expire cache entries, in milliseconds. |
createCollection | If a reference is made to a non-existent collection, create it, or throw an error. |
Definition at line 261 of file VFS_mongo.cpp.
|
virtual |
Definition at line 286 of file VFS_mongo.cpp.
|
protected |
Create a collection.
name | The collection name. |
Definition at line 488 of file VFS_mongo.cpp.
|
protected |
Create a new document in the database if it doesn't exist.
path | The "path" to write to, which will become a field in the document. |
o | The new data to write, as a QJsonObject |
size | The size of the created document (when converted to a json object). |
container | The container flag (false for files, true for directories) |
VFS_mongo_directoryException | The path is empty. |
VFS_mongo_collectionException | The collection referenced in the path does not exist. |
mongocxx::exception | The mongocxx driver has reported a problem. |
If the document already exists, return false and don't update the existing one.
Definition at line 305 of file VFS_mongo.cpp.
|
protectedvirtual |
The "disk" icon found in the VFS_icons library.
Reimplemented from VFS_node.
Definition at line 553 of file VFS_mongo.cpp.
|
protectedvirtual |
List the contents of a collection using a Mongo find() on the path.
r | The VFS_request object |
The resulting list will be of the form:
Where the true and false values correspond to whether an entry is a file or directory, which is determined by the existence of an extension on the filename of the path.
The values are sorted alphabetically by the json serializer.
A file entry itself can be used for ls(), but it will return an empty set.
VFS_mongo::ls() does not use the _cache. It will read the underlying database and block during that time.
Optionally, if r->_metadata["sequence"]==true
, the resulting list will be collapsed into a sequence view using rutils::sequenceListing().
Reimplemented from VFS_node.
Definition at line 604 of file VFS_mongo.cpp.
|
protectedvirtual |
Fetch the metadata for a database document.
r | The VFS_request object |
Uses VFS_node_type::getType() to determine a type for a path.
Reimplemented from VFS_node.
Definition at line 883 of file VFS_mongo.cpp.
|
protectedvirtual |
Read the contents of a database document.
r | The VFS_request object |
If the entry is already in the cache, return the cached value. Otherwise, create a new VFS_mongo_cache_entry and load data into it.
If r->_metadata["createIfMissing"]==true
, and the entry does not exist, the read() will be converted to a write() with a VFS_request::create type.
Reimplemented from VFS_node.
Definition at line 739 of file VFS_mongo.cpp.
|
protected |
Search for a document by "_path" in the database.
path | The path to read from / search for |
size | The size of the document... written back to the caller |
container | The container-ness of the document... written back to the caller |
VFS_mongo_collectionException | The collection referenced in the path does not exist. |
mongocxx::exception | The mongocxx driver has reported a problem. |
On a failure, this will throw an exception.
Definition at line 445 of file VFS_mongo.cpp.
|
protected |
Remove a document from the database.
path | The "path" to remove, which is queried by mongo |
VFS_mongo_directoryException | The path does not have two components. |
VFS_mongo_collectionException | The collection referenced in the path does not exist. |
mongocxx::exception | The mongocxx driver has reported a problem. |
On a failure, this will throw an exception. If a parentField is present, this method will execute a mongocxx::collection::find_one_and_delete() instead of the default mongocxx::collection::delete_one().
Definition at line 413 of file VFS_mongo.cpp.
|
virtual |
Report the current cache usage.
Reimplemented from VFS_datastore.
Definition at line 563 of file VFS_mongo.cpp.
|
protectedvirtual |
Attempt to delete a file.
r | The VFS_request object |
Attempt to remove (delete) the file from the database, and set r->_success=true
if it was possible. The parent directory has changed, so emit a diff() on the parent to notify any subscribers.
An rm() request with an empty r->_path
, following all other VFS conventions, removes the VFS_mongo node from the VFS.
In all cases, remove the cache entry for this path.
Reimplemented from VFS_node.
Definition at line 980 of file VFS_mongo.cpp.
|
protectedvirtual |
Submit data to a file, applying the data as a diff.
r | The VFS_request object |
Fetch or create a cache entry for this file, and call VFS_mongo_cache_entry::getData(). Apply the r->_data
as a diff using VFS_datastore::applyJsonDiff().
If r->_success==true
, emit a diff() of the applied data to subscribers.
Reimplemented from VFS_node.
Definition at line 913 of file VFS_mongo.cpp.
|
protectedvirtual |
Subscribe to changes on a database document.
r | The VFS_request object |
VFS_node::subscribe() is called, which will pass metadata through to metadata() and read(), and create an empty file if the entry doesn't exist and r->_metadata["createIfMissing"]==true
.
Reimplemented from VFS_node.
Definition at line 1044 of file VFS_mongo.cpp.
|
protectedvirtual |
Write data to a database document.
r | The VFS_request object |
The contents of the data portion of the document will be entirely replaced by r->_data
, converted to a bson object.
Because this is a write() operation, a diff() is emitted.
Reimplemented from VFS_node.
Definition at line 815 of file VFS_mongo.cpp.
|
protected |
Update a document in the database.
path | The "path" to write to, which will become a field in the document. |
o | The new data to write, as a QJsonObject |
container | The container flag (false for files, true for directories) |
VFS_mongo_directoryException | The path is empty. |
VFS_mongo_collectionException | The collection referenced in the path does not exist. |
mongocxx::exception | The mongocxx driver has reported a problem. |
On a failure, this will throw an exception.
Definition at line 369 of file VFS_mongo.cpp.
|
friend |
Definition at line 46 of file VFS_mongo.h.
|
private |
The Mongo (mongocxx) client object.
Definition at line 85 of file VFS_mongo.h.
|
private |
The collection to use.
Definition at line 81 of file VFS_mongo.h.
|
private |
If a reference is made to a non-existent collection, create it, or throw an error.
Definition at line 88 of file VFS_mongo.h.
|
private |
The Mongo (mongocxx) database object.
Definition at line 86 of file VFS_mongo.h.
|
private |
The name of the database to use.
Definition at line 80 of file VFS_mongo.h.
|
protected |
Interval for cache entries to expire, in milliseconds.
Definition at line 56 of file VFS_mongo.h.
|
protected |
Interval for cache entries to flush, in milliseconds.
Definition at line 55 of file VFS_mongo.h.
|
staticprivate |
The global mongocxx instance. There should only ever be one of these.
Definition at line 83 of file VFS_mongo.h.
|
private |
The database url for this node to connect to, for instance mongodb://localhost:27017.
Definition at line 79 of file VFS_mongo.h.