# `Slap.Cluster.Strategy.LeaseLoop.Store`
[🔗](https://github.com/mjrusso/slap/blob/slap_cluster-v0.6.1/slap_cluster/lib/slap/cluster/strategy/lease_loop.ex#L91)

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`.

# `ctx`

```elixir
@type ctx() :: %{
  cluster: module(),
  cluster_name: String.t(),
  me: String.t(),
  ttl: pos_integer(),
  shards: pos_integer(),
  timeout: pos_integer()
}
```

# `shard`

```elixir
@type shard() :: non_neg_integer()
```

# `state`

```elixir
@type state() :: term()
```

# `claim`

```elixir
@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}]`.

# `heartbeat`

```elixir
@callback heartbeat(state()) :: {:ok | {:error, term()}, state()}
```

# `init`

```elixir
@callback init(opts :: keyword(), ctx()) :: state()
```

# `leave`

```elixir
@callback leave(state()) :: state()
```

Frees every lease of this node and removes its heartbeat (clean stop).

# `live_nodes`

```elixir
@callback live_nodes(state()) :: {{:ok, pos_integer()} | {:error, term()}, state()}
```

# `owners`

```elixir
@callback owners(state()) ::
  {{:ok, %{required(shard()) =&gt; String.t()}} | {:error, term()}, state()}
```

The owner of every unexpired lease.

# `release`

```elixir
@callback release(state(), shard()) :: state()
```

Frees this node's lease of `shard`, if it still holds it.

# `renew`

```elixir
@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.

# `setup`

```elixir
@callback setup(state()) :: {:ok | {:error, term()}, state()}
```

Creates what is missing. A transient error is retried. Return
`{:error, {:unsupported, reason}}` when the store cannot meet the lease
protocol's requirements.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
