Skip to content

Commit

Permalink
Add more details to rotate test
Browse files Browse the repository at this point in the history
Signed-off-by: Yang Zhang <[email protected]>
  • Loading branch information
v01dstar committed Nov 28, 2023
1 parent 2c8d59a commit 395d530
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/file_pipe_log/log_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ impl<F: FileSystem> LogFileWriter<F> {
let _t = StopWatch::new(&*LOG_SYNC_DURATION_HISTOGRAM);
// Panic if sync fails, in case of data loss.
self.handle.sync().unwrap();
IoResult::Ok(())
Ok(())
}

#[inline]
Expand Down
4 changes: 1 addition & 3 deletions src/file_pipe_log/pipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,9 +395,7 @@ impl<F: FileSystem> SinglePipe<F> {
let mut writable_file = self.writable_file.lock();
let writer = &mut writable_file.writer;
let _t = StopWatch::new(perf_context!(log_sync_duration));
if let Err(e) = writer.sync() {
return Err(Error::Io(e));
}
writer.sync().map_err(|e| Error::Io(e))?;
Ok(())
}

Expand Down
24 changes: 23 additions & 1 deletion tests/failpoints/test_io_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,13 +170,19 @@ fn test_file_rotate_error() {
.is_err());
assert_eq!(engine.file_span(LogQueue::Append).1, 1);
}
let num_files_before = std::fs::read_dir(&dir).unwrap().count();
{
// Fail to write header of new log file.
let _f = FailGuard::new("log_file::write::err", "1*off->return");
assert!(engine
.write(&mut generate_batch(1, 4, 5, Some(&entry)), false)
.is_err());
assert_eq!(engine.file_span(LogQueue::Append).1, 1);
// Although the header is not written, the file is still created.
assert_eq!(
std::fs::read_dir(&dir).unwrap().count() - num_files_before,
1
);
}
{
// Fail to sync new log file. The old log file is already sync-ed at this point.
Expand All @@ -186,14 +192,30 @@ fn test_file_rotate_error() {
})
.is_err());
assert_eq!(engine.file_span(LogQueue::Append).1, 1);
// The file was created but without any content (header) should be
// recycled. And a new file should be created.
assert_eq!(
std::fs::read_dir(&dir).unwrap().count() - num_files_before,
1
);
}

drop(engine);
let engine = Engine::open_with_file_system(cfg.clone(), fs.clone()).unwrap();
// Only one log file should be created after all the incidents.
assert_eq!(
std::fs::read_dir(&dir).unwrap().count() - num_files_before,
1
);
// We can continue writing after the incidents.
engine
.write(&mut generate_batch(2, 1, 2, Some(&entry)), true)
.unwrap();
drop(engine);
let engine = Engine::open_with_file_system(cfg, fs).unwrap();
assert_eq!(
std::fs::read_dir(&dir).unwrap().count() - num_files_before,
1
);
assert_eq!(engine.first_index(1).unwrap(), 1);
assert_eq!(engine.last_index(1).unwrap(), 4);
assert_eq!(engine.first_index(2).unwrap(), 1);
Expand Down

0 comments on commit 395d530

Please sign in to comment.