@@ -104,7 +104,7 @@ struct ContextShared
104104 mutable std::recursive_mutex mutex;
105105 // / Separate mutex for access of dictionaries. Separate mutex to avoid locks when server doing request to itself.
106106 mutable std::mutex embedded_dictionaries_mutex;
107- mutable std::mutex external_dictionaries_mutex;
107+ mutable std::recursive_mutex external_dictionaries_mutex;
108108 mutable std::mutex external_models_mutex;
109109 // / Separate mutex for re-initialization of zookeer session. This operation could take a long time and must not interfere with another operations.
110110 mutable std::mutex zookeeper_mutex;
@@ -1240,44 +1240,38 @@ EmbeddedDictionaries & Context::getEmbeddedDictionariesImpl(const bool throw_on_
12401240
12411241ExternalDictionaries & Context::getExternalDictionariesImpl (const bool throw_on_error) const
12421242{
1243- const auto & config = getConfigRef ();
1243+ {
1244+ std::lock_guard lock (shared->external_dictionaries_mutex );
1245+ if (shared->external_dictionaries )
1246+ return *shared->external_dictionaries ;
1247+ }
12441248
1249+ const auto & config = getConfigRef ();
12451250 std::lock_guard lock (shared->external_dictionaries_mutex );
1246-
12471251 if (!shared->external_dictionaries )
12481252 {
12491253 if (!this ->global_context )
12501254 throw Exception (" Logical error: there is no global context" , ErrorCodes::LOGICAL_ERROR);
12511255
12521256 auto config_repository = shared->runtime_components_factory ->createExternalDictionariesConfigRepository ();
1253-
1254- shared->external_dictionaries .emplace (
1255- std::move (config_repository),
1256- config,
1257- *this ->global_context ,
1258- throw_on_error);
1257+ shared->external_dictionaries .emplace (std::move (config_repository), config, *this ->global_context );
1258+ shared->external_dictionaries ->init (throw_on_error);
12591259 }
1260-
12611260 return *shared->external_dictionaries ;
12621261}
12631262
12641263ExternalModels & Context::getExternalModelsImpl (bool throw_on_error) const
12651264{
12661265 std::lock_guard lock (shared->external_models_mutex );
1267-
12681266 if (!shared->external_models )
12691267 {
12701268 if (!this ->global_context )
12711269 throw Exception (" Logical error: there is no global context" , ErrorCodes::LOGICAL_ERROR);
12721270
12731271 auto config_repository = shared->runtime_components_factory ->createExternalModelsConfigRepository ();
1274-
1275- shared->external_models .emplace (
1276- std::move (config_repository),
1277- *this ->global_context ,
1278- throw_on_error);
1272+ shared->external_models .emplace (std::move (config_repository), *this ->global_context );
1273+ shared->external_models ->init (throw_on_error);
12791274 }
1280-
12811275 return *shared->external_models ;
12821276}
12831277
0 commit comments