-
Notifications
You must be signed in to change notification settings - Fork 411
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support default users_config implicitly (#1188)
- For most cases except mock test, there is no need to let user manually set user config explicitly. Use immutable default config implicitly if `users_config` does not exist in config file. Signed-off-by: Tong Zhigao <[email protected]>
- Loading branch information
Showing
9 changed files
with
120 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
#pragma once | ||
|
||
#include <Common/Config/ConfigReloader.h> | ||
#include <Common/Config/TOMLConfiguration.h> | ||
|
||
namespace DB | ||
{ | ||
class ImmutableConfigReloader : public ConfigReloader | ||
{ | ||
public: | ||
ImmutableConfigReloader(ConfigReloader::Updater && updater) : ConfigReloader("", std::move(updater), true) | ||
{ | ||
reloadIfNewer(/* force = */ true, /* throw_on_error = */ true); | ||
} | ||
~ImmutableConfigReloader() {} | ||
void start() override {} | ||
void reloadIfNewer(bool, bool throw_on_error) override | ||
{ | ||
auto configuration = genDefaultConfig(); | ||
|
||
std::lock_guard<std::mutex> lock(reload_mutex); | ||
|
||
try | ||
{ | ||
getUpdater()(configuration); | ||
} | ||
catch (...) | ||
{ | ||
if (throw_on_error) | ||
throw; | ||
tryLogCurrentException(log, "Error updating configuration from immutable config."); | ||
} | ||
} | ||
|
||
private: | ||
ConfigurationPtr genDefaultConfig() | ||
{ | ||
const char * DefaultConfig = "[quotas]\n" | ||
"[quotas.default]\n" | ||
"[quotas.default.interval]\n" | ||
"result_rows = 0\n" | ||
"read_rows = 0\n" | ||
"execution_time = 0\n" | ||
"queries = 0\n" | ||
"errors = 0\n" | ||
"duration = 3600\n" | ||
"[users]\n" | ||
"[users.readonly]\n" | ||
"quota = \"default\"\n" | ||
"profile = \"readonly\"\n" | ||
"password = \"\"\n" | ||
"[users.readonly.networks]\n" | ||
"ip = \"::/0\"\n" | ||
"[users.default]\n" | ||
"quota = \"default\"\n" | ||
"profile = \"default\"\n" | ||
"password = \"\"\n" | ||
"[users.default.networks]\n" | ||
"ip = \"::/0\"\n" | ||
"[profiles]\n" | ||
"[profiles.readonly]\n" | ||
"readonly = 1\n" | ||
"[profiles.default]\n" | ||
"load_balancing = \"random\"\n" | ||
"use_uncompressed_cache = 0\n" | ||
"max_memory_usage = 10000000000\n"; | ||
std::istringstream iss(DefaultConfig); | ||
cpptoml::parser p(iss); | ||
ConfigurationPtr configuration(new DB::TOMLConfiguration(p.parse())); | ||
return configuration; | ||
} | ||
|
||
private: | ||
std::mutex reload_mutex; | ||
Poco::Logger * log = &Logger::get("ImmutableConfigReloader"); | ||
}; | ||
} // namespace DB |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.