Skip to content

Fix flaky 02024_storage_filelog_mv - #109109

Merged
alexey-milovidov merged 2 commits into
ClickHouse:masterfrom
groeneai:fix-flaky-02024-filelog-mv-backoff
Jul 2, 2026
Merged

alexey-milovidov merged 2 commits into
ClickHouse:masterfrom
groeneai:fix-flaky-02024-filelog-mv-backoff

Conversation

@groeneai

@groeneai groeneai commented Jul 2, 2026 •

Copy link
Copy Markdown
Collaborator

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

Related: #107826 (requested by @alexey-milovidov on that PR, where this test flaked on Stateless tests (amd_msan, WasmEdge, parallel, 2/2)).

Fix flaky 02024_storage_filelog_mv.

The test waited for the materialized view with two unbounded while true; sleep 1 loops. FileLog's directory watcher and reader task back off exponentially up to poll_directory_watch_events_backoff_max (32s default), so on slow lanes (WasmEdge+MSan) the reader reschedule path (scheduleAfter(milliseconds_to_wait)) can wait up to 32s per idle cycle. Stacked across the two wait phases plus BackgroundSchedulePool contention under parallel load, this exceeds the 600s per-test kill and a slow-but-correct run becomes a TIMEOUT FAIL.

Failing report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=107826&sha=2e66578c83c3107834ab5e22b2f921ed42383ae8&name_0=PR&name_1=Stateless%20tests%20%28amd_msan%2C%20WasmEdge%2C%20parallel%2C%202%2F2%29 (test_duration_ms=600100, reason Timeout!, sleep 1 still running; the runner's own rerun said "not reproducible", i.e. a timing flake).

Fix (same approach as the sibling 02968_file_log_multiple_read, PR #101367):

  • Set poll_directory_watch_events_backoff_max = 1000 on the FileLog table to bound file-detection latency to ~1s.
  • Replace the unbounded loops with a bounded wait helper that fails fast with a diagnostic instead of a silent 600s timeout.
  • Mark the test no-parallel: FileLog -> MV detection latency depends on BackgroundSchedulePool scheduling, and under heavy parallel load pool contention can push the wait past its timeout even with a bounded backoff. This matches the no-parallel tag on the sibling 02968_file_log_multiple_read.

Test intent is unchanged (MV streaming path, initial 20-row load, touch-produces-no-event, incremental detection to 101 rows, same reference).

Version info

  • Merged into: 26.7.1.411 (included in 26.7 and later)

The test used two unbounded 'while true; sleep 1' loops to wait for the
materialized view to catch up. FileLog's directory watcher and reader task
back off exponentially up to poll_directory_watch_events_backoff_max (32s by
default), so on slow lanes (WasmEdge+MSan) file-detection latency on the
reader reschedule path can stack across the two wait phases past the 600s
per-test kill, turning a slow-but-correct run into a TIMEOUT FAIL.

Cap poll_directory_watch_events_backoff_max=1000 on the FileLog table (same as
02968_file_log_multiple_read) to bound detection latency to ~1s, and replace
the unbounded loops with a bounded wait helper that fails fast with a
diagnostic instead of a silent 600s job timeout. Test intent (MV streaming,
initial load, touch-produces-no-event, incremental detection) is unchanged.

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

groeneai commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes for the mechanism. The 600s wall-clock kill is a slow-lane tail-latency flake (CI's own rerun: "not reproducible"), but the trigger is deterministic: with poll_directory_watch_events_backoff_init=20000 a single reader reschedule waits the full 20s before detecting a new file (measured locally), vs 1s with the fix.
b Root cause explained? FileLog watcher + reader task back off exponentially to poll_directory_watch_events_backoff_max (32s default). On the reschedule path the reader does scheduleAfter(milliseconds_to_wait) (up to 32s) and re-enqueues on the shared BackgroundSchedulePool. Under WasmEdge+MSan slowness + pool contention, cumulative detection latency across the two wait phases exceeds the 600s per-test kill. The unbounded while true; sleep 1 loops turn a slow-but-correct run into a TIMEOUT FAIL.
c Fix matches root cause? Yes. Cap poll_directory_watch_events_backoff_max=1000 bounds each reschedule to ~1s (the exact latency driver). Bounded wait helper removes the silent 600s hang.
d Test intent preserved? Yes. MV streaming path, initial 20-row load, touch-produces-no-event, incremental detection to 101 rows, and reference file are all unchanged.
e Demonstrated both directions? Yes. Fixed test: 3/3 runs pass in ~4-5s, exact reference match. Bounded helper on an unsatisfiable target fails in ~5s with Timeout (Ns) waiting for count() == X, got Y. instead of a 600s silent kill.
f Fix general, not a narrow patch? N/A (flaky-test setting fix, not a code bug). Same approach as sibling 02968_file_log_multiple_read (PR #101367).
g Generalizes across inputs? N/A (flaky-test setting fix, not a code bug).
h Backward compatible? N/A (test-only change).
i Invariants preserved? N/A (test-only change).

Session id: cron:clickhouse-worker-slot-3:20260702-014600

@groeneai

groeneai commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator Author

cc @antaljanosbenjamin - could you review? Test-only fix for flaky 02024_storage_filelog_mv: caps poll_directory_watch_events_backoff_max=1000 on the FileLog table (same as 02968_file_log_multiple_read) so file-detection latency stays bounded on slow lanes, and replaces the unbounded while true; sleep 1 waits with a bounded helper that fails fast instead of a 600s job kill.

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

clickhouse-gh Bot commented Jul 2, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [d9de370]

Summary: ✅


AI Review

Summary

This PR makes 02024_storage_filelog_mv consistent with the sibling FileLog -> MV tests that already had to leave the parallel stateless shards: it caps poll_directory_watch_events_backoff_max, replaces the unbounded waits with a bounded helper, and now marks the test no-parallel to avoid BackgroundSchedulePool scheduling contention. I did not find a remaining correctness or reliability issue in the current version.

Final Verdict

✅ No new findings. The previously reported parallel-load flake concern is addressed in the current diff.

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Jul 2, 2026
The FileLog -> MV streaming path depends on BackgroundSchedulePool task
scheduling latency. Under heavy parallel load, pool contention can push
file-detection latency past the wait timeout even with a bounded
poll_directory_watch_events_backoff_max. The sibling FileLog -> MV tests
(02968_file_log_multiple_read, 04242/04257/04342 file_log_*) all run
no-parallel for this reason; 02024 is the only one still in the parallel
lane. Sequential execution gives consistent runtime.

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

groeneai commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator Author

Done: added no-parallel (d9de370).

I went with option 1 rather than local stress evidence, for two reasons:

  1. The instability is BackgroundSchedulePool scheduling starvation, which is server-global state. No per-test namespacing (unique files/DB, already present here) can isolate a test from pool contention created by concurrent tests, so option 2 could only ever show "stable on my hardware", not "stable in the parallel MSan/WasmEdge shard where it flaked".
  2. This is the same test family, and the sibling I modeled the fix on already walked exactly this path: 02968_file_log_multiple_read history is raise wait timeout to 120s -> Cap FileLog polling-cycle backoff -> Mark ... as no-parallel. The 120s+backoff_max=1000 combo was empirically insufficient there and needed no-parallel on top. 04242/04257/04342 all carry no-parallel with the same backoff. 02024 was the only FileLog -> MV test left in the parallel lane.

The poll_directory_watch_events_backoff_max = 1000 cap and the bounded wait_for_count helper stay: they turn the residual failure mode from a silent 600s job kill into a fast, diagnostic 120s failure, matching the siblings. Test intent unchanged.

@clickhouse-gh

clickhouse-gh Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 85.79% 85.81% +0.02%
Functions 91.46% 91.46% +0.00%
Branches 78.35% 78.39% +0.04%

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

Newly covered by added/modified tests: 136 line(s), 4 function(s) across 63 file(s) · Details

Top files
  • src/Functions/LeftRight.h: 6 line(s)
  • src/Functions/concatWithSeparator.cpp: 5 line(s)
  • src/AggregateFunctions/TimeSeries/AggregateFunctionTimeSeriesGroupArray.h: 4 line(s)
  • src/Disks/IO/ReadBufferFromRemoteFSGather.cpp: 4 line(s)
  • src/Functions/catboostEvaluate.cpp: 4 line(s)

Full report

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Jul 2, 2026
@alexey-milovidov alexey-milovidov self-assigned this Jul 2, 2026
Merged via the queue into ClickHouse:master with commit 37ef5ad Jul 2, 2026
176 checks passed
@groeneai

groeneai commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator Author

Update: the test is now also tagged no-parallel (commit d9de370). This supersedes the "parallel-safe" note in the validation-gate comment above: FileLog -> MV detection latency depends on BackgroundSchedulePool scheduling, and under heavy parallel load pool contention can push the wait past its timeout even with the bounded backoff. This matches the existing no-parallel tag on the sibling 02968_file_log_multiple_read. Re-verified: 2/2 runs pass, ~4-5s each, exact reference match.

@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 2, 2026
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…lelog-mv-backoff

Fix flaky 02024_storage_filelog_mv
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.

3 participants