model: make next_offset saturate rather than overflow #18308
Merged
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.
model::offset::max() is often used to indicate "no upper bound" on operations. E.g. for tiered storage uploads1, for reading from local storage2, etc.
We also do often convert from closed to opened offset intervals representations. E.g. committed offset to LSO and the other way around.
When combined, these can result in unexpected behaviors. In particular, if on a read path the max offset is specified as model::offset_max() but at lower level this is converted into an exclusive offset by calling next_offset(model::offset::max()), the result is model::offset::min() aka -2^63.
This is dangerous. Let's instead saturate the offset similar to how we saturate prev_offset.
We also have a few cases where we just do
o + model::offset(1)
. These should be refactored to use next_offset too.This isn't fixing any existing known bug. Discovered this while trying to rewrite some logic related to tiered storage uploads.
Backports Required
Release Notes
Footnotes
https://github.com/redpanda-data/redpanda/blob/79bf7eed6e04da1d0987b5abd719c4b289dde761/src/v/archival/ntp_archiver_service.cc#L1656 ↩
https://github.com/redpanda-data/redpanda/blob/79bf7eed6e04da1d0987b5abd719c4b289dde761/src/v/cluster/migrations/tx_manager_migrator.cc#L219 ↩