Repository navigation
fix(backup): keep scratch writes off the SD card - #1369
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
A durable goal save on homelab-rpi waited 2.65s behind backup commits on the same card. mq-deadline ignores IO priority, and smaller batches did not get under the 2s limit. The raw export now uses tmpfs when the file fits. On that Pi the same fixture then saved a goal in 18ms, and the restored archive still matched.
4c2cb31 to
0c7cb9f
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4c2cb31e2e
ℹ️ 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".
| if err == nil { | ||
| name := f.Name() | ||
| _ = f.Close() | ||
| _ = os.Remove(name) |
There was a problem hiding this comment.
Keep ownership of the temporary inode
On a multi-user Linux host, /dev/shm is world-writable, so removing the securely created file before SQLite opens the returned path creates a TOCTOU window. A local user watching the directory can replace the name with a world-writable regular file while the progress callback runs; Core then writes its raw state/configuration into an attacker-owned readable file, and the sticky bit can prevent cleanup. Keep the CreateTemp inode in place for SQLite to reopen, or use a private tmpfs directory.
Useful? React with 👍 / 👎.
| need := sourceBytes + backupScratchHeadroom | ||
| if avail, err := diskAvail("/dev/shm"); err == nil && avail >= need { | ||
| f, err := os.CreateTemp("/dev/shm", "ftw-backup-*.raw") |
There was a problem hiding this comment.
Bound tmpfs use by the service memory limit
The reference native deployment sets MemoryMax=512M in deploy/ftw.service:17, but this condition only compares the export estimate with host-wide /dev/shm space. On a 4/8 GB Raspberry Pi, an export larger than roughly 448 MiB can pass this check even though the tmpfs pages plus Core's existing memory are charged to the service cgroup, causing the backup to OOM-kill the control process instead of falling back to disk. Include cgroup/process memory headroom in this decision or cap tmpfs scratch below the unit limit.
Useful? React with 👍 / 👎.
| if _, err := os.Stat("/dev/shm"); err != nil { | ||
| t.Skip("no tmpfs") |
There was a problem hiding this comment.
Skip the test when tmpfs capacity is insufficient
This skip checks only that /dev/shm exists, while the helper requires at least 65 MiB free for this 1 MiB source. Standard containers commonly mount a 64 MiB /dev/shm, so the helper correctly falls back to disk and this test fails. Probe the available capacity and skip when sourceBytes + backupScratchHeadroom does not fit.
Useful? React with 👍 / 👎.
Summary
/dev/shmwhen the temporary file fits. Scratch commits no longer share the SD card queue with a durable charging-goal save. The compressed archive is still written to the destination and synced.Measured on homelab-rpi, synthetic data only, not the household database
FTW_STORAGE_ADMISSION=1with the 3,000-row / 48 MiB fixture:Restore checked 3,000 rows and the saved goal. All admitted telemetry committed.
Also already on master, and on the running v0.132.0-beta.1
TestCheckpointWALDoesNotWaitForReadersThose three tests passed locally. This PR does not change them.