Merge pull request #22411 from nvartolomei/nv/replication-queue-directory-already-exists

Delete temporary fetch directory if it already exists
This commit is contained in:
alexey-milovidov 2021-04-01 17:12:51 +03:00 committed by GitHub
commit 2d1a2ddb9b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -543,11 +543,22 @@ MergeTreeData::MutableDataPartPtr Fetcher::downloadPartToDisk(
static const String TMP_PREFIX = "tmp_fetch_";
String tmp_prefix = tmp_prefix_.empty() ? TMP_PREFIX : tmp_prefix_;
/// We will remove directory if it's already exists. Make precautions.
if (tmp_prefix.empty()
|| part_name.empty()
|| std::string::npos != tmp_prefix.find_first_of("/.")
|| std::string::npos != part_name.find_first_of("/."))
throw Exception("Logical error: tmp_prefix and part_name cannot be empty or contain '.' or '/' characters.", ErrorCodes::LOGICAL_ERROR);
String part_relative_path = String(to_detached ? "detached/" : "") + tmp_prefix + part_name;
String part_download_path = data.getRelativeDataPath() + part_relative_path + "/";
if (disk->exists(part_download_path))
throw Exception("Directory " + fullPath(disk, part_download_path) + " already exists.", ErrorCodes::DIRECTORY_ALREADY_EXISTS);
{
LOG_WARNING(log, "Directory {} already exists, probably result of a failed fetch. Will remove it before fetching part.",
fullPath(disk, part_download_path));
disk->removeRecursive(part_download_path);
}
disk->createDirectories(part_download_path);