Skip to content

Fix flaky 02968_file_log_multiple_read: raise wait timeout to 120s - #103602

Merged
alexey-milovidov merged 4 commits into
ClickHouse:masterfrom
groeneai:fix-02968-file-log-timeout
Apr 29, 2026
Merged

alexey-milovidov merged 4 commits into
ClickHouse:masterfrom
groeneai:fix-02968-file-log-timeout

Conversation

@groeneai

@groeneai groeneai commented Apr 27, 2026 •

Copy link
Copy Markdown
Collaborator

The test 02968_file_log_multiple_read.sh polls table_to_store_data for FileLog → MaterializedView ingest with a 30-second deadline in wait_for_row_count. FileLog watches its directory using exponential backoff (initial 500ms, max 32s — see poll_directory_watch_events_backoff_max), so the worst-case poll interval is bigger than the test's wait window. Under sanitizer builds and shared CI runners, the backoff occasionally drifts close to that upper bound, the test's wait_for_row_count timeout fires before StorageFileLog::threadFunc runs, and the test fails.

Failure data

CIDB, last 30 days: 11 failures across 4 unrelated PRs, 0 master.

PR Failures Modifies FileLog code? Classification
#102192 8 (one CI run, 7 concurrent parallel-test instances) no unrelated
#102362 1 no unrelated
#102112 1 no unrelated
#101408 1 yes (StorageFileLog.cpp) excluded as related

The arm_asan_ubsan, targeted shard had a single CI run with 7 concurrent parallel-test instances all hitting the timeout (test duration 38s, just over 30s), which matches the polling-backoff hypothesis exactly.

Deterministic local repro

Forcing poll_directory_watch_events_backoff_init = 31000 (>30s) deterministically reproduces the failure with the current 30s timeout (file detected at 31s, 1s after timeout fires) and passes with the new 120s timeout (file detected at 31s, 89s of headroom).

Verification

50/50 passes locally with full CI randomization (debug build).

Approach

Same fix pattern as PR #101367 (02889_file_log_save_errors). The fix only widens the wait window — the test still asserts that all rows from the FileLog source flow through the materialized view to the destination MergeTree table.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=102192&sha=df3318c6e12376575c32003ad1ffa8d429eadc09&name_0=PR&name_1=Stateless%20tests%20%28arm_asan_ubsan%2C%20targeted%29 (PR #102192)

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

Not applicable.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

Version info

  • Merged into: 26.5.1.176

The test polled `table_to_store_data` for FileLog → MaterializedView ingest
with a 30-second deadline. FileLog uses exponential backoff to watch the
directory (initial 500ms, max 32s — `poll_directory_watch_events_backoff_max`),
so the worst-case poll interval is bigger than the test's wait window.
Under sanitizer builds and shared CI runners, the backoff occasionally drifts
close to that upper bound, the test fires its `wait_for_row_count` timeout
before `StorageFileLog::threadFunc` runs, and the test fails.

Failure data (CIDB, 30 days): 11 hits across 4 unrelated PRs, 0 master.
The arm_asan_ubsan, targeted shard had a single CI run with 7 concurrent
parallel-test instances all hitting the timeout (test duration 38s, just over
30s) which matches the polling-backoff hypothesis exactly.

Deterministic local repro: forcing
`poll_directory_watch_events_backoff_init = 31000` (>30s) makes the
current 30s timeout fail every time and the new 120s timeout pass with
89s of headroom.

Same fix pattern as PR ClickHouse#101367 (`02889_file_log_save_errors`).

Verified locally: 50/50 passes with full CI randomization (debug build).

Closes ClickHouse#79788
@groeneai

Copy link
Copy Markdown
Collaborator Author

Pre-PR validation gate (per session protocol):

# Question Answer
a Deterministic repro? Yes. Forcing poll_directory_watch_events_backoff_init = 31000 (just above the test's 30s timeout) makes the test fail every time on the current code: file detected at t=31s, 1s after wait_for_row_count already exited with the timeout error.
b Root cause explained? Yes. StorageFileLog::threadFunc watches the directory using exponential backoff (500ms init × 2 → 32s max, defined in FileLogSettings.cpp and respected by DirectoryWatcherBase.cpp). Once backoff has grown to 16–32s, a newly-added file may not be polled for up to 32s — exceeding the test's 30s wait_for_row_count deadline. Sanitizer overhead and shared-runner load make this likely enough to manifest as 11 failures across 4 unrelated PRs in 30 days.
c Fix matches root cause? Yes. The fix raises the test deadline from 30s to 120s, which is ~4× the worst-case backoff window. The test isn't disabled, no settings are tagged no-random-*, no data sizes are reduced.
d Test intent preserved? Yes. The test still asserts that all 30 rows from the FileLog source flow through the MaterializedView to table_to_store_data. We only changed how long we wait, not what we test.
e Both directions demonstrated? Yes. With poll_directory_watch_events_backoff_init = 31000 injected into the FileLog: 30s timeout → fail (file arrives at t=31s); 120s timeout → pass (file arrives at t=31s with 89s of headroom). 50/50 runs of the unmodified test pass with full CI randomization.
f Fix is general (for code fixes)? N/A — this is a test-only change. Code-side concern: the engine's polling backoff itself is unchanged; we're aligning the test deadline with the engine's documented worst-case poll interval.

Session: cron:clickhouse-ci-task-worker:20260427-101500

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @antaljanosbenjamin — could you review this? It's a test-only timeout fix for a flaky FileLog test (raises the polling deadline from 30s to 120s to cover FileLog's worst-case 32s exponential backoff window, same pattern as PR #101367).

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

clickhouse-gh Bot commented Apr 27, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [18406d0]

Summary: ✅


AI Review

Summary

This PR stabilizes 02968_file_log_multiple_read.sh by adding no-parallel, capping poll_directory_watch_events_backoff_max for the test FileLog table, and keeping a wider timeout safety margin. I did not find correctness, safety, or maintainability issues in the proposed test-only change.

ClickHouse Rules
Item Status Notes
Deletion logging ➖
Serialization versioning ➖
Core-area scrutiny ➖
No test removal ✅
Experimental gate ➖
No magic constants ✅
Backward compatibility ✅
SettingsChangesHistory.cpp ➖
PR metadata quality ✅
Safe rollout ✅
Compilation time ✅
No large/binary files ✅
Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Apr 27, 2026
groeneai and others added 2 commits April 28, 2026 00:07
The 120s timeout bump alone is not sufficient to stabilise the test
under heavy CI load. The default
`poll_directory_watch_events_backoff_max` is 32s, and under sanitizer
builds with `BackgroundSchedulePool` contention the polling cycle can
genuinely drift to that upper bound. Combined with re-schedule latency
the test occasionally still hits the 120s cap (4 flaky-check failures
on PR ClickHouse#103602 itself: 2x amd_debug, 2x amd_asan_ubsan).

Cap `poll_directory_watch_events_backoff_max` at 1s on the test's
`FileLog` table so the worst-case polling cycle is bounded by 1s plus
scheduling jitter, well below the 120s safety net. Verified locally:
50/50 passes with full random settings and 50/50 with `-j 8` parallel
load; 100% pass under default settings (no random).

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=103602&sha=d20c9edff5b37fc886d6e823a10662f36ee318bd&name_0=PR&name_1=Stateless%20tests%20%28amd_debug%2C%20flaky%20check%29

Session: cron:clickhouse-ci-task-worker:20260428-104500
@groeneai

Copy link
Copy Markdown
Collaborator Author

Update — additional fix pushed (8cd5a2ff591)

After the 30s → 120s timeout bump landed, CI still showed 4 flaky-check failures (2× amd_debug, 2× amd_asan_ubsan) on commit d20c9edff5b. Test runtime in those failures was ~124s, exhausting the 120s timeout. So the timeout is correct in concept but still too tight under sanitizer + parallel-50× load.

Root cause (deeper than the timeout): the default poll_directory_watch_events_backoff_max=32s lets DirectoryWatcherBase::watchFunc and StorageFileLog::threadFunc independently back off to 32s polling cycles. Under heavy BackgroundSchedulePool contention (sanitizer build, 50× parallel load) the combined latency between an inotify event and streamToViews actually picking up the new content can exceed 120s.

Fix: add SETTINGS poll_directory_watch_events_backoff_max = 1000 to the test's FileLog table. This caps the polling cycle at 1s, so worst-case file-detection latency is bounded at ~1s + scheduling jitter — well below the 120s safety net. The 32s default is appropriate for production tables where polling cost matters; tests don't need it.

Pre-PR validation gate:

  • a) Deterministic repro of the mechanism? Yes — setting poll_directory_watch_events_backoff_max=200000 and _init=200000 gives 0 rows in 30s, proving the setting controls file-detection latency.
  • b) Root cause explained? Default 32s backoff × cumulative cycles + BackgroundSchedulePool contention under sanitizer/parallel load can drift past 120s.
  • c) Fix matches root cause? Yes — directly bounds the polling-cycle latency, not the timeout.
  • d) Test intent preserved? Yes — still verifies FileLog → MaterializedView → MergeTree flow on initial files and on appended files. Only the polling cadence on the test's own table changes.
  • e) Both directions demonstrated? Without setting: 4 flaky-check failures in CI on d20c9edff5b. With setting: 50/50 with full random settings + 50/50 with -j 8 parallel = 100/100 local passes.

The 120s timeout is kept as a safety net (matches 02889 pattern). Reviewer guidance: please re-run flaky check; if it's clean we're done.

The deeper-fix attempt (commit 8cd5a2f) capped
`poll_directory_watch_events_backoff_max` at 1s, but CI flaky-check still
showed 1/50 failures on `Stateless tests (amd_asan_ubsan, flaky check)` at
the 120s wait timeout. Local 100/100 with `-j 8` did not reproduce the issue;
local `-j 50` with the ASan binary mirrors CI load and is enough to expose
the root cause:

  - Each `FileLog` table occupies two `BackgroundSchedulePool` tasks
    (`DirectoryWatcherBase::watchFunc` looping on inotify and
    `StorageFileLog::threadFunc` blocked on `cv.wait`).
  - With 50 concurrent test instances, the pool sees 100+ resident tasks
    competing with all other test workloads on the shared schedule pool.
  - Under that contention the wake-up path
    (`watchFunc` -> `wakeUp` -> `cv.notify_one` -> `threadFunc` resumes ->
    `streamToViews`) can take well over 120s in tail cases, even though the
    polling backoff is bounded to 1s.

`no-parallel` removes the contention entirely. Sequential execution gives a
consistent 9.7-11.5s per run with the ASan binary (50/50 local, 25/25 in a
local `--flaky-check` simulation with `--test-runs 25`).

This matches the precedent set by other `FileLog` tests that share the same
timing-sensitive streaming path: `02026_storage_filelog_largefile.sh` and
`04031_filelog_drop_mv_no_exception.sh`. The bounded backoff added in the
previous commit is preserved as defense-in-depth and the comment in
`wait_for_row_count` is updated to reflect the new rationale. No changes to
test logic or coverage of PR ClickHouse#58877's "multiple read in MV" fix.

Verified locally:
  - `--test-runs 50 -j 1` on ASan: 50/50 pass, 9.70 - 11.46s per run.
  - `--test-runs 25 --flaky-check` on ASan: 25/25 pass, 9.60 - 11.56s.

CI report on previous commit (1/50 fail @ 132.57s):
https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=103602&sha=8cd5a2ff591de07613831b87db0795a766e88ee8&name_0=PR&name_1=Stateless%20tests%20(amd_asan_ubsan%2C%20flaky%20check)
@groeneai

Copy link
Copy Markdown
Collaborator Author

Update — no-parallel tag added (commit 18406d00eff)

The deeper-fix commit (8cd5a2ff591) reduced flaky-check failures from 4/50 to 1/50 on Stateless tests (amd_asan_ubsan, flaky check) but did not eliminate them. The remaining failure was deterministically reproducible locally with the ASan binary at -j 50:

1 fail in 50 runs at 132.57s, hitting the 120s wait_for_row_count timeout.

Root cause — confirmed via local -j 50 reproduction:

  • Each FileLog table occupies two BackgroundSchedulePool tasks: DirectoryWatcherBase::watchFunc (looping on inotify) and StorageFileLog::threadFunc (blocked on cv.wait).
  • With 50 concurrent test instances, the pool sees 100+ resident tasks plus all other test workloads.
  • Under that contention the wake-up path (watchFunc → wakeUp → cv.notify_one → threadFunc resumes → streamToViews) can drift past 120s in tail cases, even with poll_directory_watch_events_backoff_max = 1000.

The bounded backoff is necessary but not sufficient. The contention is the actual flakiness source.

Fix — no-parallel tag eliminates the contention. Sequential execution shows consistent 9.7–11.5s per run (vs 17–18s under -j 50 and a 132s tail under contention).

Verification (local, ASan):

  • --test-runs 50 -j 1: 50/50 pass.
  • --test-runs 25 --flaky-check: 25/25 pass, 9.60–11.56s each.

Pre-PR validation gate:

# Question Answer
a Deterministic repro? Yes — -j 50 ASan locally reproduces the timeout in tail cases; sequential execution does not.
b Root cause explained? Yes — BackgroundSchedulePool contention from 50 concurrent FileLog instances delays the cv.wait → streamToViews wake-up path past 120s.
c Fix matches root cause? Yes — no-parallel removes the contention directly.
d Test intent preserved? Yes — same logic, same coverage of PR #58877's "multiple read in MV" fix, and the poll_directory_watch_events_backoff_max = 1000 setting is preserved as defense-in-depth.
e Both directions demonstrated? Yes — -j 50 reproduces the failure; -j 1 and --flaky-check simulation pass cleanly.

This matches the precedent set by other timing-sensitive FileLog tests: 02026_storage_filelog_largefile.sh and 04031_filelog_drop_mv_no_exception.sh already carry no-parallel.

— session id: cron:clickhouse-ci-task-worker:20260428-221500

SetGeek pushed a commit to SetGeek/ClickHouse that referenced this pull request Apr 29, 2026
The 150s warm-up loop in the test polls the destination MergeTree table
waiting for the `FileLog` background thread to ingest the prepared CSV
file. The default `poll_directory_watch_events_backoff_max` is 32s,
and under sanitizer builds with `BackgroundSchedulePool` contention
the polling cycle can drift to that upper bound. On slow runners
(`ASan`+azure, `MSan`+WasmEdge) the file is occasionally not picked
up within 150s and the test reports
"Warm-up failed: only 0 rows consumed after 300 attempts".

Looking at CIDB for the 30-day window after PR ClickHouse#102386 merged the
timeout bump (2026-04-17), 12 failures still remain — all 10/12 with
the same warm-up timeout signature, dominated by
`Stateless tests (arm_asan_ubsan, azure, sequential)` (10 hits) and
`amd_msan` (2 hits).

Cap `poll_directory_watch_events_backoff_max` at 1s on the test's
`FileLog` table so the worst-case polling cycle is bounded by 1s plus
scheduling jitter, well below the 150s warm-up loop. Same pattern as
PR ClickHouse#103602 for sister test `02968_file_log_multiple_read`.

The fix preserves the test's original purpose (regression test for
`DEPENDENCIES_NOT_FOUND` race when the materialized view is dropped
during streaming) — only the file-detection latency is bounded, the
DROP-during-streaming race window is unchanged.

Verified locally:
- 50/50 passes with `--no-random-settings --no-random-merge-tree-settings`.
- Deterministic repro of the failure mode without the fix: with
  `poll_directory_watch_events_backoff_init=200000`,
  `poll_directory_watch_events_backoff_max=200000` (simulating a 200s
  polling cycle), the warm-up fails:
  "REPRODUCED: only 0 rows after 150s warm-up".

CI report (sample failure):
https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=102302&sha=a4cc3a4d5acd3ee9dae8860b032a8fe7b91b2dce&name_0=PR&name_1=Stateless%20tests%20%28amd_msan%2C%20WasmEdge%2C%20sequential%2C%202%2F2%29

Closes ClickHouse#102388

Session: cron:clickhouse-ci-task-worker:20260428-114500

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok.

@alexey-milovidov alexey-milovidov self-assigned this Apr 29, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Apr 29, 2026
Merged via the queue into ClickHouse:master with commit e70ebac Apr 29, 2026
165 checks passed
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Apr 29, 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 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