Remove configs loading if files are not changed.

This commit is contained in:
Yarik Briukhovetskyi 2024-10-21 17:56:16 +02:00 committed by GitHub
parent 1a958122e8
commit 034891ad80
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 32 additions and 34 deletions

View File

@ -673,9 +673,7 @@ XMLDocumentPtr ConfigProcessor::processConfig(
zkutil::ZooKeeperNodeCache * zk_node_cache,
const zkutil::EventPtr & zk_changed_event)
{
const bool write_logs = is_config_changed;
if (write_logs)
LOG_DEBUG(log, "Processing configuration file '{}'.", path);
LOG_DEBUG(log, "Processing configuration file '{}'.", path);
XMLDocumentPtr config;
@ -688,8 +686,7 @@ XMLDocumentPtr ConfigProcessor::processConfig(
/// When we can use a config embedded in the binary.
if (auto it = embedded_configs.find(path); it != embedded_configs.end())
{
if (write_logs)
LOG_DEBUG(log, "There is no file '{}', will use embedded config.", path);
LOG_DEBUG(log, "There is no file '{}', will use embedded config.", path);
config = dom_parser.parseMemory(it->second.data(), it->second.size());
}
else
@ -703,8 +700,7 @@ XMLDocumentPtr ConfigProcessor::processConfig(
{
try
{
if (write_logs)
LOG_DEBUG(log, "Merging configuration file '{}'.", merge_file);
LOG_DEBUG(log, "Merging configuration file '{}'.", merge_file);
XMLDocumentPtr with;
with = parseConfig(merge_file);

View File

@ -121,7 +121,6 @@ public:
static inline const auto SUBSTITUTION_ATTRS = {"incl", "from_zk", "from_env"};
bool is_config_changed = true;
private:
const std::string path;
std::string preprocessed_path;

View File

@ -116,37 +116,40 @@ std::optional<ConfigProcessor::LoadedConfig> ConfigReloader::reloadIfNewer(bool
ConfigProcessor config_processor(config_path);
ConfigProcessor::LoadedConfig loaded_config;
config_processor.is_config_changed = new_files.isDifferOrNewerThan(files);
LOG_DEBUG(log, "Loading config '{}'", config_path);
try
if (new_files.isDifferOrNewerThan(files))
{
loaded_config = config_processor.loadConfig(/* allow_zk_includes = */ true);
if (loaded_config.has_zk_includes)
loaded_config = config_processor.loadConfigWithZooKeeperIncludes(
zk_node_cache, zk_changed_event, fallback_to_preprocessed);
}
catch (const Coordination::Exception & e)
{
if (Coordination::isHardwareError(e.code))
need_reload_from_zk = true;
LOG_DEBUG(log, "Loading config '{}'", config_path);
if (throw_on_error)
throw;
try
{
loaded_config = config_processor.loadConfig(/* allow_zk_includes = */ true);
if (loaded_config.has_zk_includes)
loaded_config = config_processor.loadConfigWithZooKeeperIncludes(
zk_node_cache, zk_changed_event, fallback_to_preprocessed);
}
catch (const Coordination::Exception & e)
{
if (Coordination::isHardwareError(e.code))
need_reload_from_zk = true;
tryLogCurrentException(log, "ZooKeeper error when loading config from '" + config_path + "'");
return std::nullopt;
}
catch (...)
{
if (throw_on_error)
throw;
if (throw_on_error)
throw;
tryLogCurrentException(log, "Error loading config from '" + config_path + "'");
return std::nullopt;
tryLogCurrentException(log, "ZooKeeper error when loading config from '" + config_path + "'");
return std::nullopt;
}
catch (...)
{
if (throw_on_error)
throw;
tryLogCurrentException(log, "Error loading config from '" + config_path + "'");
return std::nullopt;
}
config_processor.savePreprocessedConfig(loaded_config, preprocessed_dir);
}
config_processor.savePreprocessedConfig(loaded_config, preprocessed_dir);
else
LOG_DEBUG(log, "Skipped config loading '{}', as it wasn't changed", config_path);
/** We should remember last modification time if and only if config was successfully loaded
* Otherwise a race condition could occur during config files update: