Skip to content
This repository was archived by the owner on Oct 18, 2023. It is now read-only.

Commit df92c46

Browse files
authored
check for wal presence before checkpointing (#653)
1 parent bded15e commit df92c46

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

sqld/src/replication/primary/logger.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -913,6 +913,21 @@ impl ReplicationLogger {
913913
}
914914

915915
fn checkpoint_db(data_path: &Path) -> anyhow::Result<()> {
916+
let wal_path = match data_path.parent() {
917+
Some(path) => path.join("data-wal"),
918+
None => return Ok(()),
919+
};
920+
921+
if wal_path.try_exists()? {
922+
if File::open(wal_path)?.metadata()?.len() == 0 {
923+
tracing::debug!("wal file is empty, checkpoint not necessary");
924+
return Ok(());
925+
}
926+
} else {
927+
tracing::debug!("wal file doesn't exist, checkpoint not necessary");
928+
return Ok(());
929+
}
930+
916931
unsafe {
917932
let conn = rusqlite::Connection::open(data_path)?;
918933
conn.query_row("PRAGMA journal_mode=WAL", (), |_| Ok(()))?;

0 commit comments

Comments
 (0)