Replication and clustering

Handover and rebalancing

How to move a group's primary to another node on purpose, how the watcher rebalances primaries after a node returns, and the rules for renames with several groups.

Handover#

To move the primary of group G to the node with id NODE (to take a node down, or to put leaders where you want them), run on any watcher's machine:

curl -X POST -H "Authorization: Bearer <cluster_secret>" "http://127.0.0.1:<status_port>/v1/control/handover?group=G&to=NODE"

The answer 202 only says the request was taken. A watcher that is not the quorum's leader passes the request on to the leader. The leader then:

  1. Checks that the target is a clean follower that holds at least nine tenths of what the primary holds.
  2. Decrees a revoke and waits until the old primary has stopped and the target holds all of its data.
  3. Assigns the target.

That takes about a second, against about 8 s for a failover, with nothing lost. What became of the request is in the watcher's status JSON, field handovers. It is given up (and the normal rules finish the job) if the target is not fit within 10 seconds or the whole takes more than 45 seconds. One handover runs at a time.

The status port listens on this machine only, and the cluster secret is the password for the command: protect it.

Rebalancing#

control_rebalance_after_ms (default 60000, 0 is off): when no decree has been made for that long and nothing is in progress, a group whose primary is not the node that group prefers is handed to that node as above. A node that came back after a failure gets its groups back after about a minute.

Without rebalancing (or before it fires), after a failover the surviving nodes keep the groups they took: in the real-process test, after kill -9 of node 2, node 1 led groups 0 and 1.

Renames with several groups#

A rename of a plain or a partitioned table moves it between groups, because the group follows from the name. With several groups it needs a node that leads group 0 and the groups of the old and the new names, so in a spread cluster hand the groups over to one node first. Otherwise the request is refused with 409 not_leader.

Taking a node down for maintenance#

  1. Hand over every group the node leads to other nodes (one handover per group).
  2. Check the watcher's status JSON: groups shows the new primaries, handovers the outcome.
  3. Stop the node. Its followers keep the quorum: with three nodes you can stop one and writes continue (sync_replicas = 1 still has a follower). Stopping a second node leaves no majority and no primary.
  4. Start it again; it follows its groups' primaries and, after the rebalance interval, takes its groups back.

See also#