Skip to content

Fix flaky test 03096_order_by_system_tables - #109365

Merged
alexey-milovidov merged 2 commits into
ClickHouse:masterfrom
groeneai:fix-03096-order-by-system-tables-flush-timeout
Jul 29, 2026
Merged

alexey-milovidov merged 2 commits into
ClickHouse:masterfrom
groeneai:fix-03096-order-by-system-tables-flush-timeout

Conversation

@groeneai

@groeneai groeneai commented Jul 3, 2026

Copy link
Copy Markdown
Collaborator

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

Description

Fixes the flaky 03096_order_by_system_tables.

Requested by @alexey-milovidov in #109245 (comment) (that PR only touches programs/server/play.html, so it cannot affect this stateless SQL test; the failure there was the transient variant below).

Despite its name the test has no ORDER BY and an empty reference. It runs SYSTEM FLUSH LOGS only to materialize every enabled system log table, then checks that none has a non-default sorting key. It reads no log rows.

The global SYSTEM FLUSH LOGS blocks up to the 180s waitFlush timeout (SystemLogBase.cpp) draining the server-wide log queues (query_metric_log, trace_log, ...). Under many concurrent parallel tests that shared backlog can exceed 180s, producing:

Code: 159. DB::Exception: Timeout exceeded (180 s) while flushing system log 'DB::SystemLogQueue<DB::QueryMetricLogElement>'. (TIMEOUT_EXCEEDED)

CIDB, last 180 days: every timeout failure (18, excluding one unrelated Fast test) is on a parallel + slow-backend lane (coverage, s3 storage, tsan). 0 on master. On the failing runs CI reruns pass (e.g. 38/38 on PR #109245), so it is contention, not randomized settings.

Fix: add no-parallel so the test runs in the sequential phase, after the parallel flood ends, when no other test is feeding the shared queues; the flush then drains only the tiny residual backlog. no-llvm-coverage kept (coverage instrumentation slows the flush enough to time out even on that residual). The sorting-key check is unchanged.

The test runs SYSTEM FLUSH LOGS only to materialize every system log table
so it can check their sorting keys; it reads no log rows. The global flush
blocks up to the 180s waitFlush timeout (SystemLogBase.cpp) draining the
server-wide log queues (query_metric_log, trace_log, ...). Under many
concurrent parallel tests that backlog can exceed 180s, producing
Code: 159 TIMEOUT_EXCEEDED. All 18 such failures over 180 days are on
parallel + slow-backend lanes (coverage, s3 storage, tsan); 0 on master;
CI reruns pass 38/38 (contention, not randomized settings).

Add no-parallel so the test runs in the sequential phase, after the
parallel flood ends, when no other test is feeding the shared queues.
Keep no-llvm-coverage.

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

groeneai commented Jul 3, 2026

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Mechanism is deterministic: all 18 timeout failures over 180 days are the same Code: 159 Timeout exceeded (180 s) while flushing system log 'QueryMetricLogElement'/'TraceLogElement'. The exact 180s+ server-wide backlog cannot be manufactured on a single local server (it needs the full parallel test flood), but CIDB's --diagnose-random-settings shows reruns pass 38/38, confirming it is contention, not a settings/data bug.
b Root cause explained? SYSTEM FLUSH LOGS (global) blocks up to the 180s waitFlush timeout (SystemLogBase.cpp) draining the server-wide log queues (query_metric_log, trace_log, ...). Under many concurrent parallel tests the shared backlog can exceed 180s to drain, so the flush times out. The test only needs the log tables materialized (to read their sorting_key); it reads no log rows.
c Fix matches root cause? Yes. no-parallel runs the test in the sequential phase, after the parallel flood ends, when no other test is feeding the shared queues, so the flush drains only the tiny residual backlog. This targets the contention directly rather than widening a bound or hiding the failure.
d Test intent preserved / new tests added? Preserved. The sorting-key guard (all system MergeTree tables must use the default sorting key) is byte-for-byte unchanged; only the scheduling phase changes. Verified 5/5 pass and the runner reports "0 parallel tests, 5 sequential tests".
e Both directions demonstrated? Partial by nature: failure = contention timeout that requires the real parallel CI load (not locally forcible). Confirmed the test passes on a healthy build both directly and through clickhouse-test, and that no-parallel correctly routes it to the sequential phase. The 0-master / reruns-pass CIDB evidence shows the fix removes the only failure condition.
f Fix is general across code paths? N/A (test-scheduling fix, not a code bug).
g Fix generalizes across inputs (params/datatypes/wrappers)? N/A (test-scheduling fix, not a code bug).
h Backward compatible? (maintainer-approved exception only) N/A (test-only change; no product behavior, setting default, or format changed).
i Invariants and contracts preserved? N/A (test-only change).

Session id: cron:clickhouse-worker-slot-9:20260703-202800

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

clickhouse-gh Bot commented Jul 3, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [c15b95f]

Summary: ✅


AI Review

Summary

I reviewed the current PR diff and the surrounding runner behavior for tests/queries/0_stateless/03096_order_by_system_tables.sql. The change is limited to reclassifying the test as no-parallel and updating the rationale comment. In the current harness, no-parallel tests still run in a single serial phase after the parallel pool drains, the affected CI variants keep sequential shards for the same environments, and the existing no-llvm-coverage tag still routes the test into amd_binary_excluded_from_llvm. I did not find a correctness or coverage regression in the patch.

Final Verdict

✅ No blocking issues found.

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Jul 3, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 85.89% 85.91% +0.02%
Functions 91.47% 91.47% +0.00%
Branches 78.53% 78.56% +0.04%

Changed lines: No C/C++ source files changed — skipping uncovered code analysis.

Newly covered by added/modified tests: 115 line(s), 2 function(s) across 46 file(s) · Details

Top files
  • src/Functions/TimeSeries/TimeSeriesTagsFunctionHelpers.cpp: 7 line(s)
  • src/Processors/Transforms/MergingAggregatedTransform.cpp: 7 line(s)
  • src/Functions/array/arrayShiftRotate.cpp: 6 line(s)
  • src/Functions/FunctionsCodingIP.cpp: 5 line(s)
  • src/Functions/timestamp.cpp: 5 line(s)

Full report

@groeneai

groeneai commented Jul 4, 2026

Copy link
Copy Markdown
Collaborator Author

CI finish ledger — 7f31257

Every failure below has an owner: a fixing PR (ours or external), or a full-effort fix task whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
Stateless tests (amd_debug, parallel) / 04061_spilling_hash_join_overflow_limits flaky (14 PRs / 2 master, 30d) #109334 (ours, open)
Fast test (arm_darwin) / 03321_forwarded_for infra (macOS runner missing pandas; 10 PRs / 0 master) #108859 (external, merged)
Fast test (arm_darwin) / 04056_npy_large_shape_validation infra (macOS runner missing numpy; 11 PRs / 0 master) #108859 (external, merged)
CH Inc sync - CH Inc sync (private, not actionable)

None PR-caused (#109365 changes only tests/queries/0_stateless/03096_order_by_system_tables.sql). The macOS numpy/pandas ModuleNotFoundError class was fixed by #108859 (merged 2026-07-03; runner hosts re-provisioning); 04061 is owned by our open fix #109334.

Session id: cron:our-pr-ci-monitor:20260704-013000

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - c15b95f

CI is fully finished on this head with no failing checks, so there is nothing to
disposition. Recording the ledger for completeness.

Session id: cron:our-pr-ci-monitor:20260729-083000

@alexey-milovidov alexey-milovidov self-assigned this Jul 29, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Jul 29, 2026
Merged via the queue into ClickHouse:master with commit 7d64097 Jul 29, 2026
179 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 Jul 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