Repository navigation
Do not refuse a manifest-only Iceberg rewrite over an absent parent total - #117012
Conversation
|
Workflow [PR], commit [504cd61] Summary: ✅
AI ReviewSummaryThis PR relaxes Iceberg manifest-only rewrites so a parent snapshot that omits an optional data total can still produce a Findings
Final Verdict
|
…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
6edf795 to
0572538
Compare
Build profile diff (arm_release)Commit 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]>
CI finish ledger - 6006b39Every failure below has an owner.
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, Session id: cron:our-pr-ci-monitor:20260829-160000 |
…ly-keeps-absent-parent-total
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) |
There was a problem hiding this comment.
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?
CI finish ledger - 88b16daEvery 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
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 |
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixes
OPTIMIZE TABLE ... MANIFESTfailing withBAD_ARGUMENTSon an Iceberg table whose current snapshot summary omits an optionaltotal-records,total-files-sizeortotal-data-filesmetric, 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.setSnapshotTotalsrefused to derive a new total whenever the parent summary omitted one, regardless of the delta being applied.generateManifestOnlySnapshotpasses 0 for every delta, soOPTIMIZE TABLE ... MANIFESTwas refused outright:That also contradicts the documented contract of
generateManifestOnlySnapshot, which is to carry thetotal-*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
IcebergLocaltable's current snapshot summary, reloads the table and runs the real statement, once per total. Before,OPTIMIZE TABLE t MANIFESTfailed 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 theINSERTarm, so each arm covers a different defect. The existingtest_optimize_manifest_parent_summary_missing_totalsstrips only the three delete-family counters, whichset_delete_totalalready tolerated, which is why this case was uncovered.Note for review: on this path an absent delete-family counter is still published as
0even when delete files are live. Master behaves identically, and that test pins the0, so I left it out of scope rather than widen this fix.Workflow [PR]
Sync PR [sync-upstream/pr/117012]
Version info
26.10.1.2247-master(included in26.10and later)