Skip to content

Commit

Permalink
db: Swap order of fsync and provide error context
Browse files Browse the repository at this point in the history
  • Loading branch information
kim committed Oct 17, 2023
1 parent f9157d8 commit 63ef6eb
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions crates/core/src/db/commit_log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use crate::{
error::DBError,
};

use anyhow::Context;
use spacetimedb_lib::{
hash::{hash_bytes, Hash},
DataKey,
Expand Down Expand Up @@ -69,9 +70,15 @@ impl CommitLog {
let mut mlog = mlog.lock().unwrap();
mlog.append(commit)?;
if self.fsync {
mlog.sync_all()?;
let offset = mlog.open_segment_max_offset;
// Sync the odb first, as the mlog depends on its data. This is
// not an atomicity guarantee, but the error context may help
// with forensics.
let mut odb = self.odb.lock().unwrap();
odb.sync_all()?;
odb.sync_all()
.with_context(|| format!("Error syncing odb to disk. Log offset: {offset}"))?;
mlog.sync_all()
.with_context(|| format!("Error syncing mlog to disk. Log offset: {offset}"))?;
log::trace!("DATABASE: FSYNC");
} else {
mlog.flush()?;
Expand Down

1 comment on commit 63ef6eb

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark results

Error when comparing benchmarks:

Caused by:

Please sign in to comment.