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-09-13 23:09:04 +08:00
|
|
|
#include "data_structures/concurrent/concurrent_map.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
|
|
|
/**
|
|
|
|
* 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-10-30 17:43:25 +08:00
|
|
|
*
|
|
|
|
* Always be sure that GraphDb object is destructed before main exits, i. e.
|
|
|
|
* GraphDb object shouldn't be part of global/static variable, except if its
|
|
|
|
* destructor is explicitly called before main exits. Consider code:
|
|
|
|
*
|
|
|
|
* GraphDb db; // KeyIndex is created as a part of db.
|
|
|
|
* int main() {
|
|
|
|
* GraphDbAccessor dba(db);
|
|
|
|
* auto v = dba.InsertVertex();
|
|
|
|
* v.add_label(dba.Label(
|
|
|
|
* "Start")); // New SkipList is created in KeyIndex for LabelIndex.
|
|
|
|
* // That SkipList creates SkipListGc which
|
|
|
|
* // initialises static Executor object.
|
|
|
|
* return 0;
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* After main exits: 1. Executor is destructed, 2. KeyIndex is destructed.
|
|
|
|
* Destructor of KeyIndex calls delete on created SkipLists which destroy
|
|
|
|
* SkipListGc that tries to use Excutioner object that doesn't exist anymore.
|
|
|
|
* -> CRASH
|
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-10-30 17:43:25 +08:00
|
|
|
GraphDb();
|
|
|
|
/** Delete all vertices and edges and free all deferred deleters. */
|
2017-04-14 23:32:59 +08:00
|
|
|
~GraphDb();
|
2017-02-04 16:01:15 +08:00
|
|
|
|
2017-10-30 17:43:25 +08:00
|
|
|
/** Database object can't be copied. */
|
2017-02-04 16:01:15 +08:00
|
|
|
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-10-30 17:43:25 +08:00
|
|
|
/** Stop all transactions and set is_accepting_transactions_ to false. */
|
|
|
|
void Shutdown();
|
|
|
|
|
|
|
|
void CollectGarbage();
|
|
|
|
|
|
|
|
/** When this is false, no new transactions should be created. */
|
|
|
|
std::atomic<bool> is_accepting_transactions_{true};
|
|
|
|
|
|
|
|
private:
|
|
|
|
friend class GraphDbAccessor;
|
|
|
|
|
2017-06-06 23:04:49 +08:00
|
|
|
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-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
|
|
|
|
|
|
|
// 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_;
|
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-10-30 17:43:25 +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.
|
|
|
|
*/
|
2017-08-11 15:48:13 +08:00
|
|
|
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-09-13 23:09:04 +08:00
|
|
|
|
2017-10-30 17:43:25 +08:00
|
|
|
/** DB level global counters, used in the "counter" function. */
|
2017-09-13 23:09:04 +08:00
|
|
|
ConcurrentMap<std::string, std::atomic<int64_t>> counters_;
|
2017-02-04 16:01:15 +08:00
|
|
|
};
|