nandi/gleanpublic Fork 0
b3424a2
Commits
Clone
git clone https://git.rickub.com/nandi/glean.git
git clone ssh://git@rickub.com/nandi/glean.git

Host key fingerprint (ed25519): SHA256:iycHnxEyq0Q7uyVpB7JlznP0G7JrTPXLYRcAU5CSLhc — verify it before your first connect.

Stage snapshots on local disk before copying to the volume

VACUUM INTO journals as it writes, and pointing it straight at the volume
meant SQLite was journaling on the filesystem this whole scheme exists to
keep SQLite off -- which left .tmp and .tmp-journal files behind on the
first run. Vacuum to local disk, copy only the finished file across.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
nandithebull committed 2026-09-20T19:45:27-07:00 Browse files
b3424a2 parent: fb40a9c
modified deploy/modal/modal_app.py +10 -6
@@ -108,16 +108,20 @@ def _snapshot_once() -> None:
108108 live = f"{DB_BASE}{suffix}"
109109 if not os.path.exists(live):
110110 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)
115118 subprocess.run(
116- ["sqlite3", live, f"VACUUM INTO '{tmp}'"],
119+ ["sqlite3", live, f"VACUUM INTO '{staged}'"],
117120 check=True,
118121 capture_output=True,
119122 )
120- os.replace(tmp, final)
123+ shutil.copy2(staged, f"{SNAPSHOT_DIR}/glean.db{suffix}")
124+ os.remove(staged)
121125 volume.commit()
122126
123127
@@ -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 continue110 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