Skip to content

Commit 41c316c

Browse files
authored
Commitlog stream range fix. (#2721)
1 parent 3ce4d85 commit 41c316c

2 files changed

Lines changed: 11 additions & 3 deletions

File tree

crates/commitlog/src/stream/common.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,15 +92,15 @@ impl RangeFromMaybeToInclusive {
9292
};
9393
let end = match b.end_bound() {
9494
Bound::Unbounded => None,
95-
Bound::Included(end) => Some((*end).max(start)),
96-
Bound::Excluded(end) => Some(end.saturating_sub(1).max(start)),
95+
Bound::Included(end) => Some(*end),
96+
Bound::Excluded(end) => Some(end.saturating_sub(1)),
9797
};
9898

9999
Self { start, end }
100100
}
101101

102102
pub fn is_empty(&self) -> bool {
103-
self.end.is_some_and(|end| end <= self.start)
103+
self.end.is_some_and(|end| end < self.start)
104104
}
105105

106106
pub fn contains(&self, item: &u64) -> bool {

crates/commitlog/src/stream/reader.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,14 @@ mod tests {
157157
super::retain_range(offsets, RangeFromMaybeToInclusive::from_range_bounds(range))
158158
}
159159

160+
#[test]
161+
fn test_slice_segments_on_single_commit() {
162+
let offsets = vec![0, 10];
163+
164+
let retained = retain_range(&offsets, 19..=19);
165+
assert_eq!(&retained, &[10]);
166+
}
167+
160168
#[test]
161169
fn test_slice_segments_on_boundary() {
162170
let offsets = vec![0, 10, 20, 30];

0 commit comments

Comments
 (0)