diff --git a/utils/local-engine/Storages/StorageMergeTreeFactory.cpp b/utils/local-engine/Storages/StorageMergeTreeFactory.cpp index eb76c3f1c39e..c47488e23ebb 100644 --- a/utils/local-engine/Storages/StorageMergeTreeFactory.cpp +++ b/utils/local-engine/Storages/StorageMergeTreeFactory.cpp @@ -13,9 +13,9 @@ CustomStorageMergeTreePtr StorageMergeTreeFactory::getStorage(StorageID id, ColumnsDescription columns, std::function creator) { auto table_name = id.database_name + "." + id.table_name; + std::lock_guard lock(storage_map_mutex); if (!storage_map.contains(table_name)) { - std::lock_guard lock(storage_map_mutex); if (storage_map.contains(table_name)) { std::set existed_columns = storage_columns_map.at(table_name); @@ -45,9 +45,9 @@ StorageInMemoryMetadataPtr StorageMergeTreeFactory::getMetadata(StorageID id, st { auto table_name = id.database_name + "." + id.table_name; + std::lock_guard lock(metadata_map_mutex); if (!metadata_map.contains(table_name)) { - std::lock_guard lock(metadata_map_mutex); if (!metadata_map.contains(table_name)) { metadata_map.emplace(table_name, creator());