Repository navigation
Fix flaky 04344_server_ast_fuzzer_insert_limit (filesystem cache lock wait) - #122567
Conversation
… lock wait) On the `Stateless tests (arm_asan_ubsan, azure, parallel)` lane MergeTree tables default to the `azure_cache` policy, whose disk `cached_azure` is a write-through filesystem cache (cache_on_write_operations = 1). Every file a part writes is registered in the cache priority queue by LRUFileCachePriority::add, which takes the queue lock exclusively. Debug and sanitizer builds run FileCache::assertCacheCorrectness from FileCache::getOrSet/get with probability check_cache_probability (0.001), and its second pass walks the whole queue under that lock shared, checking the file of every entry on disk. With ~42k entries on that IO-saturated host a pass takes ~2.3 s (1,086 passes, 2,517 s of checking and 7,673 s of priority write-lock wait server-wide in one job), so each of the ~11 files of a 100-row part can wait seconds. The test bounds its seed statements with the session max_execution_time = 20, and the seed INSERTs failed with Code 159: - 2026-09-27, PR ClickHouse#122520: block-forming INSERT, elapsed 20,575 ms, of which 20,454 ms was FilesystemCachePriorityWriteLockMicroseconds - 2026-09-17, PR ClickHouse#104076: plain INSERT, elapsed 28,097 ms, 28,011 ms waiting The trace_log of the 2026-09-27 query shows its writer thread in SharedMutex::lock <- LRUFileCachePriority::add <- FileCache::doTryReserve <- FileSegment::reserve <- CachedOnDiskWriteBufferFromFile::cacheData in 21 of 21 samples, and the part's 11 blob uploads took 1.6-2.9 ms each, so the time is the cache lock, not object storage latency. In the same jobs, parts on the local `default` disk took at most 104 ms / 54 ms, versus 20.6 s / 33.5 s on cached_azure. Pin t_04344 to the implicit local `default` storage policy. Where its parts live is incidental to what the test verifies (stripping of seed SETTINGS on the INSERT, block-forming, CREATE storage and BACKUP carriers), so its INSERTs, their fuzzed clones, the BACKUP and the teardown DROP no longer touch the cache, and no time bound is widened: the session max_execution_time = 20 still bounds the fuzz loop. t_04344_storage keeps the lane's default policy, because its SETTINGS clause must hold only max_rows_to_read for the empty-SETTINGS pruning carrier. Reproduced locally on a debug build with the CI test configs, the write-through local_cache as the MergeTree default, check_cache_probability = 1, ~335k cache entries and 8 concurrent readers of a cached table: the unmodified test failed 4 of 5 runs with Code 159 on a seed INSERT (elapsed 31.8-50.4 s, 98.9-99.3% of it priority write-lock wait, same stack as CI). With this change it passed 3 of 3 under the same load, while 8 of 9 seed-shaped INSERTs into a cached table in the same windows waited 24-47 s. With check_cache_probability = 0 and the same cache and readers, the unmodified test passed 3 of 3 with seed INSERT lock waits under 0.4 s. ClickHouse#114077 raised the INSERTs' bound instead, reading this wait as Azure latency; it was closed after two quiet months and the test failed twice since. Related: ClickHouse#114077 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 1 finding; full pass on this head).
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-8:20260927-184300 |
|
Workflow [PR], commit [9758102] Summary: ✅ AI ReviewSummaryThis PR pins Final VerdictStatus: ✅ Approve |
On the azure lane the default MergeTree storage policy is a write-through filesystem cache. The test's valid native-protocol INSERT writes a one-row part, and every file of that part reserves cache space under the cache's priority write lock. In Stateless tests (arm_asan_ubsan, azure, parallel) on PR ClickHouse#126978 that INSERT spent 34.07 s of 34.43 s waiting on the lock (FilesystemCachePriorityWriteLockMicroseconds), so the server's correct End of stream arrived 4.4 s after the python client's hard-coded 30 s socket timeout and the test failed with TimeoutError in readStrict. The storage is incidental to a native-protocol LowCardinality test, so pin the table to storage_policy = 'default' (the local disk on every lane). The part write stays MergeTree, the 30 s hang guard and the .reference are unchanged. Same shape as ClickHouse#122567 (04344) and ClickHouse#126252 (04949) for this lock. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Related: #114077
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
...
Description
04344_server_ast_fuzzer_insert_limitfails onStateless tests (arm_asan_ubsan, azure, parallel)withCode: 159 ... Timeout exceeded: elapsed N ms, maximum: 20000.000 mson a seedINSERT: 5 times in 90 days, all on that lane, twice since #114077 was closed (2026-09-27 job, 2026-09-17 job).Root cause: on that lane MergeTree tables default to a write-through filesystem cache. Every file a part writes is added to the cache's priority queue under an exclusive lock, and debug and sanitizer builds randomly run a full cache consistency check (
check_cache_probability) that holds the same lock shared while it stats every entry. The failing INSERTs spent 20,454 of 20,575 ms and 28,011 of 28,097 ms inFilesystemCachePriorityWriteLockMicroseconds, the 2026-09-27 writer thread was inLRUFileCachePriority::addin 21 of 21 profiler samples, and the parts' Azure uploads took 0.9-2.9 ms each. #114077 read this wait as Azure latency and raised the bound; it was closed after two quiet months.Change: pin
t_04344to the localdefaultstorage policy. Where its parts live is incidental to what the test checks (stripping of seedSETTINGS), so no bound is widened.t_04344_storagekeeps the lane default, since itsSETTINGSclause is itself a carrier (its one smallCREATEwrite has not failed in 90 days).Validation, debug build with the CI configs and a write-through
local_cacheas the MergeTree default: atcheck_cache_probability = 1with ~335k entries and 8 cached readers, the unmodified test failed 4 of 5 runs with the CI message and stack (~99% lock wait), the changed one passed 3 of 3, and at probability 0 the unmodified one passed 3 of 3. 50/50 randomized runs on the local default, 20/20 on the write-through default at the CI probability.The check's cost on write-through caches is its owners' lever; #95946 lowered its probability once.
Workflow [PR]
Sync PR [sync-upstream/pr/122567]
Version info
26.10.1.954-master(included in26.10and later)