Validates and decodes a commit at `byte_offset` in the segment. # Returns `Ok(commit::Metadata)` - If a valid commit is found with matching transaction offset `Err` - If commit can't be decoded or has mismatched transaction offset
(
reader: &mut R,
tx_offset: TxOffset,
byte_offset: u64,
)
| 735 | /// * `Ok(commit::Metadata)` - If a valid commit is found with matching transaction offset |
| 736 | /// * `Err` - If commit can't be decoded or has mismatched transaction offset |
| 737 | fn validate_commit_at_offset<R: io::Read + io::Seek>( |
| 738 | reader: &mut R, |
| 739 | tx_offset: TxOffset, |
| 740 | byte_offset: u64, |
| 741 | ) -> io::Result<commit::Metadata> { |
| 742 | reader.seek(SeekFrom::Start(byte_offset))?; |
| 743 | let commit = commit::Metadata::extract(reader)? |
| 744 | .ok_or_else(|| io::Error::new(ErrorKind::InvalidData, "failed to decode commit"))?; |
| 745 | |
| 746 | if commit.tx_range.start != tx_offset { |
| 747 | return Err(io::Error::new( |
| 748 | ErrorKind::InvalidData, |
| 749 | format!( |
| 750 | "mismatch key in index offset file: expected={} actual={}", |
| 751 | tx_offset, commit.tx_range.start |
| 752 | ), |
| 753 | )); |
| 754 | } |
| 755 | |
| 756 | Ok(commit) |
| 757 | } |
| 758 | } |
| 759 | |
| 760 | #[cfg(test)] |