Merge pull request #37763 from ClickHouse/fix_replace_range_again

Fix flaky 01154_move_partition_long
This commit is contained in:
Alexander Tokmakov 2022-06-02 14:15:16 +03:00 committed by GitHub
commit 45657d203a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 0 deletions

View File

@ -2183,6 +2183,29 @@ bool ReplicatedMergeTreeMergePredicate::canMergeSinglePart(
}
bool ReplicatedMergeTreeMergePredicate::partParticipatesInReplaceRange(const MergeTreeData::DataPartPtr & part, String * out_reason) const
{
std::lock_guard<std::mutex> lock(queue.state_mutex);
for (const auto & entry : queue.queue)
{
if (entry->type != ReplicatedMergeTreeLogEntry::REPLACE_RANGE)
continue;
for (const auto & part_name : entry->replace_range_entry->new_part_names)
{
if (part->info.isDisjoint(MergeTreePartInfo::fromPartName(part_name, queue.format_version)))
continue;
if (out_reason)
*out_reason = fmt::format("Part {} participates in REPLACE_RANGE {} ({})", part_name, entry->new_part_name, entry->znode_name);
return true;
}
}
return false;
}
std::optional<std::pair<Int64, int>> ReplicatedMergeTreeMergePredicate::getDesiredMutationVersion(const MergeTreeData::DataPartPtr & part) const
{
/// Assigning mutations is easier than assigning merges because mutations appear in the same order as

View File

@ -501,6 +501,10 @@ public:
/// This predicate is checked for the first part of each range.
bool canMergeSinglePart(const MergeTreeData::DataPartPtr & part, String * out_reason) const;
/// Returns true if part is needed for some REPLACE_RANGE entry.
/// We should not drop part in this case, because replication queue may stuck without that part.
bool partParticipatesInReplaceRange(const MergeTreeData::DataPartPtr & part, String * out_reason) const;
/// Return nonempty optional of desired mutation version and alter version.
/// If we have no alter (modify/drop) mutations in mutations queue, than we return biggest possible
/// mutation version (and -1 as alter version). In other case, we return biggest mutation version with

View File

@ -7128,6 +7128,13 @@ bool StorageReplicatedMergeTree::dropPartImpl(
return false;
}
if (merge_pred.partParticipatesInReplaceRange(part, &out_reason))
{
if (throw_if_noop)
throw Exception(ErrorCodes::PART_IS_TEMPORARILY_LOCKED, out_reason);
return false;
}
if (partIsLastQuorumPart(part->info))
{
if (throw_if_noop)