2017-02-04 16:01:15 +08:00
|
|
|
#pragma once
|
|
|
|
|
2017-03-29 18:37:58 +08:00
|
|
|
#include <thread>
|
|
|
|
|
LabelProperty index.
Summary:
Add return values.
After merge.
Inital working version. Still missing comments.
Update documentation.
Add checking for previous vlist and value equality.
After merge.
Remove functor, add boolean ffunction.
Build index.
More functionality. Start implementing tests.
Add tests.
Reviewers: matej.gradicek, mislav.bradac, mferencevic, buda, florijan
Reviewed By: mislav.bradac, buda, florijan
Subscribers: lion, florijan, teon.banek, buda, pullbot
Differential Revision: https://phabricator.memgraph.io/D355
2017-05-16 20:47:03 +08:00
|
|
|
#include "cppitertools/filter.hpp"
|
|
|
|
#include "cppitertools/imap.hpp"
|
|
|
|
|
2017-02-18 18:54:37 +08:00
|
|
|
#include "data_structures/concurrent/concurrent_set.hpp"
|
2017-02-04 16:01:15 +08:00
|
|
|
#include "data_structures/concurrent/skiplist.hpp"
|
2017-03-29 18:37:58 +08:00
|
|
|
#include "database/graph_db_datatypes.hpp"
|
2017-04-05 23:23:00 +08:00
|
|
|
#include "database/indexes/key_index.hpp"
|
LabelProperty index.
Summary:
Add return values.
After merge.
Inital working version. Still missing comments.
Update documentation.
Add checking for previous vlist and value equality.
After merge.
Remove functor, add boolean ffunction.
Build index.
More functionality. Start implementing tests.
Add tests.
Reviewers: matej.gradicek, mislav.bradac, mferencevic, buda, florijan
Reviewed By: mislav.bradac, buda, florijan
Subscribers: lion, florijan, teon.banek, buda, pullbot
Differential Revision: https://phabricator.memgraph.io/D355
2017-05-16 20:47:03 +08:00
|
|
|
#include "database/indexes/label_property_index.hpp"
|
2017-05-30 16:26:09 +08:00
|
|
|
#include "durability/snapshooter.hpp"
|
2017-02-04 16:01:15 +08:00
|
|
|
#include "mvcc/version_list.hpp"
|
2017-04-14 23:32:59 +08:00
|
|
|
#include "storage/deferred_deleter.hpp"
|
2017-03-29 18:37:58 +08:00
|
|
|
#include "storage/edge.hpp"
|
|
|
|
#include "storage/garbage_collector.hpp"
|
2017-02-06 19:40:55 +08:00
|
|
|
#include "storage/unique_object_store.hpp"
|
2017-03-29 18:37:58 +08:00
|
|
|
#include "storage/vertex.hpp"
|
2017-02-18 18:54:37 +08:00
|
|
|
#include "transactions/engine.hpp"
|
2017-04-10 21:44:36 +08:00
|
|
|
#include "utils/scheduler.hpp"
|
2017-02-04 16:01:15 +08:00
|
|
|
|
2017-06-06 23:04:49 +08:00
|
|
|
namespace fs = std::experimental::filesystem;
|
|
|
|
|
2017-02-04 16:01:15 +08:00
|
|
|
// TODO: Maybe split this in another layer between Db and Dbms. Where the new
|
|
|
|
// layer would hold SnapshotEngine and his kind of concept objects. Some
|
|
|
|
// guidelines would be: retain objects which are necessary to implement querys
|
|
|
|
// in Db, the rest can be moved to the new layer.
|
|
|
|
/**
|
|
|
|
* Main class which represents Database concept in code.
|
2017-02-16 22:47:55 +08:00
|
|
|
* This class is essentially a data structure. It exposes
|
|
|
|
* all the data publicly, and should therefore not be directly
|
|
|
|
* exposed to client functions. The GraphDbAccessor is used for that.
|
2017-02-04 16:01:15 +08:00
|
|
|
*/
|
2017-06-21 17:29:13 +08:00
|
|
|
class GraphDb {
|
2017-02-18 18:54:37 +08:00
|
|
|
public:
|
2017-02-04 16:01:15 +08:00
|
|
|
/**
|
|
|
|
* Construct database with a custom name.
|
|
|
|
*
|
|
|
|
* @param name database name
|
|
|
|
* @param import_snapshot will in constructor import latest snapshot
|
|
|
|
* into the db.
|
|
|
|
*/
|
2017-06-06 23:04:49 +08:00
|
|
|
GraphDb(const std::string &name, const fs::path &snapshot_db_dir);
|
2017-04-14 23:32:59 +08:00
|
|
|
/**
|
|
|
|
* @brief - Destruct database object. Delete all vertices and edges and free
|
|
|
|
* all deferred deleters.
|
|
|
|
*/
|
|
|
|
~GraphDb();
|
2017-02-04 16:01:15 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Database object can't be copied.
|
|
|
|
*/
|
|
|
|
GraphDb(const GraphDb &db) = delete;
|
2017-06-27 00:43:07 +08:00
|
|
|
GraphDb(GraphDb &&other) = default;
|
|
|
|
GraphDb &operator=(const GraphDb &other) = default;
|
|
|
|
GraphDb &operator=(GraphDb &&other) = default;
|
2017-02-04 16:01:15 +08:00
|
|
|
|
2017-06-06 23:04:49 +08:00
|
|
|
/**
|
|
|
|
* Starts database snapshooting.
|
|
|
|
*/
|
|
|
|
void StartSnapshooting();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Recovers database from a snapshot file and starts snapshooting.
|
|
|
|
* @param snapshot_db path to snapshot folder
|
|
|
|
*/
|
|
|
|
void RecoverDatabase(const fs::path &snapshot_db_path);
|
|
|
|
|
2017-08-16 22:25:57 +08:00
|
|
|
/**
|
|
|
|
* Collects garbage.
|
|
|
|
*/
|
|
|
|
void CollectGarbage();
|
|
|
|
|
2017-02-04 16:01:15 +08:00
|
|
|
/** transaction engine related to this database */
|
2017-07-14 19:58:25 +08:00
|
|
|
tx::Engine tx_engine_;
|
2017-02-04 16:01:15 +08:00
|
|
|
|
|
|
|
// database name
|
|
|
|
const std::string name_;
|
|
|
|
|
|
|
|
// main storage for the graph
|
2017-02-18 18:54:37 +08:00
|
|
|
SkipList<mvcc::VersionList<Vertex> *> vertices_;
|
|
|
|
SkipList<mvcc::VersionList<Edge> *> edges_;
|
2017-04-14 23:32:59 +08:00
|
|
|
|
|
|
|
// Garbage collectors
|
2017-03-29 18:37:58 +08:00
|
|
|
GarbageCollector<Vertex> gc_vertices_;
|
|
|
|
GarbageCollector<Edge> gc_edges_;
|
2017-02-04 16:01:15 +08:00
|
|
|
|
2017-04-14 23:32:59 +08:00
|
|
|
// Deleters for not relevant records
|
|
|
|
DeferredDeleter<Vertex> vertex_record_deleter_;
|
|
|
|
DeferredDeleter<Edge> edge_record_deleter_;
|
|
|
|
|
|
|
|
// Deleters for not relevant version_lists
|
|
|
|
DeferredDeleter<mvcc::VersionList<Vertex>> vertex_version_list_deleter_;
|
|
|
|
DeferredDeleter<mvcc::VersionList<Edge>> edge_version_list_deleter_;
|
|
|
|
|
2017-02-06 19:40:55 +08:00
|
|
|
// unique object stores
|
2017-03-29 18:37:58 +08:00
|
|
|
// TODO this should be also garbage collected
|
2017-02-11 14:51:02 +08:00
|
|
|
ConcurrentSet<std::string> labels_;
|
|
|
|
ConcurrentSet<std::string> edge_types_;
|
|
|
|
ConcurrentSet<std::string> properties_;
|
2017-05-30 16:26:09 +08:00
|
|
|
|
2017-04-03 17:26:32 +08:00
|
|
|
// indexes
|
2017-04-05 23:23:00 +08:00
|
|
|
KeyIndex<GraphDbTypes::Label, Vertex> labels_index_;
|
|
|
|
KeyIndex<GraphDbTypes::EdgeType, Edge> edge_types_index_;
|
LabelProperty index.
Summary:
Add return values.
After merge.
Inital working version. Still missing comments.
Update documentation.
Add checking for previous vlist and value equality.
After merge.
Remove functor, add boolean ffunction.
Build index.
More functionality. Start implementing tests.
Add tests.
Reviewers: matej.gradicek, mislav.bradac, mferencevic, buda, florijan
Reviewed By: mislav.bradac, buda, florijan
Subscribers: lion, florijan, teon.banek, buda, pullbot
Differential Revision: https://phabricator.memgraph.io/D355
2017-05-16 20:47:03 +08:00
|
|
|
LabelPropertyIndex label_property_index_;
|
2017-04-10 21:44:36 +08:00
|
|
|
|
2017-08-11 15:48:13 +08:00
|
|
|
// Flag indicating if index building is in progress. Memgraph does not support
|
|
|
|
// concurrent index builds on the same database (transaction engine), so we
|
|
|
|
// reject index builds if there is one in progress. See
|
|
|
|
// GraphDbAccessor::BuildIndex.
|
|
|
|
std::atomic<bool> index_build_in_progress_{false};
|
|
|
|
|
2017-05-17 16:08:57 +08:00
|
|
|
// snapshooter
|
|
|
|
Snapshooter snapshooter_;
|
|
|
|
|
2017-04-10 21:44:36 +08:00
|
|
|
// Schedulers
|
2017-08-17 15:19:58 +08:00
|
|
|
Scheduler gc_scheduler_;
|
|
|
|
Scheduler snapshot_creator_;
|
2017-07-14 19:58:25 +08:00
|
|
|
// Periodically wakes up and hints to transactions that are running for a long
|
|
|
|
// time to stop their execution.
|
2017-08-17 15:19:58 +08:00
|
|
|
Scheduler transaction_killer_;
|
2017-02-04 16:01:15 +08:00
|
|
|
};
|