Fix signals. Add recovery status.
Reviewers: teon.banek, buda Reviewed By: buda Subscribers: pullbot Differential Revision: https://phabricator.memgraph.io/D451
This commit is contained in:
parent
9f4e6243d8
commit
972c62e102
@ -24,7 +24,8 @@ DEFINE_bool(snapshot_on_db_destruction, false,
|
||||
DECLARE_string(snapshot_directory);
|
||||
|
||||
GraphDb::GraphDb(const std::string &name, const fs::path &snapshot_db_dir)
|
||||
: name_(name),
|
||||
: Loggable("GraphDb"),
|
||||
name_(name),
|
||||
gc_vertices_(vertices_, vertex_record_deleter_,
|
||||
vertex_version_list_deleter_),
|
||||
gc_edges_(edges_, edge_record_deleter_, edge_version_list_deleter_) {
|
||||
@ -82,8 +83,13 @@ void GraphDb::RecoverDatabase(const fs::path &snapshot_db_dir) {
|
||||
Recovery recovery;
|
||||
for (auto &snapshot_file : snapshots) {
|
||||
GraphDbAccessor db_accessor(*this);
|
||||
logger.info("Starting database recovery from snapshot {}...",
|
||||
snapshot_file);
|
||||
if (recovery.Recover(snapshot_file.string(), db_accessor)) {
|
||||
logger.info("Recovery successful.");
|
||||
return;
|
||||
} else {
|
||||
logger.error("Recovery unsuccessful, trying older snapshot...");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -99,9 +105,15 @@ GraphDb::~GraphDb() {
|
||||
// Create last database snapshot
|
||||
if (FLAGS_snapshot_on_db_destruction == true) {
|
||||
GraphDbAccessor db_accessor(*this);
|
||||
snapshooter_.MakeSnapshot(db_accessor,
|
||||
fs::path(FLAGS_snapshot_directory) / name_,
|
||||
FLAGS_max_retained_snapshots);
|
||||
logger.info("Creating snapshot on shutdown...");
|
||||
const bool status = snapshooter_.MakeSnapshot(
|
||||
db_accessor, fs::path(FLAGS_snapshot_directory) / name_,
|
||||
FLAGS_max_retained_snapshots);
|
||||
if (status) {
|
||||
logger.info("Snapshot created successfully.");
|
||||
} else {
|
||||
logger.error("Snapshot creation failed!");
|
||||
}
|
||||
}
|
||||
|
||||
// Delete vertices and edges which weren't collected before, also deletes
|
||||
|
@ -32,7 +32,7 @@ namespace fs = std::experimental::filesystem;
|
||||
* all the data publicly, and should therefore not be directly
|
||||
* exposed to client functions. The GraphDbAccessor is used for that.
|
||||
*/
|
||||
class GraphDb {
|
||||
class GraphDb : public Loggable {
|
||||
public:
|
||||
/**
|
||||
* Construct database with a custom name.
|
||||
|
@ -146,16 +146,12 @@ int main(int argc, char **argv) {
|
||||
bolt_server_t server(std::move(socket), dbms, query_engine);
|
||||
|
||||
// register SIGTERM handler
|
||||
SignalHandler::register_handler(Signal::Terminate, [&server]() {
|
||||
server.Shutdown();
|
||||
std::exit(EXIT_SUCCESS);
|
||||
});
|
||||
SignalHandler::register_handler(Signal::Terminate,
|
||||
[&server]() { server.Shutdown(); });
|
||||
|
||||
// register SIGINT handler
|
||||
SignalHandler::register_handler(Signal::Interupt, [&server]() {
|
||||
server.Shutdown();
|
||||
std::exit(EXIT_FAILURE);
|
||||
});
|
||||
SignalHandler::register_handler(Signal::Interupt,
|
||||
[&server]() { server.Shutdown(); });
|
||||
|
||||
// Start worker threads.
|
||||
logger.info("Starting {} workers", FLAGS_num_workers);
|
||||
|
Loading…
Reference in New Issue
Block a user