diff --git a/programs/local/LocalServer.cpp b/programs/local/LocalServer.cpp index f2ad0ca449f..3a1aecbc1cf 100644 --- a/programs/local/LocalServer.cpp +++ b/programs/local/LocalServer.cpp @@ -37,6 +37,7 @@ #include #include #include +#include #include @@ -148,20 +149,11 @@ void LocalServer::tryInitPath() /// or it can be some leftovers from other clickhouse-local runs /// as we can't accurately distinguish those situations we don't touch any existent folders /// we just try to pick some free name for our working folder - size_t retries = 0; - while (1) - { - retries++; + default_path = parent_folder / fmt::format("clickhouse-local-{}-{}-{}", getpid(), time(nullptr), randomSeed()); - default_path = parent_folder / fmt::format("clickhouse-local-{}-{}-{}", getpid(), time(nullptr), retries); - - if (!exists(default_path)) - break; - - if (retries >= 20) - throw Exception(ErrorCodes::FILE_ALREADY_EXISTS, "Can not find a name for a temporary folder: {} exist!", default_path.string()); - } + if (exists(default_path)) + throw Exception(ErrorCodes::FILE_ALREADY_EXISTS, "Unsuccessfull attempt to create working directory: {} exist!", default_path.string()); create_directory(default_path); temporary_directory_to_delete = default_path; @@ -467,14 +459,6 @@ void LocalServer::cleanup() { const auto dir = *temporary_directory_to_delete; temporary_directory_to_delete.reset(); - - if (dir.string().find(fmt::format("clickhouse-local-{}", getpid())) == std::string::npos) - { - throw Exception(ErrorCodes::LOGICAL_ERROR, - "The name of working directory of clickhouse-local '{}' doesn't look like temporary name. Will not delete it", - dir.string() - ); - } LOG_DEBUG(&logger(), "Removing temporary directory: {}", dir.string()); remove_all(dir); } diff --git a/src/Interpreters/Context.cpp b/src/Interpreters/Context.cpp index 7f2ada8a426..6e5274cd5b3 100644 --- a/src/Interpreters/Context.cpp +++ b/src/Interpreters/Context.cpp @@ -2029,10 +2029,13 @@ void Context::reloadConfig() const void Context::shutdown() { - for (auto & [disk_name, disk] : getDisksMap()) + if (shared->merge_tree_disk_selector) { - LOG_INFO(shared->log, "Shutdown disk {}", disk_name); - disk->shutdown(); + for (auto & [disk_name, disk] : getDisksMap()) + { + LOG_INFO(shared->log, "Shutdown disk {}", disk_name); + disk->shutdown(); + } } shared->shutdown(); diff --git a/tests/queries/0_stateless/01532_clickhouse_local_tmp_folder.sh b/tests/queries/0_stateless/01532_clickhouse_local_tmp_folder.sh index 6312885de26..f341fbcdd9b 100755 --- a/tests/queries/0_stateless/01532_clickhouse_local_tmp_folder.sh +++ b/tests/queries/0_stateless/01532_clickhouse_local_tmp_folder.sh @@ -5,4 +5,4 @@ CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) # in case when clickhouse-local can't use temp folder it will try to create # temporary subfolder in the current dir -TMP=/non-existent-folder-12123 ${CLICKHOUSE_LOCAL} -q 'SELECT 1' \ No newline at end of file +TMP=/non-existent-folder-12123 ${CLICKHOUSE_LOCAL} -q 'SELECT 1'