Repository navigation
Filesystem usage ceiling with oldest-day pruning (#14) - #23
Merged
Merged
Conversation
Add the persisted max_filesystem_used_percent setting (default 80, 10 to 95, written explicitly on every save), GET/POST /api/storage/ceiling, and a Filesystem Usage row in camera settings. No deletion yet.
Register the ceiling handler in main.go and describe the setting, the API and the settings row in docs/FILESYSTEM_USAGE.md. Nothing is deleted yet.
Load filesystem-ceiling.js into a fake DOM and check that opening settings adds one row and refreshes it, that unknown usage and failed loads are shown plainly, that only valid whole numbers from 10 to 95 are sent, that failures never announce success, that a pending save blocks a second request, and that the script loads once, after modals.js.
Add a separate prune job that, when filesystem usage reaches the ceiling minus 2 points, removes the oldest day with published MP4s from each camera, never the newest day folder. Deletion takes the media lease and reuses the published deletion engine, which gains an opt-in day-scoped, continue-on-entry-error mode. A 1 MiB no-effect guard pauses repeats, a ceiling change triggers a pass, and event records for a fully pruned day are removed.
retention_days 0 now means no age limit; 1 to 365 is the maximum age. The retention handlers require the field, so only an explicit 0 turns age cleanup off. Cameras with 0 are not retention cleanup targets, and events for any camera name that has an age-off camera are not expired by age. The settings inputs allow 0. No migration: every install is new.
Retention keeps names shorter than 15 characters, so s.mp4 was never expired by age. Use a full stamped name so the limited camera's old day is actually due.
Run the real runtime image on a loopback ext4 volume and drive it with headless Chrome and the real HTTP API: settings rows, retention 0, ceiling pruning one day per camera per pass, the 1 MiB no-effect guard (hard links stand in for snapshots), a partial failure (chattr +i), ceiling-not-met, untouched evidence, running recorder, clean shutdown and restart. Add the job to the required gate and an owner runbook for a real ZFS volume.
The auth layer allowed only GET and HEAD on paths outside mutationPaths and only POST on paths inside it, so the ceiling route (GET and POST) was rejected with 405 on every POST in a running server. CP3 tests called the handler directly and bypassed auth. Add a small read-write mutation allowlist, register the ceiling route as a tracked mutation that also serves reads, test it through the real auth handler, and print the response status when the acceptance save assertion fails.
The camera list is rendered twice with the same element ids (a hidden section and the settings dialog). getElementById returns the hidden copy, so Update sent its stale value instead of what was typed in the settings dialog. Look the input up in the settings dialog's list first, falling back to the old lookup, and test it.
requestPass re-armed the message on every ceiling save, so saving the same value twice logged it twice, contradicting the documented behavior. Remember the ceiling the state was logged for: the same ceiling stays silent, a different one logs again, and falling below the trigger or pruning something still resets it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #14
This PR carries all checkpoints of #14, one at a time. The agreed design and checkpoint plan are in #14 (comment) and the CP1 findings are in #14 (comment). The approved CP3 names are in #14 (comment), amended in #14 (comment). Running status is in #14 (comment).
This PR deletes recordings (CP4 ceiling pruning and CP5 age cleanup). Deleted footage is not recoverable.
Feature summary (as agreed in #14)
/recordings, every 5 minutes (first check 5 minutes after startup), in its own background job..mp4files from each camera, never the newest UTC day, and stop pruning if a pass frees less than 1 MiB.0= off); whichever limit applies first wins.SIMPLENVR_MIN_FREE_BYTESis unchanged. Estimated days remaining was dropped.Checkpoint status
60df3d7)e58835a, owner confirmed)13f84b5, owner signed off)4d24b37, owner signed off)d86f255; owner marked completeAll checkpoints are complete. Merging this PR closes #14.
CP6: end-to-end acceptance
d86f255fab03936b4a57b7174eb22e8e44743f8d, including the new real-container filesystem-pruning acceptance. Run: https://github.com/mouldybread/SimpleNVR/actions/runs/46217386829. I read check conclusions only, not per-test output.fd8cbd6).f9b1dc2).d86f255).CP2
used / (used + available). Blocks reserved for privileged users count as used. Inconsistent block counts are an error, never a guessed percentage.readRecordingStorageCapacityand the usage reader./api/storage/statusoutput and errors are unchanged.cmd/simplenvr/storage_usage.go,cmd/simplenvr/storage_usage_test.go,docs/FILESYSTEM_USAGE.md,cmd/simplenvr/storage_status.go,cmd/simplenvr/main.go.CP3
max_filesystem_used_percentincameras.json. Default 80; whole numbers 10 to 95 only; invalid stored values make the configuration invalid. The trigger (ceiling minus 2) is derived, never stored.GET /api/storage/ceilingandPOST /api/storage/ceilingwith{"max_filesystem_used_percent": <int>}. Invalid input is 400; failed save restores the previous value and returns a generic 500.filesystem_ceiling.goand tests,web/static/js/filesystem-ceiling.js,tests/frontend/filesystem-ceiling.cjs, plus changes topersistence.go,main.goandindex.html.CP4
cmd/simplenvr/filesystem_prune.go, a separate job every 5 minutes (first pass after 5 minutes) and soon after a successful ceiling change. Opening settings never prunes..mp4; the newest day is never removed. Only that day's.mp4files are unlinked; the folder is removed only if empty.retentionPolicyMu(read), then brieflyNVR.mu; prune and retention cleanup cannot delete at the same time..mp4of the pruned day is gone; kept if any file failed..tmp,temp/,buffer/, staging, recovery evidence, other days, recorders.CP5
retention_daysis a camera's maximum age:0= no age limit, 1 to 365 = days. No migration; new cameras register with 7./api/cameras/update-retentionand/api/cameras/update-retention-allaccept 0 to 365 and require the field.web/static/js/retention-days.jsreplaces the retention functions fromcameras.js.docs/audit/RETENTION_POLICY.mdanddocs/audit/EVENT_RETENTION.mdstill describe 0 as the seven-day default;docs/RETENTION_MAX_AGE.mdsupersedes that.Verification history
d86f255.4d24b37.13f84b5.e58835a.60df3d7.