diff --git a/src/file_pipe_log/log_file.rs b/src/file_pipe_log/log_file.rs index 45ed1c03..e7e0ca51 100644 --- a/src/file_pipe_log/log_file.rs +++ b/src/file_pipe_log/log_file.rs @@ -74,19 +74,18 @@ impl LogFileWriter { 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; } diff --git a/src/file_pipe_log/pipe.rs b/src/file_pipe_log/pipe.rs index 98ea23db..a7db0eb8 100644 --- a/src/file_pipe_log/pipe.rs +++ b/src/file_pipe_log/pipe.rs @@ -72,7 +72,9 @@ pub(super) struct SinglePipe { impl Drop for SinglePipe { 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() @@ -271,7 +273,8 @@ impl SinglePipe { // 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 = {