From 288cee5663a1e64e8a833cf0b9850d636cd777aa Mon Sep 17 00:00:00 2001 From: Vladimir Chebotarev Date: Thu, 27 Feb 2020 11:37:52 +0300 Subject: [PATCH] Fixed `DeleteOnDestroy` logic. --- dbms/src/Storages/MergeTree/IMergeTreeDataPart.cpp | 10 +++++++++- dbms/src/Storages/MergeTree/MergeTreeData.cpp | 8 ++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/dbms/src/Storages/MergeTree/IMergeTreeDataPart.cpp b/dbms/src/Storages/MergeTree/IMergeTreeDataPart.cpp index ac1df5c9ff8..e31ad853f2e 100644 --- a/dbms/src/Storages/MergeTree/IMergeTreeDataPart.cpp +++ b/dbms/src/Storages/MergeTree/IMergeTreeDataPart.cpp @@ -31,6 +31,9 @@ namespace ErrorCodes } +extern const char * DELETE_ON_DESTROY_MARKER_PATH; + + static std::unique_ptr openForReading(const DiskPtr & disk, const String & path) { return disk->readFile(path, std::min(size_t(DBMS_DEFAULT_BUFFER_SIZE), disk->getFileSize(path))); @@ -744,6 +747,7 @@ void IMergeTreeDataPart::remove() const for (const auto & file : {"checksums.txt", "columns.txt"}) disk->remove(to + "/" + file); + disk->removeIfExists(to + "/" + DELETE_ON_DESTROY_MARKER_PATH); disk->remove(to); } @@ -795,8 +799,11 @@ void IMergeTreeDataPart::makeCloneInDetached(const String & prefix) const assertOnDisk(); LOG_INFO(storage.log, "Detaching " << relative_path); + String destination_path = storage.relative_data_path + getRelativePathForDetachedPart(prefix); + /// Backup is not recursive (max_level is 0), so do not copy inner directories - localBackup(disk, getFullRelativePath(), storage.relative_data_path + getRelativePathForDetachedPart(prefix), 0); + localBackup(disk, getFullRelativePath(), destination_path, 0); + disk->removeIfExists(destination_path + "/" + DELETE_ON_DESTROY_MARKER_PATH); } void IMergeTreeDataPart::makeCloneOnDiskDetached(const ReservationPtr & reservation) const @@ -813,6 +820,7 @@ void IMergeTreeDataPart::makeCloneOnDiskDetached(const ReservationPtr & reservat reserved_disk->createDirectory(path_to_clone); disk->copy(getFullRelativePath(), reserved_disk, path_to_clone); + disk->removeIfExists(path_to_clone + "/" + DELETE_ON_DESTROY_MARKER_PATH); } void IMergeTreeDataPart::checkConsistencyBase() const diff --git a/dbms/src/Storages/MergeTree/MergeTreeData.cpp b/dbms/src/Storages/MergeTree/MergeTreeData.cpp index b3495835f10..232295bcd5e 100644 --- a/dbms/src/Storages/MergeTree/MergeTreeData.cpp +++ b/dbms/src/Storages/MergeTree/MergeTreeData.cpp @@ -116,10 +116,7 @@ namespace ErrorCodes } -namespace -{ - const char * DELETE_ON_DESTROY_MARKER_PATH = "delete-on-destroy.txt"; -} +const char * DELETE_ON_DESTROY_MARKER_PATH = "delete-on-destroy.txt"; MergeTreeData::MergeTreeData( @@ -3200,6 +3197,7 @@ MergeTreeData::MutableDataPartPtr MergeTreeData::cloneAndLoadDataPartOnSameDisk( LOG_DEBUG(log, "Cloning part " << fullPath(disk, src_part_path) << " to " << fullPath(disk, dst_part_path)); localBackup(disk, src_part_path, dst_part_path); + disk->removeIfExists(dst_part_path + "/" + DELETE_ON_DESTROY_MARKER_PATH); auto dst_data_part = createPart(dst_part_name, dst_part_info, reservation->getDisk(), tmp_dst_part_name); @@ -3285,6 +3283,8 @@ void MergeTreeData::freezePartitionsByMatcher(MatcherFn matcher, const String & String backup_part_path = backup_path + relative_data_path + part->relative_path; localBackup(part->disk, part->getFullRelativePath(), backup_part_path); + part->disk->removeIfExists(backup_part_path + "/" + DELETE_ON_DESTROY_MARKER_PATH); + part->is_frozen.store(true, std::memory_order_relaxed); ++parts_processed; }