Skip to content

Fix flaky test 05218_text_index_substreams_opened_lazily - #123823

Merged
alexey-milovidov merged 2 commits into
ClickHouse:masterfrom
groeneai:fix-flaky-05218-text-index-cache-clears
Oct 4, 2026
Merged

alexey-milovidov merged 2 commits into
ClickHouse:masterfrom
groeneai:fix-flaky-05218-text-index-cache-clears

Conversation

@groeneai

@groeneai groeneai commented Oct 4, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #121040

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

Fix flaky test 05218_text_index_substreams_opened_lazily.

Description

05218_text_index_substreams_opened_lazily (added in #121040) fails in parallel stateless runs and Fast test on master and unrelated PRs, with one FileOpen threshold flipped while the answers stay right: 8 FAIL / 485 OK in the first 4 hours after it landed, 2 of them on master (master run).

The thresholds assume the server-global mark and text index header / tokens / postings caches stay warm between the unmeasured warm-up and the measured query. A concurrent test that drops a MergeTree table in a database without table UUIDs (Ordinary, Memory) goes through MergeTreeData::dropAllData, which calls Context::clearCaches and empties all of them, so the measured query reopens every substream (in the failing jobs' query_log: 30 header, token, postings and mark misses each, FileOpen 90 against the threshold of 45).

The test is now tagged no-parallel. Only another running test can issue such a DROP (or RENAME), and clickhouse-test starts the sequential runner after all parallel workers have finished; CI runs the sequential flavor as separate jobs. Thresholds, measurements and the reference are unchanged.

Validation, local debug build, randomized settings:

  • 05218 together with the three cache-clearing tests seen in the failing jobs, -j 8, 10 runs: 05218 ran in the sequential phase after the last clearing query, 10/10 OK, every measured query with 0 cache misses.
  • 05218 alone: 30/30 OK.
  • Without the tag, one such DROP between the warm-up and the measured query flips both thresholds every time, and a loop issuing it every second fails the test 13/50.

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

Version info

  • Merged into: 26.10.1.1525-master (included in 26.10 and later)

The FileOpen thresholds of 05218_text_index_substreams_opened_lazily
assume that the mark cache and the text index header, tokens and
postings caches are still warm when the measured query runs after its
unmeasured warm-up. They are server-global: a concurrent test that drops
or renames a MergeTree table in a database without table UUIDs
(Ordinary, Memory) goes through MergeTreeData::dropAllData() / rename(),
which call Context::clearCaches() and empty all of them. The measured
query then reopens every substream and one threshold flips (8 FAIL in
the first hours after the test reached master, 2 of them on master,
answers always right). The failing jobs' query_log shows the concurrent
DROP TABLE between the warm-up and the measurement, and 30 header,
token, postings and mark misses on the measured query.

Repeat the warm-up and the measured query, at most 10 times, while the
measured query's own MarkCacheMisses, TextIndexHeaderCacheMisses and
TextIndexTokensCacheMisses (plus TextIndexPostingsCacheMisses for the
postings-cached query) are above zero. Thresholds, fixture and reference
are unchanged, and the in-range control is still measured once since a
clear only adds opens to it. A real regression opens a substream with
warm caches, shows zero misses, stops at attempt 1 and fails as before.

Locally, with a loop dropping a MergeTree table in a Memory database
every second: old test 13/50 FAIL, new test 0/50. Without interference
50/50, one attempt each. A mutation opening the dictionary substream
eagerly fails 5/5 at attempt 1; with a clear every ~15 ms, runs that
never got a warm attempt fail.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-ci-master PR origin: master/nightly CI monitoring finding labels Oct 4, 2026
@groeneai

groeneai commented Oct 4, 2026

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 of the diff.

# Sev Finding Verdict Evidence / action
1 💡 Context::clearCaches also empties caches the retry does not gate on (primary index, index marks, uncompressed) checked, no change The primary index loads before any text index header lookup, so a clear that hits it also shows header misses; index marks go through MarkCache and count as MarkCacheMisses; the uncompressed cache can only restore the uncached data-file opens (at most 1 and 30, below the thresholds 10 and 45).

Severity: ❌ blocker / ⚠️ major / 💡 nit.

Session id: cron:clickhouse-review-slot-10:20261004-042400

@groeneai

groeneai commented Oct 4, 2026

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. One CREATE DATABASE w ENGINE = Memory; CREATE TABLE w.t ... MergeTree; DROP TABLE w.t between the warm-up and the measured query flips both thresholds every time (FileOpen 1 -> 62 for the selective query, 30 -> 150 for the postings-cached one). With that loop running every second, the old test fails 13/50.
b Root cause explained? Yes. Dropping a MergeTree table in a database without table UUIDs calls Context::clearCaches from MergeTreeData::dropAllData, which empties the mark cache and the text index header / tokens / postings caches. The measured query then rereads every substream and FileOpen crosses the threshold. The failing CI jobs' query_log shows the same concurrent DROP TABLE in an Ordinary/Memory database.
c Fix matches root cause? Yes. The test checks its own precondition (warm caches) through the measured query's cache-miss counters and measures again when it ran cold. No tag, no wider threshold, no smaller fixture.
d Test intent preserved / new tests added? Yes. A mutation that opens the dictionary substream eagerly fails 5/5 at attempt 1 (zero misses, so the retry does not mask it). An environment where every attempt is cold still fails.
e Both directions demonstrated? Yes. Under the same 1 s cache-clear loop: old test 13/50 FAIL, new test 0/50. Without interference: 50/50 OK, exactly one attempt per run.
f Fix is general across code paths? Both cache-dependent assertions are gated (selective: mark + header + tokens; postings-cached: plus postings). The in-range control is deliberately not gated, because a cache clear can only raise its count.
g Fix generalizes across inputs (params/datatypes/wrappers)? N/A (test-only flakiness fix). Settings randomization was on in every run, and the gated counters were 0 in steady state across 50 randomized draws.
h Backward compatible? (maintainer-approved exception only) N/A, test-only change.
i Invariants and contracts preserved? Yes. The answers come from the same measured attempt the thresholds check, and the reference is unchanged. The retry can only add attempts; the unchanged threshold query still decides pass or fail.

Session id: cron:clickhouse-impl-slot-40:20261004-034800

@clickhouse-gh

clickhouse-gh Bot commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [bc815a6]

Summary: ✅


AI Review

Summary

This PR fixes the flakiness in 05218_text_index_substreams_opened_lazily by tagging the test no-parallel, which matches the actual source of nondeterminism: its ProfileEvents['FileOpen'] thresholds assume warm server-global caches between the test's own warm-up and measured queries, and clickhouse-test runs no-parallel cases only after the parallel worker pool drains. I did not find remaining correctness, coverage, or PR-metadata issues in the current diff; the change preserves coverage because ordinary stateless CI has separate parallel/sequential flavors and Fast test still executes sequential tests in the same invocation.

Final Verdict
  • Status: ✅ Approve

@murphy-4o

Copy link
Copy Markdown
Member

@groeneai add a no-parallel for this case is more robust and simple

Per review: drop the `measure_warm` retry helper and tag the test
`no-parallel`. The oracle needs the server-global mark cache and text index
header/tokens/postings caches to stay warm between the warm-up and the
measured query. The only thing that empties them mid-test is a concurrent
`DROP` or `RENAME` of a `MergeTree` table in a database without table UUIDs
(`MergeTreeData::dropAllData` / `MergeTreeData::rename` ->
`Context::clearCaches`), which only another running test can issue.
`clickhouse-test` starts the sequential runner after every parallel worker
has been reaped, and CI runs the parallel and sequential flavors as separate
jobs, so nothing can clear the caches while 05218 runs.

Local, randomized settings: 05218 with 03167/05214/05234 (the cache-clearing
tests seen in the failing CI jobs), -j 8, --test-runs 10: 05218 ran in the
sequential phase after the last clearing query (13:59:02.460 vs first 05218
query at 13:59:02.669), 10/10 OK, every measured query 0 cache misses
(selective `FileOpen` 1, postings-cached `FileOpen` 30). 05218 alone,
--test-runs 30: 30/30 OK.

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

groeneai commented Oct 4, 2026

Copy link
Copy Markdown
Collaborator Author

Thanks, done in bc815a6: the retry helper is gone and the test is tagged no-parallel, so the diff against master is just the tag and its comment. clickhouse-test starts the sequential runner only after all parallel workers have finished, so no concurrent DROP of a table without a UUID can reach Context::clearCaches mid-test. Locally, next to the three cache-clearing tests from the failing jobs (-j 8, 10 runs), 05218 ran after their last query, 10/10 OK with 0 cache misses; alone 30/30 OK. I updated the PR description to match.

@alexey-milovidov alexey-milovidov self-assigned this Oct 4, 2026
@alexey-milovidov alexey-milovidov added the blocker This issue / pr blocks a new release label Oct 4, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Oct 4, 2026
Merged via the queue into ClickHouse:master with commit 77abae0 Oct 4, 2026
149 checks passed
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 4, 2026
@clickhouse-gh clickhouse-gh Bot added comp-text-index Full-text search: inverted/text index in MergeTree (tokenizers, posting lists, GIN-style index bu... 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-text-index Full-text search: inverted/text index in MergeTree (tokenizers, posting lists, GIN-style index bu... groeneai-origin-ci-master PR origin: master/nightly CI monitoring finding 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