Repository navigation
feat(cluster): daemon and system control reach every server - #285
Merged
Merged
Conversation
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>
/daemons and /system/* acted only on the server that received the request. On a multi-server install an admin could not see or control another server's daemons, and applying a run state rewrote every monitor's row but restarted daemons on one server only. The others kept running the old configuration. Every daemon and system route now takes an optional server_id: - absent: this server, as before - a number: that server. The request is relayed there with the caller's own token, and its answer returned unchanged - all: every server, concurrently, with one result per server. The answer is 207, and one server failing does not fail the rest POST /system/state writes the database once, then tells each other server to bring its own daemons in line. That call carries a new daemons_only flag: the receiving server writes nothing and passes nothing on, so repeating it is harmless. The response keeps its fields and gains an optional list of the other servers' outcomes. A request another server already relayed is always handled locally. This server authenticates the caller and checks System permission before anything leaves it. Refs #230. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Why
Third PR for multi-server installs (#230). Stacked on #284: until that merges, this diff shows its commit too. Review the last commit,
feat(cluster): daemon and system control reach every server./api/v3/daemonsand/api/v3/system/*acted only on the server that received the request. On a multi-server install:What changes
Every daemon and system route takes an optional
server_id.server_idallserver_id=allanswers 207 Multi-Status, not 200. The body is{ "servers": [ { server_id, name, ok, status, result | error } ] }. One server being down does not fail the others: its entry hasok: falseand an error naming it. I chose 207 because these routes already document a 200 body, and returning a different shape under 200 would be a breaking change the OpenAPI compatibility check rejects.POST /system/statereaches every server by default. It writes the database once, on the server that got the request. It then sends each other server the same route with a newdaemons_only: trueflag. A server that receives that writes nothing and passes nothing on. It only restarts its own daemons for the monitors the state names. The response keepssuccessandmessageand gains an optionalserverslist. A numericserver_idon this route is 400, because the change is global.Loop guard. A request that carries
X-ZM-Forwarded-Byis always handled locally, whateverserver_idsays.Why not relay the same state request, or a restart
Both were tried on paper and neither works in passive mode:
POST /system/state: the other server compares rows before and after to decide what to restart. The rows have already changed, so it restarts nothing. It would also write them a second time.POST /system/restartanswers 503 in passive mode, where ZoneMinder supervises the daemons.Worth a reviewer's eye
daemons_only. It rewrites the same state, which is idempotent, and in passive mode restarts nothing.server_id=allreturns one entry withserver_id: null. A number that is not this host is 404.Checked
cargo fmt --all -- --checkandcargo clippy --all-targets --all-features -- -D warningsare cleantests/it_cluster_system.rsallwith a server down, the loop guard, permission refused before anything is relayed, a single-server install, the state fan-out,daemons_onlywriting nothing, and a passive server sending zmdc stop and start for its own monitors against a fakezmdc.sockscripts/check-openapi-compat.py: no breaking changes, four additive itemsNot checked: the takeover-mode path for a server receiving
daemons_only, and a real two-server run. Both are covered by reading only.One known flaky test,
streaming::rtsp::session::tests::a_connection_must_authorize_before_the_deadline, failed once in a full run under load and passed on every rerun. It is unrelated to this change.Refs #230.
🤖 Generated with Claude Code