Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion crates/commitlog/src/repo/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,10 @@ impl Repo for Fs {
// NOTE: We previously used `O_APPEND`, but Windows demands `write(true)`
// so that we can truncate trailing garbage in [super::resume_segment_writer].
let mut file = File::options().read(true).write(true).open(self.segment_path(offset))?;
// Ensure any outstanding writes from a crashed process are durable.
file.sync_data()?;
file.seek(io::SeekFrom::End(0))?;

Ok(file)
}

Expand All @@ -346,7 +349,11 @@ impl Repo for Fs {
fn open_segment_reader(&self, offset: u64) -> io::Result<Self::SegmentReader> {
let path = self.segment_path(offset);
debug!("fs: open segment at {}", path.display());
let file = File::open(&path)?;
// NOTE: Write access is required for `sync_data` on Windows .
let file = File::options().read(true).write(true).open(&path)?;
// Ensure any outstanding writes from a crashed process are durable.
file.sync_data()?;

let len = file.metadata()?.len();
CompressReader::new(file).map(|inner| ReadOnlySegment { inner, len })
}
Expand Down
Loading