Repository navigation
Conversation
Stress test (arm_msan) on ClickHouse#119682 at 42757a3 aborted the server with Logical error: 'Block structure mismatch in patch join cache stream: different names of columns: _row_exists UInt8 ... / _part_data_version UInt64 ...' from assertCompatibleHeader in PatchJoinCache::Entry::addBlock. The same message has fired four times in 180 days, on four unrelated PRs, always in Stress test. PatchJoinCache is one per read pool (MergeTreeReadPoolBase.cpp), shared by every read task of the query, and an entry was keyed by the patch part name alone. The blocks stored in it are produced by the block_reader lambda in MergeTreePatchReaderJoin::readPatches, which closes over that task's own sample_block, so the structure of the cached blocks was a property of whichever task happened to read the range rather than of the patch part. That structure is genuinely per-main-part. addPatchPartsColumns builds it from the main part's own task_columns, and it diverges three ways: the column order, because patch_columns_to_read_names is materialized from a NameSet; the column set, because the requested-column term is per-main-part; and the column types, because patch_part.perform_alter_conversions is per main part and drives fixPatchBlockTypes. Three of the four CI occurrences differ in order and one in the number of columns, which covers two of the three. The check at addBlock is under DEBUG_OR_SANITIZER_BUILD, so a release build stores the divergent block instead of aborting, and the same divergence is then re-checked with no #ifdef by the within-patch loop in getUpdatedHeader. Measured on the official amd_release build of master 26.10.1.139: the query fails with Code: 49 'Block structure mismatch in patch parts stream' and the server is unaffected. enable_lightweight_update defaults to 1, so a plain UPDATE reaches this path with no opt-in. Make the structure part of the entry key, so an entry holds structurally identical blocks by construction and the assertion becomes a true invariant check rather than a reachable abort. The key is computed once per reader from the reader's sample block, put through the same fixPatchBlockTypes the stored blocks get, and rendered as names and types in order; it is not hashed, because a collision would silently resurrect the bug. init now takes the ranges map and records the bucket count, and the entries of a (patch part, structure) pair are created lazily under the existing mutex. addBlock, its #ifdef and its positional version lookup are untouched, and the stats cache stays keyed by patch name alone so range statistics are not read twice. When all tasks need the same patch columns there is still one entry per patch part and behaviour is unchanged. Alternatives rejected. Sorting the block inside addBlock fixes the order divergence only, and the column-set divergence would then reach applyPatchesIndices, which decides what to patch from the first block, so a column present in one block and missing from the first would be silently left unpatched: worse than failing. Looking the version column up by name has the same shortcoming and guards the symptom. Making the patch read structure a pure function of the patch part cannot work, because perform_alter_conversions is per-main-part by design, and narrowing the column set to the query's columns would drop patch columns a part needs for its own injected columns. Correcting what I wrote on ClickHouse#119682: the has_lightweight_delete gate in addPatchPartsColumns is not the defect and cannot diverge between tasks, because AlterConversions::addPatchPart puts every non-system patch column including _row_exists into all_updated_columns and hasLightweightDelete() reads exactly that. The occurrence with no _row_exists at all refutes that framing independently. Out of scope on purpose, so that this carries one root cause: sorting patch_columns_to_read_names, whose benefit I cannot measure, and a no-parallel tag on 04034_patch_parts_column_order_mismatch.sql, which enables the server-global failpoint patch_parts_reverse_column_order untagged and is the likeliest trigger of all four occurrences. After this change a leaked failpoint is harmless on this path: every consumer of patch blocks looks columns up by name, and the two positional comparisons become intra-entry. The new test drives two merged parts that share one Join-mode patch part at patch-list indices of different parity, so the failpoint reverses exactly one of the two read structures, with one cache bucket and single-granule read ranges so that each task contributes a block the other did not. It needs patch_parts_version = 'v1', since v2 is applied in MergeOnKey mode and never uses this cache, and it asserts both the merge arrangement and the patch-part ordering it depends on so that a future change reddens it instead of quietly making it vacuous. It is red on unfixed master and green with the fix, 50 of 50 with settings randomization on, and 04034 plus the 70 tests of the 03100_lwu_* family give verdicts identical to the pristine base binary. Related: ClickHouse#119682 Co-Authored-By: Claude Opus 5 <[email protected]>
The test added with the fix was a ~40% false green on unfixed code: `clickhouse-test` randomizes `max_threads` to `randint(1, 3)`, and with `max_threads = 1` `ReadFromMergeTree` plans a per-part in-order read rather than a thread pool. A stream of its own means a `MergeTreeReadPool` of its own, and therefore a `PatchJoinCache` of its own, so the two merged parts never put their differing block structures into one cache entry and there is nothing left to assert. Measured on the unfixed binary over fresh servers: 6/10 red as written, 0/5 with `max_threads` forced to 1, 5/5 with it forced to 2, and 20/20 with it pinned at 2 and settings randomization on. `max_threads = 2` cannot collapse back to one stream: the ratio setting is not randomized, the "data is small" reduction needs `parts_with_ranges.size() < num_streams` and there are exactly two parts, and `capStreamsByReadBytes` never reduces below `MIN_STREAMS_TO_CAP_BY_READ_BYTES`. Also assert that the decisive query really applied a Join-mode patch in both read tasks, so that a regression handing every task a private entry cannot pass on the sums alone, and tag the test: it enables a server-global failpoint that another untagged test disables, it needs `SYSTEM SCHEDULE MERGE` and the exact merge layout it asserts, and both parts must read the patch part through one shared read pool.
The existing ProfileEvents assertion used PatchesJoinAppliedInAllReadTasks, which is incremented in getPatchesToRead's selection switch before any cache access, so it reports that Join mode was chosen and cannot report that the two merged parts met in one cache entry. A regression giving every read task a private entry, or reading each part through its own pool, would leave it at the same value and the test would pass while exercising nothing. PatchesJoinRowsAddedToHashTable counts rows per entry: addRangesAsync de-duplicates by mark range within an entry, so with the column-order failpoint on the shared patch part fills one entry per structure and with it off a single entry serves both parts. Comparing the decisive read against a structures-agree twin of the same query therefore carries no fixture-dependent magnitude, only the inequality. Measured: 36808 rows against 25000 with the failpoint on, and equal counts both on the unfixed binary in the configuration where the two structures never meet and in a control that never enables the failpoint.
PatchesJoinRowsAddedToHashTable counts rows per cache entry, and a Join-mode read task is handed whole chunks of the pool-wide range set rather than tight per-task ranges, so comparing the decisive read against a structures-agree twin measures whether the two structures' chunk sets overlap, not whether they shared an entry. The two are not the same question: the comparison answers yes at max_threads = 1, where the unfixed binary is measurably blind, and the chunk layout follows granularity, which the runner randomizes, so the assertion also failed one randomized run in 350 on a draw whose chunk sets happened to be disjoint. No ProfileEvent can separate the two questions on this fixture, which has exactly two patch-applying read tasks and exactly two structures, so the assertion is dropped and the guarantee the test carries is the measured failure on unfixed code. Two comments stated rationale that measurement refutes. A one-stream read does not give each part its own pool and cache: at max_threads = 1 both parts still read the shared patch part through one cache, and what makes the pin load-bearing is that reading them in turn lets the first structure claim every range the second needs, since a range is added to an entry once. And the PatchesJoinAppliedInAllReadTasks lower bound does not show that both merged parts applied a patch, because the first part alone contributes two; what it does show is that Join mode was used at all, which is what it now says.
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 4 passes, 7 findings) plus my own
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-8:20260919-152900 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-4:20260919-141400 |
|
Workflow [PR], commit [1ee6d54] Summary: ✅
AI ReviewSummaryThe PR keys Missing context / blind spots
Final VerdictStatus: ✅ Approve. No code changes requested; current-head CI should finish before merging. |
CI finish ledger - f382e10Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
Nothing else on this head is red: 154 checks pass, 18 are skipped, and the 4 red ones are the rows above. The Session id: cron:our-pr-ci-monitor:20260920-000318 |
Build profile diff (arm_release)Commit See the job log for details. |
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Master's style rule failpoint_tests_are_isolated requires a stateless test that runs SYSTEM ENABLE FAILPOINT to carry both no-parallel and no-fasttest. 04991 already had no-parallel; this adds no-fasttest, as master did for its own fail point tests in 67965ab. Co-Authored-By: Claude Opus 5.5 <[email protected]>
CI finish ledger - a5c43d0Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
Session id: cron:our-pr-ci-monitor:20261011-023008 |
…e-structure-key Co-Authored-By: Claude Opus 5.5 <[email protected]>
CI finish ledger - e1021cbEvery failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
All 162 other check runs completed and Session id: cron:our-pr-ci-monitor:20261011-073009 |
|
Correction to the ledger above: the
A run against a current master build compares flat. |
Related: #119682
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed
LOGICAL_ERROR: Block structure mismatch in patch parts streamwhen aSELECTapplies one patch part inJoinmode to several merged parts that read it with a different block structure (column order, column set or column types). The cache of patch blocks is now keyed by that structure, so one entry can no longer mix blocks of different structure.Description
PatchJoinCacheis one per read pool, shared by every read task of a query, but an entry was keyed by the patch part name alone. Its blocks come from a lambda capturing the reading task's ownsample_block, and that structure is genuinely per-main-part: the column order comes from aNameSet, the column set from that part's read set, the types from its ownperform_alter_conversions. Two tasks could therefore put blocks of different structure into one entry.A debug or sanitizer build aborts at
PatchJoinCache::Entry::addBlock. In release that check is compiled out, butgetUpdatedHeaderre-checks the same divergence unconditionally, so the query fails instead: measured on the officialamd_releasemaster build,Code: 49 ... Block structure mismatch in patch parts stream, server unaffected.Joinmode readsv1patch parts, the default until 26.9, so a plainUPDATEreached it with no opt-in; 26.9 still reads them from disk.The fix makes the structure part of the entry key, so an entry holds structurally identical blocks by construction and the existing assertion becomes a true invariant check. When all tasks need the same patch columns there is still one entry per patch part.
Correction to #119682: the
has_lightweight_delete &&gate inaddPatchPartsColumnsis not the defect and cannot diverge between tasks, becauseAlterConversions::addPatchPartputs_row_existsintoall_updated_columnsandhasLightweightDelete()reads exactly that.Out of scope: sorting
patch_columns_to_read_names; tagging04034(harmless after this fix).New test
04991_patch_join_cache_structure_mismatchis red on unfixed master with the reported signature and stack, green with the fix, 50/50 under settings randomization;04034and03100_lwu_*match the pristine base binary. The type arm holds by construction but has no test: no MergeTree lever materializes a pendingALTERon one merged part only.CI provenance: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=119682&sha=42757a345dbb20e868e799595de982d5e5b355d3&name_0=PR&name_1=Stress%20test%20%28arm_msan%29
Workflow [PR]
Sync PR [sync-upstream/pr/121044]