After CR fixes - better & simpler. Issue in Context::shutdown fixed

This commit is contained in:
Mikhail Filimonov 2020-10-23 16:57:06 +02:00
parent 58df7f7883
commit f3a18864d5
No known key found for this signature in database
GPG Key ID: 6E49C2E9AF1220BE
3 changed files with 11 additions and 24 deletions

View File

@ -37,6 +37,7 @@
#include <boost/program_options.hpp> #include <boost/program_options.hpp>
#include <common/argsToConfig.h> #include <common/argsToConfig.h>
#include <Common/TerminalSize.h> #include <Common/TerminalSize.h>
#include <Common/randomSeed.h>
#include <filesystem> #include <filesystem>
@ -148,20 +149,11 @@ void LocalServer::tryInitPath()
/// or it can be some leftovers from other clickhouse-local runs /// 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 /// 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 /// we just try to pick some free name for our working folder
size_t retries = 0;
while (1) default_path = parent_folder / fmt::format("clickhouse-local-{}-{}-{}", getpid(), time(nullptr), randomSeed());
{
retries++;
default_path = parent_folder / fmt::format("clickhouse-local-{}-{}-{}", getpid(), time(nullptr), retries); if (exists(default_path))
throw Exception(ErrorCodes::FILE_ALREADY_EXISTS, "Unsuccessfull attempt to create working directory: {} exist!", default_path.string());
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());
}
create_directory(default_path); create_directory(default_path);
temporary_directory_to_delete = default_path; temporary_directory_to_delete = default_path;
@ -467,14 +459,6 @@ void LocalServer::cleanup()
{ {
const auto dir = *temporary_directory_to_delete; const auto dir = *temporary_directory_to_delete;
temporary_directory_to_delete.reset(); 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()); LOG_DEBUG(&logger(), "Removing temporary directory: {}", dir.string());
remove_all(dir); remove_all(dir);
} }

View File

@ -2029,10 +2029,13 @@ void Context::reloadConfig() const
void Context::shutdown() void Context::shutdown()
{ {
for (auto & [disk_name, disk] : getDisksMap()) if (shared->merge_tree_disk_selector)
{ {
LOG_INFO(shared->log, "Shutdown disk {}", disk_name); for (auto & [disk_name, disk] : getDisksMap())
disk->shutdown(); {
LOG_INFO(shared->log, "Shutdown disk {}", disk_name);
disk->shutdown();
}
} }
shared->shutdown(); shared->shutdown();

View File

@ -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 # in case when clickhouse-local can't use temp folder it will try to create
# temporary subfolder in the current dir # temporary subfolder in the current dir
TMP=/non-existent-folder-12123 ${CLICKHOUSE_LOCAL} -q 'SELECT 1' TMP=/non-existent-folder-12123 ${CLICKHOUSE_LOCAL} -q 'SELECT 1'