Skip to content

Commit

Permalink
copy wal fies using memcpy
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanPleshkov committed Jan 10, 2024
1 parent fad0e7c commit 0dd89b7
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,18 @@ impl Wal {
pub fn clear(&mut self) -> Result<()> {
self.truncate(self.first_index())
}

/// copy all files to the given path directory
pub fn save_to_path<P>(&self, path: P) -> Result<()>
where
P: AsRef<Path>,
{
self.open_segment.segment.save_to_path(&path)?;
for segment in &self.closed_segments {
segment.segment.save_to_path(&path)?;
}
Ok(())
}
}

impl fmt::Debug for Wal {
Expand Down
16 changes: 16 additions & 0 deletions src/segment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,22 @@ impl Segment {
}
}
}

pub fn save_to_path<P>(&self, path: P) -> Result<()>
where
P: AsRef<Path>,
{
let file_name = self.path.file_name().unwrap();
let dst_path = path.as_ref().to_owned().join(file_name);
let mut other = Self::create(dst_path, self.capacity())?;
unsafe {
other
.mmap
.as_mut_slice()
.copy_from_slice(self.mmap.as_slice());
}
Ok(())
}
}

impl fmt::Debug for Segment {
Expand Down

0 comments on commit 0dd89b7

Please sign in to comment.