diff --git a/dbms/src/Databases/DatabaseDictionary.cpp b/dbms/src/Databases/DatabaseDictionary.cpp index 0dc471c9e0a..f41b23c9008 100644 --- a/dbms/src/Databases/DatabaseDictionary.cpp +++ b/dbms/src/Databases/DatabaseDictionary.cpp @@ -27,7 +27,7 @@ void DatabaseDictionary::loadTables(Context & context, ThreadPool * thread_pool, Tables DatabaseDictionary::loadTables() { auto objects_map = external_dictionaries.getObjectsMap(); - const auto & dictionaries = std::get<1>(objects_map); + const auto & dictionaries = objects_map.get(); Tables tables; for (const auto & pair : dictionaries) @@ -52,7 +52,7 @@ bool DatabaseDictionary::isTableExist( const String & table_name) const { auto objects_map = external_dictionaries.getObjectsMap(); - const auto & dictionaries = std::get<1>(objects_map); + const auto & dictionaries = objects_map.get(); return dictionaries.count(table_name) && !deleted_tables.count(table_name); } @@ -61,7 +61,7 @@ StoragePtr DatabaseDictionary::tryGetTable( const String & table_name) { auto objects_map = external_dictionaries.getObjectsMap(); - const auto & dictionaries = std::get<1>(objects_map); + const auto & dictionaries = objects_map.get(); if (deleted_tables.count(table_name)) return {}; @@ -90,7 +90,7 @@ DatabaseIteratorPtr DatabaseDictionary::getIterator(const Context & context) bool DatabaseDictionary::empty(const Context & context) const { auto objects_map = external_dictionaries.getObjectsMap(); - const auto & dictionaries = std::get<1>(objects_map); + const auto & dictionaries = objects_map.get(); for (const auto & pair : dictionaries) if (pair.second.loadable && !deleted_tables.count(pair.first)) return false; diff --git a/dbms/src/Interpreters/ExternalLoader.cpp b/dbms/src/Interpreters/ExternalLoader.cpp index 3bde003771b..3515ec6b2cd 100644 --- a/dbms/src/Interpreters/ExternalLoader.cpp +++ b/dbms/src/Interpreters/ExternalLoader.cpp @@ -425,9 +425,9 @@ ExternalLoader::LoadablePtr ExternalLoader::getLoadable(const std::string & name return it->second.loadable; } -std::tuple, const ExternalLoader::ObjectsMap &> ExternalLoader::getObjectsMap() const +ExternalLoader::LockedObjectsMap ExternalLoader::getObjectsMap() const { - return std::make_tuple(std::unique_lock(map_mutex), std::cref(loadable_objects)); + return LockedObjectsMap(map_mutex, loadable_objects); } } diff --git a/dbms/src/Interpreters/ExternalLoader.h b/dbms/src/Interpreters/ExternalLoader.h index 672c801424e..d42e9f07877 100644 --- a/dbms/src/Interpreters/ExternalLoader.h +++ b/dbms/src/Interpreters/ExternalLoader.h @@ -101,8 +101,18 @@ protected: virtual std::unique_ptr create(const std::string & name, const Configuration & config, const std::string & config_prefix) = 0; + class LockedObjectsMap + { + public: + LockedObjectsMap(std::mutex & mutex, const ObjectsMap & objectsMap) : lock(mutex), objectsMap(objectsMap) {} + const ObjectsMap & get() { return objectsMap; } + private: + std::unique_lock lock; + const ObjectsMap & objectsMap; + }; + /// Direct access to objects. - std::tuple, const ObjectsMap &> getObjectsMap() const; + LockedObjectsMap getObjectsMap() const; /// Should be called in derived constructor (to avoid pure virtual call). void init(bool throw_on_error); diff --git a/dbms/src/Storages/System/StorageSystemDictionaries.cpp b/dbms/src/Storages/System/StorageSystemDictionaries.cpp index 02a8c7a44aa..64d633d2d6b 100644 --- a/dbms/src/Storages/System/StorageSystemDictionaries.cpp +++ b/dbms/src/Storages/System/StorageSystemDictionaries.cpp @@ -77,7 +77,7 @@ BlockInputStreams StorageSystemDictionaries::read( const auto & external_dictionaries = context.getExternalDictionaries(); auto objects_map = external_dictionaries.getObjectsMap(); - const auto & dictionaries = std::get<1>(objects_map); + const auto & dictionaries = objects_map.get(); for (const auto & dict_info : dictionaries) {