Fix access control manager destruction order

This commit is contained in:
alesapin 2021-02-09 11:24:39 +03:00
parent 570d5efcfb
commit 15ce3dc112

View File

@ -331,7 +331,7 @@ struct ContextShared
mutable std::optional<ExternalModelsLoader> external_models_loader; mutable std::optional<ExternalModelsLoader> external_models_loader;
String default_profile_name; /// Default profile name used for default values. String default_profile_name; /// Default profile name used for default values.
String system_profile_name; /// Profile used by system processes String system_profile_name; /// Profile used by system processes
AccessControlManager access_control_manager; std::unique_ptr<AccessControlManager> access_control_manager;
mutable UncompressedCachePtr uncompressed_cache; /// The cache of decompressed blocks. mutable UncompressedCachePtr uncompressed_cache; /// The cache of decompressed blocks.
mutable MarkCachePtr mark_cache; /// Cache of marks in compressed files. mutable MarkCachePtr mark_cache; /// Cache of marks in compressed files.
ProcessList process_list; /// Executing queries at the moment. ProcessList process_list; /// Executing queries at the moment.
@ -388,7 +388,8 @@ struct ContextShared
Context::ConfigReloadCallback config_reload_callback; Context::ConfigReloadCallback config_reload_callback;
ContextShared() ContextShared()
: macros(std::make_unique<Macros>()) : access_control_manager(std::make_unique<AccessControlManager>())
, macros(std::make_unique<Macros>())
{ {
/// TODO: make it singleton (?) /// TODO: make it singleton (?)
static std::atomic<size_t> num_calls{0}; static std::atomic<size_t> num_calls{0};
@ -434,6 +435,7 @@ struct ContextShared
/// Preemptive destruction is important, because these objects may have a refcount to ContextShared (cyclic reference). /// Preemptive destruction is important, because these objects may have a refcount to ContextShared (cyclic reference).
/// TODO: Get rid of this. /// TODO: Get rid of this.
access_control_manager.reset();
system_logs.reset(); system_logs.reset();
embedded_dictionaries.reset(); embedded_dictionaries.reset();
external_dictionaries_loader.reset(); external_dictionaries_loader.reset();
@ -640,7 +642,7 @@ void Context::setConfig(const ConfigurationPtr & config)
{ {
auto lock = getLock(); auto lock = getLock();
shared->config = config; shared->config = config;
shared->access_control_manager.setExternalAuthenticatorsConfig(*shared->config); shared->access_control_manager->setExternalAuthenticatorsConfig(*shared->config);
} }
const Poco::Util::AbstractConfiguration & Context::getConfigRef() const const Poco::Util::AbstractConfiguration & Context::getConfigRef() const
@ -652,25 +654,25 @@ const Poco::Util::AbstractConfiguration & Context::getConfigRef() const
AccessControlManager & Context::getAccessControlManager() AccessControlManager & Context::getAccessControlManager()
{ {
return shared->access_control_manager; return *shared->access_control_manager;
} }
const AccessControlManager & Context::getAccessControlManager() const const AccessControlManager & Context::getAccessControlManager() const
{ {
return shared->access_control_manager; return *shared->access_control_manager;
} }
void Context::setExternalAuthenticatorsConfig(const Poco::Util::AbstractConfiguration & config) void Context::setExternalAuthenticatorsConfig(const Poco::Util::AbstractConfiguration & config)
{ {
auto lock = getLock(); auto lock = getLock();
shared->access_control_manager.setExternalAuthenticatorsConfig(config); shared->access_control_manager->setExternalAuthenticatorsConfig(config);
} }
void Context::setUsersConfig(const ConfigurationPtr & config) void Context::setUsersConfig(const ConfigurationPtr & config)
{ {
auto lock = getLock(); auto lock = getLock();
shared->users_config = config; shared->users_config = config;
shared->access_control_manager.setUsersConfig(*shared->users_config); shared->access_control_manager->setUsersConfig(*shared->users_config);
} }
ConfigurationPtr Context::getUsersConfig() ConfigurationPtr Context::getUsersConfig()