Files
julian 78b1c99890 wiki: park-2 disk growth incident (backups on the data disk, snapshot valve)
Incident analysis of 2026-11-20, measured read-only on park-2: nightly full
backups on the same disk push it past 70%, where the snapshot valve deletes
all but 500 snapshots and likely freezes the server. Records the manual
cleanup, the deferred fixes and the next deadline, and notes the findings on
backup-recovery, entry-exit-points, vision-review-outbox and open-questions.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RZgP5oZdzvo92Eouc9eRv5
2026-11-22 18:24:31 +01:00

11 KiB
Raw Permalink Blame History

type, tags, sources, updated
type tags sources updated
concept
parking
incident
disk
backup
snapshots
sqlite
park-2
2026-11-20

park-2 disk growth: backups fill the disk, and the snapshot valve fires first (2026-11-20)

An incident analysis, all measured read-only on park-2 (stage-73ada89, container up since 2026-11-09 14:16 UTC) on 2026-11-19 and 2026-11-20. Status: open, deferred (user, 2026-11-20). The immediate hazard was removed by hand; the code fixes wait until the feature work on stage is in a deployable state. The next deadline is ~2026-12-05.

State after the manual cleanup (2026-11-20)

  • The user deleted the old backup files on the host. Six remain (2026-11-14 to 2026-11-19, 35 GB). df: 231 GB, 63 GB used, 29%. The valve is a no-op and a container restart is safe.
  • Retention is unchanged (code default, keep-last 7 + keep-daily 30). The user has no app login on park-2: the admin account belongs to the site's admin. The folder regrows ~6.5 GB a night and the disk reaches 70% again around 2026-12-05. Until a fix ships: delete old files by hand again, or ask the park-2 admin to set 7/7 in Setup → Backup.
  • Not done, by decision: a support user written into the DB from the filesystem. It would be an account the site admin did not create. A support login, if wanted, is created by the admin in the app (a role with backup:read + backup:update) or designed as a standing decision.
  • Backup timing, from the file stamps: starts ~23:46 UTC, takes ~4 minutes, and starts ~15 minutes later each night (24 h after the last success, polled every 15 minutes).
  • The sections below describe the state as measured before the cleanup.

The numbers

Disk (/data, the root LV): 247.7 GB total, 74.9 GB free. statfs used% = 69.75% on 2026-11-20.

What Size Growth
/data/backup/ ~127 GB, 30 files net ~4.6–4.8 GB/day (see below)
parking.sqlite 6.58 GB ~150–200 MB/day, steady since 2026-10-09
of which snapshots 6.23 GB, 50,629 rows ~150 MB/day (~1,200 images × ~122 KB)
of which device_events + indexes 0.31 GB, 325,606 rows ~7 MB/day
everything else < 30 MB negligible

The database is not what fills the disk. The backups are, and the backups are big because of the snapshots.

Cause 1: daily full backups, uncompressed, on the same disk

  • backup-recovery writes a full encrypted copy every night (backup.ts). AES-GCM output is incompressible and nothing compresses it first, so each file is as big as the DB (6.57 GB on 2026-11-19).
  • park-2 runs the code default retention, keep-last 7 + one per day for 30 days: 30 files. Pruning works: the 2026-10-20 file was deleted on schedule on the night of 2026-11-19.
  • Steady growth anyway. Each night adds today's copy and drops the copy from 30 days ago. Today's copy is about 30 days of DB growth bigger than the one deleted, so the folder grows about 4.6 GB/day now, and about 6.2 GB/day once the copies being deleted come from after 2026-11-20 (31 × 200 MB).
  • Each run also writes a plaintext copy to os.tmpdir() before encrypting. In the container that is the overlay, which is the same disk. It needs about 6.8 GB free for the length of the run.
  • The backups sit on the disk they protect. The target is /data/backup, inside the same volume as the DB. That gives no protection against the loss of the disk or the PC, which is the scenario backup-recovery was designed for. It needs a separate disk or an off-box target.

Forecast if nothing else happened: backups start failing ~2026-12-03 (no room for the plaintext copy) and the disk is full ~2026-12-04. The DB would stop accepting writes then, including the signed ledger.

Cause 2: two-thirds of the snapshots are Car Wash "pass samples"

On 2026-11-19 there were 1,299 snapshots:

Kind Entry cam Exit cam Share
pass:<uuid>: one frame per detected car, no session 542 319 66%
tied to a ticket, card or plate in the ledger 239 199 34%
  • Pass samples come from anpr-entry.ts #recordPass (commit 30a1180, 2026-10-08, vision-review-outbox §"Every car that passes"). The ANPR bridge stores the best frame of every detected vehicle so the Car Wash module can sample it for the reviewer.
  • The review outbox makes its own blurred crop at queue time (review-outbox.ts, makeReviewCrop → carwash_review_outbox.image). After that, the pass snapshot is not read by the outbox again.
  • Nothing deletes pass snapshots except the disk-pressure valve below. They are about 105 MB a day, more than half of the DB's growth, and they are copied into every nightly backup.
  • Ledger-tied snapshots are about one per signed event: 7,856 snapshots for 7,650 identities in the 7 days to 2026-11-19. There is no multi-shot bug.
  • The entry and exit cameras also fire on refused and held events (by design, entry-exit-points §Refused entry/exit ALSO snapshots).

The hazard: the snapshot valve fires on 2026-11-21

snapshot-retention.ts (entry-exit-points §Retention) runs daily, 24 h after the container start (so ~14:16 UTC), plus once at every container start. When the disk is ≥ 70% used, it deletes the oldest snapshots until it estimates it has freed 10% of the disk (~24.8 GB), never below 500 rows. Then it runs VACUUM.

  • Tonight's backup takes the disk from 69.75% to about 71.7%. The run on 2026-11-21 ~14:16 UTC will fire.
  • It deletes almost every snapshot. The target (24.8 GB) is four times all the snapshots (6.2 GB), so it stops only at the 500-row floor: about the last 10 hours of images. Ticketed evidence goes with the pass samples. Older images survive only inside the encrypted backups.
  • It repeats daily. Backups keep the disk above 70%, so every day it prunes to the floor and logs "disk pressure is not from snapshots". Snapshot evidence older than about 10 hours stops existing on the booth.
  • It is likely to freeze the server (estimated, not measured). The delete loop is fully synchronous on the main thread (better-sqlite3, no await inside it). It runs ~250 batches, and each batch selects ORDER BY captured_at with length(bytes) over a table with no index on captured_at. A single read-only pass of that kind over this table took several minutes from a separate process on 2026-11-20. Then VACUUM rewrites the file on the same thread. Same failure class as park-2-event-loop-stall: relay pulses, reader pushes and the booth UI wait behind it.
  • Side effect: the DB drops to about 0.4 GB, nightly backups shrink, and the folder rotates down over 30 days. The disk would survive. The evidence and the booth's responsiveness would not.

Do not restart the park-2 server container while the disk is ≥ 70%. The valve runs at startup.

What to do, in order

  1. Today (2026-11-20), before tonight's backup: lower backup retention on Setup → Backup, for example keep-last 7, keep-daily 7. Retention is read fresh each run, and pruneOldBackups runs right after the new file is written, so tonight's run applies it. It should free roughly 90 GB and take the disk to about 33%. Check df on 2026-11-21 before 14:16 UTC.
  2. Move the backup target off the data disk (USB or SATA disk mounted by fstab and bind-mounted, or SFTP), per backup-recovery §The target must be a bind-mounted host path.
  3. Stop storing pass samples permanently. Options, to decide:
    • delete the pass snapshot once the outbox has made its crop, or when the module does not sample it;
    • give pass: rows a short age-based retention (for example 48 h);
    • do not store a pass frame at all when the Car Wash module is off or sampling is 0.
  4. Fix the valve itself (code, stage first):
    • add an index on snapshots(captured_at);
    • make the delete loop yield between batches, or run it off the main thread;
    • cap a run's target at what snapshots actually hold, and do not prune evidence when snapshots are not the cause of the disk pressure;
    • prune pass: rows before ledger-tied rows;
    • VACUUM off-peak, not inside the request thread.
  5. Smaller backups: compress before encrypting (gzip or zstd of a SQLite file usually shrinks it a lot; the restore tool must then decompress), or the "exclude snapshots" option already noted on backup-recovery.

Corrections from the code review (2026-11-20)

  • The freeze is likely hours, not minutes (from the schema, not measured). bytes precedes captured_at in snapshots, so each batch's ORDER BY captured_at walks every remaining row's blob pages. ~250 batches run back to back on the main thread. The server has restart: always and the valve runs at startup, so a restart of a frozen booth re-enters it.
  • A backup run holds ~13 GB extra (plaintext copy + encrypted file) until it prunes.
  • Step 1 lands near 37–40% used, not 33%, and buys about seven weeks.
  • Compression will not shrink the backups (step 5): ~95% of the DB is JPEG. Excluding snapshots would, but backups are the only place old images survive a valve run, so it depends on the evidence-retention decision below.
  • No threshold knob: SNAPSHOT_* variables are not forwarded by docker-compose.yml.
  • A failed backup leaves a partial .enc in the target and skips pruning; the partial file counts as a backup for retention.
  • Lowering the code default retention in backup.ts fixes park-2 with no DB or app access, if its retention columns are empty (not read). Any deploy carries the commits since 73ada89.

Open decisions

  • How long ledger-tied snapshots (entry and exit evidence) must be kept on the booth: an age, not "until the disk is 70% full". Add this to open-questions #10.
  • Whether pass samples are kept at all after the review crop. The camera large view (‹ › through older and newer snapshots, cb43ad7) may show them; check before deleting.

How it was measured (read-only)

  • df and ls inside the container.
  • dbstat per-table sizes.
  • Per-day count and length(bytes) from snapshots.
  • Snapshot identities joined against ledger_events.identity.
  • All run with better-sqlite3 opened readonly in a separate node process inside the container (docker exec -i park-2-server-1 nice -n 19 node -); the container has no sqlite3 CLI.
  • Full scans of snapshots take minutes; avoid them during busy hours.

Related: backup-recovery, entry-exit-points, vision-review-outbox, park-2-event-loop-stall, open-questions.