MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / sync

Method sync

nodedb-wal/src/writer.rs:346–366  ·  view source on GitHub ↗

Flush the write buffer to disk (group commit). This issues a single write + fsync for all records accumulated since the last flush. The DWB is also fsynced (one fsync for all deferred DWB writes in this batch).

(&mut self)

Source from the content-addressed store, hash-verified

344 /// since the last flush. The DWB is also fsynced (one fsync for all
345 /// deferred DWB writes in this batch).
346 pub fn sync(&mut self) -> Result<()> {
347 if self.buffer.is_empty() {
348 return Ok(());
349 }
350 // Flush DWB first — records must be durable in DWB before WAL.
351 // If DWB flush fails, torn-write protection is lost for this batch.
352 // We log a warning and detach the DWB rather than silently continuing
353 // as if torn-write protection is active.
354 if let Some(dwb) = &mut self.double_write
355 && let Err(e) = dwb.flush()
356 {
357 tracing::warn!(
358 error = %e,
359 "DWB flush failed — torn-write protection lost for this batch, detaching DWB"
360 );
361 self.double_write = None;
362 }
363 self.flush_buffer()?;
364 self.file.sync_all()?;
365 Ok(())
366 }
367
368 /// Seal the WAL — no more writes will be accepted.
369 ///

Callers 15

wal_append_fsync_1kFunction · 0.45
submitMethod · 0.45
recover_empty_walFunction · 0.45
recover_with_recordsFunction · 0.45
recover_truncated_walFunction · 0.45
sealMethod · 0.45
lazy_read_all_payloadsFunction · 0.45

Calls 3

flush_bufferMethod · 0.80
is_emptyMethod · 0.45
flushMethod · 0.45