Skip to content

Keep the case 6 tables of 04633_async_insert_select_alter_race on the local disk - #127751

Merged
alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:fix-04633-alter-race-local-disk
Oct 25, 2026
Merged

alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:fix-04633-alter-race-local-disk

Conversation

@groeneai

@groeneai groeneai commented Oct 24, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #111663

Changelog category (leave one):

  • CI Fix or Improvement (changelog entry is not required)

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

Case 6 of the 04633_async_insert_select_alter_race test now keeps its tables on the local disk, so a filesystem cache can no longer push its view creation past the lock timeout.

Description

04633_async_insert_select_alter_race failed twice in Stateless tests (arm_asan_ubsan, azure, parallel)
(1,
2):
case 6's CREATE MATERIALIZED VIEW ... POPULATE hit its 10 s lock_acquire_timeout with DEADLOCK_AVOIDED.

The owner it names is the async insert flush of the case's own INSERT, and it was slow, not stuck. On the azure
lane the default MergeTree policy is a write-through filesystem cache. In job 1 the flush held the table share lock
for 13.3 s, 13.1 s of it in FilesystemCachePriorityWriteLockMicroseconds (each Azure upload took about 1 ms), and
finished 2.2 s after the writer gave up. The view's inner table creation also waited 2.6 s on that lock, so the
writer queued after the flush took its share lock instead of during the SELECT, the ordering case 6 exists to test.

Storage is incidental to case 6, so the source table and the view's inner table now use
storage_policy = 'default'. The scenario and the 10 s budget are unchanged.

Validation on a local write-through cache rig, with file_cache_pause_before_do_eviction pausing the cache: forcing
the writer in after the flush reproduces the CI error 2/2 on the old test, with the stalled flush as the owner; with
the new tables the flush never touches the cache and the view is created in 0.2 s, 2/2. Without a failpoint the old
flush makes 22 cache reservations and the new one none. 100/100 randomized runs pass on two rigs.

No related issue is open.


Workflow [PR]
Sync PR [sync-upstream/pr/127751]

Version info

  • Merged into: 26.11.1.759-master (included in 26.11 and later)

On the azure lane the default MergeTree policy is `azure_cache`, a write-through
filesystem cache (`cache_on_write_operations = 1`), and the CI profile enables
`enable_filesystem_cache_on_write_operations`. Every file a part writes then
reserves cache space under the cache priority write lock, which debug and
sanitizer builds also hold for their randomized full-cache consistency checks.

In the failing job (PR ClickHouse#116361, `Stateless tests (arm_asan_ubsan, azure,
parallel)`) the async-insert flush of case 6 held the table share lock while
it waited 13.1 s of a 13.3 s query on that lock
(`FilesystemCachePriorityWriteLockMicroseconds`), and the view's inner-table
creation waited 2.6 s on it, so the `CREATE MATERIALIZED VIEW ... POPULATE`
writer queued only after the flush already held its share lock. The writer's
10 s `lock_acquire_timeout` expired with `DEADLOCK_AVOIDED`, naming the flush
as the owner; the flush itself finished 2.2 s later, so this is not the
deadlock case 6 pins.

Storage is incidental to case 6, which pins an RWLock ordering between the
INSERT's share lock, a queued writer and the flush. Pin the source table and
the view's inner table to `storage_policy = 'default'` (local disk on every
lane), so neither the flush's part write nor the writer's inner-table creation
goes through the cache. The scenario and the 10 s budget are unchanged.

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

Copy link
Copy Markdown
Collaborator Author
Internal second-model review: adjudication log (click to expand)

Pre-publication review by an independent model (engine: codex; 1 finding over 2 runs) plus my own review of the diff (0 findings).

# Sev Finding Verdict Evidence / action
1 💡 The second failing-job link in the description renders a passing run AGREE, fixed in the description That commit failed on 2026-10-17 and passed on a rerun on 2026-10-19; the report page shows the latest run, so the link now points to the failed attempt's job log. Re-review of the updated description: 0 findings.

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are terminal per finding.

Session id: cron:clickhouse-review-slot-9:20261024-210700

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. On a local write-through cache rig with file_cache_pause_before_do_eviction, the writer started once the flush is in system.processes gets Code: 473 ... has timed out (10000ms) ... Owner query ids: <flush query id> (2). (DEADLOCK_AVOIDED), 2/2, the CI text and owner shape.
b Root cause explained? The azure lane's default MergeTree policy is a write-through filesystem cache: the flush held the share lock 13.3 s (13.1 s on the cache priority lock) and the inner table creation waited 2.6 s on it, so the writer queued behind a slow (not stuck) flush.
c Fix matches root cause? Both case 6 tables use storage_policy = 'default', so neither the flush's part write nor the inner table creation goes through the cache. No timeout widened, no tag, no data reduced.
d Test intent preserved / new tests added? Preserved: same statements, same 10 s budget, .reference unchanged; the writer again queues while the SELECT reads in all 100 randomized runs. The change is itself the test fix.
e Both directions demonstrated? Yes, same failpoint: the old test fails 2/2 as in CI, the new one creates the view in 0.2 s, 2/2. Without a failpoint the old flush makes 22 cache reservations, the new one 0.
f Fix is general across code paths? Case 7 waits for its flush before its RENAME; cases 3/4/5 have no lock timeout; no other test failed with DEADLOCK_AVOIDED in CI in 30 days.
g Fix generalizes across inputs (params/datatypes/wrappers)? 100/100 runs with random settings, 50 on the cache rig and 50 on a plain local rig. The default policy exists on every lane, and 04344, 04839 and 04949 already pin it.
h Backward compatible? (maintainer-approved exception only) Test-only. No setting, default, format or docs change.
i Invariants and contracts preserved? Case 6 still asserts that a writer queued behind the INSERT and its flush gets the lock within 10 s, and the row count is still 2000. Other cases untouched.

Session id: cron:clickhouse-impl-slot-5:20261024-203400

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @Felixoid, could you review this and add the can be tested label so CI runs? On the azure lane the case 6 flush waited 13 s on the write-through filesystem cache while holding the share lock, so the POPULATE writer hit its 10 s timeout; pinning both case 6 tables to storage_policy = 'default' takes the cache out of a scenario that is only about lock ordering.

@clickhouse-gh

clickhouse-gh Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [f49651c]

Summary: ✅


AI Review

Summary

The change pins both case 6 tables in 04633_async_insert_select_alter_race to storage_policy = 'default', removing filesystem-cache contention from the lock-ordering regression test while preserving its statements, assertions, and 10-second timeout. No actionable findings. The modified test passed in Fast test in 14.72 seconds; the PR also provides focused before/after cache-failpoint validation.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added pr-ci comp-testing Test content only (no production code). labels Oct 24, 2026
@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Oct 25, 2026
@alexey-milovidov alexey-milovidov self-assigned this Oct 25, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Oct 25, 2026
Merged via the queue into ClickHouse:master with commit 15c433e Oct 25, 2026
526 of 528 checks passed
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 25, 2026
@clickhouse-gh clickhouse-gh Bot added comp-async-insert Asynchronous INSERT buffering/queueing and flush semantics. and removed comp-testing Test content only (no production code). labels Nov 22, 2026
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 comp-async-insert Asynchronous INSERT buffering/queueing and flush semantics. pr-ci 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.

3 participants