Skip to content

Throw BAD_ARGUMENTS, not LOGICAL_ERROR, for incompatible granularity in MOVE/REPLACE PARTITION - #110535

Merged
tiandiwonder merged 1 commit into
ClickHouse:masterfrom
groeneai:groeneai/reintroduce-103881-move-partition-bad-args
Jul 24, 2026
Merged

tiandiwonder merged 1 commit into
ClickHouse:masterfrom
groeneai:groeneai/reintroduce-103881-move-partition-bad-args

Conversation

@groeneai

@groeneai groeneai commented Jul 15, 2026 •

Copy link
Copy Markdown
Collaborator

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

ALTER TABLE ... MOVE/REPLACE PARTITION between two MergeTree tables with incompatible granularity (one adaptive, one non-adaptive) now throws BAD_ARGUMENTS instead of LOGICAL_ERROR. This is a user-reachable condition, so it should not surface as an internal error (which aborts the server in debug/sanitizer builds).

Description

Reintroduces #103881, which was reverted in #110526 because it broke the private CI.

MergeTreeData::canReplacePartition rejects MOVE/REPLACE/ATTACH PARTITION when the source part's mark_type.adaptive does not match the destination's canUseAdaptiveGranularity(). Any user can create two tables with different index_granularity_bytes/enable_mixed_granularity_parts and trigger a partition transfer between them, so the correct error code is BAD_ARGUMENTS. Three of the four call sites threw LOGICAL_ERROR; the fourth (StorageMergeTree::replacePartitionFrom) already threw BAD_ARGUMENTS. This aligns all four.

Originally found by BuzzHouse (STID 4063-3b45) on BuzzHouse (amd_tsan):
https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=103862&sha=3bec163c6ba8dcb12ed1144c8ac75c261863cc81&name_0=PR&name_1=BuzzHouse%20%28amd_tsan%29

Difference from #103881 (private CI fix): the regression test 04150_move_partition_inconsistent_granularity now carries the no-shared-merge-tree tag. Under the Cloud/private SharedMergeTree substitution, ReplicatedMergeTree partition moves go through a different code path that does not hit this canReplacePartition granularity check, so the Replicated BAD_ARGUMENTS assertions do not hold there. The plain MergeTree cases still exercise the fix on every configuration. This is the most likely cause of the private-CI break; @Algunenano / @hanfei1991, please run private CI before merging to confirm.

Version info

  • Merged into: 26.8.1.61 (included in 26.8 and later)

…in MOVE/REPLACE PARTITION

Reintroduces ClickHouse#103881 (reverted in ClickHouse#110526 because it broke the private CI).
The regression test now carries the no-shared-merge-tree tag so its
ReplicatedMergeTree assertions are not run under the Cloud SharedMergeTree
substitution, which routes partition moves through a different code path.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. Two tables, one index_granularity_bytes=0, enable_mixed_granularity_parts=0 (non-adaptive), one index_granularity_bytes=10485760 (adaptive), then MOVE/REPLACE PARTITION between them fails every time.
b Root cause explained? MergeTreeData::canReplacePartition returns false when source part mark_type.adaptive != destination canUseAdaptiveGranularity(). This is user-reachable, so throwing LOGICAL_ERROR (three of four call sites) is wrong; it aborts the server in debug/sanitizer builds and misreports an internal bug in release.
c Fix matches root cause? Yes. Changes the three LOGICAL_ERROR throws to BAD_ARGUMENTS, matching the already-correct fourth site (StorageMergeTree::replacePartitionFrom).
d Test intent preserved / new tests added? New regression test 04150_move_partition_inconsistent_granularity exercises all four call sites (plain MergeTree MOVE+REPLACE, Replicated MOVE+REPLACE).
e Demonstrated in both directions? Yes. Pre-fix: LOGICAL_ERROR (Code 49). Post-fix: all four sites return BAD_ARGUMENTS (Code 36), verified locally on a debug build.
f Fix is general, not a narrow patch? Yes. All four canReplacePartition throw sites are now consistent; no sibling site left on LOGICAL_ERROR.
g Generalizes across inputs? The granularity mismatch is symmetric (adaptive->non-adaptive and vice-versa) and applies to MOVE, REPLACE, and ATTACH PARTITION; all covered.
h Backward compatible? Yes. Only the error code of an already-failing operation changes; no format/setting/default change.
i Invariants and contracts preserved? Yes. The operation is still rejected; only the exception class changes from internal-bug to user-error.

Difference from the reverted #103881: the regression test now carries no-shared-merge-tree, so the ReplicatedMergeTree assertions are skipped under the Cloud SharedMergeTree substitution (different partition-move path). This is the most likely cause of the private-CI break in #103881.

Session id: cron:clickhouse-worker-slot-0:20260715-110200

@PedroTadim PedroTadim added the can be tested Allows running workflows for external contributors label Jul 15, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jul 15, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [55de501]

Summary: ❌

job_name test_name status info comment
Stateless tests (amd_asan_ubsan, distributed plan, parallel) FAIL
04033_tpc_ds_q80 FAIL cidb
03826_calculate_subcolumn_size_during_merge_tree_read FAIL cidb
Integration tests (amd_msan, 7/8) FAIL
test_replicated_database/test.py::test_replicated_table_structure_alter FAIL cidb, issue
Stress test (amd_debug) FAIL
Logical error: Block structure mismatch in A stream: different number of columns: (STID: 0993-386d) FAIL cidb
Stress test (arm_asan_ubsan) FAIL
Logical error: Block structure mismatch in A stream: different number of columns: (STID: 0993-386d) FAIL cidb

AI Review

Summary

This PR reintroduces the LOGICAL_ERROR to BAD_ARGUMENTS fix for incompatible-granularity ALTER TABLE ... MOVE/REPLACE PARTITION in MergeTree and ReplicatedMergeTree and adds a regression test. I did not find a remaining correctness issue in the public OSS diff: the three changed throw sites now match the existing StorageMergeTree::replacePartitionFrom behavior, and the new test exercises the public MergeTree / ReplicatedMergeTree paths that actually call canReplacePartition.

Missing context / blind spots
  • ⚠️ The reintroduced test is tagged no-shared-merge-tree at tests/queries/0_stateless/04150_move_partition_inconsistent_granularity.sql:1. In tests/clickhouse-test that tag skips the entire test under both Cloud (args.cloud, around line 2658) and --replace-replicated-with-shared (around line 2781), so the private / Cloud SharedMergeTree path that caused the previous revert is not verifiable from this checkout. A private CI run is still needed to prove the reintroduction is safe there.
Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Jul 15, 2026
@hanfei1991 hanfei1991 self-assigned this Jul 15, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 85.90% 85.80% -0.10%
Functions 92.70% 92.70% +0.00%
Branches 78.10% 78.00% -0.10%

Changed lines: Changed C/C++ lines covered: 14/14 (100.00%) · Uncovered code

Full report · Diff report

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger — 55de501

CI fully finished (Finish Workflow pass, no checks pending). This PR reintroduces the reverted #103881 (BAD_ARGUMENTS instead of LOGICAL_ERROR for incompatible-granularity MOVE/REPLACE/ATTACH PARTITION + regression test 04150, now tagged no-shared-merge-tree). The diff touches only StorageMergeTree.cpp / StorageReplicatedMergeTree.cpp error codes and the test — none of the failures below are in that code path.

Check / test Reason Owner
Integration tests (amd_msan, 7/8) / test_replicated_database::test_replicated_table_structure_alter flaky (565 hits / 290 PRs / 64 master, 30d) #110030 (ours, open)
Stateless (amd_asan_ubsan, distributed plan, parallel) / 04033_tpc_ds_q80 flaky (13 hits / 13 PRs / 0 master) a fix task is created (investigating at full effort — fixing PR link to follow here)
Stateless (amd_asan_ubsan, distributed plan, parallel) / 03826_calculate_subcolumn_size_during_merge_tree_read flaky (12 hits / 12 PRs / 0 master) a fix task is created (investigating at full effort — fixing PR link to follow here)
Stress test (amd_debug) + Stress test (arm_asan_ubsan) / Block structure mismatch in A stream (STID 0993-386d) chronic trunk fuzzer LOGICAL_ERROR (174 hits / 134 PRs / 6 master) a fix task is moved to pending (investigating at full effort — fixing PR link to follow here)
CH Inc sync — CH Inc sync (private, not actionable)

Every failure has an owner; none are PR-caused. Requesting private-CI verification before merge per @Algunenano's revert directive.

Session id: cron:our-pr-ci-monitor:20260715-180000

@groeneai

Copy link
Copy Markdown
Collaborator Author

Fixing PR for the 04033_tpc_ds_q80 failure (Stateless tests, amd_asan_ubsan, distributed plan, parallel): #110572.

The failure was code 241 with the server-total-RSS signature maximum: 41.84 GiB (ConcurrentHashJoin / OvercommitTracker), i.e. aggregate concurrent working set exceeding the lowered cap introduced by #110293 ("Lower max_server_memory_usage_to_ram_ratio to 0.7 on sanitizer stateless runs"), not a defect in this test or this PR. #110293 was reverted by #110572 (merged 2026-07-15 15:03 UTC). This PR's failed build predates the revert; a rebase / master-merge will pick it up.

@groeneai

Copy link
Copy Markdown
Collaborator Author

The 03826_calculate_subcolumn_size_during_merge_tree_read failure on Stateless tests (amd_asan_ubsan, distributed plan, parallel) was a bystander of the fleet-wide server-global OOM outage on 2026-07-15 (13008 Code-241 (total) memory limit exceeded failures across 6258 tests / 155 PRs on that one lane that day; 0-4/day before). The test's 1M-row insert cannot OOM a 41 GiB server on its own; the OvercommitTracker killed it as one of ~19 co-scheduled queries.

Fixing PR: #110503 (retry functional tests on server (total) memory limit exceeded).

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger follow-up (covered SHA 55de501).

The Stress-test Block structure mismatch in JoinStep line (STID 0993-386d), previously owned by an in-progress fix task, now has its fixing PR:

Fixing PR: #109114 "Fix Block structure mismatch in JoinStep for decorrelated correlated subquery with duplicate column name" (merged 2026-07-17). Verified held on master: 0 hits for this signature since the merge (baseline was 12 hits / 11 distinct master SHAs in the 7 days before merge). Rebasing this PR past the merge picks up the fix.

@hanfei1991

Copy link
Copy Markdown
Member

@groeneai Please merge master and run CI again

@tiandiwonder
tiandiwonder added this pull request to the merge queue Jul 24, 2026
Merged via the queue into ClickHouse:master with commit b027830 Jul 24, 2026
172 of 176 checks passed
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 24, 2026
@clickgapai

Copy link
Copy Markdown
Contributor

Hi — this looks like a backport candidate for 26.1, 26.2, 26.3, 26.4, 26.5, 26.6. I ran this PR's own regression test against each branch's binary and the bug reproduces there (the fix isn't present yet).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors pr-bugfix Pull request with bugfix, not backported by default pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants