Repository navigation
Throw BAD_ARGUMENTS, not LOGICAL_ERROR, for incompatible granularity in MOVE/REPLACE PARTITION - #103881
Conversation
…rity in MOVE/REPLACE PARTITION `MergeTreeData::canReplacePartition` rejects MOVE/REPLACE/ATTACH PARTITION between two MergeTree tables when one is on adaptive granularity and the other is on non-adaptive granularity (i.e. when the destination has `enable_mixed_granularity_parts = false` or `index_granularity_bytes = 0`, and the source part's mark type does not match the destination's `canUseAdaptiveGranularity`). This is a user-reachable condition: a user can create two MergeTree tables with intentionally different granularity settings, insert data, and then run `ALTER TABLE ... MOVE/REPLACE PARTITION ...`. Out of the four call sites that throw on this condition, three threw `LOGICAL_ERROR`: * `StorageMergeTree::movePartitionToTable` (was: `LOGICAL_ERROR`) * `StorageReplicatedMergeTree::replacePartitionFromImpl` (was: `LOGICAL_ERROR`) * `StorageReplicatedMergeTree::movePartitionToTable` (was: `LOGICAL_ERROR`) The fourth (`StorageMergeTree::replacePartitionFrom`) already used `BAD_ARGUMENTS`. `LOGICAL_ERROR` is reserved for assertion failures and internal-bug conditions: it aborts the server in debug / sanitizer builds and surfaces in operator alerts as a critical incident. It is the wrong error code for a user-reachable input mismatch. This commit aligns all four sites on `BAD_ARGUMENTS` and adds a regression test covering all four code paths. The bug was found by BuzzHouse on `amd_tsan` (STID 4063-3b45) on 2026-05-01. CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=103862&sha=3bec163c6ba8dcb12ed1144c8ac75c261863cc81&name_0=PR&name_1=BuzzHouse%20%28amd_tsan%29
Pre-PR validation gate (TASK.md Phase 4)Session: (a) Deterministic repro — yes: CREATE TABLE src (a UInt64, b UInt64) ENGINE = MergeTree ORDER BY a
SETTINGS index_granularity_bytes = 0, enable_mixed_granularity_parts = 0;
CREATE TABLE dst (a UInt64, b UInt64) ENGINE = MergeTree ORDER BY a
SETTINGS index_granularity_bytes = 10485760, enable_mixed_granularity_parts = 0;
INSERT INTO src SELECT number, number FROM numbers(1000);
ALTER TABLE src MOVE PARTITION tuple() TO TABLE dst;
-- Before fix: LOGICAL_ERROR (server abort in debug/sanitizer)
-- After fix: BAD_ARGUMENTS(b) Root cause explained — (c) Fix matches root cause — yes. The fix changes (d) Test intent preserved / new tests added — (e) Demonstrated in both directions — yes:
(f) Fix is general, not a narrow patch — yes:
|
|
cc @alesapin @CurtizJ — could you review this? It changes |
|
Workflow [PR], commit [0ba2ebb] Summary: ✅
AI ReviewSummaryThis PR fixes the user-facing error classification for incompatible-granularity Final VerdictStatus: ✅ Approve |
CI ledger — covered SHA:
|
| Check | Test | Disposition |
|---|---|---|
Stateless tests (amd_tsan, parallel, 1/2) |
00096_obfuscator_save_load |
flaky chronic trunk — task 2026-06-02-ci-00096obfuscatorsaveload-chronic-f |
Stateless tests (amd_tsan, parallel, 1/2) |
00175_obfuscator_schema_inference |
flaky chronic trunk — task 2026-06-02-ci-00175obfuscatorschemainference-ab |
Unit tests (asan_ubsan) |
(check-level) | infra/chronic UBSan in UntrackedMemoryCounter — task 2026-06-03-ci-p1-chronic-ubsan-in-untrackedmemoryc |
No PR-caused failures. Awaiting human review.
Session: cron:our-pr-ci-monitor:20260604-213000
|
Dear @hanfei1991, you haven't been active on this PR for 30 days. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself. |
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 14/14 (100.00%) · Uncovered code |
b3df6de
|
This broke the private CI. Reverting. @groeneai @hanfei1991 Please reintroduce but check private CI before merging |
|
Reintroduced in #110535. Likely private-CI cause: the regression test's ReplicatedMergeTree assertions expect |
…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]>
…ranularity for non-adaptive parts A non-adaptive data part stores no per-mark row counts on disk: its mark file holds only the two offsets per mark, so the rows per granule have to be reconstructed when the part is loaded, and they are reconstructed from the READING table's `index_granularity`. `MergeTreeData::canReplacePartition` is the only compatibility gate on the partition-manipulation path, and it compared mark adaptivity only. With both tables non-adaptive (`index_granularity_bytes = 0`) neither adaptivity branch fires, so a part written at `index_granularity = N` was admitted into a table declared with `index_granularity = M != N`. `MergeTreeDataPartWide::loadIndexGranularityImpl` then paired the source's mark offsets with the destination's rows per mark, mapping every mark to the wrong row range. Observable consequences, both measured on 8627fa2: - Release build: the part attaches and the table disagrees with itself. For 18 rows moved from `index_granularity = 8` into `index_granularity = 4`, `SELECT count() FROM t WHERE <primary key condition>` returned 10; in the other direction (4 into 8) it returned 24, while `SELECT count() FROM t` returned the correct 18. - Debug and sanitizer builds: the consistency check in `IMergeTreeDataPart::loadRowsCount` throws `LOGICAL_ERROR`, which those builds turn into a server abort. The new condition is placed outside the `enable_mixed_granularity_parts` block on purpose: a destination that accepts mixed granularity still reinterprets a non-adaptive part, because `changeGranularityIfRequired` clears `mark_type.adaptive` and `index_granularity_bytes` from the filesystem but leaves `fixed_index_granularity` at the destination's value. That case was measured to abort on master too, and it is the only arm of the new test that distinguishes this placement from putting the check inside the block. Comparing against the source part's own `fixed_index_granularity` is sound because `index_granularity` is read-only after table creation (`MergeTreeSettings::isReadonlySetting`, enforced as `READONLY_SETTING` in `MergeTreeData::checkAlterIsPossible`), so for any part the source table wrote itself the setting is the value the part was written with. `MergeTreeDataPartCompact` needs no equivalent guard: a Compact part is always adaptive and its marks record per-granule row counts, so nothing is reconstructed. Verified that a non-adaptive table cannot write a Compact part even with `min_bytes_for_wide_part` and `min_rows_for_wide_part` set to 1e9. The condition only ever adds rejections, so it cannot make a previously rejected operation succeed. Previously accepted DDL now errors with `BAD_ARGUMENTS`; the accepted cases produced a part whose marks map to the wrong rows unless the partition fitted in a single granule. The new test arms live in the existing `04150_move_partition_inconsistent_granularity`, which carries `no-shared-merge-tree`: in Cloud `ReplicatedMergeTree` is substituted by `SharedMergeTree`, whose partition-move path does not call `canReplacePartition`. Dropping that tag is what got ClickHouse#103881 reverted. The arms cover both directions of the mismatch and all of `REPLACE`/`MOVE`/`ATTACH PARTITION FROM`, so a one-sided comparison does not satisfy them. `r_src_nonadaptive` pins `index_granularity = 8192`, its default, because `clickhouse-test` otherwise injects a random value as the CREATE TABLE default and a draw equal to the destination's 4096 would remove that arm's expected rejection. One arm asserts an acceptance instead: an adaptive source part at a different `index_granularity` is still admitted, because its marks carry per-granule row counts and the destination's setting never enters their interpretation. It pins the scope of the new condition, so dropping the `!adaptive` conjunct would be caught by the test rather than silently rejecting a valid transfer. That arm pins its source part to the `Wide` format, which is the format whose granularity load path holds the defect, and without which restating the conjunct as a `Wide` part-type test would also pass. Reported and root-caused by Pedro Ferreira. Found by the server-side AST fuzzer under Stress test (arm_debug) on ClickHouse#116783 : https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=116783&sha=dd8310bb0d928a3aa50822f052cc835cf86efac0&name_0=PR&name_1=Stress%20test%20%28arm_debug%29 Closes ClickHouse#117524
…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]>
…4063-3b45-move-partition-bad-args Throw BAD_ARGUMENTS, not LOGICAL_ERROR, for incompatible granularity in MOVE/REPLACE PARTITION
This fix addresses a BuzzHouse fuzzer finding (STID
4063-3b45) where aMOVE PARTITIONbetween two MergeTree tables with incompatible granularitysettings throws
LOGICAL_ERRORinstead of a user-error code.LOGICAL_ERRORaborts the server in debug / sanitizer builds and surfaces in operator alerts
as a critical incident, which is wrong for a user-reachable input mismatch.
MergeTreeData::canReplacePartitionrejectsMOVE/REPLACE/ATTACH PARTITIONbetween two tables when one is on adaptive granularity and the other is on
non-adaptive granularity (i.e. when the destination has
enable_mixed_granularity_parts = falseorindex_granularity_bytes = 0,and the source part's mark type does not match the destination's
canUseAdaptiveGranularity). Out of the four call sites that throw on thiscondition, three threw
LOGICAL_ERROR:StorageMergeTree::movePartitionToTableStorageReplicatedMergeTree::replacePartitionFromImplStorageReplicatedMergeTree::movePartitionToTableThe fourth (
StorageMergeTree::replacePartitionFrom) already usedBAD_ARGUMENTS.This PR aligns all four sites on
BAD_ARGUMENTSand adds a regression testcovering all four code paths (plain MergeTree
MOVE/REPLACE, ReplicatedMergeTreeMOVE/REPLACE).Reproducer:
Originally hit by BuzzHouse (
amd_tsan) on 2026-05-01:Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Throw
BAD_ARGUMENTSinstead ofLOGICAL_ERRORwhenALTER TABLE ... MOVE/REPLACE/ATTACH PARTITIONis run between twoMergeTreetables with incompatible granularity settings (one adaptive, one non-adaptive).Documentation entry for user-facing changes
Version info
26.7.1.899(included in26.7and later)