Skip to content

[v25.3.x] tiered_storage: fix bad_optional_access#30639

Merged
wdberkeley merged 1 commit into
redpanda-data:v25.3.xfrom
vbotbuildovich:ai-backport-pr-30303-v25.3.x-1780002203
Jun 1, 2026
Merged

[v25.3.x] tiered_storage: fix bad_optional_access#30639
wdberkeley merged 1 commit into
redpanda-data:v25.3.xfrom
vbotbuildovich:ai-backport-pr-30303-v25.3.x-1780002203

Conversation

@vbotbuildovich

Copy link
Copy Markdown
Collaborator

Backport of PR #30303

  • Command: git cherry-pick -x 3d9ea78
  • Commits backported: 1
  • Conflicts resolved: 1
  • Commits skipped (already on target): 0
  • Backport branch: ai-backport-pr-30303-v25.3.x-1780002203

Conflict details

  • 3d9ea78 (src/v/cloud_storage/partition_manifest.cc): the target branch had the original _segments.begin() fallback under a slightly different clang-format wrapping; applied the cherry-pick's lower_bound(_start_offset) fix using the target branch's multi-line if style.
  • 3d9ea78 (src/v/cloud_storage/tests/remote_partition_test.cc): three-way merge pulled in four unrelated small_segment_prefetch_* tests that exist on dev but not on v25.3.x. Kept only the new test_remote_partition_start_beyond_all_segments_crash regression test (the actual change in the cherry-picked commit) and adapted its add_expectations(chunked_vector<...>::single(...)) call to the v25.3.x signature add_expectations(std::vector<expectation>{...}).

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)
@vbotbuildovich vbotbuildovich added this to the v25.3.x-next milestone May 28, 2026
@vbotbuildovich vbotbuildovich added the kind/backport PRs targeting a stable branch label May 28, 2026
@vbotbuildovich vbotbuildovich requested a review from wdberkeley May 28, 2026 21:08
@wdberkeley wdberkeley merged commit 9cfb9c8 into redpanda-data:v25.3.x Jun 1, 2026
19 checks passed
@tyson-redpanda tyson-redpanda modified the milestones: v25.3.x-next, v25.3.15 Jun 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/redpanda kind/backport PRs targeting a stable branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants