Repository navigation
Cherry pick #116564 to 26.8: Fix a crash on an Iceberg manifest list with a huge manifest_length - #128616
Merged
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 #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: #116496
Co-Authored-By: Claude Opus 5 <[email protected]>
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.
…t-length-cache-weight
…cache-weight Fix a crash on an Iceberg manifest list with a huge manifest_length
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Original pull-request #116564
Do not merge this PR manually
This pull-request is a first step of an automated backporting.
It contains changes similar to calling
git cherry-picklocally.If you intend to continue backporting the changes, then resolve all conflicts if any.
Otherwise, if you do not want to backport them, then just close this pull-request.
The check results does not matter at this step - you can safely ignore them.
Before you resolve anything
Conflicts are often caused by a prerequisite change that has not been backported yet, rather than by a real divergence. The bot re-tries this cherry-pick against the release branch on every run, so if that is the case here it will merge itself as soon as the prerequisite lands, and you will see a comment saying so. Manual resolution is only needed while the conflict persists.
Troubleshooting
If the conflicts were resolved in a wrong way
If this cherry-pick PR is completely screwed by a wrong conflicts resolution, and you want to recreate it:
pr-cherrypicklabel from the PRYou also need to check the Original pull-request for
pr-backports-createdlabel, and delete if it's presented thereThe PR source
The PR is created in the CI job