From 028d1c9478e1dc264907edaf2616d776c68bf8f4 Mon Sep 17 00:00:00 2001 From: Han Fei Date: Mon, 18 Dec 2023 14:47:54 +0100 Subject: [PATCH 1/2] refine error message --- src/Storages/MergeTree/MergeTreeData.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Storages/MergeTree/MergeTreeData.cpp b/src/Storages/MergeTree/MergeTreeData.cpp index 8445c513372..d7b444f7763 100644 --- a/src/Storages/MergeTree/MergeTreeData.cpp +++ b/src/Storages/MergeTree/MergeTreeData.cpp @@ -4063,10 +4063,10 @@ void MergeTreeData::forcefullyMovePartToDetachedAndRemoveFromMemory(const MergeT Strings restored; Strings error_parts; - auto is_appropriate_state = [] (DataPartState state) + auto is_appropriate_state = [] (const DataPartPtr & part_) { - if (state != DataPartState::Outdated) - throw Exception(ErrorCodes::LOGICAL_ERROR, "Trying to restore a part from unexpected state: {}", state); + if (part_->getState() != DataPartState::Outdated) + throw Exception(ErrorCodes::LOGICAL_ERROR, "Trying to restore a part {} from unexpected state: {}", part_->name, part_->getState()); return true; }; @@ -4111,7 +4111,7 @@ void MergeTreeData::forcefullyMovePartToDetachedAndRemoveFromMemory(const MergeT for (const auto & part_candidate_in_partition : parts_candidates | std::views::reverse) { if (part->info.contains(part_candidate_in_partition->info) - && is_appropriate_state(part_candidate_in_partition->getState())) + && is_appropriate_state(part_candidate_in_partition)) { String out_reason; /// Outdated parts can itersect legally (because of DROP_PART) here it's okay, we From de7a349f0d0918e9352c5e7145d63588949b6820 Mon Sep 17 00:00:00 2001 From: Alexander Tokmakov Date: Mon, 18 Dec 2023 20:44:50 +0100 Subject: [PATCH 2/2] Update MergeTreeData.cpp --- src/Storages/MergeTree/MergeTreeData.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Storages/MergeTree/MergeTreeData.cpp b/src/Storages/MergeTree/MergeTreeData.cpp index d7b444f7763..da0dc6625c2 100644 --- a/src/Storages/MergeTree/MergeTreeData.cpp +++ b/src/Storages/MergeTree/MergeTreeData.cpp @@ -4065,9 +4065,12 @@ void MergeTreeData::forcefullyMovePartToDetachedAndRemoveFromMemory(const MergeT auto is_appropriate_state = [] (const DataPartPtr & part_) { - if (part_->getState() != DataPartState::Outdated) + /// In rare cases, we may have a chain of unexpected parts that cover common source parts, e.g. all_1_2_3, all_1_3_4 + /// It may happen as a result of interrupted cloneReplica + bool already_active = part_->getState() == DataPartState::Active; + if (!already_active && part_->getState() != DataPartState::Outdated) throw Exception(ErrorCodes::LOGICAL_ERROR, "Trying to restore a part {} from unexpected state: {}", part_->name, part_->getState()); - return true; + return !already_active; }; auto activate_part = [this, &restored_active_part](auto it)