# slap_cluster v0.2.0 - Table of Contents

> Runs N SlateDB databases (shards) in one store, with placement, fencing, durability notifications and routing.

## Pages

- [slap_cluster](readme.md)
- [Changelog](changelog.md)
- [LICENSE](license.md)

## Modules

- [Slap.Cluster.Host](Slap.Cluster.Host.md): Starts and stops the shards placed on this node, for the strategy.

- Cluster
  - [Slap.Cluster](Slap.Cluster.md): Runs N SlateDB databases ("shards") in one bucket: opens and closes them,
turns SlateDB's writer fencing into supervised events, fans out durability
notifications, and finds the shard for a key. It knows nothing about what
the application stores; the application puts its own per-shard processes
on top.
  - [Slap.Cluster.Hash](Slap.Cluster.Hash.md): XXH64 (xxHash, 64-bit), for placing keys on shards.
  - [Slap.Cluster.Peers](Slap.Cluster.Peers.md): Keeps this node connected to a fixed list of other nodes, retrying every
2 s. Routing between nodes needs distributed Erlang: the node must have a
name and share the cookie.
  - [Slap.Cluster.Shard](Slap.Cluster.Shard.md): The context of a shard placed on this node, given to the application's
shard children and to functions run with `call/3`.
  - [Slap.Cluster.ShardChildren](Slap.Cluster.ShardChildren.md): Starts application processes for a shard after its database opens.

- Placement
  - [Slap.Cluster.Strategy](Slap.Cluster.Strategy.md): Decides which node owns which shard.
  - [Slap.Cluster.Strategy.Distributed](Slap.Cluster.Strategy.Distributed.md): Places shards on the connected nodes of a distributed Erlang cluster with
no database and no leases: every node computes the same placement from
the list of nodes running the cluster (a `:pg` group), by rendezvous
hashing with bounded loads: shard `n` prefers the nodes in decreasing
order of `xxh64("<n>/<node>")`, and goes to the first of them that has
fewer than `ceil(shards / nodes)` shards so far. Every node gets its fair
share, and a node joining or leaving moves few shards besides its own.
  - [Slap.Cluster.Strategy.LeaseLoop](Slap.Cluster.Strategy.LeaseLoop.md): The placement loop of `Slap.Cluster.Strategy.ObjectLease` (leases in
the object store), behind a storage behaviour for other lease stores:
one lease per shard, a heartbeat per node, fair shares, and self-fencing.
Where the leases live is a `Slap.Cluster.Strategy.LeaseLoop.Store`.
  - [Slap.Cluster.Strategy.LeaseLoop.Store](Slap.Cluster.Strategy.LeaseLoop.Store.md): 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`.

  - [Slap.Cluster.Strategy.Local](Slap.Cluster.Strategy.Local.md): Places every shard on this node. For single-node deployments, development
and CI.
  - [Slap.Cluster.Strategy.ObjectLease](Slap.Cluster.Strategy.ObjectLease.md): Places shards on the nodes of a cluster through leases kept as objects in
the cluster's own object store: no database is needed, only the bucket
the shards already live in. It is the lease strategy for deployments
without a database.
  - [Slap.Cluster.Strategy.Static](Slap.Cluster.Strategy.Static.md): A fixed assignment of shards to nodes, from configuration: no database,
no leases, no failover. A node opens its own shards (and reopens them
after a backoff if they fail, like `Slap.Cluster.Strategy.Local`), and
routes to the others by the assignment. If a node is down, its shards are
unavailable until it is back.

