Skip to content

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
Signed-off-by: Yang Zhang <[email protected]>
  • Loading branch information
v01dstar committed Nov 25, 2023
1 parent 2c81285 commit bd2c3b4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
5 changes: 2 additions & 3 deletions src/file_pipe_log/log_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,19 +74,18 @@ impl<F: FileSystem> LogFileWriter<F> {
self.write(&buf, 0)
}

pub fn close(&mut self) -> Result<()> {
pub fn close(&mut self) -> IoResult<()> {
// Necessary to truncate extra zeros from fallocate().
self.truncate()?;
self.sync();
Ok(())
}

pub fn truncate(&mut self) -> Result<()> {
pub fn truncate(&mut self) -> IoResult<()> {
if self.written < self.capacity {
fail_point!("file_pipe_log::log_file_writer::skip_truncate", |_| {
Ok(())
});
// Panic if truncate fails, in case of data loss.
self.writer.truncate(self.written)?;
self.capacity = self.written;
}
Expand Down
7 changes: 5 additions & 2 deletions src/file_pipe_log/pipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ pub(super) struct SinglePipe<F: FileSystem> {
impl<F: FileSystem> Drop for SinglePipe<F> {
fn drop(&mut self) {
let mut writable_file = self.writable_file.lock();
writable_file.writer.close().unwrap();
if let Err(e) = writable_file.writer.close() {
error!("error while closing the active writer: {e}");
}
let mut recycled_files = self.recycled_files.write();
let mut next_reserved_seq = recycled_files
.iter()
Expand Down Expand Up @@ -271,7 +273,8 @@ impl<F: FileSystem> SinglePipe<F> {
// File header must be persisted. This way we can recover gracefully if power
// loss before a new entry is written.
new_file.writer.sync();
self.sync_dir(path_id)?;
// Panic if sync calls fail, keep consistent with the behavior of `LogFileWriter::sync()`.
self.sync_dir(path_id).unwrap();

**writable_file = new_file;
let len = {
Expand Down

0 comments on commit bd2c3b4

Please sign in to comment.