▾ modified deploy/modal/modal_app.py +10 -6 Viewed
@@ -108,16 +108,20 @@ def _snapshot_once() -> None: 108 108 live = f"{DB_BASE}{suffix}" 109 109 if not os.path.exists(live): 110 110 continue 111 - final = f"{SNAPSHOT_DIR}/glean.db{suffix}" 112 - tmp = f"{final}.tmp" 113 - if os.path.exists(tmp): 114 - os.remove(tmp) 111 + # VACUUM INTO writes to local disk, never straight to the Volume: 112 + # it journals as it goes, and the Volume is the filesystem this whole 113 + # scheme exists to avoid putting SQLite on. Only the finished file is 114 + # copied across. 115 + staged = f"{LIVE_DIR}/snapshot{suffix}" 116 + if os.path.exists(staged): 117 + os.remove(staged) 115 118 subprocess.run( 116 - ["sqlite3", live, f"VACUUM INTO '{tmp}'"], 119 + ["sqlite3", live, f"VACUUM INTO '{staged}'"], 117 120 check=True, 118 121 capture_output=True, 119 122 ) 120 - os.replace(tmp, final) 123 + shutil.copy2(staged, f"{SNAPSHOT_DIR}/glean.db{suffix}") 124 + os.remove(staged) 121 125 volume.commit() 122 126 123 127
@@ -108,16 +108,20 @@ def _snapshot_once() -> None: 108 live = f"{DB_BASE}{suffix}" 108 live = f"{DB_BASE}{suffix}" 109 if not os.path.exists(live): 109 if not os.path.exists(live): 110 continue 110 continue 111 - final = f"{SNAPSHOT_DIR}/glean.db{suffix}" 111 + # VACUUM INTO writes to local disk, never straight to the Volume: 112 - tmp = f"{final}.tmp" 112 + # it journals as it goes, and the Volume is the filesystem this whole 113 - if os.path.exists(tmp): 113 + # scheme exists to avoid putting SQLite on. Only the finished file is 114 - os.remove(tmp) 114 + # copied across. 115 + staged = f"{LIVE_DIR}/snapshot{suffix}" 116 + if os.path.exists(staged): 117 + os.remove(staged) 115 subprocess.run( 118 subprocess.run( 116 - ["sqlite3", live, f"VACUUM INTO '{tmp}'"], 119 + ["sqlite3", live, f"VACUUM INTO '{staged}'"], 117 check=True, 120 check=True, 118 capture_output=True, 121 capture_output=True, 119 ) 122 ) 120 - os.replace(tmp, final) 123 + shutil.copy2(staged, f"{SNAPSHOT_DIR}/glean.db{suffix}") 124 + os.remove(staged) 121 volume.commit() 125 volume.commit() 122 126 123 127