Skip to content

Commit

Permalink
squash!: update segment size during recovery
Browse files Browse the repository at this point in the history
Signed-off-by: bsbds <69835502+bsbds@users.noreply.github.com>
  • Loading branch information
bsbds committed Apr 29, 2024
1 parent db86719 commit ff69e2d
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion crates/curp/src/server/storage/wal/segment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ impl WALSegment {
{
let encoded_bytes = encoder.encode(item)?;
self.file.write_all(&encoded_bytes)?;
self.size = self.size.overflow_add(encoded_bytes.len().numeric_cast());
self.update_size(encoded_bytes.len().numeric_cast());
self.file.flush()?;
self.file.sync_data()?;

Expand Down Expand Up @@ -173,10 +173,16 @@ impl WALSegment {
};
entries.push(item);
pos += n;
self.update_size(n.numeric_cast());
}
Ok(entries)
}

/// Updates the size of this segment
pub(super) fn update_size(&mut self, increment: u64) {
self.size = self.size.overflow_add(increment);
}

/// Updates the seal index
pub(super) fn update_seal_index(&mut self, index: LogIndex) {
self.seal_index = self.seal_index.max(index);
Expand Down

0 comments on commit ff69e2d

Please sign in to comment.