The test built its query_id as 03652_query_id_$RANDOM, drawing 4 times per
run from bash's 15-bit $RANDOM (0..32767). When two of the 4 loop iterations
draw the same number they share one query_id, and every predicate of the
test's system.query_log filter is true of both INSERTs, so the later SELECT
returns two rows instead of one. order by ALL prints the smaller first, which
is the extra 1 above a 7 seen in CI: 11 of the 13 failures recorded in the
last 90 days have that shape, spread over 11 unrelated pull requests.
This is a test bug and not a query_log defect. query_id uniqueness is
enforced only among concurrently running queries, in ProcessList::insert, and
system.query_log is append-only history, so several rows for one query_id are
by design. My earlier fix in ClickHouse#106671 tightened this same filter, which lowered
the rate but could not help, because each predicate it added is also true of
both colliding rows.
There is a second collision axis. current_database = currentDatabase()
isolates executions only when each execution gets a fresh database, whereas
the stress arms pass a fixed --database, so one database serves many
executions and a repeat draw from an earlier execution matches as well.
The id is now composed from the per-iteration loop variables, which closes
the within-run axis by construction with no randomness involved, plus a
server-generated UUIDv4, which closes the across-execution axis.
The natural failure rate is roughly 1 in 11,000, so the mechanism was proven
by forcing the collision rather than by repetition: replacing $RANDOM with a
constant makes the test fail deterministically with the same diff class in
maximal form, and adding only the loop-variable component makes it pass again.
The second axis reproduces with a fixed --database, 1 pass and 2 failures in 3
runs, and passes 5 of 5 with the fix. Two mutations confirm each component is
load-bearing. Randomized 50/50 run: 50 OK, 0 FAIL. No blanket
no-random-settings tag was added, since the mechanism is independent of the
randomizer.
One of the 13 failures, on ClickHouse#110015, is a different mechanism: a thread-count
shortfall printing 4 instead of 7, with the same line count rather than an
extra line. It is deliberately not addressed here and is tracked separately,
so the residual rate should fall to about 1 per 90 days rather than to zero.
Co-Authored-By: Claude Opus 5 <[email protected]>
The flaky-test pattern was an extra
1row appearing before the expected7in themax_threads = 7iterations oftests/queries/0_stateless/03652_threads_count_insert.sh,seen across multiple unrelated PRs and on
masterover the last ~3 months(observed under at least
amd_msan + WasmEdge,arm_binary,amd_asan_ubsan db disk distributed plan, andamd_debugsequential variants).The per-iteration query against
system.query_logwas filtering only bycurrent_database = currentDatabase() AND type != 'QueryStart' AND query_id = '$QUERY_ID'.Under CI's randomized settings, a second
query_logrow can match the samequery_id(a subquery, a distributed sub-fragment, or a non-
Insertfollow-up running with thesame id), so the test sometimes saw two rows instead of the expected one and printed
an extra entry whose
peak_threads_usagewas small (typically mapped to1by theif(peak_threads_usage >= 6, 7, peak_threads_usage)bucketing).Tighten the filter to match only the successful initial
INSERTlog row:This is the same shape used by the sibling test
02871_peak_threads_usage(which filters on
type = 'QueryFinish').Verified locally that the new filter correctly suppresses a duplicate
query_logrowsharing the same
query_idwhile still returning exactly one row for the real INSERT.CI report (one of the recent failures):
https://s3.amazonaws.com/clickhouse-test-reports/101143/
No related open issue found.
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
...
Documentation entry for user-facing changes