2017-04-10 21:44:36 +08:00
|
|
|
#include <functional>
|
|
|
|
|
2017-03-29 18:37:58 +08:00
|
|
|
#include "config/config.hpp"
|
2017-02-04 16:01:15 +08:00
|
|
|
#include "database/creation_exception.hpp"
|
2017-04-10 21:44:36 +08:00
|
|
|
#include "database/graph_db.hpp"
|
2017-03-29 18:37:58 +08:00
|
|
|
#include "logging/logger.hpp"
|
|
|
|
#include "storage/edge.hpp"
|
|
|
|
#include "storage/garbage_collector.hpp"
|
2017-02-15 21:10:16 +08:00
|
|
|
//#include "snapshot/snapshoter.hpp"
|
2017-02-04 16:01:15 +08:00
|
|
|
|
2017-03-29 18:37:58 +08:00
|
|
|
const int DEFAULT_CLEANING_CYCLE_SEC = 30; // 30 seconds
|
|
|
|
|
|
|
|
GraphDb::GraphDb(const std::string &name, bool import_snapshot)
|
|
|
|
: name_(name),
|
|
|
|
gc_vertices_(&vertices_, &tx_engine),
|
|
|
|
gc_edges_(&edges_, &tx_engine) {
|
2017-04-10 21:44:36 +08:00
|
|
|
const std::string time_str = CONFIG(config::CLEANING_CYCLE_SEC);
|
2017-03-29 18:37:58 +08:00
|
|
|
int pause = DEFAULT_CLEANING_CYCLE_SEC;
|
2017-04-10 21:44:36 +08:00
|
|
|
if (!time_str.empty()) pause = CONFIG_INTEGER(config::CLEANING_CYCLE_SEC);
|
|
|
|
// Pause of -1 means we shouldn't run the GC.
|
|
|
|
if (pause != -1) {
|
|
|
|
gc_vertices_scheduler_.Run(
|
|
|
|
std::chrono::seconds(pause),
|
|
|
|
std::bind(&GarbageCollector<Vertex>::Run, gc_vertices_));
|
|
|
|
gc_edges_scheduler_.Run(std::chrono::seconds(pause),
|
|
|
|
std::bind(&GarbageCollector<Edge>::Run, gc_edges_));
|
|
|
|
}
|
2017-02-18 18:54:37 +08:00
|
|
|
// if (import_snapshot)
|
|
|
|
// snap_engine.import();
|
2017-02-04 16:01:15 +08:00
|
|
|
}
|