Fsync at server shutdown

This commit is contained in:
alesapin 2021-02-17 23:36:25 +03:00
parent 6e244e7bb1
commit ff663dc511
4 changed files with 20 additions and 1 deletions

View File

@ -467,6 +467,17 @@ void Changelog::flush()
current_writer->flush();
}
Changelog::~Changelog() = default;
Changelog::~Changelog()
{
try
{
if (current_writer)
current_writer->flush();
}
catch (...)
{
tryLogCurrentException(__PRETTY_FUNCTION__);
}
}
}

View File

@ -66,6 +66,11 @@ void InMemoryStateManager::loadLogStore(size_t start_log_index)
log_store->init(start_log_index);
}
void InMemoryStateManager::flushLogStore()
{
log_store->flush();
}
void InMemoryStateManager::save_config(const nuraft::cluster_config & config)
{
// Just keep in memory in this example.

View File

@ -27,6 +27,8 @@ public:
void loadLogStore(size_t start_log_index);
void flushLogStore();
nuraft::ptr<nuraft::cluster_config> load_config() override { return cluster_config; }
void save_config(const nuraft::cluster_config & config) override;

View File

@ -67,6 +67,7 @@ void NuKeeperServer::startup()
void NuKeeperServer::shutdown()
{
state_machine->shutdownStorage();
state_manager->flushLogStore();
if (!launcher.shutdown(coordination_settings->shutdown_timeout.totalSeconds()))
LOG_WARNING(&Poco::Logger::get("NuKeeperServer"), "Failed to shutdown RAFT server in {} seconds", 5);
}