Skip to content

Fix flaky test 05339_filelog_shared_watch_thread - #131241

Merged
alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:fix-flaky-05339-filelog-watch-thread-count
Nov 14, 2026
Merged

alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:fix-flaky-05339-filelog-watch-thread-count

Conversation

@groeneai

@groeneai groeneai commented Nov 13, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #125794

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 required.

Description

05339_filelog_shared_watch_thread, added by #125794, fails its first line only in Stateless tests (arm_binary, s3 storage, DBReplicated, sequential): 14 of about 500 runs since the merge, 3 of them on master (MasterCI, 149b9fac86), 0 failures on every other job.

The test required the server-wide GlobalThread metric to grow by less than 100 while it creates 200 FileLog tables. That metric also counts the threads of unrelated pools that grow lazily. In the 3 failing master runs, a merge of system.metric_log on the cached_s3 disk started inside that window and the threadpool remote-FS reader took 119-163 new global threads in one second; the CREATEs themselves added about one. The window is ~18 s with a Replicated database (each CREATE goes through Keeper) and ~1 s elsewhere, which is why only that job fails.

The test now counts the shared watch thread itself: system.stack_trace rows named FileLogWatch. There is one reactor per server and DirectoryWatchReactor::add waits for its thread, so the count is 1 whatever else runs.

Validation (master debug build), on a fresh server with a 256-thread query started inside the CREATE window: the old test fails with the CI diff (GlobalThread +255), the new one passes under the same load (GlobalThread +256). The new line reads 0 on 26.10, which still has a thread per table. 50/50 randomized runs and 10/10 with a Replicated database pass.


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

Version info

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

The test compared the server-wide `GlobalThread` metric before and after
creating 200 FileLog tables and required a growth below 100. That metric also
counts the threads of unrelated, lazily growing pools. In the failing master
runs (4a88506, fc8a491, 149b9fa) a background merge of the wide
`system.metric_log` table on the `cached_s3` disk grew the threadpool remote-FS
reader by 119-163 threads inside the CREATE window, while the CREATEs added
about one. Only the DatabaseReplicated lane failed: each CREATE there goes
through Keeper, so the window is ~18 s instead of ~1 s.

Count the shared watch thread itself: rows of `system.stack_trace` named
`FileLogWatch`. There is one reactor per server and `DirectoryWatchReactor::add`
waits for its thread, so after the CREATEs the count is 1 whatever else runs on
the server. It reads 0 on 26.10, which still has a thread per table. Reading
only `thread_name` sends no signals to other threads.

Related: ClickHouse#125794

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; 0 findings) plus my own cold review (2 nits, no change).

# Sev Finding Verdict Evidence / action
1 💡 no-parallel is kept although the new count is safe under concurrency DISAGREE The tag comes with the test from #125794. Without it the flaky check runs copies concurrently (one copy takes ~55 s there), so it stays, with its reason updated.
2 💡 An unnamed per-table thread elsewhere in FileLog would not be counted DISAGREE The per-table design (26.10.2.103) reads 0 and a reactor per table would read 200. The old GlobalThread check caught that case only when no other pool grew, which is the flake.

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

Session id: cron:clickhouse-review-slot-10:20261113-093500

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @mu-soliman, could you review this? The test now counts the FileLogWatch thread in system.stack_trace instead of the server-wide GlobalThread delta, which a concurrent system.metric_log merge on cached_s3 grew by 119-163 threads inside the ~18 s Replicated-database CREATE window.

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. On a freshly started server, a background SELECT sum(number) FROM numbers_mt(20000000000) SETTINGS max_threads = 256, max_threads_min_free_memory_per_thread = 0 started inside the CREATE window makes the old test fail with the CI diff (GlobalThread 401 -> 656).
b Root cause explained? GlobalThread counts every thread of the global pool, including unrelated pools that grow lazily and keep their threads. A system.metric_log merge on cached_s3 grew the remote-FS reader by 119-163 threads inside the window in all 3 failing master runs; growth > 100 prints 0. The Replicated-database window (~18 s vs ~1 s) makes the overlap likelier.
c Fix matches root cause? Yes. The oracle counts the one thread the property is about (FileLogWatch in system.stack_trace) instead of a server-wide metric. No bound widened, no tag added, no data reduced.
d Test intent preserved / new tests added? Yes. It still asserts that 200 tables share ONE watch thread; the new line reads 0 on 26.10 (a thread per table). No new test needed for a test-only fix.
e Both directions demonstrated? Yes. Same load, fresh server per run: old test FAIL (+255 global threads), new test OK (+256).
f Fix is general across code paths? No other stateless test reads GlobalThread. The sibling tests from #125794 read no metrics and have not failed. The other lines of this test are unchanged and have never failed.
g Fix generalizes across inputs (params/datatypes/wrappers)? N/A (test oracle). The count is 1 for max_block_size 1 to 65409 and under 50 randomized runs; 10/10 with a Replicated database.
h Backward compatible? (maintainer-approved exception only) N/A: test-only.
i Invariants and contracts preserved? Yes. Tags and every other assertion of the test are unchanged. Reading only thread_name from system.stack_trace sends no signals.

Session id: cron:clickhouse-impl-slot-40:20261113-091500

@clickhouse-gh

clickhouse-gh Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [82d32b2]

Summary: ✅


AI Review

Summary

PR #131241 replaces the noisy server-wide GlobalThread delta in 05339_filelog_shared_watch_thread with an exact count of FileLogWatch threads in system.stack_trace. The change preserves the shared-watcher assertion while removing interference from unrelated thread pools. No actionable findings in head 82d32b21cdcbca21407c3432ee9813ebb7d602c3.

Missing context / blind spots
  • ⚠️ Independent runtime verification was unavailable: this checkout has no ClickHouse binary/build, and the queried CI report contained no executed result for this test. The author documents an old/new comparison under concurrent load, 50 randomized runs, and 10 runs with a replicated database. A completed CI run of the modified test in the affected ARM replicated-database lane would independently confirm those results.
Final Verdict

Status: ✅ Approve. No code changes requested; the documented validation supports this focused test correction.

@clickhouse-gh clickhouse-gh Bot added pr-ci can be tested Allows running workflows for external contributors comp-testing Test content only (no production code). labels Nov 13, 2026
@PedroTadim

Copy link
Copy Markdown
Member

cc @mu-soliman

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Nov 14, 2026
Merged via the queue into ClickHouse:master with commit c623786 Nov 14, 2026
410 of 411 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 Nov 14, 2026
@clickhouse-gh clickhouse-gh Bot added comp-message-queues Message queue integrations (Kafka, RabbitMQ, NATS table engines for stream ingestion/egress). 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

blocker This issue / pr blocks a new release can be tested Allows running workflows for external contributors comp-message-queues Message queue integrations (Kafka, RabbitMQ, NATS table engines for stream ingestion/egress). 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