mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-18 13:42:02 +00:00
Create snapshot on shutdown
This commit is contained in:
parent
6d14d8d366
commit
7cdad88327
@ -8,7 +8,8 @@ struct KeeperContext
|
||||
enum class Phase : uint8_t
|
||||
{
|
||||
INIT,
|
||||
RUNNING
|
||||
RUNNING,
|
||||
SHUTDOWN
|
||||
};
|
||||
|
||||
Phase server_state{Phase::INIT};
|
||||
|
@ -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)
|
||||
|
@ -64,6 +64,8 @@ private:
|
||||
|
||||
std::shared_ptr<KeeperContext> keeper_context;
|
||||
|
||||
const bool create_snapshot_on_exit;
|
||||
|
||||
public:
|
||||
KeeperServer(
|
||||
const KeeperConfigurationAndSettingsPtr & settings_,
|
||||
|
@ -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");
|
||||
|
Loading…
Reference in New Issue
Block a user