Skip to content

Fix flaky text_log/query_log scans on busy CI workers (03312, 03335 azure/s3, 03735) - #103290

Merged
alexey-milovidov merged 2 commits into
ClickHouse:masterfrom
groeneai:fix-text-log-max-rows-to-read-03312-03335
May 23, 2026
Merged

alexey-milovidov merged 2 commits into
ClickHouse:masterfrom
groeneai:fix-text-log-max-rows-to-read-03312-03335

Conversation

@groeneai

@groeneai groeneai commented Apr 21, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Several stateless tests fail on CI workers whose system.text_log has accumulated more than 20M rows, with:

Code: 158. DB::Exception: Limit for rows (controlled by 'max_rows_to_read' setting)
exceeded, max rows: 20.00 million, current rows: 22.96 million. (TOO_MANY_ROWS)

The test queries scan system.text_log (or system.query_log) with LIKE predicates that require a full-table read to find the matching messages, so they hit the randomized max_rows_to_read ceiling the test runner injects into CLICKHOUSE_CLIENT_OPT. The per-failure CI diagnostic confirms the failures reproduce both with AND without random settings — this is a deterministic environmental flake, not a settings randomization issue.

This PR fixes four tests with the same root cause:

  • 03312_line_numbers.sql
  • 03335_empty_blobs_on_azure.sh
  • 03335_empty_blobs_on_s3.sh (added 2026-05-21)
  • 03735_excessive_buffer_flush.sql (added 2026-05-21)

Fix

Add SETTINGS max_rows_to_read = 0 to each system.text_log (and the system.query_log) query, following the well-established pattern in other tests such as 02935_parallel_replicas_settings.sql, 02813_starting_in_text_log.sql, 03096_text_log_format_string_args_not_empty.sh, and 01165_lost_part_empty_partition.sql.

For 03312_line_numbers.sql the fix is applied at the query level rather than as a top-of-file SET, because the test asserts on script_line_number — adding any line above the tracked queries would shift them and break the reference.

CIDB evidence (30 days)

Verification

  • Without the fix: running the unmodified 03312_line_numbers.sql with CLICKHOUSE_CLIENT_OPT="--max_rows_to_read=1000" reliably reproduces
    Code: 158. DB::Exception: ... Limit for rows ...
    (query: SELECT 'Ok' FROM system.text_log ... LIMIT 1;)
    
  • With the fix: 30/30 runs pass at that same restrictive limit with full CI randomization enabled. 03735_excessive_buffer_flush was additionally verified locally (1 OK / 21s) after the new commit.

CI report

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

...

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

Version info

  • Merged into: 26.6.1.113

Both tests fail with `Limit for rows (controlled by 'max_rows_to_read'
setting) exceeded, max rows: 20.00 million, current rows: 22.19 million.
(TOO_MANY_ROWS)` when run on CI workers whose `system.text_log` has
accumulated more than 20M rows. The test queries scan `system.text_log`
with LIKE predicates that require a full-table read to find matching
messages, hitting the randomized `max_rows_to_read` ceiling.

Fix: add `SETTINGS max_rows_to_read = 0` to the `system.text_log` and
`system.query_log` queries, following the established pattern used in
`02935_parallel_replicas_settings.sql`, `02813_starting_in_text_log.sql`,
`03096_text_log_format_string_args_not_empty.sh`, and many others.

For `03312_line_numbers.sql`, the fix is applied at the query level
(not as a top-of-file `SET`) because the test asserts on
`script_line_number` — adding any line before the tracked queries would
shift them and break the reference.

Verification:
- Without the fix: test reliably FAILS with
  `CLICKHOUSE_CLIENT_OPT="--max_rows_to_read=1000"` on the same query
  pattern CI hits.
- With the fix: 30/30 runs pass with the same restrictive setting plus
  full randomization.
@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @alexey-milovidov — could you review this? It fixes two chronic flaky tests (03312, 03335) that fail on busy CI workers when system.text_log exceeds 20M rows; the fix adds SETTINGS max_rows_to_read = 0 to the text_log/query_log scans, following the same pattern as PR #103287 and PR #103226.

@nikitamikhaylov nikitamikhaylov added the can be tested Allows running workflows for external contributors label Apr 22, 2026
@clickhouse-gh

clickhouse-gh Bot commented Apr 22, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [377453f]

Summary: ✅


AI Review

Summary

This PR removes deterministic TOO_MANY_ROWS flakes in four stateless tests by setting max_rows_to_read = 0 on the specific system.text_log / system.query_log scans that can require full-table reads on busy CI workers. The change is tightly scoped to test queries, keeps test behavior intact, and follows the same mitigation pattern already used in other log-based tests.

Final Verdict
  • Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Apr 22, 2026
Two more stateless tests hit the same `system.text_log` randomized
`max_rows_to_read = 20000000` cap as the previously-fixed `03312` /
`03335_empty_blobs_on_azure`:

- `03335_empty_blobs_on_s3.sh` is the S3 sibling of the Azure variant;
  both `Skipped empty blobs after 1 insert:` and
  `Skipped empty blobs after 2 inserts and merge:` queries scan
  `system.text_log` with a `LIKE` predicate.
- `03735_excessive_buffer_flush.sql` ends with a `system.text_log` scan
  using `logger_name LIKE format('%StorageBuffer ({}.%', ...)` to count
  Buffer flush logs.

Both reproduce the chronic CI flake on `Stateless tests (arm_binary,
parallel)` workers whose `text_log` has accumulated >20M rows.
Per-failure CI diagnostic confirms the failure is environmental
(reproduces with AND without random settings), not setting-driven:
`03335_empty_blobs_on_s3` 32/32 fail with randomization, 68/68 without;
`03735_excessive_buffer_flush` 3/3 with, 3/3 without. Error message
verbatim:

    Code: 158. DB::Exception: Limit for rows (controlled by
    'max_rows_to_read' setting) exceeded, max rows: 20.00 million,
    current rows: 22.96 million. (TOO_MANY_ROWS)

Fix: append `SETTINGS max_rows_to_read = 0` to each `system.text_log`
query, following the exact pattern already applied earlier in this PR
to `03335_empty_blobs_on_azure.sh` and `03312_line_numbers.sql`, and
established in 15+ other tests (`02935`, `02813`, `03096`, `01165`, ...).
@groeneai groeneai changed the title Fix flaky tests 03312_line_numbers and 03335_empty_blobs_on_azure on busy CI workers Fix flaky text_log/query_log scans on busy CI workers (03312, 03335 azure/s3, 03735) May 21, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author

Extended this PR to cover two more sibling tests that hit the same system.text_log max_rows_to_read = 20000000 cap on busy CI workers:

  • 03335_empty_blobs_on_s3.sh — S3 sibling of the already-fixed 03335_empty_blobs_on_azure.sh. Two system.text_log LIKE scans get the same SETTINGS max_rows_to_read = 0 clause.
  • 03735_excessive_buffer_flush.sql — final system.text_log scan using logger_name LIKE format('%StorageBuffer ({}.%', ...) gets the same clause.

The fix in the new commit is mechanically identical to the merged 03335_azure / 03312 pattern.

Pre-PR validation gate

a) Deterministic repro? Yes — Code: 158. ... Limit for rows ... current rows: 22.96 million. (TOO_MANY_ROWS) from CI test_context_raw. The runner's diagnose-random-settings step reports 03335_empty_blobs_on_s3 32/32 fail WITH randomization and 68/68 fail WITHOUT; 03735_excessive_buffer_flush 3/3 with and 3/3 without — environmental, not setting-driven.

b) Root cause explained? system.text_log on the affected CI workers holds >20M rows; the tests scan it with a LIKE predicate so the executor must read the full table; the CI runner randomizes max_rows_to_read = 20_000_000 for queries; the count of rows read exceeds the cap and the executor throws TOO_MANY_ROWS. Setting max_rows_to_read = 0 at the query level exempts that single read from the cap.

c) Fix matches root cause? Yes — max_rows_to_read = 0 directly removes the limit that the executor is checking. Same fix used in 15+ existing tests (02935, 02813, 03096, 01165, ...). No symptom-widening, no broad no-random-* tag.

d) Test intent preserved? Yes — the queries still scan the same rows with the same predicates and still produce the same output. Only the artificial row-count cap on the system.text_log read is lifted; the max2(count(), 20) cap inside 03735 is a separate test-defined assertion, untouched.

e) Both directions demonstrated? The failure direction is established by CI: deterministic TOO_MANY_ROWS from test_context_raw on the failing runs, 32/32 and 68/68 without the fix. The pass direction: the merged azure variant — fixed with the identical pattern in the first commit of this PR — passes 30/30 with CLICKHOUSE_CLIENT_OPT="--max_rows_to_read=1000" + full randomization. Locally I additionally ran the new 03735_excessive_buffer_flush against a fresh local server after the commit: 1 OK / 21.27s. 03335_empty_blobs_on_s3 requires an S3 disk and only runs in CI's S3 environment; EXPLAIN SYNTAX parses both modified queries cleanly.

f) Fix is general? Same pattern now applied symmetrically to the S3 sibling and to the Buffer-engine variant — no remaining system.text_log LIKE-scan tests in this PR have an unaddressed cap.

cc @alexey-milovidov — same scope as before, just two more sibling tests folded in. CI is re-running now.

— Session: cron:clickhouse-ci-task-worker:20260521-004500

@clickhouse-gh

clickhouse-gh Bot commented May 21, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.10% 84.10% +0.00%
Functions 91.40% 91.40% +0.00%
Branches 76.50% 76.50% +0.00%

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

Newly covered by added/modified tests: 490 line(s), 52 function(s) across 139 file(s) · Details

Top files
  • src/Common/QueryFuzzer.cpp: 36 line(s)
  • src/Storages/StorageReplicatedMergeTree.cpp: 36 line(s)
  • src/Backups/BackupEntriesCollector.cpp: 31 line(s), 2 function(s)
  • src/Storages/MergeTree/IMergeTreeDataPart.cpp: 27 line(s)
  • src/AggregateFunctions/TimeSeries/AggregateFunctionTimeseriesLinearRegression.h: 14 line(s), 32 function(s)

Full report

@alexey-milovidov alexey-milovidov self-assigned this May 23, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue May 23, 2026
Merged via the queue into ClickHouse:master with commit 83e3672 May 23, 2026
166 checks passed
@robot-ch-test-poll1 robot-ch-test-poll1 added the pr-synced-to-cloud The PR is synced to the cloud repo label May 23, 2026
DavidHe-2008 pushed a commit to DavidHe-2008/ClickHouse that referenced this pull request Jun 1, 2026
…ows-to-read-03312-03335

Fix flaky text_log/query_log scans on busy CI workers (03312, 03335 azure/s3, 03735)
pull Bot pushed a commit to AnotherGenZ/ClickHouse that referenced this pull request Sep 27, 2026
04640_deduplication_log_reattach_no_phantom_blobs and
05258_deduplication_log_alter_window_no_phantom_blobs end with a count()
over system.text_log that filters only on level and message. Neither column
is in the table's key (ORDER BY (event_date, event_time)), so the read
selects every granule, and once a long parallel run has logged more than
20 million rows the query fails with TOO_MANY_ROWS against
max_rows_to_read = 20000000 from tests/config/users.d/limits.yaml (seen in
the CH Inc sync check: "current rows: 20.31 million", query 15, line 39 of
05258).

Apply the two levers already used for this family of tests:
- event_date >= yesterday() AND event_time >= now() - 600, the convention
  of 9eaf025 and b8c39c9, so the primary key prunes the read to
  the last ten minutes;
- SETTINGS max_rows_to_read = 0, as in ClickHouse#103290, because the window alone
  can exceed the limit on a log-heavy run (a time-bounded query of
  00956_sensitive_data_masking failed at 21.28 million rows in the CI of
  PR 103706).

The bound cannot hide a real error row: the row is logged by the test's
own ATTACH shortly before the check, these tests are killed after 600 s
(the runner's --timeout default, which CI keeps; they are not tagged
long), and yesterday() leaves a day of slack against the randomized
session_timezone.

Validated on master e5b8853 with the CI config overlay and a local
MinIO, with a text_log of 21 million rows: the unmodified tests fail 6/6
with the same TOO_MANY_ROWS, the fixed ones pass 6/6, also with 21 million
rows inside the window (their SELECT then reads 21.02 million rows); a
corrupted deduplication log is still counted (base and fixed check both
return 1); 100/100 randomized runs pass.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
zvonand pushed a commit to zvonand/ClickHouse that referenced this pull request Oct 8, 2026
The final assertion joined `system.text_log` with no predicate, so the
whole table was read as the join's build side and, on a log-heavy CI
server, exceeded the `max_rows_to_read = 20000000` of
`tests/config/users.d/limits.yaml` (`TOO_MANY_ROWS`, query 35, line 53,
reported from the CH Inc sync check on ClickHouse#100394).

Read `text_log` through a subquery bounded by its primary key to the
last 10 minutes and lift the row limit for that statement, as ClickHouse#103290
and ClickHouse#122525 do. The bound stays inside the subquery so the `LEFT JOIN`
keeps the queries that log no row store line. The joined rows are
written by the test's own queries, and the test is killed after 600 s,
so they are always inside the window.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.

4 participants