# Cluster Membership

> Read the cluster's nodes and operations, admit a node as a learner and retry a membership change safely.

Rendered page: https://iggy.apache.org/docs/sdk/cluster-membership/

Source: https://github.com/apache/iggy/blob/master/docs/sdk/cluster-membership.mdx

Docs version: the upcoming Apache Iggy release, from the master branches of apache/iggy and apache/iggy-connectors

The cluster membership reads and changes need root or the global `manage_servers` permission. In this release only the Rust SDK exposes them.

## Read members and operations

`get_cluster_members_page` returns one page of the cluster's nodes in node id order. Each node carries three separate records: the membership it is meant to have (`intent`), the membership the metadata group committed (`committed_role`), and what the answering node observed of it (`observation`).

The page header names the observer, its metadata role, the view, the configuration epoch and when it answered. An admitted learner reports its role as `learner`. The primary can report fresh peer observations. A backup or learner reports only its own reachability. Missing or stale peer evidence reads as unknown. The legacy `get_cluster_metadata` read keeps its shape and lists only the configured roster.

`get_cluster_operation` returns one operation with one page of the group progress the observer holds. Select the operation in progress, an operation by id, or the operation a request started. The reply names the first thing the operation waits for and never contains a grant, verifier or secret. A pending admission waits only for its joining node.

Both reads page in id order with [`PageQuery`](https://iggy.apache.org/docs/sdk/introduction). Read the next page with `PageQuery::next` until the page has no `next`. `get_cluster_operation` refuses a descending page.

## Admit a node

A node absent from the static roster joins as a nonvoting learner:

```rust
let members = client.get_cluster_members_page(&PageQuery::default()).await?;
let secret = JoinGrantSecret::generate()?;
let admission = AdmitClusterNode {
    request_id: ClusterRequestId::generate()?,
    expected_revision: members.revision,
    requested_slot: None,
    endpoint: ClusterNodeEndpoint {
        name: "joiner".to_owned(),
        ip: "10.0.0.9".to_owned(),
        tcp: 8090,
        quic: 0,
        http: 0,
        websocket: 0,
        replica: 8091,
    },
    rack: None,
    grant_verifier: secret.verifier(members.cluster_id),
    expires_at: IggyTimestamp::from(IggyTimestamp::now().as_micros() + 3_600_000_000),
};
let committed = client.admit_cluster_node(&admission).await?;
// The joining node needs three values, once:
// `cluster.join.operation_id` = `committed.operation_id`,
// `--replica-id` = `committed.node_id`,
// `cluster.join.secret` = `secret.expose_hex()`.
```

The joining node presents the secret to an authenticated seed. Enable cluster TLS to encrypt it in transit. The cluster stores only its verifier. See [Joining a running cluster](https://iggy.apache.org/docs/clustering/configuration#joining-a-running-cluster) for the joiner's configuration.

The cluster refuses an admission on a server without clustering, when it does not authenticate its replica links, while another admission is pending, or when a roster node, a pending admission or a bound node holds the slot or the replica endpoint. It refuses with `ClusterInvalidAdmissionExpiry` an `expires_at` that has passed or that lies more than 7 days after the cluster commits the request. `cancel_cluster_admission` cancels a pending admission and revokes its grant.

A node that bound its disk keeps its slot and replica endpoint. This release has no action that removes a bound node, and cancelling one is refused with `ClusterAdmissionRefused`. A node that replaces a lost learner needs a new slot and a new replica endpoint. A later release adds removal.

The cluster keeps up to 1024 admission operations. When an admission finds no room, the cluster drops the oldest operation that is not bound and whose grant expired, together with its request identities. With none to drop the admission fails with `ClusterHistoryFull`. Every grant expires within 7 days, so a full history has room again once its oldest grant expires.

## Retry a membership change

Every change carries a request identity and an expected revision. Keep the `AdmitClusterNode` or `CancelClusterAdmission` value and send it again unchanged after a timeout, a reconnect or a new login: the cluster checks the request identity before the revision and returns the operation the first attempt started, with `existing` set. That reply does not say whether the operation is still pending, so read it with `get_cluster_operation` to see whether it was bound, cancelled or expired since.

Sending the same identity with other parameters fails with `ClusterRequestMismatch`. A new request against a revision that moved fails with `ClusterRevisionChanged`: read the members again and decide anew. A caller that lost the reply entirely finds its operation with `ClusterOperationSelector::Request`.

A retry is answered from the request identity until its operation is dropped to make room, which happens only after the grant expired. A retry after that fails with `ClusterRevisionChanged`. Against the current revision, a dropped admission fails with `ClusterOperationActive` while another admission is pending and with `ClusterInvalidAdmissionExpiry` for its expired grant otherwise, and a dropped cancellation fails with `ClusterOperationNotFound`. A retry never admits the node again.

## SDK methods

| SDK | Methods |
| --- | --- |
| Rust | `get_cluster_members_page`, `get_cluster_operation`, `admit_cluster_node`, `cancel_cluster_admission` |

The HTTP routes are `GET /cluster/members`, `POST /cluster/members` to admit, `GET /cluster/operations/active`, `GET /cluster/operations/{operation_id}`, `GET /cluster/operations/requests/{request_id}` and `POST /cluster/operations/{operation_id}/cancel`, whose body carries the `request_id` and the `expected_revision`. Add `consistency=linearizable` to a read to have a follower relay it to the metadata primary, which holds the fresh evidence. The Rust HTTP client adds it to both reads.
