Skip to content

Operator lesson 3: A cluster

Join two more nodes to a forge on one machine, see every group settle on three voters, land through any node, stop the leader and keep landing, and see the node that was stopped catch up.

Time: 30 minutes. Track: operator. Before this: operator lesson 1.

By the end of this lesson you will be able to:

  • enroll a node and join it to a forge;
  • read the cluster as a node sees it with af cluster peers, and say when it is settled;
  • land through a node that does not lead, and keep landing while a node is down;
  • retire a voter, and see a learner take its place.

Enroll two nodes

A forge is a cluster of nodes that each hold every group’s copy: the platform’s, each organization’s and each repository’s, each its own Raft group. A group answers while a majority of its voters is up, so a cluster of three keeps working with any one node down. The three nodes run on one machine here, each on ports of its own; on several machines the commands are the same, with each machine’s own address.

Start the forge, node 1, in your home directory: it keeps its data in ~/af-dev, and writes the forge’s address and certificate to ~/af-dev/dev/env.

$ af-server --dev
...

No node joins on its own say. On the new machine, af-server --enrollment makes the node’s keys in its data directory and prints the af command that enrolls it: its name, the address other nodes reach it at, and its public keys. A platform administrator, here you, runs that command; the node is born, and its ID is what it joins as:

$ source ~/af-dev/dev/env
$ af-server --data-dir ~/node-2 --raft-advertise 127.0.0.1:7788 --node-name node-2 --enrollment > ~/node-2.enroll
$ sh ~/node-2.enroll | tee ~/node-2.id
done: it took effect at once, on your word as an administrator
born bec991b296d7fa20832d7b77f52e6c411a092a58387fa2895c15efdfef119291
$ af-server --data-dir ~/node-3 --raft-advertise 127.0.0.1:7798 --node-name node-3 --enrollment > ~/node-3.enroll
$ sh ~/node-3.enroll | tee ~/node-3.id
done: it took effect at once, on your word as an administrator
born 4e66aebf9d491f5259eab28da13454409c9ee64c663f306b25fba453ec2f10b6

Join them

Each node joins through the forge’s address, naming the ID it was born with and trusting the forge’s certificate by its hash. It takes the cluster’s key from a member, sealed to its own sealing key, and then a copy of every group. Start each in a terminal of its own; a new terminal takes the forge’s address and certificate from ~/af-dev/dev/env first:

$ source ~/af-dev/dev/env && af-server --data-dir ~/node-2 --join "$AF_ADDRESS" --join-as "$(sed -n 's/^born //p' ~/node-2.id)" \
>     --join-cert-hash "$AF_CERT_HASH" --tls-cert ~/af-dev/dev/tls.pem --tls-key ~/af-dev/dev/tls.pem \
>     --listen 127.0.0.1:7787 --raft-listen 127.0.0.1:7788
$ source ~/af-dev/dev/env && af-server --data-dir ~/node-3 --join "$AF_ADDRESS" --join-as "$(sed -n 's/^born //p' ~/node-3.id)" \
>     --join-cert-hash "$AF_CERT_HASH" --tls-cert ~/af-dev/dev/tls.pem --tls-key ~/af-dev/dev/tls.pem \
>     --listen 127.0.0.1:7797 --raft-listen 127.0.0.1:7798

Each answers once its copies have arrived:

$ af --address 127.0.0.1:7787 log -r 'root()'
○  zzzzzzzz  1970-01-01T00:00:00Z 00000000
   (no description set)
$ af --address 127.0.0.1:7797 log -r 'root()'
○  zzzzzzzz  1970-01-01T00:00:00Z 00000000
   (no description set)

Wait for the cluster to settle

A node that joins is first a learner in each group: it takes the group’s log but does not vote, so a node still catching up cannot hold back a majority. The forge then makes it a voter. af cluster peers shows the cluster as the node you ask sees it: each node enrolled, and each group with its leader and voters. Wait until every group has all three voters:

$ af cluster peers
...
node 2  node-2  127.0.0.1:7788  enrolled
node 3  node-3  127.0.0.1:7798  enrolled
group 1  the platform              leader 1  voters 1 2 3  settled
group 2  organization operator     leader 1  voters 1 2 3  settled
group 3  repository operator/main  leader 1  voters 1 2 3  settled
all 3 groups settled with voters 1 2 3, each with a leader

The first two lines name node 1, which a development forge names after your machine. A group whose membership is being changed shows changing, with the voters committed so far. Until the last line says every group is settled with all three voters, a node down can still cost a group its majority: do not stop one before.

Land through any node

Every node answers reads from its own copy and sends a write to the group’s leader. Point af at node 2 and land a change:

$ export AF_ADDRESS=127.0.0.1:7787
$ af workspace add ~/w
Workspace at /home/you/w
Paths: **
main has no landing yet
$ cd ~/w
$ af new -m "Land through node two"
Working on change yrxkropulxrlnrnqrwzzstmnysurutmx at commit c4c12587db0d6f115674aab61e8253ba9557e7ee25e0a8fd4a3c692c30a393fe
$ printf 'one\n' > one.txt
$ af submit
Submitted commit ecd87b4fda34bb362ab1f742eb1bb3832b29c7a3cd5e794dec521165943ca4d6, 1 edit in its last snapshot

Node 2 sent the landing to node 1, which leads the repository’s group, and node 3 has it too:

$ af status
Change yrxkropulxrlnrnqrwzzstmnysurutmx (landed) at commit ecd87b4fda34bb362ab1f742eb1bb3832b29c7a3cd5e794dec521165943ca4d6
$ af --address 127.0.0.1:7797 log -r main
@  yrxkropu dev@localhost 2026-11-26T11:03:09Z ecd87b4f
│  Land through node two
~

Stop the leader

Stop node 1, the leader of every group, in the terminal where it runs:

^C

Nodes 2 and 3 are two of three voters, a majority. A follower that hears nothing from node 1 for its election timeout, between one and two seconds, starts an election, and its group elects one of them, voting again if a vote splits. Node 2 answers once its group has a leader:

$ af log -r main
@  yrxkropu dev@localhost 2026-11-26T11:03:09Z ecd87b4f
│  Land through node two
~

Node 1 is still a voter of each group: a node that stops changes no membership, so it can come back. Ask node 2 how it sees the cluster now:

$ af cluster peers
...
all 3 groups settled with voters 1 2 3, each with a leader

Which of nodes 2 and 3 leads each group differs from one run to the next. Just after the stop a node can still name node 1 as a leader, until its election timeout has passed; af cluster peers --verbose says when each node last heard from each leader.

Landing with node 1 down is what shows the groups take writes again. Each write goes through node 2 to whichever node leads its group now. One that reaches node 2 while its group is still electing waits for the new leader, for up to the group’s longest election, rather than being refused at once:

$ af new -m "Land with node one down"
Working on change twukxpvyksvkrltnopwkwttkvunrpvts at commit 407bc523705549e58d8bae4bc9fb24a7deed0457d6e1624fe4fd08d5ffc37d2f
$ printf 'two\n' > two.txt
$ af submit
Submitted commit 6fa6f1e2ca3943d9abc78be40e71d7eecf6be8515ed2a3db3022bb1889a83fa2, 1 edit in its last snapshot
$ af status
Change twukxpvyksvkrltnopwkwttkvunrpvts (landed) at commit 6fa6f1e2ca3943d9abc78be40e71d7eecf6be8515ed2a3db3022bb1889a83fa2
Based on landing 1

Bring node 1 back

Start node 1 again, in your home directory as before. It catches up on what each group decided while it was down, and serves the second landing, which it never saw made. A production node also takes the cluster’s key from a member as it starts, sealed to its own sealing key; a development forge reads its key from its own file:

$ af-server --dev
...

Until node 1 has caught up, it answers that the repository has not yet arrived there; how long that takes depends on how much it missed and how busy the machine is. Wait for it to answer, here for up to a minute and a half:

$ timeout 90 sh -c 'until af --address 127.0.0.1:7777 log -r main >/dev/null 2>&1; do sleep 1; done'
$ af --address 127.0.0.1:7777 log -r main
@  twukxpvy dev@localhost 2026-11-26T11:06:20Z 6fa6f1e2
│  Land with node one down
~

A fourth node, and a voter replaced

Each group has at most three voters; a fourth node follows every group as a learner, holding the same databases and answering reads without voting. Enroll and join one, as before:

$ af-server --data-dir ~/node-4 --raft-advertise 127.0.0.1:7808 --node-name node-4 --enrollment > ~/node-4.enroll
$ sh ~/node-4.enroll | tee ~/node-4.id
done: it took effect at once, on your word as an administrator
born 5d3f1a2b8c9e0f7a6b5c4d3e2f1a0b9c8d7e6f5a4b3c2d1e0f9a8b7c6d5e4f3a
$ source ~/af-dev/dev/env && af-server --data-dir ~/node-4 --join "$AF_ADDRESS" --join-as "$(sed -n 's/^born //p' ~/node-4.id)" \
>     --join-cert-hash "$AF_CERT_HASH" --tls-cert ~/af-dev/dev/tls.pem --tls-key ~/af-dev/dev/tls.pem \
>     --listen 127.0.0.1:7807 --raft-listen 127.0.0.1:7808

Once node 4 is enrolled, each group’s leader adds it as a learner. Each group’s line ends with its voters, then its learners, and the last line sums them up:

$ af --address 127.0.0.1:7777 cluster peers | grep -o 'voters .*'
voters 1 2 3  learners 4  settled
voters 1 2 3  learners 4  settled
voters 1 2 3  learners 4  settled
voters 1 2 3, each with a leader

A node that stops keeps its vote, as node 1 did: it may come back. A machine that is going for good is retired instead, as an operator retires it: af stop ends its enrollment, and only then is it shut down. Retire node 3, a voter:

$ af stop "$(sed -n 's/^born //p' ~/node-3.id)" --reason "machine retired"
stop reference 78ff4613f3b3ab5b6c189040e40829baecea8ae029aaf78d3b5bd161d8a9f965
stopped 4e66aebf9d491f5259eab28da13454409c9ee64c663f306b25fba453ec2f10b6

Each group’s leader takes node 3 out of its voters and makes node 4 a voter in its place, once node 4 has stayed caught up for ten seconds, as Consul’s autopilot waits for a server to stabilize. Those ten seconds count from when node 4 caught up, not from af stop: node 4 has most likely been caught up that long already, so both can happen at the leader’s next look, in one membership change. A learner that falls behind starts its ten seconds again, and each change must be committed before the next. A group that node 3 led has no leader for a moment once its enrollment ends, as the other nodes no longer answer it, and af may say so: the loop below drops those answers and asks again. The retirement is done when every group has voters 1, 2 and 4. Wait for that, here for up to a minute and a half:

$ timeout 90 sh -c 'until af --address 127.0.0.1:7777 cluster peers 2>/dev/null | grep -q "settled with voters 1 2 4,"; do sleep 2; done'
$ af --address 127.0.0.1:7777 cluster peers
...
node 2  node-2  127.0.0.1:7788  enrolled
node 4  node-4  127.0.0.1:7808  enrolled
...
all 3 groups settled with voters 1 2 4, each with a leader

Node 3 is no longer listed, nor counted. Shut it down:

^C

Exercises

  1. Ask node 4 how it sees the cluster, with when it last heard from each group’s leader.

    $ af --address 127.0.0.1:7807 cluster peers --verbose
    ...
    all 3 groups settled with voters 1 2 4, each with a leader
  2. Stop node 2, land from node 1, and start node 2 again with the command that joined it, less --join and its options: with any one voter down, the other two are a majority.

Check your understanding

Why does a node that joins start as a learner?

A learner takes the group’s log but does not vote. While it catches up it would answer slowly, and as a voter it could keep the group from a majority; as a learner it never counts until it is made a voter.

Why is it safe to stop node 1 only once every group is settled with three voters?

A group answers while a majority of its voters is up. While a group still has one voter and two learners, that voter is the whole majority, and stopping it leaves the group with no leader until it comes back.

Does stopping a node remove it from the cluster?

No. It stays a voter of each group, and catches up when it starts again. The other two voters are a majority meanwhile.

What does retiring a node with af stop do that shutting it down does not?

It ends the node’s enrollment. The node is no longer a member: each group takes it out of its voters, and makes a caught-up learner a voter in its place, so the cluster has three voters again without waiting for a machine that is not coming back.

Next

Operator lesson 5: Purging what must go takes out contents that must not be kept. Lesson 4 needs an identity provider. Running af-server covers a cluster on several machines, and the vault covers unsealing it from recovery shares.

Type to search…

↑↓ navigate↵ selectEsc close