From f6a2c927e6d4c37342502abb7d14326c4f80e103 Mon Sep 17 00:00:00 2001 From: Sh0rck_Wang Date: Fri, 4 Sep 2026 15:55:24 +0800 Subject: [PATCH] fix(storage): preserve WAL on checkpoint failure --- src/sirchmunk/storage/duckdb.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/sirchmunk/storage/duckdb.py b/src/sirchmunk/storage/duckdb.py index b4726713..9b293f40 100644 --- a/src/sirchmunk/storage/duckdb.py +++ b/src/sirchmunk/storage/duckdb.py @@ -119,19 +119,17 @@ def _checkpoint_wal(db_file: str): logger.info( f"Stale WAL detected at {wal_file}, checkpointing before load" ) + tmp_conn = None try: tmp_conn = duckdb.connect(db_file) tmp_conn.execute("CHECKPOINT") - tmp_conn.close() logger.info(f"WAL checkpoint completed for {db_file}") except Exception as e: - logger.warning(f"WAL checkpoint failed for {db_file}: {e}") - # Last resort: remove the stale WAL so READ_ONLY ATTACH can proceed - try: - wal_file.unlink() - logger.info(f"Removed stale WAL file {wal_file}") - except Exception: - pass + logger.error(f"WAL checkpoint failed for {db_file}: {e}") + raise + finally: + if tmp_conn is not None: + tmp_conn.close() @staticmethod def _cleanup_wal(db_file: str):