barrel_design_slots (barrel_design v0.1.0)
View SourceConcurrency caps for guest jobs, per node and per database, and the activations allowed to run them.
Every guest call runs under a slot: indexing batches, previews and read-time reducers. A slot is held by its caller and bound to the job process the runner spawns, and it lives as long as either: when the caller dies its job is killed, and the slot is freed only once that job is gone, so a cancelled request never frees capacity while its guest still runs. try_acquire/2 answers busy at once; acquire/2,3 wait until a deadline. A slot names the manager that granted it.
An activation is one running life of a design name in a database, owned by that database's process. Slots tagged {Name, Activation} are admitted, at acquire and at bind, only while the activation is current and its owner alive. Deactivating it, or its owner's death, kills its bound jobs and answers once they are gone; adopting a database waits for every such drain. Jobs are linked to the manager and listed in a table the supervisor owns: a restarted manager kills the jobs still listed and waits for them before serving anything.
node_jobs defaults to half the schedulers (at least 1), db_jobs to 2. info/0 reports held slots, running jobs and their high-water marks.
Summary
Functions
Wait for a slot until Deadline (monotonic milliseconds).
acquire/2 for the jobs of one activation, {Name, Activation}.
The current activation of a name, made if it has none. Only the owner of the database may ask.
The calling process owns Db from now on. Returns once every job of an earlier owner's activations, and of any drain in progress for the database, is gone.
Bind the job process the runner spawned to its slot, at the manager that granted it. {error, revoked} when the slot's activation is gone or that manager is: the job must not run.
End the activation of a name, or of every name of the caller's database (all): nothing tagged with it is admitted any more, and this returns once its bound jobs are gone.
Whether the manager that granted the slot still runs: a job that died while it does died for its own reason.
The table of bound jobs, {Job, Db, Tag}, created by the supervisor so it survives this process.
Give the slot back; returns once its job, if any, is gone. A slot of a manager that is gone is already free.
Start the high-water marks again from the current values.
A slot now, or busy.
Run Fun(Slot) under a slot taken before Deadline.
Types
Functions
Wait for a slot until Deadline (monotonic milliseconds).
-spec acquire(binary(), integer() | infinity, term()) -> {ok, slot()} | {error, timeout} | {error, revoked}.
acquire/2 for the jobs of one activation, {Name, Activation}.
The current activation of a name, made if it has none. Only the owner of the database may ask.
-spec adopt(binary()) -> ok.
The calling process owns Db from now on. Returns once every job of an earlier owner's activations, and of any drain in progress for the database, is gone.
Bind the job process the runner spawned to its slot, at the manager that granted it. {error, revoked} when the slot's activation is gone or that manager is: the job must not run.
End the activation of a name, or of every name of the caller's database (all): nothing tagged with it is admitted any more, and this returns once its bound jobs are gone.
Whether the manager that granted the slot still runs: a job that died while it does died for its own reason.
-spec info() -> map().
-spec jobs_table() -> atom().
-spec new_jobs_table() -> ok.
The table of bound jobs, {Job, Db, Tag}, created by the supervisor so it survives this process.
-spec release(slot()) -> ok.
Give the slot back; returns once its job, if any, is gone. A slot of a manager that is gone is already free.
-spec reset_peaks() -> ok.
Start the high-water marks again from the current values.
A slot now, or busy.
Run Fun(Slot) under a slot taken before Deadline.