#pragma once #include #include #include "gflags/gflags.h" #include "glog/logging.h" #include "database/counters.hpp" #include "database/storage.hpp" #include "database/storage_gc.hpp" #include "database/types.hpp" #include "durability/wal.hpp" #include "io/network/network_endpoint.hpp" #include "storage/concurrent_id_mapper.hpp" #include "transactions/engine.hpp" #include "utils/scheduler.hpp" namespace database { /// Database configuration. Initialized from flags, but modifiable. struct Config { Config(); // Durability flags. bool durability_enabled; std::string durability_directory; bool db_recover_on_startup; int snapshot_cycle_sec; int snapshot_max_retained; int snapshot_on_exit; // Misc flags. int gc_cycle_sec; int query_execution_time_sec; // Distributed master/worker flags. int worker_id; io::network::NetworkEndpoint master_endpoint; io::network::NetworkEndpoint worker_endpoint; }; namespace impl { class Base; } /** * An abstract base class for a SingleNode/Master/Worker graph db. * * 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 database::Storage * 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 */ class GraphDb { public: Storage &storage(); durability::WriteAheadLog &wal(); tx::Engine &tx_engine(); storage::ConcurrentIdMapper