Skip to content

Fix flaky test 03411_dynamic_resize_filesystem_cache_3 - #109391

Merged
kssenii merged 1 commit into
ClickHouse:masterfrom
groeneai:fix-flaky-03411-dynamic-resize-fs-cache
Jul 7, 2026
Merged

kssenii merged 1 commit into
ClickHouse:masterfrom
groeneai:fix-flaky-03411-dynamic-resize-fs-cache

Conversation

@groeneai

@groeneai groeneai commented Jul 4, 2026

Copy link
Copy Markdown
Collaborator

Related: #109331

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):

...

Description

03411_dynamic_resize_filesystem_cache_3 runs in parallel and uses the shared s3_cache. It warms the cache with a SELECT and then asserts current_size > 0. A concurrent test can drop (name-less SYSTEM DROP FILESYSTEM CACHE) or evict the shared cache in the window between the warm-up and the assertion, so the check reads 0 instead of 1. CI's own randomized-settings diagnosis on the failures confirms it is not a settings issue (reruns with identical settings pass), i.e. a timing race on the shared cache.

Fix: re-warm and re-check in a bounded retry loop (the warm-up SELECT repopulates the cache), so a transient empty-cache moment no longer fails the test. The concurrent dynamic-resize stress that is the actual purpose of the test is unchanged, and the expected output stays 1.

Reproduced locally on a real s3_cache-over-S3 (MinIO) disk: under a concurrent SYSTEM DROP FILESYSTEM CACHE aggressor the old single-shot check failed 5/8 runs (current_size > 0 returned 0), while the fixed version passed 8/8.

@groeneai

groeneai commented Jul 4, 2026

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. On a real s3_cache-over-S3 (MinIO) disk: warm cache, then SYSTEM DROP FILESYSTEM CACHE, then the old single-shot SELECT current_size > 0 returns 0 every time (the exact CI -1 +0 diff).
b Root cause explained? The test uses the shared s3_cache. Between the warm-up SELECT (line 21) and the current_size > 0 assertion (line 24), a concurrent parallel test issues a name-less SYSTEM DROP FILESYSTEM CACHE (16 stateless tests do) or the shared 200 MB cache is evicted, emptying it, so the assertion reads 0. CI's own randomized-settings diagnosis on the failures (reruns with identical settings pass 3/3 and 6/6) confirms it is a timing race, not a settings issue.
c Fix matches root cause? Yes. It targets the warm-up to check window directly: re-warm and re-check in a bounded retry loop; the warm-up SELECT repopulates the cache, so a transient empty-cache moment recovers. Not a band-aid (no assertion weakened, no no-parallel/no-random-* tag added, no data reduction).
d Test intent preserved / new tests added? Yes. The assertion still verifies the cache was populated before the resize stress; the concurrent dynamic-resize stress that is the test's actual purpose is untouched; .reference still expects 1.
e Both directions demonstrated? Yes. Under a concurrent SYSTEM DROP FILESYSTEM CACHE aggressor: old single-shot check failed 5/8 runs; fixed retry version passed 8/8. A clean end-to-end run (with the sed-based up/down resize) also outputs exactly 1.
f Fix is general across code paths? N/A (test-only shell fix, not a code bug).
g Fix generalizes across inputs (params/datatypes/wrappers)? N/A (test-only shell fix, not a code bug).
h Backward compatible? (maintainer-approved exception only) N/A (test-only shell fix, no product behavior/format/setting change).
i Invariants and contracts preserved? N/A (test-only shell fix, not a code bug).

Session id: cron:clickhouse-worker-slot-3:20260704-050300

@groeneai

groeneai commented Jul 4, 2026

Copy link
Copy Markdown
Collaborator Author

cc @kssenii — could you review this? It fixes the flaky 03411_dynamic_resize_filesystem_cache_3 by re-warming and re-checking current_size > 0 in a bounded retry loop, since a concurrent test can drop or evict the shared s3_cache between the warm-up and the assertion. Test-only change; the concurrent dynamic-resize stress is unchanged.

@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Jul 4, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jul 4, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [66ccbcd]

Summary: ⏳

job_name test_name status info comment
Stateless tests (amd_debug, parallel) FAIL
03532_window_function_and_null_source_max_threads FAIL issue ISSUE EXISTS

AI Review

Summary

This PR wraps the flaky warm-up check in a bounded retry loop so a transient concurrent SYSTEM DROP FILESYSTEM CACHE no longer fails 03411_dynamic_resize_filesystem_cache_3. The timeout regression from the earlier table-scoped attempt is gone, but the current loop still leaves one unresolved hole: it can succeed on unrelated shared-cache activity and therefore no longer proves that this test's own read path populated the cache before the resize stress. Verdict: request changes.

Findings

⚠️ Majors

  • [tests/queries/0_stateless/03411_dynamic_resize_filesystem_cache_3.sh:28] [dismissed by author -- https://github.com/ClickHouse/ClickHouse/pull/109391#discussion_r3523553985] The retry exits on system.filesystem_cache_settings.current_size > 0, which is global for the shared s3_cache. Any parallel test that repopulates that cache can satisfy this loop even if SELECT * FROM ${table_name} stopped writing this table into the cache, so the PR weakens the only signal that this test is actually exercising its own filesystem-cache path before resize. The earlier per-table residency check timed out, but the tree already has a cheaper query-local signal: tests/queries/0_stateless/02226_filesystem_cache_profile_events.sh:26 reads ProfileEvents['CachedReadBufferCacheWriteBytes'] and related counters from system.query_log by query_id, which would survive later eviction without scanning system.remote_data_paths or depending on unrelated cache activity.
Final Verdict
  • Status: ⚠️ Request changes
  • Minimum required action: replace the global current_size > 0 exit condition with a query-local cache-population signal, for example query-specific ProfileEvents or system.filesystem_cache_log, so the retry remains bounded but still proves this table's warm-up populated the cache.

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Jul 4, 2026
@groeneai
groeneai force-pushed the fix-flaky-03411-dynamic-resize-fs-cache branch from 6c2cf5f to 03fb03b Compare July 4, 2026 18:00
@groeneai
groeneai force-pushed the fix-flaky-03411-dynamic-resize-fs-cache branch 3 times, most recently from 3b3668c to 88a9e7d Compare July 4, 2026 20:00
@groeneai

groeneai commented Jul 4, 2026

Copy link
Copy Markdown
Collaborator Author

Revised fix — pre-PR validation gate

The previous revision scoped the warm-up sanity check to this table's own cache entries via a system.remote_data_paths metadata walk + cache_path IN (...) predicate, retried in two 30-iteration loops. Under the flaky-check's 50x self-parallel contention on the shared 200 MB s3_cache, this table's own 10 MB is continuously LRU-evicted, so the per-table predicate can never hold, both loops run to exhaustion, and a single run hits the hard --timeout 600 (Timeout! Killing process group). CIDB confirms it: every failing run on the prior head had test_duration_ms ~= 600000 across amd_debug, amd_asan_ubsan, and amd_tsan flaky-check lanes.

This revision reverts to the cheap global current_size > 0 smoke-check (satisfied by any resident data, so it converges in 1-2 iterations) wrapped in a short bounded re-warm/re-check loop that still tolerates a transient concurrent SYSTEM DROP FILESYSTEM CACHE.

Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. Under local MinIO-backed s3_cache saturated by 6-12 foreign readers, the prior strict per-table warm-up loop spins for >385 s (does not finish under a 150 s cap in the sharpest case); CIDB shows the CI runs hit test_duration_ms ~= 600000 (the --timeout 600 process-group kill).
b Root cause explained? s3_cache is a globally shared 200 MB LRU cache. Under the flaky-check's 50x self-parallel load, ~50 copies each insert 10 MB (~500 MB >> 200 MB), so THIS table's blobs are evicted faster than re-warmed. The prior per-table predicate (cache_path IN (this table's blobs)) therefore never holds -> both 30-iteration loops run to exhaustion, each iteration doing a system.remote_data_paths metadata walk + a 10 MB S3 re-read -> single run exceeds --timeout 600 -> Killing process group.
c Fix matches root cause? Yes. The unbounded worst case comes from asserting "MY specific data is resident" in a thrashed shared cache — impossible to guarantee. The fix removes that requirement: it checks the global current_size > 0 (satisfied by any resident data, so it converges in 1-2 iterations) in a short bounded loop, eliminating the unbounded spin while still tolerating a transient concurrent drop.
d Test intent preserved / new tests added? Yes. The current_size > 0 warm-up is only an incidental sanity assertion; the test's real purpose is the concurrent dynamic-resize stress that follows, which is untouched. .reference stays 1.
e Both directions demonstrated? Yes. FIXED test on real s3_cache-over-MinIO: 5/5 clean pass (stdout=1, rc 0, max_size resized up x3 then restored, ~9.9 s/run); 3/3 pass under saturation contention (~10 s/run, bounded). The prior strict warm-up loop reproduced the >385 s spin under the same contention.
f Fix is general across code paths? N/A (flaky test setting fix, not a code bug). Single test file; no sibling code paths.
g Fix generalizes across inputs (params/datatypes/wrappers)? N/A (flaky test setting fix, not a code bug).
h Backward compatible? (maintainer-approved exception only) N/A (flaky test setting fix, not a code bug). No settings/format/validation change.
i Invariants and contracts preserved? N/A (flaky test setting fix, not a code bug). Loop is now bounded to 10 iterations; no server-side contract touched.

Session id: cron:clickhouse-worker-slot-2:20260704-191100

The shared s3_cache warm-up sanity check (`current_size > 0`) could fail when a
concurrent test dropping the filesystem cache (or eviction) transiently emptied
the cache between the warm-up read and the check. Wrap the warm-up read and the
check in a short bounded retry loop so a transient empty instant no longer fails
the test, without touching the concurrent dynamic-resize stress that is the
test's actual purpose.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@groeneai
groeneai force-pushed the fix-flaky-03411-dynamic-resize-fs-cache branch from 88a9e7d to 66ccbcd Compare July 4, 2026 20:24
@clickhouse-gh

clickhouse-gh Bot commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 85.84% 85.86% +0.01%
Functions 91.48% 91.48% +0.00%
Branches 78.45% 78.49% +0.04%

Changed lines: No C/C++ source files changed — skipping uncovered code analysis.

Newly covered by added/modified tests: 98 line(s), 6 function(s) across 44 file(s) · Details

Top files
  • src/Server/KeeperTCPHandler.cpp: 6 line(s)
  • src/AggregateFunctions/AggregateFunctionQuantileExactInclusive.cpp: 5 line(s)
  • src/Functions/UserDefined/UserDefinedExecutableFunctionFactory.cpp: 5 line(s)
  • src/AggregateFunctions/AggregateFunctionEstimateCompressionRatio.cpp: 4 line(s)
  • src/Columns/ColumnDecimal.cpp: 4 line(s)

Full report

@groeneai

groeneai commented Jul 5, 2026

Copy link
Copy Markdown
Collaborator Author

CI finish ledger — 66ccbcd

Every failure below has an owner: a fixing PR (ours or external), or a full-effort fix task whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
Stateless tests (amd_debug, parallel) / 03532_window_function_and_null_source_max_threads flaky (query_plan_optimize_join_order_randomize collapses the crazy-max_threads pipeline so error 290 is not raised) #109330 (external, open)
Mergeable Check rollup of the above owned via #109330
PR rollup aggregator owned via #109330
CH Inc sync private sync CH Inc sync (private, not actionable)

The PR-caused failures on earlier heads (03411 flaky-check 600s timeout on the modified test; Style check system<ws>drop comment token) are resolved on this head: 03411_dynamic_resize_filesystem_cache_3 and Style check are both green here. The sole remaining red is the pre-existing PR-only flaky 03532 (0 master, 25+ unrelated PRs in 30d), unrelated to this PR's single-file change, and already tracked by external fixing PR #109330.

Session id: cron:our-pr-ci-monitor:20260705-000000

@kssenii kssenii self-assigned this Jul 6, 2026
@kssenii
kssenii added this pull request to the merge queue Jul 7, 2026
Merged via the queue into ClickHouse:master with commit af447eb Jul 7, 2026
173 of 175 checks passed
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 7, 2026
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…namic-resize-fs-cache

Fix flaky test 03411_dynamic_resize_filesystem_cache_3
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 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.

4 participants