Try to advance `reader` to `offset` using the offset index. If successful, returns the offset index and the byte position of `reader`. `None` if the position of `reader` is unchanged.
(
repo: &R,
reader: &mut segment::Reader<R::SegmentReader>,
offset: u64,
)
| 1007 | /// If successful, returns the offset index and the byte position of `reader`. |
| 1008 | /// `None` if the position of `reader` is unchanged. |
| 1009 | fn try_seek_using_offset_index<R: Repo>( |
| 1010 | repo: &R, |
| 1011 | reader: &mut segment::Reader<R::SegmentReader>, |
| 1012 | offset: u64, |
| 1013 | ) -> Option<(TxOffsetIndex, u64)> { |
| 1014 | let segment_offset = reader.min_tx_offset; |
| 1015 | let index = repo |
| 1016 | .get_offset_index(segment_offset) |
| 1017 | .inspect_err(|e| { |
| 1018 | if e.kind() == io::ErrorKind::NotFound { |
| 1019 | debug!("offset index does not exist segment={segment_offset}"); |
| 1020 | } else { |
| 1021 | warn!( |
| 1022 | "error opening offset index segment={segment_offset}: {e} {}", |
| 1023 | source_chain(&e) |
| 1024 | ); |
| 1025 | } |
| 1026 | }) |
| 1027 | .ok()?; |
| 1028 | |
| 1029 | reader |
| 1030 | .seek_to_offset(&index, offset) |
| 1031 | .inspect_err(|e| match e { |
| 1032 | // Can happen if the segment is empty or small, so don't spam the logs. |
| 1033 | IndexError::KeyNotFound => { |
| 1034 | debug!("offset not found segment={segment_offset} offset={offset}"); |
| 1035 | } |
| 1036 | e => { |
| 1037 | warn!( |
| 1038 | "error reading index segment={segment_offset} offset={offset}: {e} {}", |
| 1039 | source_chain(&e) |
| 1040 | ); |
| 1041 | } |
| 1042 | }) |
| 1043 | .ok() |
| 1044 | .map(|pos| (index, pos)) |
| 1045 | } |
| 1046 | |
| 1047 | // `range_bounds_is_empty` https://github.com/rust-lang/rust/issues/137300 |
| 1048 | // |
no test coverage detected
searching dependent graphs…