Repository navigation
Conversation
Pre-update snapshots used to land at ~200 MB raw on a mature site, making the five-slot retention budget ~1 GB on disk. SQLite's hot-tier tables compress 5–10x with gzip, so we now VACUUM INTO a temp file and gzip-stream it into snapshots/<id>/state.db.gz. The temp is removed on success and on every error path. The rollback sidecar transparently decompresses any *.gz entry in a snapshot's Files list to a sibling temp before docker cp, then strips the .gz suffix on the container destination so the main service still finds plain /app/data/state.db. Snapshots without .gz entries (older formats) take the legacy direct-cp path unchanged. Tests cover the round-trip and the existing-file refusal on the compressed variant, plus a new ftw-updater rollback test that verifies state.db.gz is decompressed and the rollback temp is cleaned up after. https://claude.ai/code/session_01SQtNeXFhRoEiwjLghE69KR
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: bd4af1f18c
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| var tempToRemove string | ||
| if strings.HasSuffix(f, ".gz") { | ||
| plain := strings.TrimSuffix(f, ".gz") | ||
| tmp := filepath.Join(hostSnapDir, plain+".rollback.tmp") |
There was a problem hiding this comment.
Decompress rollback payload into a writable directory
For .gz snapshot entries this now writes a temp file under hostSnapDir, but in the default deployment that path is mounted read-only in the updater container (docker-compose.yml mounts ${PWD} as :ro). As a result, rollback of state.db.gz will fail at temp-file creation with a read-only filesystem error before docker cp runs, so the new compressed snapshots cannot be restored in production unless the mount policy changes.
Useful? React with 👍 / 👎.
|
Superseded by #309 (merged 2026-05-25), which made snapshots skip the TS tables and brought the snapshot size from ~198 MB down to ~50 MB — that fix removes the original motivation for issue #147. Adding gzip on top of a 50 MB snapshot only saves single-digit MB at the cost of extra rollback complexity in ftw-updater. Closing this; #147 should likely be closed too. |
Summary
Closes #147. Pre-update snapshots used to land at ~200 MB raw on a mature site, making the five-slot retention budget ~1 GB on disk. SQLite's hot-tier tables compress 5–10× with gzip, so we now
VACUUM INTOa temp file and gzip-stream it intosnapshots/<id>/state.db.gz. Expected steady-state on the same site: ~25–40 MB per snapshot, ~150–200 MB total for five slots.What changes
state.SnapshotToCompressed(dst)(go/internal/state/store.go) — wraps the existingSnapshotTo(which can't stream — SQLite'sVACUUM INTOrequires a file path) with a gzip stream into the final.gzpath. The intermediate raw temp is removed on success and on every error path. Refuses to overwrite an existing destination, matchingSnapshotTo.Server.createPreUpdateSnapshot(go/internal/api/snapshots.go) now writesstate.db.gzand records that name inmeta.json#files, so the existingmeta.Files-driven rollback flow picks up the new format with no code change inselfupdate.TriggerRollback.ftw-updaterrollback (go/cmd/ftw-updater/main.go) — for each entry inFilesthat ends with.gz, decompress to a sibling<plain>.rollback.tmpin the snapshot dir,docker cpthat into the container at/app/data/<plain>(suffix stripped), then unconditionally remove the temp. Files without.gztake the legacy direct-cp path unchanged, so older snapshots still restore.The schema version in
SnapshotMetadoesn't change because nothing in the snapshot dir layout is renamed — the file list is data, and readers already iterate it.Tests
state.TestSnapshotToCompressedRoundTrip— gzip → gunzip → reopen, asserts seeded rows survive and the raw temp is cleaned up.state.TestSnapshotToCompressedRefusesExistingFile— second call to the same path errors instead of stomping.ftw-updater.TestHandleUpdate_RollbackDecompressesGz— end-to-end: astate.db.gzentry in the snapshot is decompressed,docker cptargets/app/data/state.db(no.gzon the container side), and no*.rollback.tmpleaks after the rollback completes.api.TestVersionUpdate_CreatesSnapshotBeforeTriggerupdated to look forstate.db.gzand assert that the rawstate.dbis NOT left next to it. The test also gunzips the snapshot in-process and reopens it as astate.Storeto prove the bytes round-trip.Verified
go build ./...cleango vet ./internal/state/ ./internal/api/ ./cmd/ftw-updater/cleango test ./... -count=1 -short— full module green (state, api, ftw-updater + e2e)Test plan
du -sh snapshots/is ~5–10× smaller than before; trigger a rollback, verify the main service comes up on the restored state.Out of scope
state.db(uncompressed) snapshots already on disk. Existing snapshots stay valid because the rollback path falls through to the legacy direct-cp branch when the file list lacks.gzentries; we don't rewrite history.gzipis stdlib, no new dependency.https://claude.ai/code/session_01SQtNeXFhRoEiwjLghE69KR
Generated by Claude Code