wasm_cleanup_manager (wasm v0.16.0)
View SourceInternal: the node-wide cleanup manager.
It performs no filesystem I/O and runs no cleanup callback, so the reaper being slow or absent can never stall it. What it does today:
- The operator view. The reaper pushes its per-state counts and live
requests here, and
stats/0andrequests/0serve that copy, whichwasm_script_worker:cleanup_stats/0andwasm_script_worker:cleanup_requests/0read. They answer while the reaper is busy with its journal, and answer an empty view between a reaper's death and its replacement's first push. - Job leases for cleanup the reaper cannot own.
start_local_cleanup/2andrun_bounded_action/3run under at mostmax_cleanup_jobsleases, with the overflow queued. This count is separate from the reaper's own jobs. - Whether a reaper can be reached, for a steward whose reaper died:
reaper/0. - Admission capacity.
capacity/0is the same ceiling the reaper refuses requests at (max_cleanup_jobs + cleanup_queue_len), andadmit/1andrelease/1keep a count against it, keyed by request id. Nothing insrc/callsadmit/1orrelease/1yet: the reaper still decides admission and answerscleanup_saturateditself. Onlywasm_cleanup_manager_SUITEuses them.
The cleanup work is moving here from the reaper in stages, and the move is not
finished. test/audit/CLEANUP_STEWARD.md is the design record for where it is
going; "Who owns what while the cleanup migration is in progress" in
docs/worker-internals.md says who owns each job today.
The manager is recovering until it has learned the current reaper's generation.
The reaper announces its generation and recovered record count by sending the
manager a message addressed to its pid, so nothing here calls into the reaper and
no module cycle is formed. A reaper-only crash restarts the reaper beneath the
manager (the supervisor is rest_for_one); the manager sees the monitored reaper
go down, returns to recovering, and reaches ready again on the replacement's
announcement. An announcement from an older generation is ignored.
Summary
Functions
Reserve admission for a request. cleanup_saturated when the node is already at
capacity. Admission is idempotent per request id.
How many requests currently hold admission.
How many requests may hold cleanup state at once.
Whether the manager has learned the current reaper's generation. recovering
until it has, ready after.
The hold-vs-fail decision a steward needs when its pinned reaper dies: whether a
reaper can be reached now. {ok, Pid} when one is registered (a supervised
restart is established first through wasm_worker_sup:ensure_reaper/0); gone
when none can be reached, so the steward stops holding and fails the operation.
The generation of the reaper the manager tracks, or 0 if it tracks none.
Release a request's admission. A no-op if it held none.
The operator view's live requests, served from the reaper's last push.
Run one unaccepted cleanup action under a job lease, off the caller.
Run a request's local cleanup fallback under a job lease, off the guardian.
The operator view's per-state counts, served from the reaper's last push so it answers even while the reaper is wedged in journal I/O.
Functions
-spec admit(term()) -> ok | {error, cleanup_saturated}.
Reserve admission for a request. cleanup_saturated when the node is already at
capacity. Admission is idempotent per request id.
-spec admitted() -> non_neg_integer().
How many requests currently hold admission.
-spec capacity() -> non_neg_integer().
How many requests may hold cleanup state at once.
-spec phase() -> recovering | ready.
Whether the manager has learned the current reaper's generation. recovering
until it has, ready after.
-spec reaper() -> {ok, pid()} | gone.
The hold-vs-fail decision a steward needs when its pinned reaper dies: whether a
reaper can be reached now. {ok, Pid} when one is registered (a supervised
restart is established first through wasm_worker_sup:ensure_reaper/0); gone
when none can be reached, so the steward stops holding and fails the operation.
-spec reaper_generation() -> non_neg_integer().
The generation of the reaper the manager tracks, or 0 if it tracks none.
-spec release(term()) -> ok.
Release a request's admission. A no-op if it held none.
-spec requests() -> [map()].
The operator view's live requests, served from the reaper's last push.
Run one unaccepted cleanup action under a job lease, off the caller.
For a register the steward could not have the reaper own -- past the per-request
operation ceiling -- the action still has to run rather than leak. It runs under
the same max_cleanup_jobs bound, and {Tag, released | cleanup_failed} is sent
to ReplyTo when it is done, so the steward answers the guardian without ever
running a callback itself.
-spec start_link() -> {ok, pid()}.
Run a request's local cleanup fallback under a job lease, off the guardian.
The guardian hands over the request's complete mirror when no reaper can own the
cleanup. The manager starts a terminal replacement steward to run it and holds a
lease, so local fallback jobs share the node's max_cleanup_jobs bound with the
reaper's own jobs and a reaper outage cannot create an unbounded burst. Returns
once the job is leased or queued; the manager owns it from there.
-spec stats() -> map().
The operator view's per-state counts, served from the reaper's last push so it answers even while the reaper is wedged in journal I/O.