Skip to content

Remove flaky text_log assertions from test 03312_line_numbers - #100715

Closed
groeneai wants to merge 1 commit into
ClickHouse:masterfrom
groeneai:fix-03312-line-numbers
Closed

groeneai wants to merge 1 commit into
ClickHouse:masterfrom
groeneai:fix-03312-line-numbers

Conversation

@groeneai

@groeneai groeneai commented Mar 25, 2026 •

Copy link
Copy Markdown
Collaborator

Remove two flaky system.text_log assertions from test 03312_line_numbers. The text_log checks were non-deterministic because text log ingestion is asynchronous and SYSTEM FLUSH LOGS does not guarantee all entries are materialized. The remaining query_log assertions are deterministic and fully cover script_query_number / script_line_number tracking.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=100699&sha=d3364a856816a3c582441841e5a85806271c9a6f&name_0=PR&name_1=Stateless%20tests%20%28amd_tsan%2C%20parallel%2C%201%2F2%29
#100699

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 not required for this change.

The two `SELECT 'Ok' FROM system.text_log` assertions were flaky
because text log writes are asynchronous and `SYSTEM FLUSH LOGS`
does not guarantee all async text-log entries are fully materialized.
CI logs from a failing run (PR ClickHouse#100699, amd_tsan) show ~430K messages
dropped from `AsyncLogMessageQueue` due to queue overflow during the
test's execution window, confirming the messages were permanently lost.

The remaining `query_log` assertions are deterministic (synchronous
flush) and fully cover the feature under test: correct
`script_query_number` and `script_line_number` propagation.

https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=100699&sha=d3364a856816a3c582441841e5a85806271c9a6f&name_0=PR&name_1=Stateless%20tests%20%28amd_tsan%2C%20parallel%2C%201%2F2%29

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@CLAassistant

CLAassistant commented Mar 25, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@groeneai

Copy link
Copy Markdown
Collaborator Author

Detailed Analysis

What failed

Test 03312_line_numbers intermittently fails because its two SELECT 'Ok' FROM system.text_log ... assertions return empty results. The expected output has 8 lines: 6 from system.query_log (QueryStart/QueryFinish for two queries) and 2 Ok lines from system.text_log lookups. In failing runs, all 6 query_log lines are present and correct, but both Ok lines are missing.

Failure history (last 30 days): amd_tsan, amd_debug, amd_msan, amd_asan_ubsan, arm_binary — all on unrelated PRs, confirming this is pre-existing flakiness.

Root cause: AsyncLogMessageQueue overflow

Log messages destined for system.text_log travel through two async queues before reaching the table:

  1. Queue 1 — AsyncLogMessageQueue (src/Loggers/OwnSplitChannel.cpp): LOG_DEBUG calls enqueue messages here via enqueueMessage
  2. Queue 2 — SystemLogQueue<TextLogElement>: the async thread in runTextLog drains Queue 1 and pushes structured elements here for the saving thread to INSERT

By contrast, system.query_log entries are pushed synchronously into SystemLogQueue<QueryLogElement> during query execution — no async intermediate queue. This is why query_log assertions are deterministic and text_log assertions are not.

Evidence from CI logs

The server log from the failing run (PR #100699, amd_tsan) shows massive queue overflow during the test's execution window:

2026.03.25 13:45:00 <Warning> AsyncLogMessageQueue: We've dropped 60885 log messages in this channel due to queue overflow
2026.03.25 13:45:04 <Warning> AsyncLogMessageQueue: We've dropped 204806 log messages in this channel due to queue overflow
2026.03.25 13:45:07 <Warning> AsyncLogMessageQueue: We've dropped 164079 log messages in this channel due to queue overflow

~430K messages dropped in a 7-second window. The test's database (test_2hp5rf32) was created at 13:45:04 and queries 1-2 executed immediately after. Their LOG_DEBUG messages from executeQuery (which the text_log assertions search for) were permanently dropped — they never reached either the server log file or system.text_log. The SYSTEM FLUSH LOGS on thread 4900 took 25.4 seconds (TSan overhead) and flushed everything that was in the queue, but the test's messages were already gone.

Why the fix is correct

  • The query_log assertions (line 11 of the .sql) fully and deterministically verify that script_query_number and script_line_number are correctly computed, propagated, and persisted end-to-end (client → server → query_log). These are schema-level columns, not derived from log text.
  • The text_log assertions test a debug log format string and the async text_log pipeline — neither is the test's purpose.
  • Direct precedent: PR Fix flaky test 01165_lost_part_empty_partition #100434 (merged 2026-03-24) removed identical flaky text_log assertions from test 01165_lost_part_empty_partition for the same reason.

@clickhouse-gh

clickhouse-gh Bot commented Mar 25, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [68104ed]

Summary: ✅


AI Review

Summary

This PR removes two flaky system.text_log assertions from 03312_line_numbers and updates the reference output accordingly. The remaining checks on system.query_log still deterministically validate script_query_number and script_line_number, which matches the stated goal and linked CI failure mode. I did not find correctness, safety, performance, or compliance issues in the diff.

ClickHouse Rules
Item Status Notes
Deletion logging ➖
Serialization versioning ➖
Core-area scrutiny ➖
No test removal ✅
Experimental gate ➖
No magic constants ✅
Backward compatibility ✅
SettingsChangesHistory.cpp ➖
PR metadata quality ✅
Safe rollout ✅
Compilation time ✅
Final Verdict
  • Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Mar 25, 2026
@antonio2368 antonio2368 added the can be tested Allows running workflows for external contributors label Mar 25, 2026
@Algunenano

Copy link
Copy Markdown
Member

This is caused by too many throttler logs: #100228

@serxa @alexey-milovidov We have way too many logs now:

● Here's the problem. The LOG_TRACE at line 104 fires on every single call to Throttler::throttle where max_speed > 0 but the throttler    
  doesn't need to sleep (tokens are sufficient). This is the hot path — every read/write I/O operation goes through the throttler.
                                                                                                                                           
  In the TSAN run, local_read_query alone generated 125K trace messages in one minute, and local_write_query another 17K. Together with    
  other throttler types, this produced ~145K messages/minute, which overflowed the AsyncLogMessageQueue (default capacity ~10M entries, but
   the queue is shared across all parallel tests), causing ~430K messages to be dropped — including the text_log entries that test         
  03312_line_numbers was looking for.

  Root cause: Commit 7cec67c4c68 ("Add trace logging to Throttler") added a LOG_TRACE on the "not sleeping" fast path of the throttler.    
  This path is hit on every I/O operation when a throttler has max_speed > 0 but there are enough tokens — which is essentially always
  under normal load. In TSAN builds (which are slower), the log queue fills up faster than it can be drained.                              
                               
  The fix in PR #100715 is a workaround — it removes the text_log assertions from the test since they're inherently racy. But the actual   
  fix should be to remove or downgrade the "Not sleeping" log line (line 104), since it provides no useful diagnostic information (the
  interesting case is when the throttler does sleep) and generates extreme log volume.                                                     

Basically this only works because async logger works as it is, with sync logger the performance would be really affected

@Algunenano Algunenano self-assigned this Mar 25, 2026

@Algunenano Algunenano left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix is avoiding overflowing text_log

@antonio2368

Copy link
Copy Markdown
Member

Yes that is correct, but the analysis still made sense to me. If we don't need to check text_log why do it?

@Algunenano

Copy link
Copy Markdown
Member

It's checking that the text_log shows line numbers, e.g. query 1, line 4. This is why the test was added (both for text_log and query_log)

@antonio2368

Copy link
Copy Markdown
Member

Which is just same info from query log printed (script_query_number, script_line_number). But okay maybe it makes sense to check we are printing that exact info.

@Algunenano

Copy link
Copy Markdown
Member

They are different paths and different logs, it's better to test them both if we want the feature in both

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants