[v25.3.x] tiered_storage: fix bad_optional_access#30639
Merged
wdberkeley merged 1 commit intoJun 1, 2026
Merged
Conversation
When retention advances _start_offset past all segments (the "delete everything" case) but GC fails to truncate the manifest, stale segments accumulate below _start_offset. When a new segment then arrives with a base_offset that doesn't match _start_offset exactly (there is a gap due to config batches), the fallback branch in compute_start_kafka_offset_local() used _segments.begin() and checked base_offset >= _start_offset. With stale segments present, begin() points below _start_offset, the condition is false, and the function returns nullopt. The caller (first_uploaded_offset) then calls .value() on the nullopt, throwing std::bad_optional_access through the Kafka fetch path. Fix by using lower_bound(_start_offset) instead of begin(), which skips any stale segments and finds the first valid one at or above _start_offset. (cherry picked from commit 3d9ea78)
wdberkeley
approved these changes
Jun 1, 2026
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.
Backport of PR #30303
Conflict details
_segments.begin()fallback under a slightly different clang-format wrapping; applied the cherry-pick'slower_bound(_start_offset)fix using the target branch's multi-lineifstyle.small_segment_prefetch_*tests that exist on dev but not on v25.3.x. Kept only the newtest_remote_partition_start_beyond_all_segments_crashregression test (the actual change in the cherry-picked commit) and adapted itsadd_expectations(chunked_vector<...>::single(...))call to the v25.3.x signatureadd_expectations(std::vector<expectation>{...}).