Where a lease strategy keeps its leases and heartbeats. Each callback gets
the store's state and returns it, possibly changed. A lease is
{owner, generation} while unexpired; owners/1 returns only those.
Every call must return within the :timeout given to init/2.
Summary
Callbacks
Claims up to count free or expired leases; returns [{shard, generation}].
Frees every lease of this node and removes its heartbeat (clean stop).
The owner of every unexpired lease.
Frees this node's lease of shard, if it still holds it.
Renews the leases of shards held by this node; returns those renewed.
The others are lost. If some calls failed, it returns {:error, reason, renewed, failed}: failed are the shards whose lease may or may not
still be held (the next renewal tries them again), and the others not
renewed are lost.
Creates what is missing. A transient error is retried. Return
{:error, {:unsupported, reason}} when the store cannot meet the lease
protocol's requirements.
Types
@type ctx() :: %{ cluster: module(), cluster_name: String.t(), me: String.t(), ttl: pos_integer(), shards: pos_integer(), timeout: pos_integer() }
@type shard() :: non_neg_integer()
@type state() :: term()
Callbacks
@callback claim(state(), count :: pos_integer()) :: {{:ok, [{shard(), non_neg_integer()}]} | {:error, term()}, state()}
Claims up to count free or expired leases; returns [{shard, generation}].
Frees every lease of this node and removes its heartbeat (clean stop).
@callback live_nodes(state()) :: {{:ok, pos_integer()} | {:error, term()}, state()}
@callback owners(state()) :: {{:ok, %{required(shard()) => String.t()}} | {:error, term()}, state()}
The owner of every unexpired lease.
Frees this node's lease of shard, if it still holds it.
@callback renew(state(), [shard()]) :: {{:ok, [shard()]} | {:error, term(), [shard()], [shard()]}, state()}
Renews the leases of shards held by this node; returns those renewed.
The others are lost. If some calls failed, it returns {:error, reason, renewed, failed}: failed are the shards whose lease may or may not
still be held (the next renewal tries them again), and the others not
renewed are lost.
Creates what is missing. A transient error is retried. Return
{:error, {:unsupported, reason}} when the store cannot meet the lease
protocol's requirements.