2017-02-04 16:01:15 +08:00
|
|
|
#pragma once
|
|
|
|
|
2017-03-29 18:37:58 +08:00
|
|
|
#include <thread>
|
|
|
|
|
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"
|
2017-02-04 16:01:15 +08:00
|
|
|
#include "mvcc/version_list.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
|
|
|
|
|
|
|
// 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
|
|
|
*/
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
GraphDb(const std::string &name, bool import_snapshot = true);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Database object can't be copied.
|
|
|
|
*/
|
|
|
|
GraphDb(const GraphDb &db) = delete;
|
|
|
|
|
|
|
|
/** transaction engine related to this database */
|
|
|
|
tx::Engine tx_engine;
|
|
|
|
|
|
|
|
/** garbage collector related to this database*/
|
2017-02-18 18:54:37 +08:00
|
|
|
// TODO bring back garbage collection
|
|
|
|
// Garbage garbage = {tx_engine};
|
2017-02-04 16:01:15 +08:00
|
|
|
|
2017-02-18 18:54:37 +08:00
|
|
|
// TODO bring back shapshot engine
|
|
|
|
// SnapshotEngine snap_engine = {*this};
|
2017-02-04 16:01:15 +08:00
|
|
|
|
|
|
|
// database name
|
2017-02-06 19:40:55 +08:00
|
|
|
// TODO consider if this is even necessary
|
2017-02-04 16:01:15 +08:00
|
|
|
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-03-29 18:37:58 +08:00
|
|
|
GarbageCollector<Vertex> gc_vertices_;
|
|
|
|
GarbageCollector<Edge> gc_edges_;
|
2017-02-04 16:01:15 +08:00
|
|
|
|
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-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_;
|
2017-04-10 21:44:36 +08:00
|
|
|
|
|
|
|
// Schedulers
|
|
|
|
Scheduler<std::mutex> gc_vertices_scheduler_;
|
|
|
|
Scheduler<std::mutex> gc_edges_scheduler_;
|
2017-02-04 16:01:15 +08:00
|
|
|
};
|