Skip to content

Fix exception in system log flush when table has extra columns - #102316

Merged
alexey-milovidov merged 22 commits into
masterfrom
fix-system-log-column-mismatch
May 1, 2026
Merged

alexey-milovidov merged 22 commits into
masterfrom
fix-system-log-column-mismatch

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Apr 10, 2026 •

Copy link
Copy Markdown
Member

The SystemLog::flushImpl method creates an INSERT query without an explicit column list. When the system log table has been altered to include extra columns (e.g. by a fuzzer or a user), the INSERT pipeline expects all table columns, but the block only contains the columns from getColumnsDescription. This causes a "Invalid number of columns in chunk pushed to OutputPort. Expected 23, found 22" exception.

Fix by explicitly specifying column names in the INSERT query, so that extra columns added to the table get their default values instead of causing a mismatch.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=a4b72fe91e7c174e0a5347a49d32b5b3e5719d47&name_0=MasterCI&name_1=BuzzHouse%20%28amd_tsan%29

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.5.1.216

The `SystemLog::flushImpl` method creates an INSERT query without an
explicit column list. When the system log table has been altered to
include extra columns (e.g. by a fuzzer or a user), the INSERT pipeline
expects all table columns, but the block only contains the columns from
`getColumnsDescription`. This causes a "Invalid number of columns in
chunk pushed to OutputPort. Expected 23, found 22" exception.

Fix by explicitly specifying column names in the INSERT query, so that
extra columns added to the table get their default values instead of
causing a mismatch.

https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=a4b72fe91e7c174e0a5347a49d32b5b3e5719d47&name_0=MasterCI&name_1=BuzzHouse%20%28amd_tsan%29

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

clickhouse-gh Bot commented Apr 10, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [23f5def]

Summary: ✅


AI Review

Summary

This PR fixes SystemLog::flushImpl for altered system log tables by inserting with an explicit column list, and adds a clickhouse-local regression test that reproduces the column-mismatch exception scenario. I did not find new correctness, safety, performance, or compatibility issues in the current PR state.

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 ✅
No large/binary files ✅
Final Verdict
  • Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Apr 10, 2026
@tiandiwonder tiandiwonder self-assigned this Apr 10, 2026
SET log_processors_profiles = 1;

SELECT 1 FORMAT Null;
SYSTEM FLUSH LOGS;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should be SYSTEM FLUSH LOGS processors_profile_log

@@ -0,0 +1,18 @@
-- Verify that system log tables can be flushed after ALTER TABLE adds a column.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Missing -- Tags: no-parallel
The test does ALTER TABLE system.processors_profile_log ADD COLUMN / DROP COLUMN on a global system
table. Without the tag, it races with any concurrent test that flushes logs.

alexey-milovidov and others added 2 commits April 10, 2026 02:34
…ile_log`

The test alters a global system table (`system.processors_profile_log`),
so it must not run in parallel with other tests that flush logs.
Also flush only the specific log table instead of all logs.

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

@tiandiwonder tiandiwonder left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

better to test query_log as well.

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Now ok.

@alexey-milovidov

Copy link
Copy Markdown
Member Author

Not quite... I'll have to convert to an sh test and configure clickhouse-local accordingly...

alexey-milovidov and others added 3 commits April 10, 2026 06:05
…test `query_log`

The `.sql` test failed in CI because `ALTER TABLE ... DROP COLUMN` on
`system.processors_profile_log` is forbidden when materialized views
reference the table. Convert to a `.sh` test so the cleanup can
suppress errors from dependent views.

Also add coverage for `query_log` per review feedback.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Add `initializeSystemLogs` call to `LocalServer` so that
`clickhouse-local` creates system log tables (like `query_log`,
`processors_profile_log`) when they are configured via `--config-file`.
Without a config, this is a no-op.

Rewrite the test to run entirely in `clickhouse-local` with a custom
config, avoiding ALTER on the shared server where materialized views
prevent column modifications.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Comment thread programs/local/LocalServer.cpp Outdated

/// Initialize system logs if configured (e.g. query_log, processors_profile_log).
/// This must happen after the system database is attached.
global_context->initializeSystemLogs();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

initializeSystemLogs is now called unconditionally, even when --no-system-tables is set.

That option explicitly promises not to attach system tables, but this path can still create/start system logs (and potentially prepare system.query_log / system.processors_profile_log if configured), which violates the flag semantics and may fail in setups where the system DB is intentionally absent.

Please gate this call the same way as system table attachment, e.g.:

if (!getClientConfiguration().has("no-system-tables"))
    global_context->initializeSystemLogs();

alexey-milovidov and others added 16 commits April 12, 2026 18:16
… `query_log` query

The style check requires that any test querying `system.query_log` or
`system.query_thread_log` includes a `current_database = currentDatabase()`
condition to avoid interfering with concurrent tests.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
…alServer`

When `--no-system-tables` is set, the system database is not attached,
so initializing system logs would fail or violate the flag semantics.
Skip the call in that case, consistent with how system table attachment
is gated.

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

A default `clickhouse-local` invocation has no system log sections in the config.
Initializing `SystemLogs` regardless meant the unique pointer in `ContextSharedPart`
was written during construction and again during teardown, racing under TSan with a
concurrent read from a `BackgroundSchedulePool` worker that calls
`getBackgroundSchedulePoolLog` after a task finishes. The race surfaced as a
"Scraping system tables" failure in the `Stateless tests (amd_tsan, parallel, 1/2)`
job, since CI scrapes system tables via short-lived `clickhouse-local` processes.

Gate the call on the config actually containing at least one entry from
`LIST_OF_ALL_SYSTEM_LOGS`. The custom config used by `04093_system_log_alter_column`
declares `query_log` and `processors_profile_log`, so the regression test continues
to exercise the original fix; default invocations stop touching `system_logs`.

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

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
In `--only-system-tables` mode, `clickhouse-local` is meant to read existing
persisted system tables (the stress test harness uses this to dump
`system.query_log` after a run). Starting the system loggers there is
unnecessary and triggers a TSan-visible data race between background pool
work scheduled during system log startup and `~ContextSharedPart` resetting
`async_read_counters_thread_pool_reader` during shutdown.

CI report: #102316
TSan stack: https://s3.amazonaws.com/clickhouse-test-reports/PRs/102316/63cb4d0ded2a8ca7ef8a6825ce7295010a738235/stress_test_arm_tsan/job.log
@clickhouse-gh

clickhouse-gh Bot commented Apr 30, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.00% 84.10% +0.10%
Functions 91.10% 91.10% +0.00%
Branches 76.50% 76.50% +0.00%

Changed lines: 100.00% (22/22) · Uncovered code

Full report · Diff report

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue May 1, 2026
Merged via the queue into master with commit f60c963 May 1, 2026
165 checks passed
@alexey-milovidov
alexey-milovidov deleted the fix-system-log-column-mismatch branch May 1, 2026 05:13
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-synced-to-cloud The PR is synced to the cloud repo label May 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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