Skip to content

Do not refuse a manifest-only Iceberg rewrite over an absent parent total - #117012

Merged
PedroTadim merged 7 commits into
ClickHouse:masterfrom
groeneai:groeneai/iceberg-manifest-only-keeps-absent-parent-total
Oct 13, 2026
Merged

PedroTadim merged 7 commits into
ClickHouse:masterfrom
groeneai:groeneai/iceberg-manifest-only-keeps-absent-parent-total

Conversation

@groeneai

@groeneai groeneai commented Aug 29, 2026 •

Copy link
Copy Markdown
Collaborator

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

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

Fixes OPTIMIZE TABLE ... MANIFEST failing with BAD_ARGUMENTS on an Iceberg table whose current snapshot summary omits an optional total-records, total-files-size or total-data-files metric, which made manifest compaction permanently unavailable on tables written by engines that omit those metrics. Closes #117000.

Description

Closes: #117000

The total-* snapshot summary metrics are optional per the Iceberg spec, so a table written by another engine may omit them and still read correctly. setSnapshotTotals refused to derive a new total whenever the parent summary omitted one, regardless of the delta being applied. generateManifestOnlySnapshot passes 0 for every delta, so OPTIMIZE TABLE ... MANIFEST was refused outright:

Code: 36. DB::Exception: Cannot derive Iceberg snapshot total 'total-records':
the parent snapshot's summary omits it. (BAD_ARGUMENTS)

That also contradicts the documented contract of generateManifestOnlySnapshot, which is to carry the total-* counters forward so the rewrite is idempotent.

I made the refusal depend on the delta rather than on the caller. A zero delta leaves the total exactly as the parent had it, so an absent counter is carried forward by staying absent, as the sibling delete-family totals already tolerate absence. A non-zero delta still cannot be derived from an unknown total, so the INSERT path keeps refusing.

The new stateless test strips one of the three data totals from an IcebergLocal table's current snapshot summary, reloads the table and runs the real statement, once per total. Before, OPTIMIZE TABLE t MANIFEST failed as above while the table read correctly; after, it succeeds and the new snapshot omits the stripped total while forwarding the other two unchanged. Widening the new condition to accept any delta instead fails the INSERT arm, so each arm covers a different defect. The existing test_optimize_manifest_parent_summary_missing_totals strips only the three delete-family counters, which set_delete_total already tolerated, which is why this case was uncovered.

Note for review: on this path an absent delete-family counter is still published as 0 even when delete files are live. Master behaves identically, and that test pins the 0, so I left it out of scope rather than widen this fix.


Workflow [PR]
Sync PR [sync-upstream/pr/117012]

Version info

  • Merged into: 26.10.1.2247-master (included in 26.10 and later)

@clickhouse-gh

clickhouse-gh Bot commented Aug 29, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [504cd61]

Summary: ✅


AI Review

Summary

This PR relaxes Iceberg manifest-only rewrites so a parent snapshot that omits an optional data total can still produce a REPLACE snapshot when the net delta for that total is 0, and it adds an end-to-end stateless regression test covering all three data-total fields. The write-side change and the new test look solid, but one impacted read-side surface still turns those intentionally absent totals into literal 0, so I would keep this at ⚠️ Request changes until that representation stays consistent.

Findings
  • ⚠️ Majors
    • [src/Storages/ObjectStorage/DataLakes/Iceberg/MetadataGenerator.cpp:94, src/Storages/ObjectStorage/DataLakes/Iceberg/SnapshotSummary.cpp:208, src/Storages/System/StorageSystemIcebergHistory.cpp:141] The new contract is that a zero-delta rewrite carries an absent parent total-records / total-files-size / total-data-files forward as still absent. However, SnapshotSummary::fromJSON still normalizes every missing total to 0, and system.iceberg_history serializes that parsed summary back out via toMap. On the reproduced table, OPTIMIZE TABLE ... MANIFEST will therefore succeed yet report a live table as total-records = 0 / total-data-files = 0 in system.iceberg_history, which breaks the same invariant on a user-visible surface.
    • Suggested fix: preserve optionality through the SnapshotSummary read path (for example by tracking which totals were present and omitting absent ones from toJSON / toMap, or by modeling those totals as std::optional values) before relying on absent totals as a first-class state in newly written snapshots.
Final Verdict
  • Status: ⚠️ Request changes
  • Minimum required actions: keep absent data totals absent through the SnapshotSummary / system.iceberg_history path, or otherwise avoid exposing the new write-side behavior as 0 on the read side.

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Aug 29, 2026
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-review-bot PR origin: review-bot finding on a groeneai PR labels Aug 29, 2026
…otal

The `total-*` snapshot summary metrics are optional per the Iceberg spec, so a table
written by another engine may omit them and still read correctly. `set_data_total` threw
BAD_ARGUMENTS whenever the parent summary omitted one, regardless of the delta being
applied. `generateManifestOnlySnapshot` passes 0 for every delta, so `OPTIMIZE TABLE ...
MANIFEST` was permanently unavailable on such a table:

  Code: 36. DB::Exception: Cannot derive Iceberg snapshot total 'total-records':
  the parent snapshot's summary omits it. (BAD_ARGUMENTS)

That contradicts the documented contract of `generateManifestOnlySnapshot`, which is to
carry the `total-*` counters forward so the rewrite is idempotent.

Condition the refusal on the delta rather than on the caller. A zero delta leaves the
table-wide total exactly as the parent had it, so an absent counter is carried forward by
staying absent, the way the sibling `set_delete_total` already tolerates absence. A
non-zero delta still cannot be derived from an unknown total, so the INSERT path keeps
refusing: writing the delta alone would report a total that omits the parent's rows.

Verified at SQL level on an `IcebergLocal` table whose current snapshot summary has
`total-records` removed: before, `OPTIMIZE TABLE t MANIFEST` failed with the error above
while the table read correctly; after, it succeeds and the new snapshot omits
`total-records` while forwarding `total-files-size` and `total-data-files` unchanged. An
untouched control table compacts identically in both cases, which is what shows the
fixture reaches this code rather than an earlier threshold check.

Two tests are added to the existing gtest module, one per branch of the new condition.
Making the carry-forward unconditional instead does not compile
(-Werror,-Wunreachable-code), so the over-broad form of this change is rejected by the
build.

Closes: ClickHouse#117000
@groeneai
groeneai force-pushed the groeneai/iceberg-manifest-only-keeps-absent-parent-total branch from 6edf795 to 0572538 Compare August 29, 2026 10:39
@clickhouse-gh

clickhouse-gh Bot commented Aug 29, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Commit 504cd61e0fac5562b432d99a6d025e0199d44f68 was not compared: the CI logs cluster did not answer (every POST attempt failed with an exception).

See the job log for details.

The unit tests only reached MetadataGenerator, while the refusal reported in
issue ClickHouse#117000 happens on the SQL OPTIMIZE TABLE ... MANIFEST path against
on-disk metadata, so a caller-side regression could reappear unnoticed. A
stateless test now strips total-records from the current snapshot's summary,
reloads the table so the edit is actually read, and runs the real statement.

The two generator unit tests are dropped rather than kept alongside it: both
properties they pinned are asserted by the new test, and SQL coverage is
preferred when the behaviour is reachable from SQL.

Each arm was checked against a separate defect. On master the test fails with
BAD_ARGUMENTS and the snapshot stays `append`; with the fix it passes 28 of 28
runs; with the new condition widened to `added >= 0` only the INSERT arm fails,
which is what keeps the guard from being removed silently.

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

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 6006b39

Every failure below has an owner.

Check / test Reason Owner / fixing PR
Integration tests (amd_asan_ubsan, db disk, old analyzer, 5/6) Session-budget overrun, not a test defect: xdist.dsession.Interrupted: session-timeout: 7200.0 sec exceeded after 7345s. The shard still published 918 CIDB rows against 1027 to 1669 on its five siblings, so its results were ingested and no signal was lost. #116591 (external, open)
Finish Workflow / new_tests_check.py Cascade of the row above rather than an independent finding. praktika stamps each dropped job with the job that dropped it, and all 103 DROPPED nodes at this head name the 5/6 shard, including both Bugfix validation (functional tests, *) jobs. The hook's passed: none is therefore reporting per-arch jobs that never ran. #116591 (external, open)
CH Inc sync Private sync, never completes on a fork PR. CH Inc sync (private, not actionable)

Coverage note for a reviewer: the cascade above left 103 of 171 jobs unrun at this head, so this run validates 47 completed jobs (all builds that produce test binaries, Fast test, Style check, unit tests, the five sibling integration shards) and not the full matrix. A re-run once #116591 lands would exercise the rest.

Session id: cron:our-pr-ci-monitor:20260829-160000

@PedroTadim

Copy link
Copy Markdown
Member

cc @SmitaRKulkarni

setSnapshotTotals derives total-records, total-files-size and total-data-files
through one shared lambda, but the test only ever stripped total-records. The
rewritten snapshot still carried the other two, so a regression that
special-cased that single field would have passed unnoticed. The absent-total
sequence now runs once per data total.

Checked with a mutant that restricts the zero-delta carry-forward to
total-records: the total-records block of the output is unchanged while both
added blocks fail, so the new arms catch exactly that regression. With the fix
the test passes 20 of 20 sequential runs and 8 of 8 concurrent ones; against
master all three blocks fail with BAD_ARGUMENTS and an `append` snapshot.

Co-Authored-By: Claude Opus 5 <[email protected]>
{
/// A zero delta leaves the total exactly as the parent had it, so an absent counter is carried
/// forward by staying absent; a non-zero delta genuinely cannot be derived from a missing total.
if (added == 0)

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.

Allowing a zero-delta rewrite to keep an absent parent total-* field out of the new snapshot is fine for the metadata JSON itself, but our read side still treats missing totals as literal 0 in SnapshotSummary::fromJSON (src/Storages/ObjectStorage/DataLakes/Iceberg/SnapshotSummary.cpp:221-223). system.iceberg_history then serializes that parsed summary back out (src/Storages/System/StorageSystemIcebergHistory.cpp:131-133).

That means this fix now makes the reproduced table compact successfully, but the new REPLACE snapshot will be reported as total-records = 0 / total-data-files = 0 in system.iceberg_history even though the live table still has rows and data files. Can we preserve "missing" through SnapshotSummary / system.iceberg_history (or otherwise cover this surface) before merge?

@groeneai

groeneai commented Sep 1, 2026

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 88b16da

Every failure below has an owner: a fixing PR (mine 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
Bugfix validation (functional tests, amd64) / job-level AssertionError: Could not find master builds in S3 CI harness: find_master_builds still builds the REFs/master/<sha> prefix the artifact uploader stopped writing, so no arm can validate anything. 87 distinct PRs carry it since 2026-08-31 19:31Z #117433 (mine, open)
Bugfix validation (functional tests, aarch64) / same assertion same harness defect, sibling arch #117433 (mine, open)
Finish Workflow / new_tests_check.py cascade: it needs one per-arch arm to report OK or XFAIL, and both functional arms errored above #117433 (mine, open)
Docs examples / Documentation examples, Function/toYYYYMM#0 the example pinned SELECT toYYYYMM(now(), 'US/Eastern') to 202608 and the month rolled over. 128 PRs plus 6 master runs carry it since 2026-09-01 04:10Z #117459 (mine, merged 2026-09-01), absent from this tree
Integration tests (amd_asan_ubsan, db disk, old analyzer, 6/6) / Container memory budget exceeded (/docker) the nested-container budget sized the unreclaimable /docker leaf last #117412 (external, merged 2026-09-01), absent from this tree
CH Inc sync StatusContext that stays pending on a fork PR CH Inc sync (private, not actionable by me)

Both merged owners landed after this tree was built, which is why they are absent from it. I am holding the master merge until #117433 merges, so one rebuild picks up all three owners instead of three rebuilds.

Session id: cron:our-pr-ci-monitor:20260901-153000

@clickhouse-gh clickhouse-gh Bot added the comp-datalake Data lake table formats (Iceberg/Delta/Hudi) integration. label Sep 4, 2026
@PedroTadim PedroTadim self-assigned this Oct 9, 2026
@PedroTadim
PedroTadim enabled auto-merge October 9, 2026 15:56
@PedroTadim
PedroTadim added this pull request to the merge queue Oct 13, 2026
Merged via the queue into ClickHouse:master with commit 730f84f Oct 13, 2026
177 checks passed
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 13, 2026
@clickhouse-gh clickhouse-gh Bot added comp-iceberg Apache Iceberg tables: reading and writing Iceberg metadata (snapshots, manifests, schema evoluti... and removed comp-datalake Data lake table formats (Iceberg/Delta/Hudi) integration. labels Nov 22, 2026
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 comp-iceberg Apache Iceberg tables: reading and writing Iceberg metadata (snapshots, manifests, schema evoluti... groeneai-origin-review-bot PR origin: review-bot finding on a groeneai PR pr-bugfix Pull request with bugfix, not backported by default 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.

OPTIMIZE MANIFEST refused when snapshot summary omits total-records

3 participants