Skip to content

Fix select parts for merge#14444

Merged
alesapin merged 5 commits intomasterfrom
fix_select_parts_for_merge
Sep 4, 2020
Merged

Fix select parts for merge#14444
alesapin merged 5 commits intomasterfrom
fix_select_parts_for_merge

Conversation

@alesapin
Copy link
Copy Markdown
Member

@alesapin alesapin commented Sep 3, 2020

I hereby agree to the terms of the CLA available at: https://yandex.ru/legal/cla/?lang=en

Changelog category (leave one):

  • Bug Fix

Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
Fix bug which leads to wrong merges assignment if table has partitions with a single part.

@robot-clickhouse robot-clickhouse added the pr-bugfix Pull request with bugfix, not backported by default label Sep 3, 2020
@@ -275,7 +291,7 @@ bool MergeTreeDataMergerMutator::selectPartsToMerge(
prev_part = ∂
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The bug is here. If we found a new partition we will reset prev_part to nullptr at line 255, but after that restore it back. So on the next iteration, we will skip can_merge_callback check for the first part in the partition, because partition_id != *prev_partition_id and unconditionally add this part to the candidates list. Even if this part already participates in merge/mutation. MergeSelectors can easily select this part and assign a merge.
Previously we have seen very similar behavior for ReplicatedMergeTree in 00992 and 00993 tests.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By the way, does it lead only to extra merges being assigned (with no harm) + subsequent exception with logical error in code? Or something more dangerous?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the worst consequence is unprocessable entries https://github.com/clickhouse/ClickHouse/blob/master/src/Storages/StorageReplicatedMergeTree.cpp#L1465 in the ReplicatedMergeTreeQueue (we have seen this rare error in 00992 and 00993 tests).


/// Parts are belong to partitions. Only parts within same partition could be merged.
using PartsInPartition = std::vector<Part>;
using PartsRange = std::vector<Part>;
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've renamed these aliases because they don't represent partitions, but just continuous parts range. Previous naming was slightly confusing.

@nikitamikhaylov nikitamikhaylov self-assigned this Sep 3, 2020
# This test was introduced to check concurrency for TTLs merges and mutations
# but it revealed a bug when we assign different merges to the same part
# on the borders of partitions.
def test_no_ttl_merges_in_busy_pool(started_cluster):
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually crash reproduces only in debug build. In other modes it will hang until timeout.

alesapin added a commit that referenced this pull request Sep 7, 2020
Backport #14444 to 20.7: Fix select parts for merge
alesapin added a commit that referenced this pull request Sep 8, 2020
Backport #14444 to 20.5: Fix select parts for merge
alesapin added a commit that referenced this pull request Sep 8, 2020
Backport #14444 to 20.6: Fix select parts for merge
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no-docs-needed pr-bugfix Pull request with bugfix, not backported by default

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants