Skip to content

Commit

Permalink
fixup!: fix comment
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 May 16, 2024
1 parent 61f4db3 commit 57860a5
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions crates/curp/src/server/storage/wal/remover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ pub(super) struct SegmentRemover {
}

impl SegmentRemover {
#[allow(clippy::doc_markdown)] // False positive for ASCII graph
#[allow(
clippy::doc_markdown, // False positive for ASCII graph
clippy::arithmetic_side_effects, // won't overflow
clippy::verbose_file_reads // needs to create `LockedFile` first, can't direct read from a dir
)]
/// Recover from existing RWAL
///
/// * RWAL layout
Expand All @@ -53,9 +57,11 @@ impl SegmentRemover {
/// |------+------+------+------+------+------+------+------|
/// | SegmentID |
/// |------+------+------+------+------+------+------+------|
#[allow(clippy::arithmetic_side_effects)] // won't overflow
#[allow(clippy::verbose_file_reads)] // needs to create `LockedFile` first, can't direct read from a dir
pub(super) fn recover(dir: impl AsRef<Path>) -> io::Result<()> {
/// Each checksum occupies 32 bytes
const CHECKSUM_SIZE: usize = 32;
/// Each record occupies 16 bytes
const RECORD_SIZE: usize = 16;
let wal_path = Self::rwal_path(&dir);
if !is_exist(&wal_path) {
return Ok(());
Expand All @@ -65,15 +71,15 @@ impl SegmentRemover {
let mut buf = vec![];
let n = wal.read_to_end(&mut buf)?;
/// At least checksum + one record
if n < 32 + 16 {
if n < CHECKSUM_SIZE + RECORD_SIZE {
return Err(io::Error::from(io::ErrorKind::UnexpectedEof));
}
let checksum = buf.split_off(n - 32);
let checksum = buf.split_off(n - CHECKSUM_SIZE);
if !validate_data(&buf, &checksum) {
return Err(io::Error::from(io::ErrorKind::InvalidData));
}

let to_remove_paths = buf.chunks_exact(16).map(|chunk| {
let to_remove_paths = buf.chunks_exact(RECORD_SIZE).map(|chunk| {
let (base_index_bytes, segment_id_bytes) = chunk.split_at(8);
let segment_id = parse_u64(segment_id_bytes);
let base_index = parse_u64(base_index_bytes);
Expand All @@ -99,7 +105,6 @@ impl SegmentRemover {
Self::remove_rwal(&wal_path)?;
}

//let file_name = WALSegment::segment_name(segment_id, base_index);
let mut wal_data: Vec<_> = segments
.clone()
.flat_map(|s| {
Expand Down

0 comments on commit 57860a5

Please sign in to comment.