malletgu opened a new pull request, #16681: URL: https://github.com/apache/kafka/pull/16681
Fixes an edge case where segments that failed to be copied to the tiered storage layer caused an early deletion of relevant segments. This edge case occurs because we are counting up the amount of data to delete in `buildRetentionSizeData` before counting down from there in `remoteLogRetentionHandler.isSegmentBreachedByRetentionSize` untill we have deleted enough bytes. In the case where we have some segments in state `COPY_SEGMENT_STARTED` those segments will increase the counter of bytes to be deleted which will cause the eviction of the oldest segment as the loop on L1221 building the list of segments to be deleted `segmentsToDelete` is sorted from oldest to earliest. As part of this PR I have made a small refactor of building the leader epoch set in its own function as we were reaching the maximum complexity. ### Committer Checklist (excluded from commit message) - [ ] Verify design and implementation - [ ] Verify test coverage and CI build status - [ ] Verify documentation (including upgrade notes) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: jira-unsubscr...@kafka.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org