Skip to content

feat(cluster): recordings follow the server their storage is on - #284

Merged
SteveGilvarry merged 1 commit into
masterfrom
feat/cluster-storage
Nov 18, 2026
Merged

SteveGilvarry merged 1 commit into
masterfrom
feat/cluster-storage

Conversation

@SteveGilvarry

Copy link
Copy Markdown
Member

Why

Second PR for multi-server installs (#230), after #283.

Storage.ServerId says which server holds a storage area's files. NULL or 0 means shared storage that every server reaches. Any other value is local to that server. zm-api ignored the column everywhere, so with per-server storage:

  • The retention reaper and the audit ran against storages whose files this server cannot see. The audit could take every event there for media-less, and the reaper measured the wrong disk. This is the part that could cost recordings.
  • Event video, frame images and thumbnails failed on the wrong server.
  • Deleting an event there removed the row and left the files.
  • A media job could be claimed by a server that cannot read the event.

What changes

Background jobs leave another server's storage alone, files and rows both.

  • the retention reaper
  • the audit's filesystem pass, and its removal of events with no frames
  • the event audit report's media check (the events are still counted)
  • the media job worker, which leaves the job queued for the owning server
  • the storage endpoints, which report no filesystem figures for it

These skip regardless of cluster.enabled. A server can't read another's files whatever that setting says.

Requests for an event's files are relayed to the server that holds them, through the same relay #283 added for monitors: playback and HLS, video, thumbnail, frame images, synopsis, generated videos, and DELETE /events/{id}. The caller must be able to see the event's monitor before anything leaves this server.

Routes that only read or write the event's row stay on the server asked: event lists and detail, PATCH, tags, notes, frame rows.

Export degrades, it does not fail. An export that includes an event on another server's storage carries that event's details and a files-unavailable.txt naming the server, without the media.

Worth a reviewer's eye

  • Two notions of "this server". The relay uses the id ZoneMinder's daemons go by. The reaper and audit use the wider answer, which also matches by hostname, so a host that only matched that way still skips other servers' files. Skipping more is the safe direction.
  • Default storage. An event with storage id NULL or 0 is treated as local. If that default path is in fact per-server and unshared, the relay and export won't detect it. The reaper still skips correctly, because it works per storage.
  • media_job_store::next_queued gained a skip argument. That is the whole change to the store.
  • forward_to_owner's shared tail moved into relay_to_server, so the event relay reuses the loop guard, the no-address error and the WebSocket refusal. The monitor relay's messages are unchanged.

Limits

  • /jobs lists the queue this server sees.
  • Export does not fetch media from the other server.
  • There is no bulk event delete, so nothing to split across servers.

Checked

  • cargo fmt --all -- --check and cargo clippy --all-targets --all-features -- -D warnings are clean
  • cargo test --all-features: 1416 passed, 0 failed
  • Database-backed suite: 564 passed, 0 failed
  • New tests: 9 relay tests in tests/it_cluster.rs, plus one each in it_retention.rs, it_maintenance.rs and it_media_jobs.rs. They cover shared storage (NULL and 0), own storage, a single-server install, a caller who can't see the monitor, a relayed delete, the loop guard, and the reaper and audit leaving another server's storage untouched
  • openapi.json is unchanged

Not checked: a real two-node install with per-server storage. The holodeck lab uses shared storage, so it does not exercise this. Signed-link (?st=) requests through the new layer are covered by reading, not by a test.

Refs #230.

🤖 Generated with Claude Code

Storage.ServerId says which server holds a storage area's files. NULL or
0 is shared storage every server reaches; any other value is local to
that server. zm-api ignored the column everywhere, so on a multi-server
install with per-server storage:

- the retention reaper and the audit ran against storages whose files
  this server cannot see. The audit could take every event there for
  media-less, and the reaper measured the wrong disk
- event video, frame images and thumbnails failed on the wrong server
- deleting an event there removed the row and left the files
- a media job could be claimed by a server that cannot read the event

Background jobs now leave another server's storage alone, files and rows
both: the reaper, the audit's filesystem pass and its removal of empty
events, the event audit's media check, and the media job worker. The
storage endpoints report no filesystem figures for it.

Requests that read or change an event's files are relayed to the server
that holds them, as monitor requests already are: playback, HLS, frame
images, thumbnails, synopsis, generated videos and DELETE /events/{id}.
Routes that only touch the event's row stay on the server asked. The
caller must be able to see the event's monitor before anything is
relayed.

An export that includes an event on another server's storage carries
its details and a note naming the server, without the media.

Refs #230.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@SteveGilvarry
SteveGilvarry merged commit 69755d4 into master Nov 18, 2026
15 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 18, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant