dracoooooo commented on code in PR #1556:
URL: https://github.com/apache/horaedb/pull/1556#discussion_r1743356372
##########
src/wal/src/local_storage_impl/segment.rs:
##########
@@ -213,154 +238,270 @@ impl Segment {
// Validate segment header
let header_len = SEGMENT_HEADER.len();
- ensure!(size >= header_len as u64, InvalidHeader);
+ ensure!(
+ file_size >= (VERSION_SIZE + header_len) as u64,
+ InvalidHeader
+ );
let header = &mmap[VERSION_SIZE..VERSION_SIZE + header_len];
ensure!(header == SEGMENT_HEADER, InvalidHeader);
// Read and validate all records
let mut pos = VERSION_SIZE + header_len;
let mut record_position = Vec::new();
- while pos < size as usize {
- let data = &mmap[pos..];
- let record = self
- .record_encoding
- .decode(data)
- .box_err()
- .context(InvalidRecord)?;
+ // Update min and max sequence number
+ let mut min_seq = MAX_SEQUENCE_NUMBER;
+ let mut max_seq = MIN_SEQUENCE_NUMBER;
- record_position.push(Position {
- start: pos as u64,
- end: (pos + record.len()) as u64,
- });
+ while pos < file_size as usize {
+ let data = &mmap[pos..];
- // Move to the next record
- pos += record.len();
+ match self.record_encoding.decode(data).box_err() {
+ Ok(record) => {
+ record_position.push(Position {
+ start: pos,
+ end: pos + record.len(),
+ });
+ min_seq = min_seq.min(record.sequence_num);
Review Comment:
The `min_seq` of the segment was initially set to the maximum value, so it
is updated here.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]