From 5cd1dc485fbc5b8767f76e3abbb81c63218a6532 Mon Sep 17 00:00:00 2001 From: Nicolae Vartolomei Date: Wed, 31 Mar 2021 14:14:46 +0100 Subject: [PATCH] Delete temporary fetch directory if it already exists It could be left there after a network timeout, a system crash, or checksum issues. The downside of this PR is that it would be harder to debug checksum issues if replication will continuously delete and try to fetch the same part. --- src/Storages/MergeTree/DataPartsExchange.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Storages/MergeTree/DataPartsExchange.cpp b/src/Storages/MergeTree/DataPartsExchange.cpp index cf8de4456dd..b9ff7b41af6 100644 --- a/src/Storages/MergeTree/DataPartsExchange.cpp +++ b/src/Storages/MergeTree/DataPartsExchange.cpp @@ -547,7 +547,11 @@ MergeTreeData::MutableDataPartPtr Fetcher::downloadPartToDisk( 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);