Skip to content

Fix server crash on deduplicated async insert with optimize_on_insert - #109229

Merged
Diskein merged 2 commits into
masterfrom
dk-rmt-fix-sigfault-on-async-insert-optimize-insert-dedupliacation-token
Jul 6, 2026
Merged

Diskein merged 2 commits into
masterfrom
dk-rmt-fix-sigfault-on-async-insert-optimize-insert-dedupliacation-token

Conversation

@Diskein

@Diskein Diskein commented Jul 2, 2026 •

Copy link
Copy Markdown
Contributor

An async insert that hits a deduplication conflict re-writes its temporary part. With optimize_on_insert the re-written block can become empty (e.g. rows summing to zero in SummingMergeTree). In that case no part is created, temp_part->part is null, and the server crashed on dereferencing it. Fixed both ReplicatedMergeTreeSink and MergeTreeSink.

Added SQL tests for both engines.

Changelog category (leave one):

  • Critical Bug Fix (crash, data loss, RBAC)

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

Fixed a server crash on asynchronous insert with deduplication when optimize_on_insert makes the inserted block empty (for example, rows summing to zero in SummingMergeTree).

Version info

  • Merged into: 26.7.1.559 (included in 26.7 and later)
  • Backported to: 26.6.2.37, 26.5.6.19, 26.4.5.107, 26.3.17.27

@clickhouse-gh

clickhouse-gh Bot commented Jul 2, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [db31f8c]

Summary: ❌

job_name test_name status info comment
Stateless tests (amd_tsan, s3 storage, parallel, 1/2) FAIL
Server died FAIL cidb, issue ISSUE EXISTS
ThreadSanitizer: data race (STID: 1464-2f74) FAIL cidb, issue ISSUE EXISTS
Integration tests (amd_tsan, 5/6) FAIL
test_database_delta/test.py::test_snapshot_version FAIL cidb, issue ISSUE CREATED

AI Review

Summary

This PR adds null-part guards to the deduplication-conflict retry path in MergeTreeSink and ReplicatedMergeTreeSink, plus stateless regressions for SummingMergeTree and ReplicatedSummingMergeTree. The current code closes the dereferences that were previously reported, and I did not find a remaining correctness issue in the touched paths or the new tests.

Missing context / blind spots
  • ⚠️ I reviewed the current diff, prior threads, and surrounding code, but I did not run 04493_async_insert_dedup_optimize_on_insert_replicated_merge_tree / 04498_async_insert_dedup_optimize_on_insert_merge_tree locally. Running those two stateless tests would close the runtime gap.
Final Verdict

✅ No blocking issues found in the current version of this PR.

@clickhouse-gh clickhouse-gh Bot added pr-critical-bugfix pr-must-backport Pull request should be backported intentionally. Use this label with great care! labels Jul 2, 2026
@tiandiwonder tiandiwonder self-assigned this Jul 3, 2026
@Diskein
Diskein force-pushed the dk-rmt-fix-sigfault-on-async-insert-optimize-insert-dedupliacation-token branch from e216661 to b7a1b69 Compare July 3, 2026 07:50
@Diskein
Diskein marked this pull request as draft July 3, 2026 08:55
@Diskein
Diskein force-pushed the dk-rmt-fix-sigfault-on-async-insert-optimize-insert-dedupliacation-token branch 2 times, most recently from b60579a to d13d487 Compare July 3, 2026 09:04
@Diskein
Diskein force-pushed the dk-rmt-fix-sigfault-on-async-insert-optimize-insert-dedupliacation-token branch from d13d487 to 794f752 Compare July 3, 2026 09:28
@Diskein

Diskein commented Jul 3, 2026

Copy link
Copy Markdown
Contributor Author

03716_mutations_parts_postpone_reasons_rmt - #107488

@Diskein
Diskein requested a review from tiandiwonder July 3, 2026 16:40
@Diskein
Diskein marked this pull request as ready for review July 3, 2026 17:11
pull Bot pushed a commit to admariner/ClickHouse that referenced this pull request Jul 3, 2026
The per-arch `Bugfix validation` jobs (functional and integration) were
cacheable via a `digest_config`, but their verdict cannot be soundly cached.
The runner runs the new regression test on the PR and on a master-HEAD binary
that it downloads at run time from a recent master commit (see
`bugfix_validation.find_master_builds`), then inverts the status. The verdict
therefore depends on (1) the PR's source fix and (2) master HEAD, neither of
which is a repository file, so no digest can capture the job's true inputs.

When the bug does not reproduce on master HEAD on an arch, the per-arch job
legitimately reports a top-level `SKIPPED`. The CI cache decides what to
persist as a reusable success with `Result.is_ok`, which treats `SKIPPED` as
success, so that `SKIPPED` is pushed as a cache-success record. On a later
commit whose test content hashes to the same digest, the config job reuses it
("reused from cache") instead of re-running - even after the fix or master
HEAD changed. Because the merge-blocking `new_tests_check.py` post-hook uses
strict `is_success` (a reused `SKIPPED` does not count), it then fails with
"No per-arch Bugfix Validation job validated the bug", and the job never
re-runs to produce a real verdict.

Fix: drop `digest_config` from all four per-arch jobs. `calc_job_digest` then
returns the null digest, which `hook_cache.py` excludes from both cache lookup
and cache push, so the jobs re-run on every eligible commit. They stay gated
to bug-fix PRs with test changes by `filter_job.py` and run only the changed
tests, so this is cheap.

Add `ci/tests/test_bugfix_validation_not_cached.py` to pin the jobs as
non-cacheable so the digest is not reintroduced.

Observed on ClickHouse#109229

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 85.50% 85.60% +0.10%
Functions 92.60% 92.70% +0.10%
Branches 77.70% 77.80% +0.10%

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

Full report · Diff report

@Diskein
Diskein added this pull request to the merge queue Jul 6, 2026
@Diskein

Diskein commented Jul 6, 2026

Copy link
Copy Markdown
Contributor Author

The tests failures aren't related. I've fixed all reviews remarks, but have to merge the PR, since it affects users

Merged via the queue into master with commit 5b6713f Jul 6, 2026
171 of 174 checks passed
@Diskein
Diskein deleted the dk-rmt-fix-sigfault-on-async-insert-optimize-insert-dedupliacation-token branch July 6, 2026 17:17
@robot-ch-test-poll4 robot-ch-test-poll4 added pr-synced-to-cloud The PR is synced to the cloud repo pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR labels Jul 6, 2026
clickhouse-gh Bot added a commit that referenced this pull request Jul 6, 2026
Backport #109229 to 26.6: Fix server crash on deduplicated async insert with optimize_on_insert
tiandiwonder added a commit that referenced this pull request Jul 7, 2026
Backport #109229 to 26.3: Fix server crash on deduplicated async insert with optimize_on_insert
tiandiwonder added a commit that referenced this pull request Jul 7, 2026
Backport #109229 to 26.4: Fix server crash on deduplicated async insert with optimize_on_insert
tiandiwonder added a commit that referenced this pull request Jul 7, 2026
Backport #109229 to 26.5: Fix server crash on deduplicated async insert with optimize_on_insert
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Jul 7, 2026
@samay-sharma samay-sharma added v26.2-must-backport and removed pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore labels Jul 10, 2026
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Jul 10, 2026
@nikitamikhaylov nikitamikhaylov removed the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Jul 13, 2026
@robot-ch-test-poll robot-ch-test-poll added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Jul 13, 2026
kewin-robetti pushed a commit to viasoftkorp/ClickHouse that referenced this pull request Aug 24, 2026
kewin-robetti pushed a commit to viasoftkorp/ClickHouse that referenced this pull request Aug 24, 2026
kewin-robetti pushed a commit to viasoftkorp/ClickHouse that referenced this pull request Aug 24, 2026
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
The per-arch `Bugfix validation` jobs (functional and integration) were
cacheable via a `digest_config`, but their verdict cannot be soundly cached.
The runner runs the new regression test on the PR and on a master-HEAD binary
that it downloads at run time from a recent master commit (see
`bugfix_validation.find_master_builds`), then inverts the status. The verdict
therefore depends on (1) the PR's source fix and (2) master HEAD, neither of
which is a repository file, so no digest can capture the job's true inputs.

When the bug does not reproduce on master HEAD on an arch, the per-arch job
legitimately reports a top-level `SKIPPED`. The CI cache decides what to
persist as a reusable success with `Result.is_ok`, which treats `SKIPPED` as
success, so that `SKIPPED` is pushed as a cache-success record. On a later
commit whose test content hashes to the same digest, the config job reuses it
("reused from cache") instead of re-running - even after the fix or master
HEAD changed. Because the merge-blocking `new_tests_check.py` post-hook uses
strict `is_success` (a reused `SKIPPED` does not count), it then fails with
"No per-arch Bugfix Validation job validated the bug", and the job never
re-runs to produce a real verdict.

Fix: drop `digest_config` from all four per-arch jobs. `calc_job_digest` then
returns the null digest, which `hook_cache.py` excludes from both cache lookup
and cache push, so the jobs re-run on every eligible commit. They stay gated
to bug-fix PRs with test changes by `filter_job.py` and run only the changed
tests, so this is cheap.

Add `ci/tests/test_bugfix_validation_not_cached.py` to pin the jobs as
non-cacheable so the digest is not reintroduced.

Observed on ClickHouse#109229

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…ult-on-async-insert-optimize-insert-dedupliacation-token

Fix server crash on deduplicated async insert with optimize_on_insert
pull Bot pushed a commit to stnxo2023/ClickHouse that referenced this pull request Sep 13, 2026
The CI cache pushes a success record whenever Result.is_ok() holds, which covers
OK, SKIPPED and XFAIL. That is right for a verdict determined by the checked-out
tree, and wrong for a job whose outcome also depends on run-time state no digest
input captures: the record is then reused on a later commit that hashes the same,
and the run that would have produced a real verdict never happens. See ClickHouse#109229,
where the functional and integration bugfix validators hit exactly this and were
made non-cacheable by dropping their digest entirely.

do_not_cache is the narrower lever for a job whose digest is load-bearing for
scheduling, and it mirrors the existing per-run do_not_block_pipeline_on_failure
flag: same Result.ext dict, same complete_job keyword, one runner consumer. It is
opt-in and appended last in the signature, so a job that does not pass it keeps
today's behaviour exactly, and nothing about digests, affectedness, changed-file
filtering or cache lookup changes.
bytehalo-infra added a commit to sentioxyz/ClickHouse that referenced this pull request Sep 25, 2026
STOR: async insert with dedup when optimize_on_insert empties the block -> crash.
Effect in the production build a394e92: its upstream test(s) 04493_async_insert_dedup_optimize_on_insert_replicated_merge_tree fail on it (the server process died in 04493_async_insert_dedup_optimize_on_insert_replicated_merge_tree) and pass on official 26.8.8.8, run on isolated servers (evidence/fix_ci_20260925/upstream_repro/server_triage_PROD263_vs_UP2688.tsv).
Upstream patch unchanged, with its test(s): 04493_async_insert_dedup_optimize_on_insert_replicated_merge_tree.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-critical-bugfix pr-must-backport Pull request should be backported intentionally. Use this label with great care! pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-synced-to-cloud The PR is synced to the cloud repo v26.2-must-backport

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants