Running a cluster
Step by step, three servers and three watchers with automatic failover, using the settings of the project's own test harness, plus how to check, test and stop it.
This page builds a three-node cluster with automatic failover from the commands and settings of the project's real-process failover test and the watcher's settings. The test runs everything on loopback; the notes say what changes across machines. Nothing here has been run by this manual's author on your hardware: test your own cluster as in the last section.
What you need#
- Three machines (or, for a try-out, three ports on one machine). Three watchers, one per node.
- A private network or tunnels between them: no TLS on the data stream, the control calls or the watcher messages.
- The same
userlines on every node (accounts are not replicated).
1. The nodes#
Each node's raftdb.conf (from the harness, with the data directory and ports changed per node):
dir = /var/lib/raftdb
addr = 127.0.0.1:7480
shards = 2
control = true
user = ctl:CTL_PASSWORD:control
user = app:APP_PASSWORD:admin
replica-user = app:APP_PASSWORD
sync-replicas = 1
sync-timeout-ms = 1500control = truemakes the node read-only until a watcher gives it a role.ctlis the control account the watchers use; it can do nothing with data.appis the data account;replica-useris what a follower uses to read the leader, so it must be able to read every database.sync-replicas = 1with three nodes: each write is confirmed by one follower.- Across machines, bind a network address:
addr = 0.0.0.0:7480needsprofile = primary(thesingleprofile refuses non-loopback addresses). Note that with explicituserlines theprimaryprofile creates noreplicatoraccount. - Use a different
dirper node on one machine, and a differentaddrport. - Start each node:
raftdb-server --config /etc/raftdb/raftdb.conf.
2. The watchers#
Each watcher's watch.conf (the harness's, for node 1; change cluster_id, name, address per node):
name = n1
address = NODE1_HOST:7480
user = app
password_file = /etc/raftdb/app.pw
probe_write = false
interval_seconds = 5
timeout_ms = 2000
cluster_id = 1
cluster_peers = 1=W1HOST:7600@N1HOST:7480,2=W2HOST:7600@N2HOST:7480,3=W3HOST:7600@N3HOST:7480
cluster_secret = LONG_RANDOM_SECRET
control_user = ctl
control_password_file = /etc/raftdb/ctl.pw
lease_ms = 3000
control_margin_ms = 500
sync_replicas = 1
control_fail_after_ms = 3000
control_dir = /var/lib/raftdb-watchaddressis this watcher's own node.cluster_idis its id incluster_peers.sync_replicasmust equal the nodes'sync-replicas.control_dirholds the quorum's persistent state. Give each watcher its own.cluster_secretmust be the same on all three and kept private.- Start each:
raftdb-watch --config /etc/raftdb/watch.conf(after--check-config).
3. Check it#
Within a few seconds one node should be primary and the other two followers in sync. Look at:
- the watcher's status page (
status_port): agroupsarray of{group, epoch, primary}; GET /v1/control/stateon each node (log in with thectlaccount):writabletrue on exactly one node,inSyncon the followers,dirtyfalse.GET /v1/server:node.roleismasteron the primary andreplicaon followers.
Write through the primary, read from a follower (a synchronous write is already there).
4. Try a failover#
Only on a test cluster. Stop the primary's server (Ctrl-C or kill). Expect writes to fail for about fail_after + 2 x lease + margin (about 12 seconds with these settings), then another node becomes primary and accepts writes. Start the stopped node: it follows the new primary, becomes clean and in sync. Every acknowledged write must be on the new primary; verify with your own row counts. The project's own failover test does the same with real processes; it is not part of the download.
5. Several groups#
Set groups = N on every node and cluster_groups = N on every watcher, the same everywhere. See Table groups and partitioned tables. The project's own three-group test is not part of the download.
6. Operating it#
| Task | How |
|---|---|
| Move a primary on purpose | Handover and rebalancing |
| Take a node down | Hand over its groups first. Stopping two of three nodes leaves no primary. |
| Add or remove a node | Not supported on a running cluster: membership is fixed in cluster_peers (the Raft core has no membership change yet). |
| Replace a lost node | Start a node with an empty data directory and the same settings; it should fetch the catalog and follow the primary (replica copying is tested; replacing a node of a managed cluster this way is not). cluster_peers keeps the same ids. |
Change groups | Not supported on a running cluster. |
| Add an account | Edit the user lines on every node and restart them one at a time, or the new account works on some nodes only. |
| Restart a watcher | The node's lease is no longer renewed while it is down: if it is the primary's watcher, the node stops writing when the lease ends and another node takes over. Restart watchers one at a time. |
Single primary with manual promotion#
If you want a replica but no automatic failover, do not use control: run the primary with --profile primary (and --sync-replicas if you want) and a replica as in Log shipping and read-only replicas. To fail over, stop the primary, POST /v1/promote on the replica, and point the clients to it. A node started without control and without replica-of is a plain primary; without a watcher quorum there is no automatic failover at all.