Advisory locks, the registry and its operations.
They live here rather than in the server because a TRANSLATED
pg_advisory_lock(…) -- one written inside an expression rather than
as a whole statement -- has to reach them from the SQL layer, which
the server namespace requires rather than the other way round.
Advisory locks, the registry and its operations. They live here rather than in the server because a TRANSLATED `pg_advisory_lock(…)` -- one written inside an expression rather than as a whole statement -- has to reach them from the SQL layer, which the server namespace requires rather than the other way round.
(advisory-lock! lock-key session-id xact?)(advisory-lock! lock-key session-id xact? mode)Blocking acquire. Spin-wait with exponential backoff up to 100ms.
Blocking acquire. Spin-wait with exponential backoff up to 100ms.
(advisory-lock-try! lock-key session-id xact?)(advisory-lock-try! lock-key session-id xact? mode)Acquire a single advisory lock, non-blocking. Returns true on success, false while another session holds it in a conflicting mode.
mode is :exclusive or :shared, PostgreSQL's
pg_advisory_lock / pg_advisory_lock_shared pair: two SHARED
holders coexist, an exclusive holder excludes every other session.
A same-session, same-level, same-mode re-lock increments the refcount
at session level and is a no-op at transaction level, as in
PostgreSQL.
Acquire a single advisory lock, non-blocking. Returns true on success, false while another session holds it in a conflicting mode. `mode` is `:exclusive` or `:shared`, PostgreSQL's `pg_advisory_lock` / `pg_advisory_lock_shared` pair: two SHARED holders coexist, an exclusive holder excludes every other session. A same-session, same-level, same-mode re-lock increments the refcount at session level and is a no-op at transaction level, as in PostgreSQL.
(advisory-unlock! lock-key session-id)(advisory-unlock! lock-key session-id mode)Release one SESSION-level hold of lock-key in mode: decrement the
refcount, dropping the hold at zero. Returns true when we held one.
A transaction-level lock cannot be unlocked by hand in PostgreSQL --
it releases at transaction end -- and answers false here too (with a
WARNING there, which we do not emit).
Release one SESSION-level hold of `lock-key` in `mode`: decrement the refcount, dropping the hold at zero. Returns true when we held one. A transaction-level lock cannot be unlocked by hand in PostgreSQL -- it releases at transaction end -- and answers false here too (with a WARNING there, which we do not emit).
(held-advisory-locks)The advisory locks currently held, as [[lock-key mode] …], one entry
per object and mode -- which is how pg_locks reports them: a session
holding the same object at both levels is ONE row there.
The advisory locks currently held, as `[[lock-key mode] …]`, one entry per object and mode -- which is how `pg_locks` reports them: a session holding the same object at both levels is ONE row there.
(release-advisory-locks! session-id)(release-advisory-locks! session-id scope)Release advisory locks owned by session-id, within scope:
:xact only the transaction-level ones (COMMIT / ROLLBACK)
:session only the session-level ones -- what
pg_advisory_unlock_all() does, which in PostgreSQL
leaves a transaction-level lock held until the
transaction ends
:all every one of them (connection close, DISCARD ALL)
The legacy boolean arity means :xact when true, :all when false.
Release advisory locks owned by `session-id`, within `scope`:
:xact only the transaction-level ones (COMMIT / ROLLBACK)
:session only the session-level ones -- what
`pg_advisory_unlock_all()` does, which in PostgreSQL
leaves a transaction-level lock held until the
transaction ends
:all every one of them (connection close, DISCARD ALL)
The legacy boolean arity means `:xact` when true, `:all` when false.(reset-advisory-locks!)Clear the advisory-lock registry. Test-fixture helper; not for handler code. In production, locks release on unlock, COMMIT/ROLLBACK (xact- level), DISCARD ALL, or connection close.
Clear the advisory-lock registry. Test-fixture helper; not for handler code. In production, locks release on unlock, COMMIT/ROLLBACK (xact- level), DISCARD ALL, or connection close.
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 |