2021-02-09 15:39:15 +00:00
|
|
|
#include <Coordination/CoordinationSettings.h>
|
|
|
|
#include <Core/Settings.h>
|
2021-10-02 07:13:14 +00:00
|
|
|
#include <base/logger_useful.h>
|
2021-10-27 12:26:42 +00:00
|
|
|
#include <filesystem>
|
2021-10-27 15:21:26 +00:00
|
|
|
#include <Coordination/Defines.h>
|
2021-11-12 12:48:42 +00:00
|
|
|
#include <IO/WriteHelpers.h>
|
|
|
|
#include <IO/WriteIntText.h>
|
2021-02-09 15:39:15 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
namespace ErrorCodes
|
|
|
|
{
|
|
|
|
extern const int UNKNOWN_SETTING;
|
|
|
|
}
|
|
|
|
|
|
|
|
IMPLEMENT_SETTINGS_TRAITS(CoordinationSettingsTraits, LIST_OF_COORDINATION_SETTINGS)
|
|
|
|
|
|
|
|
void CoordinationSettings::loadFromConfig(const String & config_elem, const Poco::Util::AbstractConfiguration & config)
|
|
|
|
{
|
|
|
|
if (!config.has(config_elem))
|
|
|
|
return;
|
|
|
|
|
|
|
|
Poco::Util::AbstractConfiguration::Keys config_keys;
|
|
|
|
config.keys(config_elem, config_keys);
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
for (const String & key : config_keys)
|
|
|
|
set(key, config.getString(config_elem + "." + key));
|
|
|
|
}
|
|
|
|
catch (Exception & e)
|
|
|
|
{
|
|
|
|
if (e.code() == ErrorCodes::UNKNOWN_SETTING)
|
|
|
|
e.addMessage("in Coordination settings config");
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-05 10:21:34 +00:00
|
|
|
|
2021-11-18 20:17:22 +00:00
|
|
|
const String KeeperConfigurationAndSettings::DEFAULT_FOUR_LETTER_WORD_CMD = "conf,cons,crst,envi,ruok,srst,srvr,stat,wchc,wchs,dirs,mntr,isro";
|
2021-11-05 10:21:34 +00:00
|
|
|
|
2021-11-18 20:17:22 +00:00
|
|
|
KeeperConfigurationAndSettings::KeeperConfigurationAndSettings()
|
2021-10-28 08:01:30 +00:00
|
|
|
: server_id(NOT_EXIST)
|
|
|
|
, tcp_port(NOT_EXIST)
|
|
|
|
, tcp_port_secure(NOT_EXIST)
|
|
|
|
, standalone_keeper(false)
|
|
|
|
, coordination_settings(std::make_shared<CoordinationSettings>())
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-11-18 20:17:22 +00:00
|
|
|
void KeeperConfigurationAndSettings::dump(WriteBufferFromOwnString & buf) const
|
2021-10-27 12:26:42 +00:00
|
|
|
{
|
2021-11-18 20:17:22 +00:00
|
|
|
auto write_int = [&buf](int64_t value)
|
2021-10-27 14:26:53 +00:00
|
|
|
{
|
2021-11-12 12:48:42 +00:00
|
|
|
writeIntText(value, buf);
|
2021-10-27 12:26:42 +00:00
|
|
|
buf.write('\n');
|
|
|
|
};
|
|
|
|
|
2021-10-27 14:26:53 +00:00
|
|
|
auto write_bool = [&buf](bool value)
|
|
|
|
{
|
2021-10-27 12:26:42 +00:00
|
|
|
String str_val = value ? "true" : "false";
|
2021-11-12 12:48:42 +00:00
|
|
|
writeText(str_val, buf);
|
2021-10-27 12:26:42 +00:00
|
|
|
buf.write('\n');
|
|
|
|
};
|
|
|
|
|
2021-11-12 12:48:42 +00:00
|
|
|
writeText("server_id=", buf);
|
2021-10-27 12:26:42 +00:00
|
|
|
write_int(server_id);
|
|
|
|
|
2021-10-28 08:01:30 +00:00
|
|
|
if (tcp_port != NOT_EXIST)
|
2021-10-27 12:26:42 +00:00
|
|
|
{
|
2021-11-12 12:48:42 +00:00
|
|
|
writeText("tcp_port=", buf);
|
2021-10-27 12:26:42 +00:00
|
|
|
write_int(tcp_port);
|
|
|
|
}
|
2021-10-28 08:01:30 +00:00
|
|
|
if (tcp_port_secure != NOT_EXIST)
|
2021-10-27 12:26:42 +00:00
|
|
|
{
|
2021-11-12 12:48:42 +00:00
|
|
|
writeText("tcp_port_secure=", buf);
|
2021-10-27 12:26:42 +00:00
|
|
|
write_int(tcp_port_secure);
|
|
|
|
}
|
|
|
|
|
2021-11-12 12:48:42 +00:00
|
|
|
writeText("four_letter_word_white_list=", buf);
|
|
|
|
writeText(four_letter_word_white_list, buf);
|
2021-10-28 14:22:56 +00:00
|
|
|
buf.write('\n');
|
|
|
|
|
2021-11-12 12:48:42 +00:00
|
|
|
writeText("log_storage_path=", buf);
|
|
|
|
writeText(log_storage_path, buf);
|
2021-10-27 12:26:42 +00:00
|
|
|
buf.write('\n');
|
|
|
|
|
2021-11-12 12:48:42 +00:00
|
|
|
writeText("snapshot_storage_path=", buf);
|
|
|
|
writeText(snapshot_storage_path, buf);
|
2021-10-27 12:26:42 +00:00
|
|
|
buf.write('\n');
|
|
|
|
|
|
|
|
/// coordination_settings
|
|
|
|
|
2021-11-12 12:48:42 +00:00
|
|
|
writeText("max_requests_batch_size=", buf);
|
2021-10-27 12:26:42 +00:00
|
|
|
write_int(coordination_settings->max_requests_batch_size);
|
2021-11-12 12:48:42 +00:00
|
|
|
writeText("session_timeout_ms=", buf);
|
2021-11-18 20:17:22 +00:00
|
|
|
write_int(uint64_t(coordination_settings->session_timeout_ms));
|
2021-11-12 12:48:42 +00:00
|
|
|
writeText("operation_timeout_ms=", buf);
|
2021-11-18 20:17:22 +00:00
|
|
|
write_int(uint64_t(coordination_settings->operation_timeout_ms));
|
2021-11-12 12:48:42 +00:00
|
|
|
writeText("dead_session_check_period_ms=", buf);
|
2021-11-18 20:17:22 +00:00
|
|
|
write_int(uint64_t(coordination_settings->dead_session_check_period_ms));
|
2021-10-27 12:26:42 +00:00
|
|
|
|
2021-11-12 12:48:42 +00:00
|
|
|
writeText("heart_beat_interval_ms=", buf);
|
2021-11-18 20:17:22 +00:00
|
|
|
write_int(uint64_t(coordination_settings->heart_beat_interval_ms));
|
2021-11-12 12:48:42 +00:00
|
|
|
writeText("election_timeout_lower_bound_ms=", buf);
|
2021-11-18 20:17:22 +00:00
|
|
|
write_int(uint64_t(coordination_settings->election_timeout_lower_bound_ms));
|
2021-11-12 12:48:42 +00:00
|
|
|
writeText("election_timeout_upper_bound_ms=", buf);
|
2021-11-18 20:17:22 +00:00
|
|
|
write_int(uint64_t(coordination_settings->election_timeout_upper_bound_ms));
|
2021-10-27 12:26:42 +00:00
|
|
|
|
2021-11-12 12:48:42 +00:00
|
|
|
writeText("reserved_log_items=", buf);
|
2021-10-27 12:26:42 +00:00
|
|
|
write_int(coordination_settings->reserved_log_items);
|
2021-11-12 12:48:42 +00:00
|
|
|
writeText("snapshot_distance=", buf);
|
2021-10-27 12:26:42 +00:00
|
|
|
write_int(coordination_settings->snapshot_distance);
|
|
|
|
|
2021-11-12 12:48:42 +00:00
|
|
|
writeText("auto_forwarding=", buf);
|
2021-10-27 12:26:42 +00:00
|
|
|
write_bool(coordination_settings->auto_forwarding);
|
2021-11-12 12:48:42 +00:00
|
|
|
writeText("shutdown_timeout=", buf);
|
2021-11-18 20:17:22 +00:00
|
|
|
write_int(uint64_t(coordination_settings->shutdown_timeout));
|
2021-11-12 12:48:42 +00:00
|
|
|
writeText("startup_timeout=", buf);
|
2021-11-18 20:17:22 +00:00
|
|
|
write_int(uint64_t(coordination_settings->startup_timeout));
|
2021-10-27 12:26:42 +00:00
|
|
|
|
2021-11-12 12:48:42 +00:00
|
|
|
writeText("raft_logs_level=", buf);
|
|
|
|
writeText(coordination_settings->raft_logs_level.toString(), buf);
|
2021-10-27 12:26:42 +00:00
|
|
|
buf.write('\n');
|
|
|
|
|
2021-11-12 12:48:42 +00:00
|
|
|
writeText("snapshots_to_keep=", buf);
|
2021-10-27 12:26:42 +00:00
|
|
|
write_int(coordination_settings->snapshots_to_keep);
|
2021-11-12 12:48:42 +00:00
|
|
|
writeText("rotate_log_storage_interval=", buf);
|
2021-10-27 12:26:42 +00:00
|
|
|
write_int(coordination_settings->rotate_log_storage_interval);
|
2021-11-12 12:48:42 +00:00
|
|
|
writeText("stale_log_gap=", buf);
|
2021-10-27 12:26:42 +00:00
|
|
|
write_int(coordination_settings->stale_log_gap);
|
2021-11-12 12:48:42 +00:00
|
|
|
writeText("fresh_log_gap=", buf);
|
2021-10-27 12:26:42 +00:00
|
|
|
write_int(coordination_settings->fresh_log_gap);
|
|
|
|
|
2021-11-12 12:48:42 +00:00
|
|
|
writeText("max_requests_batch_size=", buf);
|
2021-10-27 12:26:42 +00:00
|
|
|
write_int(coordination_settings->max_requests_batch_size);
|
2021-11-12 12:48:42 +00:00
|
|
|
writeText("quorum_reads=", buf);
|
2021-10-27 12:26:42 +00:00
|
|
|
write_bool(coordination_settings->quorum_reads);
|
2021-11-12 12:48:42 +00:00
|
|
|
writeText("force_sync=", buf);
|
2021-10-27 12:26:42 +00:00
|
|
|
write_bool(coordination_settings->force_sync);
|
2021-10-27 15:21:26 +00:00
|
|
|
|
2021-11-12 12:48:42 +00:00
|
|
|
writeText("compress_logs=", buf);
|
2021-10-27 15:21:26 +00:00
|
|
|
write_bool(coordination_settings->compress_logs);
|
2021-11-12 12:48:42 +00:00
|
|
|
writeText("compress_snapshots_with_zstd_format=", buf);
|
2021-10-27 15:21:26 +00:00
|
|
|
write_bool(coordination_settings->compress_snapshots_with_zstd_format);
|
2021-11-12 12:48:42 +00:00
|
|
|
writeText("configuration_change_tries_count=", buf);
|
2021-10-27 15:21:26 +00:00
|
|
|
write_int(coordination_settings->configuration_change_tries_count);
|
2021-10-27 12:26:42 +00:00
|
|
|
}
|
|
|
|
|
2021-11-18 20:17:22 +00:00
|
|
|
KeeperConfigurationAndSettingsPtr
|
|
|
|
KeeperConfigurationAndSettings::loadFromConfig(const Poco::Util::AbstractConfiguration & config, bool standalone_keeper_)
|
2021-10-27 12:26:42 +00:00
|
|
|
{
|
2021-11-18 20:17:22 +00:00
|
|
|
std::shared_ptr<KeeperConfigurationAndSettings> ret = std::make_shared<KeeperConfigurationAndSettings>();
|
2021-10-27 12:26:42 +00:00
|
|
|
|
|
|
|
ret->server_id = config.getInt("keeper_server.server_id");
|
|
|
|
ret->standalone_keeper = standalone_keeper_;
|
|
|
|
|
2021-10-27 14:26:53 +00:00
|
|
|
if (config.has("keeper_server.tcp_port"))
|
2021-10-27 12:26:42 +00:00
|
|
|
{
|
|
|
|
ret->tcp_port = config.getInt("keeper_server.tcp_port");
|
|
|
|
}
|
2021-10-27 14:26:53 +00:00
|
|
|
if (config.has("keeper_server.tcp_port_secure"))
|
2021-10-27 12:26:42 +00:00
|
|
|
{
|
|
|
|
ret->tcp_port_secure = config.getInt("keeper_server.tcp_port_secure");
|
|
|
|
}
|
2021-10-27 14:26:53 +00:00
|
|
|
if (config.has("keeper_server.superdigest"))
|
2021-10-27 12:26:42 +00:00
|
|
|
{
|
2021-10-28 11:05:19 +00:00
|
|
|
ret->super_digest = config.getString("keeper_server.superdigest");
|
2021-10-27 12:26:42 +00:00
|
|
|
}
|
|
|
|
|
2021-11-05 10:21:34 +00:00
|
|
|
ret->four_letter_word_white_list = config.getString("keeper_server.four_letter_word_white_list", DEFAULT_FOUR_LETTER_WORD_CMD);
|
2021-10-28 14:22:56 +00:00
|
|
|
|
2021-10-27 12:26:42 +00:00
|
|
|
ret->log_storage_path = getLogsPathFromConfig(config, standalone_keeper_);
|
|
|
|
ret->snapshot_storage_path = getSnapshotsPathFromConfig(config, standalone_keeper_);
|
|
|
|
|
|
|
|
ret->coordination_settings->loadFromConfig("keeper_server.coordination_settings", config);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2021-11-18 20:17:22 +00:00
|
|
|
String KeeperConfigurationAndSettings::getLogsPathFromConfig(const Poco::Util::AbstractConfiguration & config, bool standalone_keeper_)
|
2021-10-27 12:26:42 +00:00
|
|
|
{
|
|
|
|
/// the most specialized path
|
|
|
|
if (config.has("keeper_server.log_storage_path"))
|
|
|
|
return config.getString("keeper_server.log_storage_path");
|
|
|
|
|
|
|
|
if (config.has("keeper_server.storage_path"))
|
|
|
|
return std::filesystem::path{config.getString("keeper_server.storage_path")} / "logs";
|
|
|
|
|
|
|
|
if (standalone_keeper_)
|
|
|
|
return std::filesystem::path{config.getString("path", KEEPER_DEFAULT_PATH)} / "logs";
|
|
|
|
else
|
|
|
|
return std::filesystem::path{config.getString("path", DBMS_DEFAULT_PATH)} / "coordination/logs";
|
|
|
|
}
|
|
|
|
|
2021-11-18 20:17:22 +00:00
|
|
|
String KeeperConfigurationAndSettings::getSnapshotsPathFromConfig(const Poco::Util::AbstractConfiguration & config, bool standalone_keeper_)
|
2021-10-27 12:26:42 +00:00
|
|
|
{
|
|
|
|
/// the most specialized path
|
|
|
|
if (config.has("keeper_server.snapshot_storage_path"))
|
|
|
|
return config.getString("keeper_server.snapshot_storage_path");
|
|
|
|
|
|
|
|
if (config.has("keeper_server.storage_path"))
|
|
|
|
return std::filesystem::path{config.getString("keeper_server.storage_path")} / "snapshots";
|
|
|
|
|
|
|
|
if (standalone_keeper_)
|
|
|
|
return std::filesystem::path{config.getString("path", KEEPER_DEFAULT_PATH)} / "snapshots";
|
|
|
|
else
|
|
|
|
return std::filesystem::path{config.getString("path", DBMS_DEFAULT_PATH)} / "coordination/snapshots";
|
|
|
|
}
|
|
|
|
|
2021-02-09 15:39:15 +00:00
|
|
|
}
|