Circuit breaker for Milvus protocol operations.
States: :closed (normal) | :open (fail-fast) | :half-open (probing).
Flow:
check returns {:success? false :error :circuit-open
:retry-after ms :reconnecting? true} until cooldown-ms has elapsed
since opened-at.check transitions to :half-open and allows
the call through as a probe. record-success! closes the breaker
and notifies subscribers; record-failure! reopens it (resets
opened-at=now).Subscribers: callers can subscribe! a 0-arity fn invoked on every
:closed transition (open->closed or half-open->closed). Used by the
queue drain module to flush buffered writes when Milvus is healthy.
Thread-safety: single atom, swap! transitions; listener fns run on the caller's thread that closed the breaker (keep them fast or spawn futures inside).
Time discipline: routes wall-clock through hive-ttracking.clock/now-millis
so tests can pin time deterministically — never call
System/currentTimeMillis directly.
Circuit breaker for Milvus protocol operations.
States: :closed (normal) | :open (fail-fast) | :half-open (probing).
Flow:
- :closed - calls pass through. N consecutive connection failures
(threshold) -> :open with opened-at=now.
- :open - `check` returns {:success? false :error :circuit-open
:retry-after ms :reconnecting? true} until cooldown-ms has elapsed
since opened-at.
- cooldown elapsed - next `check` transitions to :half-open and allows
the call through as a probe. `record-success!` closes the breaker
and notifies subscribers; `record-failure!` reopens it (resets
opened-at=now).
Subscribers: callers can `subscribe!` a 0-arity fn invoked on every
:closed transition (open->closed or half-open->closed). Used by the
queue drain module to flush buffered writes when Milvus is healthy.
Thread-safety: single atom, swap! transitions; listener fns run on
the caller's thread that closed the breaker (keep them fast or spawn
futures inside).
Time discipline: routes wall-clock through `hive-ttracking.clock/now-millis`
so tests can pin time deterministically — never call
`System/currentTimeMillis` directly.(check)Gate a protocol call against the breaker.
Returns nil when the call is allowed (:closed or :half-open probe). Returns a fail map when :open and still in cooldown:
{:success? false :error :circuit-open :retry-after <ms remaining> :reconnecting? true}
Side effect: transitions :open -> :half-open when cooldown has elapsed, so the next caller gets a probe slot.
Gate a protocol call against the breaker.
Returns nil when the call is allowed (:closed or :half-open probe).
Returns a fail map when :open and still in cooldown:
{:success? false
:error :circuit-open
:retry-after <ms remaining>
:reconnecting? true}
Side effect: transitions :open -> :half-open when cooldown has
elapsed, so the next caller gets a probe slot.(configure! {:keys [threshold cooldown-ms]})Update breaker tunables without changing :state. Accepts {:threshold N :cooldown-ms ms} - only non-nil keys are merged.
Update breaker tunables without changing :state. Accepts
{:threshold N :cooldown-ms ms} - only non-nil keys are merged.(force-reset!)Force the breaker back to fresh :closed state. Intended for tests and manual admin recovery. Does NOT notify listeners.
Force the breaker back to fresh :closed state. Intended for tests and manual admin recovery. Does NOT notify listeners.
(record-failure!)Record a connection-failure outcome. State transitions:
Record a connection-failure outcome. State transitions: - :closed -> inc failures; if failures>=threshold trip :open. - :half-open -> trip back to :open (probe failed). - :open -> no-op (cooldown already running).
(record-success!)Record a successful outcome. State transitions:
check).Record a successful outcome. State transitions:
- :closed -> reset failures to 0.
- :half-open -> close the breaker, reset failures, notify listeners.
- :open -> close the breaker, reset failures, notify listeners
(defensive: should not normally happen because :open
short-circuits via `check`).(state)Return the current breaker state map.
Return the current breaker state map.
(subscribe! f)Register a 0-arity fn to be invoked on every transition to :closed. Returns the registered fn. Duplicate registrations are no-ops.
Register a 0-arity fn to be invoked on every transition to :closed. Returns the registered fn. Duplicate registrations are no-ops.
(unsubscribe! f)Deregister a previously-subscribed listener fn.
Deregister a previously-subscribed listener fn.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |