Repository navigation
Conversation
…duplication AddDeduplicationInfoTransform numbered every arriving chunk with an incrementing source block number, including row-less chunks. A row-less chunk contributes no deduplication token (setUserToken with a zero row count is a no-op) and is later dropped by squashing, so numbering it only leaves a gap in the source block numbers. That gap breaks the contiguity check in TokenDefinition::canBeExtended (source number ranges must be adjacent), so squashing merges the two surrounding data blocks with do_concat instead of extending a single token. The resulting single part then carries several deduplication tokens, getDeduplicationHashes returns several hashes for one part, and ReplicatedMergeTreeSink asserts deduplication_hashes.size() == 1. Guard the source block numbering so row-less chunks do not consume a number; the numbers then stay contiguous across data chunks and a squashed block keeps a single deduplication token and hash. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Covers the insert deduplication bug where a row-less chunk consumed a source block number, leaving a gap that broke token merging on squashing and produced several deduplication hashes for a single part (which trips deduplication_hashes.size() == 1 in ReplicatedMergeTreeSink). The test drives AddDeduplicationInfoTransform directly with the shape data / row-less / data / data. Two adjacent data chunks separated only by the row-less chunk must merge into one token: without the guard they get non-adjacent source numbers (0 and 2), mergeSelf concatenates into two tokens (getCount() == 2) and the test fails; with the guard they get 0 and 1 and extend into one token (getCount() == 1). A second assertion merges two data chunks separated by another data chunk and requires two tokens, so the test also fails if source numbering is silently removed altogether. Two companion tests pin the hash-layer behavior for the gap (two hashes) and for contiguous numbers (one hash). This is a unit test rather than an SQL test because the interleaved row-less chunk only forms under real multi-host parallel-replicas timing; a local single-node run never delivers one to the transform (verified across six query shapes and eighty iterations), so no SQL shape can demonstrate the failure deterministically. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Internal second-model review — adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 4 review rounds, final round 0 findings; plus the reviewer's own cold pass each round).
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-9:20260725-080500 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-5:20260725-075700 |
|
cc @CheSema - could you review this? AddDeduplicationInfoTransform numbered row-less chunks, leaving a gap in source block numbers that makes canBeExtended fall back to concat, so one squashed part ends up with two deduplication hashes (asserts deduplication_hashes.size() == 1 in sanitizer builds, nondeterministic dedup ids in release). |
|
Workflow [PR], commit [ff60399] Summary: ❌
AI ReviewSummaryThis PR fixes insert deduplication so a 0-row chunk no longer advances the source block counter before squashing drops it, which keeps later data chunks contiguous and prevents timing-dependent deduplication hashes. I reviewed the current diff, the surrounding deduplication/squashing/sink code paths, and the existing PR discussion, and I did not find a remaining issue that warrants an inline review comment. Final Verdict
|
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 49/49 (100.00%) · Uncovered code |
CI finish ledger — ff60399Every failure below has an owner: a fixing PR (ours or external), or a full-effort fix task
Startup abort, from Hung check, the single hung row in
Not caused by this PR: the diff is one Reports: Session id: cron:our-pr-ci-monitor:20260726-083000 |
|
Fixing PR for the hung check on this run: #112003 The processlist text recorded for that hung row ( |
Follow-up to the previous commit on this branch, addressing review feedback. The comment above the incremental cursor in `CountSubstringsImpl::vectorConstant` justified the row-identity check with "rows never share a start offset". That is not true of `ColumnString`: its strings carry no terminator, `sizeAt` permits `offsets[i] == offsets[i - 1]`, and a zero-length insert pushes the unchanged offset, so adjacent empty rows do share a start offset. The check is still exact for a narrower reason, which the comment now states: only a row that contains a match ever sets the cursor, and such a row is non-empty because the index scan leaves `haystack_offsets[i - 1] <= pos < haystack_offsets[i]`. The change to the header is comment-only - the preprocessed token stream is unchanged. `04648_count_substrings_utf8_complexity` pinned the complexity but not the cursor arithmetic. Its multi-row query uses a 10-character, 11-byte chunk with `start_pos` thresholds of 1 to 4, i.e. below both the character and the byte distance between matches, so a per-match delta cursor and a byte-offset cursor produce the same numbers as the correct one. Two small cases are added where multibyte characters precede the matches and `start_pos` exceeds the distance between matches. Each is verified against three wrong implementations: a per-match delta cursor returns 0 and 0, a byte-offset cursor returns 2 and 2, and a cursor that never restarts on a row change returns 3 for the second case, against a reference of 1 and 1. Reverting the whole cursor hunk still makes the file time out, so the complexity assertions are unaffected by the addition. The reference was regenerated with `clickhouse-test --record`. Existing suites `01590_countSubstrings`, `02346_position_countsubstrings_zero_byte`, `01163_search_case_insensetive_utf8`, `03278_enum_string_functions`, `03666_count_matches_complexity` and `00233_position_function_family` pass with unchanged references, and 50 runs of `04648` pass at 0.23 to 0.28 s each. CI reports for the hung check that led to this branch: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=111881&sha=ff60399af8498b3ce3db0df35c2317474779b732&name_0=PR&name_1=Stress%20test%20%28arm_asan_ubsan%29 ClickHouse#111881 https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=108977&sha=852e60ed1f6b4b834b49e4421043f1edf1adb501&name_0=PR&name_1=Stress%20test%20%28arm_tsan%29 ClickHouse#108977
|
@groeneai is this PR still needed? |
|
Yes, it is still needed. Checked on current master (
It is rare in CI: Stress test (amd_msan) on 2026-07-24 and Stress test (arm_msan) on 2026-08-11, none on master. The added gtest fails without the fix (Bugfix validation (unit tests) passed), and the branch still merges cleanly. |
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixes nondeterministic insert deduplication block ids when a row-less chunk interleaves with data chunks during an
INSERT SELECT(for example under parallel replicas). Such an insert can miss deduplication and produce duplicate rows on retry, and assertsdeduplication_hashes.size() == 1in debug and sanitizer builds.Description
AddDeduplicationInfoTransformnumbered every arriving chunk with an incrementing source block number, including row-less chunks (0 rows, with columns; these reach the transform becauseISimpleTransformonly skips chunks that have neither rows nor columns). A row-less chunk contributes no deduplication token (setUserTokenwith count 0 is a no-op) and is later dropped by squashing, so numbering it only leaves a gap in the source block numbers.That gap breaks the contiguity check in
TokenDefinition::canBeExtended(source number ranges must be adjacent), so squashing merges the two surrounding data blocks withdo_concatinstead of extending a single token. The squashed single part then carries several deduplication tokens,getDeduplicationHashesreturns several hashes for one part, andReplicatedMergeTreeSinkassertsdeduplication_hashes.size() == 1. In release builds the assert is compiled out and the part commits with two block ids whose values depend on where the row-less chunk interleaved (thread-timing dependent), so an identical retried insert computes different ids, misses deduplication, and duplicates rows.Fix: do not consume a source block number for row-less chunks. Source numbers then stay contiguous arrival indices of data chunks, a squashed block keeps a single deduplication token and hash, and the assert holds.
The regression test is a unit test (
gtest_dedup_source_block_number) rather than an SQL test: the interleaved row-less chunk only forms under real multi-host parallel-replicas timing, so no local single-node SQL shape delivers one to the transform (verified across six query shapes and eighty iterations). The test drivesAddDeduplicationInfoTransformdirectly and fails without this fix (two tokens) and passes with it (one token).Surfaced as
Logical error: 'deduplication_hashes.size() == 1'by theStress test (amd_msan)check on an unrelated docs-only PR: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=111754&sha=79ec7ed9daf6348f4d886d723048dbacf5a4324a&name_0=PR&name_1=Stress%20test%20%28amd_msan%29