Create snapshot on shutdown

This commit is contained in:
Antonio Andelic 2022-07-30 11:34:17 +00:00
parent 6d14d8d366
commit 7cdad88327
4 changed files with 19 additions and 3 deletions

View File

@ -8,7 +8,8 @@ struct KeeperContext
enum class Phase : uint8_t
{
INIT,
RUNNING
RUNNING,
SHUTDOWN
};
Phase server_state{Phase::INIT};

View File

@ -107,8 +107,9 @@ KeeperServer::KeeperServer(
: server_id(configuration_and_settings_->server_id)
, coordination_settings(configuration_and_settings_->coordination_settings)
, log(&Poco::Logger::get("KeeperServer"))
, is_recovering(config.has("keeper_server.force_recovery") && config.getBool("keeper_server.force_recovery"))
, is_recovering(config.getBool("keeper_server.force_recovery", false))
, keeper_context{std::make_shared<KeeperContext>()}
, create_snapshot_on_exit(config.getBool("keeper_server.create_snapshot_on_exit", true))
{
if (coordination_settings->quorum_reads)
LOG_WARNING(log, "Quorum reads enabled, Keeper will work slower.");
@ -367,6 +368,12 @@ void KeeperServer::shutdownRaftServer()
}
raft_instance->shutdown();
keeper_context->server_state = KeeperContext::Phase::SHUTDOWN;
if (create_snapshot_on_exit)
raft_instance->create_snapshot();
raft_instance.reset();
if (asio_listener)

View File

@ -64,6 +64,8 @@ private:
std::shared_ptr<KeeperContext> keeper_context;
const bool create_snapshot_on_exit;
public:
KeeperServer(
const KeeperConfigurationAndSettingsPtr & settings_,

View File

@ -383,7 +383,13 @@ void KeeperStateMachine::create_snapshot(nuraft::snapshot & s, nuraft::async_res
};
LOG_DEBUG(log, "In memory snapshot {} created, queueing task to flash to disk", s.get_last_log_idx());
if (keeper_context->server_state == KeeperContext::Phase::SHUTDOWN)
{
snapshot_task.create_snapshot(std::move(snapshot_task.snapshot));
return;
}
LOG_DEBUG(log, "In memory snapshot {} created, queueing task to flush to disk", s.get_last_log_idx());
/// Flush snapshot to disk in a separate thread.
if (!snapshots_queue.push(std::move(snapshot_task)))
LOG_WARNING(log, "Cannot push snapshot task into queue");