Repository navigation
Fix a crash on an Iceberg manifest list with a huge manifest_length - #116564
PedroTadim merged 3 commits into
Conversation
An Iceberg manifest-list entry declares manifest_length, and that declared
number became ManifestFileCacheableInfo::file_bytes_size, whose only reader is
the metadata cache cell weight: 3 * file_bytes_size + 200. The cache policy
adds that to current_size_in_bytes, and SLRUCachePolicy::removeOverflow ends
with
if (current_size_in_bytes > (1ull << 63))
std::terminate(); // Queue became inconsistent
so any declared value above (2^63 - 200) / 3 = 3074457345618258536 terminates
the server. It is abnormal termination rather than an exception, so a release
build dies with an empty response to the client and nothing in the log.
The mechanism is magnitude, not signedness. memory_bytes was declared Int64 and
the huge size_t expression was narrowed into it, but the weight function
converts it straight back to size_t and recovers the identical bit pattern, and
the guard that fires is a magnitude test. Building the Int64 -> size_t change on
its own still reproduces the abort; that hunk is type correctness, matching the
weight function's own return type, not the fix.
The fix is to stop letting a metadata-declared number reach the weight at all.
getManifestFile now takes the manifest file's size from the object storage,
which createReadBuffer already populates unconditionally and which the function
previously discarded, so there is no extra request. The size_t bytes_size
parameter is deleted, which fixes all three call sites structurally: there is
nowhere left to pass a declared length. This mirrors the Paimon sibling, which
was never vulnerable, and it makes the read side use the same definition of
manifest_length the write side already uses, getObjectMetadata(...).size_bytes.
Confirmed the abort site under gdb with a breakpoint conditioned on the Iceberg
cell, since the two identical std::terminate() blocks in that function are tail
merged and a plain backtrace attributes the frame elsewhere: it is the magnitude
check, reached from the protected-queue pass of set, with current_size_in_bytes
= 13835058055282168350 for a declared 2^62. The other std::terminate() in the
same function is not reachable on this path, because the eviction loop guarding
it does not run. Exposure is limited to the default SLRU policy; LRU evicts the
oversized cell before reaching its own equivalent check.
ManifestFileCacheKey::manifest_file_byte_size keeps the declared value and now
has no readers. It is left in place deliberately: the struct is a faithful
record of a manifest-list entry, and removing it would conflict with ClickHouse#90740,
which edits that construction line.
Regression coverage is an integration test rather than a functional one, because
the shape needs a hand-written Avro manifest list and a functional test may not
fabricate metadata files. It reuses the existing Avro harness in
test_storage_iceberg_no_spark and carries a control arm that performs the same
manifest-list round trip without changing the value, so "any rewrite breaks it"
cannot masquerade as the finding. The control is ordered first: the defect
aborts the server and the package fixture is stay_alive, so running the huge
case first makes the control fail with a connection error instead of reporting
its own result.
Closes: ClickHouse#116496
Co-Authored-By: Claude Opus 5 <[email protected]>
Internal second-model reviewIndependent cold review of the resulting code plus a second-model gate pass, adjudicated against
On the test oracle. The concern is that the test could pass with the cache bypassed, or with the On the changelog category. I do not self-select One thing I noticed and am not raising: |
|
Workflow [PR], commit [ea66278] Summary: ✅
AI ReviewSummaryThis PR fixes Final VerdictStatus: ✅ Approve LLVM Coverage ReportMeasured on commit ea66278.
Changed lines: Changed C/C++ lines covered: 31/31 (100.00%) · Uncovered code |
Pre-PR validation gate
Verification: new integration test base-reddened through the test itself (control passes, huge case aborts, harness reports |
The cell weight was taken from `manifest_object_info.metadata->size_bytes`, which `createReadBuffer` leaves at `0` whenever the storage does not report a size: `getObjectInfo.cpp:75-76` sets `is_size_known = ContentLengthHasBeenSet()`, so an S3 HEAD without `Content-Length` yields `0`, and `WebObjectStorage.cpp:399-402` is a second carrier. A manifest cached on that path weighed only the 200-byte floor, so the 128 MiB `iceberg_metadata_files_cache_size` stopped bounding it and only the 1000-entry limit remained. Before this PR the weight came from the manifest list's declared `manifest_length`, which is always present, so this was a regression introduced here. `AvroForIcebergDeserializer`'s constructor already drains the whole file, so the bytes it read are the file's size on storage and need no cooperation from the storage layer. `AvroInputStreamReadBufferAdapter::byteCount()` is already `in.count()`, so this is the existing idiom rather than a new one. Measured weight-preserving, not merely plausible: on the same table `system.metrics.IcebergMetadataFilesCacheBytes` is bit-identical before and after (31815, and 123882 on a second fixture). That equality is not vacuous, because the declared length works as a knob that proves the cell's weight lands in that metric with coefficient 3: with `manifest_length` set to 1000000 on a 9064-byte manifest, the pre-fix build reports 3004626 against 31818, a delta of exactly 3 * (1000000 - 9064), while both fixed builds ignore the declared number. The regression test now asserts that weight against the manifest's real size on disk, read from the file rather than hardcoded so that it stays stable as the fixture moves. Charging the cell from a declared `1` instead makes it fail (`weight 4695 < 3 * 9085`) while the result assertions still pass, so the bound is what catches a weight that does not come from the real size. Its read-back queries also pin `use_iceberg_metadata_files_cache`. Without the pin the test depends on the setting's default: with it flipped off, the poisoned case passes against a pre-fix binary, i.e. the test goes blind while still looking green.
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction. Object file sizes23 object files changed (-3.89 KiB total), 0 added.
835 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Compile time of recompiled translation units46 translation units recompiled, 479 s compile time in total, 46 of them have a recent master baseline. |
CI finish ledger - 6d2cb70Every failure below has an owner: a fixing PR (ours or external), or a full-effort fix task
That is the only failure: praktika's report for this head is Session id: cron:our-pr-ci-monitor:20260827-013000 |
…t-length-cache-weight
|
This LGTM, it's mostly changing an Int64 with size_t, the correct type |
Merge backport/26.8/116723 into cherrypick/26.8/116723 to finish the robot cherry-pick of #116723 "Parallelize Iceberg data manifest decoding", which GitHub reports as CONFLICTING. Five of the nineteen paths needed a decision; the other fourteen land as the merge produced them. src/Storages/ObjectStorage/DataLakes/Iceberg/IcebergIterator.cpp: the rewrite consolidated both manifest-iterator call sites into createManifestIterator, so the resolved file is master's file plus two argument-level edits. 26.8's Iceberg::getManifestFile still takes the bytes_size parameter that master dropped in #116564, so manifest_list_entry.manifest_file_byte_size is passed; 26.8's ManifestFileIterator::create has no row-lineage parameter, so manifest_list_entry.first_row_id is not passed. src/Storages/ObjectStorage/DataLakes/Iceberg/ManifestFileIterator.cpp: the incoming constructor body materializes per-entry first_row_id values for format-version 3 manifests. Iceberg row lineage does not exist on 26.8, so the 26.8 (empty) side is taken. The cancellation check the PR adds between rows in next() sits outside the conflict and is kept, so the new stop flag still reaches the decode loop rather than being dropped with the walk. src/Interpreters/PreparedSets.h: include union only. 26.8 keeps its own include block plus <mutex> for the mutex member the PR adds. src/Core/SettingsChangesHistory.cpp: a plain merge resolves this file by importing master's whole "26.9" section, which names settings that do not exist on 26.8, so applyCompatibilitySetting() throws UNKNOWN_SETTING for every SET compatibility and a server with compatibility in a profile exits with code 115 at startup. That was fixed once already on this branch, by 0debf7d. The imported section is therefore dropped and the two new entries are appended to the branch's own "26.8" block, without master's "pre-26.9" and "compatibility at or below 26.8" clauses, which are false here. The branch's existing iceberg_delete_manifest_decode_concurrency entry is unchanged, so compatibility at or below 26.7 yields 2 for both the data and the delete path, and an unpinned server yields 4 for both. Leaving the entries out entirely is not an option: 03999_stateless_settings_history requires every setting absent from the frozen baseline to be recorded, and neither new setting is in the baseline. tests/integration/test_storage_iceberg_with_spark/test_data_manifest_decode_concurrency.py: test_data_manifest_decode_concurrency_row_lineage writes a format-version 3 table and selects _row_id, a virtual column 26.8 does not have. It is excised and the other five tests are unchanged. Nothing on 26.8 loses coverage, because the behavior it pins, per-entry first_row_id materialization under concurrency, has no implementation on this branch. Related: #116723 Related: #120406
…h a huge manifest_length
…h a huge manifest_length
Backport #116564 to 26.3: Fix a crash on an Iceberg manifest list with a huge manifest_length
Backport #116564 to 26.8: Fix a crash on an Iceberg manifest list with a huge manifest_length
Closes: #116496
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed a server crash when reading an Iceberg table whose manifest list declares a very large
manifest_length. The declared value was used as the metadata cache entry weight, overflowing the cache accounting and terminating the server. The size measured while reading the manifest file is now used instead.Description
An Iceberg manifest-list entry declaring a large
manifest_lengthterminates the server on read.It is
std::terminate, not an exception: a release build dies with an empty response and nothingin the log.
The cause is magnitude, not signedness: the declared number became the cache cell weight,
3 * manifest_length + 200(IcebergMetadataFilesCache.h:97), andSLRUCachePolicy::removeOverflowends with
if (current_size_in_bytes > (1ull << 63)) std::terminate();. Anything above(2^63 - 200) / 3trips it. I confirmed that site under gdb; the otherstd::terminatethere,which the issue cites, is unreachable. Only the default
SLRUpolicy is affected.The fix weighs the cell by the bytes the Avro parse consumed and deletes
getManifestFile'sbytes_sizeparameter, so no caller can pass a declared length. The constructor already reads thewhole file, so this needs no extra I/O and no size from the storage, which does not always report
one: on an S3 HEAD without
Content-Length,size_bytesstays0and a manifest of any size ischarged at its 200-byte floor. The writer already takes its buffer's own count first
(
IcebergWrites.cpp:1268-1272), so the two sides now agree.memory_bytesis unsigned now to matchthe weight function; alone that fixes nothing, verified by building it by itself.
ManifestFileCacheKey::manifest_file_byte_sizenow has no readers but is kept, since removing itwould conflict with #90740. The
std::terminateinSLRUCachePolicyis left alone as its owner'scall.
The regression test is an integration test: the shape needs a hand-written Avro manifest list, and a
functional test may not fabricate metadata files. Its control arm rewrites the manifest list without
changing the value, so on master the control passes and the huge case aborts; with the fix both
pass. It also bounds the cache weight by the manifest's real size on disk, which fails if the weight
stops tracking that size while the results stay correct.
Workflow [PR]
Sync PR [sync-upstream/pr/116564]
Version info
26.9.1.289-master(included in26.9and later)