Skip to content
Merged
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
7 changes: 6 additions & 1 deletion libsql-server/src/replication/primary/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,10 @@ impl LogFile {
}

pub fn commit(&mut self) -> anyhow::Result<()> {
// Ensure frame data is durable before updating the header.
// Without this, a crash could leave the header claiming more frames
// than actually exist on disk.
self.file.sync_data()?;
self.header.frame_count += self.uncommitted_frame_count.into();
self.uncommitted_frame_count = 0;
self.commited_checksum = self.uncommitted_checksum;
Expand All @@ -193,6 +197,7 @@ impl LogFile {
pub fn write_header(&mut self) -> anyhow::Result<()> {
self.file.write_all_at(self.header.as_bytes(), 0)?;
self.file.flush()?;
self.file.sync_all()?;

Ok(())
}
Expand Down Expand Up @@ -387,7 +392,7 @@ impl LogFile {
..self.header
};
new_log_file.header = new_header;
new_log_file.write_header().unwrap();
new_log_file.write_header()?;
// swap old and new snapshot
// FIXME(marin): the dest path never changes, store it somewhere.
atomic_rename(&to_compact_log_path, path.join("wallog")).unwrap();
Expand Down
Loading