From 1488e01bf911b9ffe25f89a86e495264f7384d44 Mon Sep 17 00:00:00 2001 From: ZdenekSrotyr Date: Thu, 9 Apr 2026 07:00:19 +0200 Subject: [PATCH] feat: add temp-file swap to BigQuery extractor Write to extract.duckdb.tmp, then atomically swap into place with WAL cleanup. Prevents lock conflicts with orchestrator holding read lock on existing database. --- connectors/bigquery/extractor.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/connectors/bigquery/extractor.py b/connectors/bigquery/extractor.py index efbdafc..7917052 100644 --- a/connectors/bigquery/extractor.py +++ b/connectors/bigquery/extractor.py @@ -112,6 +112,18 @@ def init_extract( finally: conn.close() + # Atomic swap with WAL cleanup + old_wal = Path(str(db_path) + ".wal") + if old_wal.exists(): + old_wal.unlink() + + if tmp_db_path.exists(): + shutil.move(str(tmp_db_path), str(db_path)) + + tmp_wal = Path(str(tmp_db_path) + ".wal") + if tmp_wal.exists(): + tmp_wal.unlink() + return stats