Liking cljdoc? Tell your friends :D

hive-compose.pipeline.stacks

Stack runs over a context (the one hive-compose.pipeline.ops takes; its engine must satisfy hive-compose.port/IStackEngine):

stack-up! resolve (hc-3) -> plan (hc-4) -> wiring (hc-5) -> view networks -> instances in start order, each up --waited and health-gated -> each instance joins its consumers' view networks under its aliases -> consumers, each only once every instance it binds is healthy, on its view network alone, with its wiring env (secrets read at spawn). stack-down! consumers, then the run's view networks (which detaches shared instances from them), then instances in reverse start order releasing only what no other live run, active section, or the world before this run keeps (hc-4 instance-release). Never volumes. stack-status what each run's containers are doing now. plan hc-4 plan-diff of a stack against what runs. reap! takes down idle, unclaimed runs, as the reaper does sections. claim!/release-claim! agents hold a run (target=stack:<run>).

Runs persist under :stacks {run entry} in the state, beside :active. An entry: {:stack/id :run :started-at :last-touch :plan StackPlan :networks [name] :consumers {consumer {:compose-project :services}} :status :up|:partial :claims {agent Claim} :orphaned-at ms}. What ran before the runs is global, not per run: :preexisting {provider-project #{service}} beside :stacks (run/mark-preexisting, run/reconcile-preexisting).

stack-up!, stack-down!, reap!, claim! and release-claim! are serialized on one lock per state: the monitor of the context's state atom (a reloaded context shares the atom, so it shares the lock). Each holds it across its plan, its engine IO and its state writes, so no down plans a release an up then relies on, and no probe reads a world another stack op is changing. Reads (stack-status, plan) take no lock.

Stack runs over a context (the one `hive-compose.pipeline.ops` takes; its
engine must satisfy `hive-compose.port/IStackEngine`):

  stack-up!     resolve (hc-3) -> plan (hc-4) -> wiring (hc-5) -> view
                networks -> instances in start order, each `up --wait`ed
                and health-gated -> each instance joins its consumers'
                view networks under its aliases -> consumers, each only
                once every instance it binds is healthy, on its view
                network alone, with its wiring env (secrets read at spawn).
  stack-down!   consumers, then the run's view networks (which detaches
                shared instances from them), then instances in reverse
                start order releasing only what no other live run, active
                section, or the world before this run keeps (hc-4
                instance-release). Never volumes.
  stack-status  what each run's containers are doing now.
  plan          hc-4 plan-diff of a stack against what runs.
  reap!         takes down idle, unclaimed runs, as the reaper does sections.
  claim!/release-claim!  agents hold a run (`target=stack:<run>`).

Runs persist under `:stacks {run entry}` in the state, beside `:active`.
An entry: {:stack/id :run :started-at :last-touch :plan StackPlan
:networks [name] :consumers {consumer {:compose-project :services}}
:status :up|:partial :claims {agent Claim} :orphaned-at ms}. What ran
before the runs is global, not per run: `:preexisting {provider-project
#{service}}` beside `:stacks` (`run/mark-preexisting`,
`run/reconcile-preexisting`).

stack-up!, stack-down!, reap!, claim! and release-claim! are serialized
on one lock per state: the monitor of the context's state atom (a
reloaded context shares the atom, so it shares the lock). Each holds it
across its plan, its engine IO and its state writes, so no down plans a
release an up then relies on, and no probe reads a world another stack
op is changing. Reads (stack-status, plan) take no lock.
raw docstring

admitclj

(admit ctx stack-id budget running)

Result<Budget>: budget admitted against :stack/budget, :compose/budget (host-wide: every live run's capped memory plus this stack's) and the host's MemAvailable minus :compose/host-reserve, the instances in running (ids) counting as already paid; else :compose/over-budget.

Result<Budget>: `budget` admitted against :stack/budget, :compose/budget
(host-wide: every live run's capped memory plus this stack's) and the
host's MemAvailable minus :compose/host-reserve, the instances in
`running` (ids) counting as already paid; else :compose/over-budget.
sourceraw docstring

attach-extra!clj

(attach-extra! ctx rid plan consumer? created)

Result<[network]>: in live run rid, each consumer of plan (the run's StackPlan re-resolved with extra consumers, hc-8 suites) matching consumer? gets its view network, joined by the instances it binds, which must already run in the run. Each network is recorded on the run before anything joins it, so a stack-down removes it even when a connect fails; every network this call CREATED is conj'ed onto atom created as soon as its create answers, so the caller can detach them whatever happens. Holds the stack lock for the attach only, never across what runs afterwards.

Result<[network]>: in live run `rid`, each consumer of `plan` (the run's
StackPlan re-resolved with extra consumers, hc-8 suites) matching
`consumer?` gets its view network, joined by the instances it binds, which
must already run in the run. Each network is recorded on the run before
anything joins it, so a stack-down removes it even when a connect fails;
every network this call CREATED is conj'ed onto atom `created` as soon as
its create answers, so the caller can detach them whatever happens. Holds
the stack lock for the attach only, never across what runs afterwards.
sourceraw docstring

claim!clj

(claim! ctx rid agent {:keys [note ttl-minutes seen]})

Result<{:run :claims :claim}>: agent holds run rid; renews an existing claim. ttl-minutes makes it a wave claim, the same law as a section's (promote.swarm/claim-end, bounded by :compose/claim-max-ttl-minutes, needs a note). seen (epoch ms, plain claims only) is when the claim counts as last renewed: a time ahead of now leases a plain claim past the claim TTL for one long step (hc-8 test!'s lease before each cell).

Result<{:run :claims :claim}>: `agent` holds run `rid`; renews an existing
claim. `ttl-minutes` makes it a wave claim, the same law as a section's
(`promote.swarm/claim-end`, bounded by :compose/claim-max-ttl-minutes,
needs a `note`). `seen` (epoch ms, plain claims only) is when the claim
counts as last renewed: a time ahead of now leases a plain claim past the
claim TTL for one long step (hc-8 test!'s lease before each cell).
sourceraw docstring

claim-exclusive!clj

(claim-exclusive! ctx rid agent {:keys [note seen prefix]})

Result<{:run :claims}>: agent claims run rid in ONE swap, iff the run is recorded, is :up, and holds no LIVE claim (claim TTL) of another agent whose id starts with prefix; else :compose/unknown-run, :compose/run-not-up or :compose/run-busy, and nothing is written. A dead claim of that prefix (a JVM that died mid-run) is taken over.

Result<{:run :claims}>: `agent` claims run `rid` in ONE swap, iff the run
is recorded, is :up, and holds no LIVE claim (claim TTL) of another agent
whose id starts with `prefix`; else :compose/unknown-run,
:compose/run-not-up or :compose/run-busy, and nothing is written. A dead
claim of that prefix (a JVM that died mid-run) is taken over.
sourceraw docstring

claim-prefixclj

source

claim-runclj

(claim-run target)

The run id named by a claim target stack:<run>, nil for any other target.

The run id named by a claim target `stack:<run>`, nil for any other target.
sourceraw docstring

claim-ttl-msclj

(claim-ttl-ms settings)

The claim TTL settings decide, in milliseconds: :compose/claim-ttl-minutes, else default-claim-ttl-minutes. ONE reading, shared by claim!, claim-exclusive!, the reaper's idle test and what stack-status shows, so none of them can disagree about when a claim is live.

The claim TTL `settings` decide, in milliseconds: :compose/claim-ttl-minutes,
else `default-claim-ttl-minutes`. ONE reading, shared by claim!,
claim-exclusive!, the reaper's idle test and what stack-status shows, so
none of them can disagree about when a claim is live.
sourceraw docstring

default-claim-ttl-minutesclj

Length a claim holds when the settings name no :compose/claim-ttl-minutes: the default hive-compose.promote.config/defaults carries, read from there, never a second literal to drift from it.

Length a claim holds when the settings name no :compose/claim-ttl-minutes:
the default `hive-compose.promote.config/defaults` carries, read from
there, never a second literal to drift from it.
sourceraw docstring

detach-extra!clj

(detach-extra! ctx rid nets)

Remove networks nets (those attach-extra! created) from run rid, under the stack lock. A run gone meanwhile is left alone: its stack-down removed every network recorded on it. Answers the first error, nil when clean.

Remove networks `nets` (those `attach-extra!` created) from run `rid`, under
the stack lock. A run gone meanwhile is left alone: its stack-down removed
every network recorded on it. Answers the first error, nil when clean.
sourceraw docstring

end-claim!clj

(end-claim! ctx rid agent {:keys [down?]})

{:others [agent] :down Result?}: agent ends its hold on run rid in ONE step under the stack lock: its claim is dropped and the run touched (a kept run gets a full idle TTL from now), then the claims left are re-read, and with down? and none left the run is taken down (stack-down!, reentrant). No claim can land between the check and the down. A run already gone answers {:others []} and is left alone. hc-8 test! ends every matrix through it.

{:others [agent] :down Result?}: `agent` ends its hold on run `rid` in ONE
step under the stack lock: its claim is dropped and the run touched (a kept
run gets a full idle TTL from now), then the claims left are re-read, and
with `down?` and none left the run is taken down (stack-down!, reentrant).
No claim can land between the check and the down. A run already gone
answers {:others []} and is left alone. hc-8 test! ends every matrix
through it.
sourceraw docstring

others-memclj

(others-mem ctx budget)

What :compose/budget is already spent on besides budget (this stack's): the capped memory (closures included) of every live run's instances.

A SHARED instance is one container whoever binds it, so it is keyed by its id, counted once at the largest cap any run gives it, and for one this stack binds too only what the live runs give it beyond this stack's own count. A PRIVATE instance is a container per run: its id (<provider>/<cap>@<consumer>) carries no run, so it is keyed by its compose project and always adds; two runs of one stack sum, they never collapse into one. A run recorded before runs carried :budget counts 0.

What :compose/budget is already spent on besides `budget` (this stack's):
the capped memory (closures included) of every live run's instances.

A SHARED instance is one container whoever binds it, so it is keyed by
its id, counted once at the largest cap any run gives it, and for one
this stack binds too only what the live runs give it beyond this stack's
own count. A PRIVATE instance is a container per run: its id
(`<provider>/<cap>@<consumer>`) carries no run, so it is keyed by its
compose project and always adds; two runs of one stack sum, they never
collapse into one. A run recorded before runs carried :budget counts 0.
sourceraw docstring

planclj

(plan ctx {stack-id :stack run-id :run extra :extra})

Result<{:diff :text :budget :admission}>: hc-4 plan-diff of stack stack-id against what runs now (by compose project label), the capped memory of every instance with the total and what sharing saves (hc-16a), and the rendering of both. :admission is :ok, or the :compose/over-budget error stack-up would answer (then the text says so).

Result<{:diff :text :budget :admission}>: hc-4 plan-diff of stack
`stack-id` against what runs now (by compose project label), the capped
memory of every instance with the total and what sharing saves (hc-16a),
and the rendering of both. `:admission` is :ok, or the
:compose/over-budget error stack-up would answer (then the text says so).
sourceraw docstring

pressure-step!clj

(pressure-step! ctx)

The reaper's memory pressure guard (hc-16a): when the host's MemAvailable is below :compose/host-reserve, stop ONE run, the idle unclaimed run of the lowest :stack/priority (resources/pressure-victim). Answers its row (with :reason :memory-pressure, :available, :reserve), or nil.

The reaper's memory pressure guard (hc-16a): when the host's MemAvailable
is below :compose/host-reserve, stop ONE run, the idle unclaimed run of
the lowest :stack/priority (resources/pressure-victim). Answers its row
(with :reason :memory-pressure, :available, :reserve), or nil.
sourceraw docstring

project-healthclj

(project-health engine cp)

Result<{service {:state :health}}> of the containers of compose project cp, found by compose's own label (no compose file loaded).

Result<{service {:state :health}}> of the containers of compose project
`cp`, found by compose's own label (no compose file loaded).
sourceraw docstring

reap!clj

(reap! ctx)

{:reaped [report]}: take down every idle, unclaimed run, then, while the host is under memory pressure, the lowest-priority unclaimed run (one per pass, so the next pass sees what it freed). A run that cannot be taken down answers its error row and stays. Holds the stack lock from choosing the idle runs and the pressure victim to the last down, so no claim, up or down lands between a choice and its release.

{:reaped [report]}: take down every idle, unclaimed run, then, while the
host is under memory pressure, the lowest-priority unclaimed run (one per
pass, so the next pass sees what it freed). A run that cannot be taken
down answers its error row and stays. Holds the stack lock from choosing
the idle runs and the pressure victim to the last down, so no claim, up
or down lands between a choice and its release.
sourceraw docstring

release-claim!clj

(release-claim! ctx rid agent {:keys [stop?]})

Result<{:run :claims ..}>: agent gives up run rid. With no claim left the run is orphaned (reaped after the orphan TTL), or taken down now with stop?.

Result<{:run :claims ..}>: `agent` gives up run `rid`. With no claim left the
run is orphaned (reaped after the orphan TTL), or taken down now with `stop?`.
sourceraw docstring

resolve-planclj

(resolve-plan ctx stack-id run-id)
(resolve-plan ctx stack-id run-id extra)

Result<{:resolution :plan :wirings :budget}> of stack stack-id for run run-id: resolution (hc-3), StackPlan (hc-4), Wirings (hc-5) and the capped-memory Budget (hc-16a). Pure, no engine. extra ({consumer Needs}, optional) adds consumers that run no containers of their own, such as a suite suite:<id> (hc-8): they are resolved, wired and budgeted, and the stack never starts them. nil or empty changes nothing.

Result<{:resolution :plan :wirings :budget}> of stack `stack-id` for run
`run-id`: resolution (hc-3), StackPlan (hc-4), Wirings (hc-5) and the
capped-memory Budget (hc-16a). Pure, no engine.
`extra` ({consumer Needs}, optional) adds consumers that run no containers
of their own, such as a suite `suite:<id>` (hc-8): they are resolved,
wired and budgeted, and the stack never starts them. nil or empty
changes nothing.
sourceraw docstring

stack-down!clj

(stack-down! ctx opts)

Result<{:runs [report]}>: take down opts {:run id} or every run of {:stack id}. Volumes are never removed. Holds the stack lock throughout.

Result<{:runs [report]}>: take down `opts` {:run id} or every run of
{:stack id}. Volumes are never removed. Holds the stack lock throughout.
sourceraw docstring

stack-statusclj

(stack-status ctx {stack-id :stack run-id :run})

Result<{:stacks [row]}>: every run (narrowed by opts {:stack :run}), its instances' and consumers' containers as they are now.

Result<{:stacks [row]}>: every run (narrowed by `opts` {:stack :run}), its
instances' and consumers' containers as they are now.
sourceraw docstring

stack-up!clj

(stack-up! ctx
           {stack-id :stack
            run-id :run
            wait? :wait?
            extra :extra
            claim :claim
            :or {wait? true}})

Result<{:run :stack :instances [..] :consumers [..] :networks [..]}>: run stack stack (opts {:stack id :run id? :wait? (default true) :claim {agent {:seen ms? :note s?}}?}). The run is recorded before anything starts, so a failure midway answers an error carrying :run that stack-down! releases. With :claim the run is recorded already claimed by those agents, in the same swap that records it (hc-8 test! holds its run from its first instant). Holds the stack lock throughout; a run id already recorded answers :compose/run-exists.

Result<{:run :stack :instances [..] :consumers [..] :networks [..]}>: run
stack `stack` (`opts` {:stack id :run id? :wait? (default true) :claim
{agent {:seen ms? :note s?}}?}). The run is recorded before anything
starts, so a failure midway answers an error carrying `:run` that
stack-down! releases. With `:claim` the run is recorded already claimed by
those agents, in the same swap that records it (hc-8 test! holds its run
from its first instant). Holds the stack lock throughout; a run id already
recorded answers :compose/run-exists.
sourceraw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
←Move to previous article
→Move to next article
Ctrl+/Jump to the search field
× close