portunus_session (portunus v0.8.0)

View Source

A per-node session: one lease, one renewer, many exclusive keys claimed under it. The session process is the lease holder, so its death releases all of its keys at once. Renewal cost is O(sessions), not O(keys).

On lease loss the session exits with reason lease_lost. A linked opener that does not trap exits crashes with it (the fail-stop default, since its claims are gone). Trap exits to handle the loss instead.

Summary

Functions

Claim an exclusive key under the session; returns its fencing token.

Open a session. Opts: ttl_ms, proposed_id (a stable proposed lease id). After a partition, reopening with a proposed_id can return {error, id_in_use} until the previous incarnation's lease expires; supervisor restart handles it.

Types

session()

-type session() :: pid().

session_opts()

-type session_opts() :: #{ttl_ms => pos_integer(), proposed_id => portunus:lease_id()}.

Functions

claim(Session, Key)

-spec claim(session(), portunus:lock_key()) ->
               {ok, portunus:token()} | {error, portunus:acquire_error()}.

Claim an exclusive key under the session; returns its fencing token.

close(Session)

-spec close(session()) -> ok.

handle_call/3

handle_cast(Msg, State)

handle_info/2

init/1

keys(Session)

-spec keys(session()) -> [portunus:lock_key()].

open(Name)

-spec open(portunus:name()) -> {ok, session()} | {error, term()}.

open(Name, Opts)

-spec open(portunus:name(), session_opts()) -> {ok, session()} | {error, term()}.

Open a session. Opts: ttl_ms, proposed_id (a stable proposed lease id). After a partition, reopening with a proposed_id can return {error, id_in_use} until the previous incarnation's lease expires; supervisor restart handles it.

release(Session, Key)

-spec release(session(), portunus:lock_key()) -> ok | {error, portunus:release_error()}.

terminate/2