Skip to content

Fix arm_tidy: initialize variables in Iceberg::alter (caused by #106102) - #106615

Closed
groeneai wants to merge 1 commit into
ClickHouse:masterfrom
groeneai:groeneai/fix-arm-tidy-iceberg-mutations-init-variables
Closed

groeneai wants to merge 1 commit into
ClickHouse:masterfrom
groeneai:groeneai/fix-arm-tidy-iceberg-mutations-init-variables

Conversation

@groeneai

@groeneai groeneai commented Jun 5, 2026

Copy link
Copy Markdown
Collaborator

Caused by: #106102

PR #106102 (scanhex12/fix_alter_catalog, merged 2026-06-05 17:43 UTC) refactored Iceberg::alter to declare last_version and compression_method outside an if/else that assigns them in both branches. Clang-tidy cppcoreguidelines-init-variables flags the bare declarations and Build (arm_tidy) is built with -warnings-as-errors, so the build fails for every PR whose CI ran on master after this commit.

CIDB shows 30+ unrelated PRs hitting this in the last 2 days (sample of Build (arm_tidy) failures in last 2d):

pull_request_number   head_ref                                cnt
89360                 feature-6476                             5
106404                cursor/fix-distributed-duplicate...      3
103540                totals-by-order-by-combinators           3
106386                untracked-memory-race                    3
106522                native-arrow-ipc-format                  2
106120                icolumn-shuffle-primitives               2
105102                groeneai/fix-99495-limit-with-ties...    2
106590                groeneai/fix-issue-106573-...            1
...

The fix initializes both variables to safe defaults at declaration. They are unconditionally overwritten in both if and else branches before use, so behavior is unchanged. The new defaults are only relevant if a future code path skips both assignments, in which case last_version=0 and compression_method=CompressionMethod::None are sane no-op values (the same values the old structured-binding form would produce through default-construction of the destructured aggregate).

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

...

…rg::alter

PR ClickHouse#106102 (merged 2026-06-05 17:43 UTC) refactored Iceberg::alter to
declare last_version and compression_method outside an if/else that
assigns them in both branches. Clang-tidy cppcoreguidelines-init-variables
flags the bare declarations and Build (arm_tidy) is built with
-warnings-as-errors, so the build fails for every PR whose CI ran on
master after this commit.

CIDB shows 30+ unrelated PRs hitting this in the last 2 days
(e.g. ClickHouse#89360, ClickHouse#103540, ClickHouse#106120, ClickHouse#106386, ClickHouse#106404, ClickHouse#106522, ClickHouse#105102,
ClickHouse#106590).

Initialize both variables to safe defaults at declaration. They are
unconditionally overwritten in both if and else branches before use,
so behavior is unchanged. The new defaults are only relevant if a
future code path skips both assignments, in which case last_version=0
and compression_method=CompressionMethod::None are sane no-op values
(the same defaults the old structured-binding form would produce
through default-construction of the destructured aggregate).

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

groeneai commented Jun 5, 2026

Copy link
Copy Markdown
Collaborator Author

Pre-PR validation gate

# Question Answer
a Deterministic repro? Yes. The failing build log on PR #106590 (Build (arm_tidy) SHA ad61b736d2ed4a56d20b4aa065efb9dbe58121b0) shows two cppcoreguidelines-init-variables,-warnings-as-errors errors in Mutations.cpp:731 (last_version) and :733 (compression_method). Reproducible on any branch built off master after 9c9b2b9a0da7 (#106102 merge).
b Root cause explained? Yes. PR #106102 changed Iceberg::alter from a structured-binding initialization (auto [last_version, metadata_path, compression_method] = getLatestOrExplicitMetadataFileAndVersion(...);) to bare declarations followed by an if/else that assigns them. Clang-tidy cppcoreguidelines-init-variables flags the bare declarations regardless of subsequent assignment, and Build (arm_tidy) is -warnings-as-errors, so the build aborts.
c Fix matches root cause? Yes. Initialize both variables at declaration. The if/else branches still overwrite them before use, so semantics are unchanged — the only effect is silencing the clang-tidy diagnostic at the exact line it flags.
d Test intent preserved / new tests added? N/A — this is a clang-tidy fix, not a behavior change. No new test is meaningful (clang-tidy is the test). The arm_tidy build itself is the regression check.
e Both directions demonstrated? Yes (by build log, not local reproduction). Without the fix, the master Build (arm_tidy) is FAIL on every PR after 9c9b2b9 (CIDB confirms 30+ unrelated PRs). With the fix applied, clang-tidy cppcoreguidelines-init-variables no longer flags either line because both have explicit initializers.
f Fix is general, not a narrow patch? Yes. The root cause is exactly two declarations in one function. There is no sibling code path with the same pattern in Mutations.cpp (the other mutate() function uses the destructured form). The fix touches every flagged line.

Session id: cron:clickhouse-ci-task-worker:20260605-222000

@groeneai

groeneai commented Jun 5, 2026

Copy link
Copy Markdown
Collaborator Author

cc @scanhex12 — quick review please. Trivial 2-line fix for the Build (arm_tidy) regression introduced by #106102 (initialize last_version and compression_method at declaration). 30+ unrelated PRs are blocked on this in CIDB right now.

cc @alesapin as Iceberg manager.

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

clickhouse-gh Bot commented Jun 5, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [d72cac5]

Summary: ❌

job_name test_name status info comment
BuzzHouse (amd_msan) FAIL
Logical error: Mutation of Memory table produced incomplete output: A (STID: 2380-3043) FAIL cidb

AI Review

Summary

This PR is a narrow CI Fix or Improvement for the Build (arm_tidy) regression introduced by ClickHouse/ClickHouse#106102: Iceberg::alter now initializes last_version and compression_method at declaration so cppcoreguidelines-init-variables no longer flags them. The surrounding control flow still assigns both values in the !catalog and catalog branches before FileNamesGenerator or getMetadataJSONObject consume them, so I do not see a behavior change or a code issue that needs an inline comment.

Missing context / blind spots
  • ⚠️ The dedicated Build (arm_tidy) job was still in progress when checked. Its successful completion would close the CI-level validation gap for the stated fix.
Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Jun 5, 2026
@alexey-milovidov

Copy link
Copy Markdown
Member

@groeneai, fix this logical error: Logical error: Mutation of Memory table produced incomplete output: A (STID: 2380-3043). Send a new PR which does the fix, and also includes the fix for clang-tidy, so at least we will be able to merge that PR.

@clickhouse-gh

clickhouse-gh Bot commented Jun 6, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.40% 84.50% +0.10%
Functions 92.30% 92.40% +0.10%
Branches 77.00% 77.10% +0.10%

Changed lines: Changed C/C++ lines covered by tests: 6/6 (100.00%) | Lost baseline coverage: none · Uncovered code

Full report · Diff report

@groeneai

groeneai commented Jun 6, 2026

Copy link
Copy Markdown
Collaborator Author

CI ledger — covered SHA d72cac531fac

check_name / test_name Classification Disposition
BuzzHouse (amd_msan) / Logical error: Mutation of \Memory` table produced incomplete output: A (STID: 2380-3043)` known-chronic Pre-existing chronic master flaky, unrelated to this 2-line clang-tidy fix in Iceberg/Mutations.cpp. CIDB shows STID 2380-3043 hitting 30+ unrelated PRs + master (10 hits) over the last 30d. The actual bug is in StorageMemory::mutate (src/Storages/StorageMemory.cpp:317) emitting fewer rows than declared during APPLY PATCHES mutations — completely separate code path from this PR's diff. Tracked in dedicated task following @alexey-milovidov's 2026-06-06 02:01Z directive requesting a new PR bundling the STID 2380-3043 fix with this clang-tidy fix.

All other CI checks pass (Finish Workflow + Mergeable Check both green). PR is already APPROVED by @ alexey-milovidov.

Session: cron:our-pr-ci-monitor:20260606-040000

@groeneai

groeneai commented Jun 6, 2026

Copy link
Copy Markdown
Collaborator Author

@alexey-milovidov — done. New bundled PR is #106621.

Two notes on the bundling:

@alexey-milovidov

Copy link
Copy Markdown
Member

Closing as superseded: the identical fix (initialize last_version and compression_method in Iceberg::alter) was merged into master on 2026-06-06 via #106609 (commit 1c0b3c1b407), so this PR's diff is now empty relative to master. The bundled follow-up requested in this PR's discussion continues in #106621.

Related: #106609
Related: #106621

groeneai added a commit to groeneai/ClickHouse that referenced this pull request Jun 13, 2026
…ect (STID 2380-3043)

Fixes `STID: 2380-3043` (`Logical error: Mutation of \`Memory\` table produced incomplete
output: block 0 has 0 rows, expected N`), reported by `@alexey-milovidov` on
ClickHouse#106615 and seen on master and 8+ unrelated PRs.

Reproducer (master HEAD, deterministic; aborts the server in debug builds):

    CREATE TABLE t (id UInt64, value String) ENGINE = Memory;
    INSERT INTO t VALUES (1, 'a'), (2, 'b');
    ALTER TABLE t (APPLY PATCHES);
    -- or: ALTER TABLE t MATERIALIZE STATISTICS ALL;
    -- or: ALTER TABLE t MATERIALIZE INDEX nonex;

Root cause: `MutationsInterpreter` short-circuits `APPLY_PATCHES` and
`APPLY_DELETED_MASK` in its prepare loop without adding a stage. For
`MATERIALIZE_INDEX`, `MATERIALIZE_PROJECTION`, `MATERIALIZE_STATISTICS`, and
`MATERIALIZE_TTL`, the prepare loop also adds no column dependencies when the
target structure does not exist on the storage (`Memory` has no indices,
projections, statistics or TTL). The resulting pipeline pulls one output block
per input block but with zero rows in each. `StorageMemory::mutate` then walks
the partial-column path and fails the per-block row-count invariant.

Fix: filter at the storage entry point. `Memory` tables hold raw column blocks
in RAM and have no on-storage analog of indices, projections, statistics, TTL,
patch parts, or a `_row_exists` deletion mask. Mutation commands that target
those structures are semantic no-ops on `Memory` and are removed from the
command set before constructing the pipeline. If all commands are filtered
out, `mutate` returns immediately. A real `UPDATE` / `DELETE` /
`MATERIALIZE_COLUMN` mixed into the same `ALTER` still executes.

This supersedes ClickHouse#105286, which filtered only `APPLY_PATCHES` and
`APPLY_DELETED_MASK`; CIDB shows the same `LOGICAL_ERROR` reaching the same
code path via `MATERIALIZE STATISTICS ALL`, `MATERIALIZE INDEX <name>`, and
`MATERIALIZE PROJECTION <name>` shapes that the narrower fix did not cover.

Regression test `04322_memory_mutate_no_op_commands_2380_3043` exercises every
no-op shape (`APPLY PATCHES` parens form and bare form, `APPLY DELETED MASK`,
`MATERIALIZE STATISTICS ALL`, `MATERIALIZE INDEX nonex`, `MATERIALIZE
PROJECTION nonex`) plus a mixed `UPDATE ... APPLY PATCHES SETTINGS
mutations_sync = 1` to prove that real updates still execute. The existing
`01867_fix_storage_memory_mutation` and `04229_memory_mutation_timeout_break`
tests still pass.

Caused by: ClickHouse#103706

Co-Authored-By: Claude Opus 4.8 <[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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants