Skip to content

Make MutateTask metadata/commands drift observable - #110157

Closed
groeneai wants to merge 1 commit into
ClickHouse:masterfrom
groeneai:groeneai/observe-mutate-metadata-drift
Closed

groeneai wants to merge 1 commit into
ClickHouse:masterfrom
groeneai:groeneai/observe-mutate-metadata-drift

Conversation

@groeneai

Copy link
Copy Markdown
Collaborator

Related: #109205
Related: #105912

Changelog category (leave one):

  • Improvement

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Add a MutateTaskMetadataDriftDetected profile event (and a log warning) that fires when a mutation observes a column present in its commands but missing from the metadata snapshot under concurrent ALTERs. Previously this drift silently degraded the metadata-only ALTER MODIFY COLUMN ... Nullable optimization into a full part rewrite with no signal.

Description

Follow-up to @ alexey-milovidov's analysis on #109205 (closed): the canSkipConversionToNullable fail-open path added in #105917 replaced the #105912 SIGSEGV with if (!column_desc) return false, which is correct but silently converts a metadata/commands drift into a full rewrite. There is currently no way to tell that drift happened.

This makes that branch observable, splitting the benign "column has statistics" skip from the interesting drift skip:

  • new profile event MutateTaskMetadataDriftDetected (visible in system.part_log MutatePart ProfileEvents and system.events);
  • a LOG_WARNING naming the column and part.

No behavior change. The existing #105912 failpoint regression test (04295_105912_...) is extended to assert the event fires on the forced-drift path.

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. SYSTEM ENABLE FAILPOINT mt_mutate_task_can_skip_conversion_to_nullable_force_null_column_desc forces the null-column_desc branch on every run (existing #105912 test).
b Root cause explained? The #105917 fail-open (if (!column_desc) return false) fixed the SIGSEGV but silently turns a metadata/commands drift into a full part rewrite; there is no signal for it.
c Fix matches root cause? Yes. Adds a profile event + LOG_WARNING on exactly that branch, separated from the benign statistics skip.
d Test intent preserved / new tests? The #105912 crash-guard assertions are unchanged; the test is extended to assert the new event fires on the forced-drift path.
e Demonstrated both directions? With the failpoint on, MutateTaskMetadataDriftDetected = 1 (part_log + system.events) and the warning is logged; without it (normal MODIFY) the event stays 0.
f General, not narrow patch? Only observability is added; no code path is guarded or altered. The event covers the single drift branch.
g Generalizes across inputs? N/A (observability only; no input-dependent logic changed).
h Backward compatible? Yes. New profile event only; no setting, format, or behavior change.
i Invariants/contracts preserved? Yes. canSkipConversionToNullable returns the same value on all paths; only a counter increment + log added before the existing return false.

Session id: cron:clickhouse-worker-slot-1:20260712-134000

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @CurtizJ — small observability follow-up on the mutation path (profile event + warning on the metadata/commands drift branch in canSkipConversionToNullable, no behavior change). Context in #109205.

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

clickhouse-gh Bot commented Jul 12, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [351a942]

Summary: ❌

job_name test_name status info comment
Integration tests (amd_msan, 7/8) FAIL
test_replicated_database/test.py::test_replicated_table_structure_alter FAIL cidb, issue

AI Review

Summary

This PR makes the metadata/commands drift branch in MutateTask::canSkipConversionToNullable observable by adding a MutateTaskMetadataDriftDetected profile event, a warning log, and a focused stateless regression test. The change is narrowly scoped, the mutation task already records profile counters into system.part_log on both plain and replicated paths, and I did not find unresolved correctness, performance, compatibility, or test-evidence issues in the current diff.

Final Verdict
  • Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-improvement Pull request with some product improvements label Jul 12, 2026
@groeneai
groeneai force-pushed the groeneai/observe-mutate-metadata-drift branch from 79fb931 to 34b7cb6 Compare July 12, 2026 15:20
When ALTER MODIFY COLUMN ... Nullable(T) reaches canSkipConversionToNullable
and the target column is present in the mutation commands but missing from the
metadata snapshot (metadata and commands drifted apart under concurrent
ALTERs), the metadata-only optimization is skipped and the part is fully
rewritten. Since ClickHouse#105917 this fail-open path is silent, so a real drift only
shows up as an unexplained full rewrite.

Add a MutateTaskMetadataDriftDetected profile event and a LOG_WARNING on that
branch so the drift is observable. No behavior change. Extend the existing
ClickHouse#105912 failpoint regression test to assert the event fires.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@groeneai
groeneai force-pushed the groeneai/observe-mutate-metadata-drift branch from 34b7cb6 to 351a942 Compare July 12, 2026 19:03
@groeneai

Copy link
Copy Markdown
Collaborator Author

Pushed 351a942 fixing the two 04295 test failures on the previous head:

  1. Regular runs (asan/tsan, --ratio_of_defaults_for_sparse_serialization 0.0): the randomized sparse serialization made y sparse, so canSkipConversionToNullable returned early at the getKindStack() != DEFAULT guard, never reaching the drift branch, so the event was 0. Pinned ratio_of_defaults_for_sparse_serialization = 1.0 in the CREATE (verified: sparse -> event=0, default -> event=1; the CREATE SETTINGS overrides the runner-injected value).

  2. Flaky check (concurrent same-test): mt_mutate_task_..._force_null_column_desc is a process-global failpoint, so concurrent instances race on ENABLE/DISABLE FAILPOINT (one run DISABLEs it before another run mutation observes it). Added no-parallel; the failpoint is true server-global state, which is the documented last-resort case for the tag.

Validated locally on debug build 351a942: 50 serial runs and 50 runs under -j 8 (serialized by no-parallel) all pass with randomization on.

@clickhouse-gh

clickhouse-gh Bot commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 85.80% 85.80% +0.00%
Functions 92.70% 92.70% +0.00%
Branches 77.90% 78.00% +0.10%

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

Full report · Diff report

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger — 351a942

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
Integration tests (amd_msan, 7/8) / test_replicated_database::test_replicated_table_structure_alter flaky (191 hits / 128 unrelated PRs / 22 master in 30d; unrelated to this PR's MutateTask/ProfileEvents change) #110030 (ours, open)

The PR's own extended test 04295_105912_modify_column_to_nullable_with_statistics now passes on this head (fixed in 351a942).

Session id: cron:our-pr-ci-monitor:20260712-233000

@rschu1ze

rschu1ze commented Jul 14, 2026 •

Copy link
Copy Markdown
Member

Closing.

Reason 1: Mutations are metadata-only only on a best-effort basis.

Reason 2: Adding a profile event with a generic name for a very specific situation (conversion to Nullable) is doubtful.

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-improvement Pull request with some product improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants