mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-12-18 04:12:19 +00:00
Merge pull request #9970 from vitlibar/fix-reusing-connection-after-change-of-default-settings
Fix reusing connection after changing user's default settings
This commit is contained in:
commit
300fb2f258
@ -147,6 +147,10 @@ void TCPHandler::runImpl()
|
||||
if (server.isCancelled() || in->eof())
|
||||
break;
|
||||
|
||||
/// receiveHello() has set the default settings for the current user,
|
||||
/// but this default itself could change while we were waiting for a packet from the client.
|
||||
connection_context.resetSettingsToDefault();
|
||||
|
||||
/// Set context of request.
|
||||
query_context = connection_context;
|
||||
|
||||
|
@ -542,14 +542,14 @@ std::shared_ptr<const ContextAccess> ContextAccess::getFullAccess()
|
||||
std::shared_ptr<const Settings> ContextAccess::getDefaultSettings() const
|
||||
{
|
||||
std::lock_guard lock{mutex};
|
||||
return enabled_settings->getSettings();
|
||||
return enabled_settings ? enabled_settings->getSettings() : nullptr;
|
||||
}
|
||||
|
||||
|
||||
std::shared_ptr<const SettingsConstraints> ContextAccess::getSettingsConstraints() const
|
||||
{
|
||||
std::lock_guard lock{mutex};
|
||||
return enabled_settings->getConstraints();
|
||||
return enabled_settings ? enabled_settings->getConstraints() : nullptr;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -909,6 +909,7 @@ void Context::setSettings(const Settings & settings_)
|
||||
auto old_allow_introspection_functions = settings.allow_introspection_functions;
|
||||
|
||||
settings = settings_;
|
||||
active_default_settings = nullptr;
|
||||
|
||||
if ((settings.readonly != old_readonly) || (settings.allow_ddl != old_allow_ddl) || (settings.allow_introspection_functions != old_allow_introspection_functions))
|
||||
calculateAccessRights();
|
||||
@ -918,6 +919,7 @@ void Context::setSettings(const Settings & settings_)
|
||||
void Context::setSetting(const StringRef & name, const String & value)
|
||||
{
|
||||
auto lock = getLock();
|
||||
active_default_settings = nullptr;
|
||||
if (name == "profile")
|
||||
{
|
||||
setProfile(value);
|
||||
@ -933,6 +935,7 @@ void Context::setSetting(const StringRef & name, const String & value)
|
||||
void Context::setSetting(const StringRef & name, const Field & value)
|
||||
{
|
||||
auto lock = getLock();
|
||||
active_default_settings = nullptr;
|
||||
if (name == "profile")
|
||||
{
|
||||
setProfile(value.safeGet<String>());
|
||||
@ -959,6 +962,20 @@ void Context::applySettingsChanges(const SettingsChanges & changes)
|
||||
}
|
||||
|
||||
|
||||
void Context::resetSettingsToDefault()
|
||||
{
|
||||
auto lock = getLock();
|
||||
auto default_settings = getAccess()->getDefaultSettings();
|
||||
if (default_settings && (default_settings == active_default_settings))
|
||||
return;
|
||||
if (default_settings)
|
||||
setSettings(*default_settings);
|
||||
else
|
||||
setSettings(Settings{});
|
||||
active_default_settings = default_settings;
|
||||
}
|
||||
|
||||
|
||||
void Context::checkSettingsConstraints(const SettingChange & change) const
|
||||
{
|
||||
if (auto settings_constraints = getSettingsConstraints())
|
||||
|
@ -151,6 +151,7 @@ private:
|
||||
bool use_default_roles = false;
|
||||
std::shared_ptr<const ContextAccess> access;
|
||||
std::shared_ptr<const EnabledRowPolicies> initial_row_policy;
|
||||
std::shared_ptr<const Settings> active_default_settings;
|
||||
String current_database;
|
||||
Settings settings; /// Setting for query execution.
|
||||
using ProgressCallback = std::function<void(const Progress & progress)>;
|
||||
@ -345,6 +346,9 @@ public:
|
||||
void applySettingChange(const SettingChange & change);
|
||||
void applySettingsChanges(const SettingsChanges & changes);
|
||||
|
||||
/// Reset settings to the default values for the current user.
|
||||
void resetSettingsToDefault();
|
||||
|
||||
/// Checks the constraints.
|
||||
void checkSettingsConstraints(const SettingChange & change) const;
|
||||
void checkSettingsConstraints(const SettingsChanges & changes) const;
|
||||
|
Loading…
Reference in New Issue
Block a user