Repository navigation
Conversation
The test asserts sum(ProfileEvents['TextIndexUsedEmbeddedPostings']) > 0 read back from system.query_log, and that column flaps to 0 while the sibling ParallelReplicasUsedCount column never does. TextIndexUsedEmbeddedPostings is incremented at exactly one site, TextIndexSerialization::deserializeTokenInfo in MergeTreeIndexText.cpp, by whichever server performs the text index dictionary analysis. ParallelReplicasUsedCount is incremented in the coordinator, which always lives on the initiator, which is why column 1 is stable. With parallel_replicas_local_plan = 0, canUseLocalPlanForParallelReplicas returns false and executeQueryWithParallelReplicas builds only ReadFromParallelRemoteReplicasStep, so the initiator performs no local read and no index analysis at all. Every increment then happens on a follower and reaches the test's sum() only through a follower's query_log row, which depends on replica scheduling rather than on the behaviour under test. That setting is 0 in 6 of 6 genuine flap rows over 60 days, against a control base rate of 0.385 measured over 400 failing rows of other tests from the same two check types in the same window. Measured on a three replica loopback cluster: with local_plan = 1 the initiator's row carries the counter (ep = 3, misses = 9), with local_plan = 0 it carries ep = 0 with no cache activity at all, in 20 out of 20 runs. Re-running the first arm with use_text_index_tokens_cache = 0 still gives the initiator a non-zero counter, so the effect is replica placement and not the tokens cache. Pin the setting to its own product default so the initiator performs the analysis itself. The assertion, the reference file and every other randomized setting are unchanged. This is the same shape as ClickHouse#93287, which fixed an earlier flake in this file by pinning one parallel replicas setting with an explanatory comment. The comment is deliberately verbose because the pinned value equals the product default: without stating that the test runner randomizes the setting, a future cleanup would delete the pin as a no-op and silently re-arm the flake. This replaces ClickHouse#111138, whose stated mechanism (a warm global TextIndexTokensCache persisting across stateless runs) was wrong, since the cache key is disk:part_path:index_file and every stateless run gets a fresh database.
The comment above the pin stated two supporting sub-mechanisms as fact: that a follower increments the counter only when it wins the shared tokens-cache race for a part, and that it reports the counter only when the coordinator did not cancel it. Both are source-real, but neither was observed in the twenty measured runs used to justify the pin (zero follower cache hits, zero cancellation exception rows), and the pull request description already lists them as possible rather than asserting them. State only what was measured. The remaining text keeps the three clauses that are load-bearing: which counter the probe reads and that it is incremented by whichever server performs the index analysis, that under parallel_replicas_local_plan = 0 the initiator builds no local plan and so the counter lands only on scheduling-dependent follower query_log rows, and that the test runner randomizes the setting, so pinning it to its own default is not a redundant line a future cleanup can delete. The earlier commit message called the comment deliberately verbose for that last reason; that reason still holds, the two unmeasured clauses were not part of it. Comment text only. The SET statement, the assertion, the reference file and the binary are unchanged.
Internal second-model review (click to expand)Before opening this PR the diff and the description went through two review rounds, each a cold Counts, taken from the per-round ledgers rather than restated: cold review 5 findings in round 1
💡 Countables corrected after re-deriving each from CIDB rather than from the earlier 💡 The relationship links did not render. They sat inside the template's HTML comment. 💡 An @-mention used as narrative. The description referred to the requester by handle in 💡 The description promised "falsifiable by two commands" and then gave two expected outcomes 💡 The test would not deterministically fail if this pin were reverted -- DISAGREED as a 💡 Is one pin enough? Recorded as a non-defect after enumerating the carriers independently: Every source citation in the description was re-verified independently against |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-46:20260727-184700 |
|
cc @devcrafter, could you review this? It pins |
|
Workflow [PR], commit [3122af7] AI ReviewSummaryThis PR pins Final VerdictStatus: ✅ Approve |
|
The fix defeats the purpose of the test. |
|
Agreed, and I withdraw it. Pinning It was also unnecessary, which I should have established before opening the PR. Per-row
The counter has a single increment site ( So I have not reproduced the failing direction and I do not have a mechanism worth proposing. I also checked the guess that a cancelled replica could be the one that did the analysis while the probe filters Before I spend more on it: do you consider a ProfileEvents counter a sound oracle for this test at all under parallel replicas, or would you rather the second column asserted something else? |
Related: #110057
Related: #111138
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
...
Description
The fix was requested in #110057. It supersedes #111138, which is closed.
02346_text_index_parallel_replicasflaps on line 3 of its output:i.e.
sum(ProfileEvents['TextIndexUsedEmbeddedPostings']) > 0reads0. Column 1 of the samestatement (
ParallelReplicasUsedCount > 0) never flaps.This is the fix requested in #110057. It replaces #111138, which I closed as wrong:
that PR blamed a warm global
TextIndexTokensCachepersisting across stateless runs, which isimpossible because the cache key is
disk:part_path:index_fileand every stateless run gets afresh database. That concession stands. The mechanism below is a different one, it comes from
the CI settings data rather than from a hand-built local probe, and the two arms that establish
it are stated at the end so you can check them.
The data
Over 60 days, 15 CIDB rows match this test name. Split by failure signature, only 6 are this
flap; the other 9 fall in four unrelated classes (5 x
return code: 241, a host-OOM class,current RSSbetween 41.84 and 53.68 GiB; 2 xCode: 49from one PR's own analyzer change; 1 xCode: 36;1 x deb-unpack
server died). Those 6 flap rows are 5 distinct pull requests (#111690, #110057,#108673, #109696, #109083) plus 1 master run, so this is cross-author flakiness rather than any
PR's own test.
Extracting the runner's
Settings used in the test:line from each of the 6 rows andintersecting them, one randomized setting is constant across all of them:
parallel_replicas_local_planenable_vertical_finaldistributed_aggregation_memory_efficientuse_top_k_dynamic_filtering_for_variable_length_typesThe control base rate is measured over 400 failing rows of other tests from the same two
check types in the same window, i.e. the same randomizer population. It also matches the runner
arithmetic:
tests/clickhouse-test:1548draws the setting withrandom.randint(0, 1), andadjust_settings_for_autopr(:1687-1700) force-sets it to1wheneverautomatic_parallel_replicas_mode == 2, itself drawn with probability0.25(:1608), soP(local_plan = 0) = 0.75 * 0.5 = 0.375.0.375^6is about2.8e-3. More decisively,parallel_replicas_local_planis the only one of those settings with a source path to thiscounter.
The mechanism
TextIndexUsedEmbeddedPostingsis incremented at exactly one place,MergeTreeIndexText.cpp:1193inTextIndexSerialization::deserializeTokenInfo, reached fromMergeTreeIndexGranuleText::analyzeDictionaryForTokens. That is index-analysis work, performedby whichever server does the index analysis.
ParallelReplicasUsedCountis incremented in thecoordinator (
ParallelReplicasReadingCoordinator.cpp:1335), which always lives on theinitiator, which is why column 1 of the probe never flaps.
With
parallel_replicas_local_plan = 1(the default),ClusterProxy::canUseLocalPlanForParallelReplicasreturns true andexecuteQueryWithParallelReplicasbuilds a local plan for the local replica, so the initiatorreads parts itself and the counter lands in the initiator's own
query_logrow.With
parallel_replicas_local_plan = 0that predicate returns false and onlyReadFromParallelRemoteReplicasStepis built. The initiator performs no local read and no indexanalysis at all, so every increment happens on a follower and reaches the test's
sum(...)onlythrough a follower's
query_logrow.Measured, on a 3-replica loopback cluster
Running the test body verbatim in a fresh database and reading
system.query_logper rowinstead of via
sum()(notype = 'QueryFinish'predicate, since the row type is itself part ofthe story):
--parallel_replicas_local_plan 1--parallel_replicas_local_plan 0The initiator row carries
ep = 3in the first arm andep = 0withhits = misses = dict_blocks = 0in the second: it did no index analysis whatsoever. Repeated20 times, the initiator's
epwas 0 in 20 out of 20 runs withlocal_plan = 0, and how manyfollowers actually perform the analysis varied run to run (
ParallelReplicasUsedCounton theinitiator was 1 in 15 runs and 2 in 5).
Two controls.
ParallelReplicasUsedCounton the initiator's row is non-zero in both arms, sothe
ep = 0reading is not "parallel replicas never ran". And re-running the first arm withuse_text_index_tokens_cache = 0still gives the initiatorep = 3, so the effect is aboutreplica placement and not about the tokens cache.
Why the CI reruns pass
Every failing row carries the runner's own
Runs: 94..113, Failed: 0block. That is expectedand not a contradiction:
local_plan = 0is necessary but not sufficient. On top of it, nosurviving follower must have contributed the counter. Locally I did not reproduce the flap
either (
sumwas non-zero in 20 out of 20 runs), and I did not tune the harness until itfailed. So this PR does not claim a reproduced failure; it claims, and measures, that
local_plan = 0moves the counter off the row the probe is anchored on, which is the dependencethat makes the assertion a race.
For completeness about what I did not observe: with
local_plan = 0a follower could inprinciple also fail to contribute because the coordinator cancelled it (a cancelled replica logs
an exception row, which the probe's
type = 'QueryFinish'filter excludes) or because it took atokens-cache hit for a part another replica had already analysed. Neither showed up in my 20
runs (0 exception rows, 0 cache hits), so I am listing them as possible and not asserting them.
The change
One
SET parallel_replicas_local_plan = 1;with a comment, in the test only. No source changeand no
.referencechange. This restores the setting's own product default, keeps the assertionverbatim, and leaves every other randomized setting varying.
This is the established idiom for text index tests, and three of them already do it:
02346_text_index_function_hasAnyAllTokens_partially_materialized.sql:2--SET parallel_replicas_local_plan = 1; -- this setting may skip index analysis when false(Cleanups a text index test #88392)02346_text_index_part_format.sql:6--SET parallel_replicas_local_plan=1; -- this setting is randomized, set it explicitly to have local plan for parallel replicas(Support packed storage for full text index #80852)03776_text_index_covered_sparse_grams.sql:7--SET parallel_replicas_local_plan = 1;(Update text index docs, minor test fixes #94077)It is also the same shape as #93287, which fixed an earlier flake in this same file by pinning one
parallel-replicas setting with an explanatory comment (still lines 11-12 today).
Worth adding as a second, independent reason the pin is the right lever: with
parallel_replicas_local_plan = 1the followers stop doing the index analysis too, becauseReadFromMergeTree.cpp:2788-2796skips it on a follower whenparallel_replicas_index_analysis_only_on_coordinator(defaulttrue) is set. So the pin does notjust add the initiator as one more candidate incrementer; it concentrates the analysis on the one
server whose
query_logrow the probe is anchored to.Alternatives, in case you prefer one
query_id = initial_query_id, the form02950_parallel_replicas_used_count.sqluses). That narrows the assertion to what theinitiator does. I did not do it because under
local_plan = 0the initiator'sepis 0, so itwould turn the flaky failure into a deterministic one unless the pin is added as well.
ProfileEventsinto the initiator'squery_logrow. Remote profile eventscurrently reach the initiator only through
Protocol::Server::ProfileEventsinto the internalprofile-events queue, which feeds the client display, not
logQueryFinishImpl's map. That is across-cutting change to every parallel-replicas query and does not belong in a flaky-test fix,
but say the word and I will open it separately.
How to check the two arms
Run the test body in a fresh database against a cluster of three loopback replicas, then read
system.query_logselectingProfileEvents['TextIndexUsedEmbeddedPostings']andquery_id = initial_query_idper row rather thansum(). Thesum()in the test hides whichrow the counter landed on, which is the whole point.