Replication and clustering

Node health shared by the watchers

How the watchers of a cluster agree that a node is down, what they stop sending it, how it comes back, and how to stop a node for maintenance.

In a cluster, the watchers keep one health table in their own replicated log. A node is up, down or in maintenance. Every watcher holds the same table, so when one watcher finds a node dead, all of them know it, and a watcher that takes over as leader keeps the table instead of counting again.

When a node is marked down#

Every watcher checks the other nodes once a second and tells the other watchers which nodes it cannot reach. The leading watcher marks a node down only when both hold:

  1. it has had no report showing the node reachable for health_down_after_ms (default 5 seconds), and
  2. at least health_confirm observers agree (default 2: the leader and one more watcher).

So one watcher alone never marks a live node down: a watcher cut off from the others, or one that cannot reach a healthy node, changes nothing. The leader shows such a node as suspect, with the watchers that cannot reach it, and decides nothing.

What a down node gets#

While a node is down:

  • it is not chosen as the primary of a group, and it does not count as an answering node when a primary is chosen;
  • a handover or a rebalance to it is refused;
  • its own watcher tells it to stay idle instead of acting as a primary;
  • placement counts it as unreachable at once and starts copying its groups to another node, and with placement rules the placement map sent to every node lists it;
  • no server names it to a client: it is left out of the holders and the primary given in a redirect, in the placement view of the binary protocol and in the read hints, and a query over partitions is not sent to it. Clients follow these answers, so they stop using the node within about half a second of the decision. A node in maintenance is left out the same way, except as the primary of a group it still leads.

A primary that is down is still replaced by the normal failover rule (control_fail_after_ms), not by the table.

When a node comes back#

Answering is not enough. The node is up again only after health_up_after_ms (default 10 seconds) of continuous reports and once it has caught up with the primaries of the groups it holds. A node that keeps restarting is not put in and out of use.

Maintenance#

A planned stop is not a failure. Before you stop a node, put it in maintenance on the leading watcher's machine:

curl -X POST -H "Authorization: Bearer <cluster_secret>" "http://127.0.0.1:<status_port>/v1/health/maintenance?node=N&for=SECONDS"

While in maintenance the node gets nothing new, but it is not treated as dead. When the time runs out (or you end it with for=0) it is up if it is back, down if it is confirmed dead, and otherwise stays in maintenance until one of the two is true. Maintenance does not move a running primary: hand its groups over first (see Handover and rebalancing). At most 7 days. A watcher that is not the leader answers 503 with the leader's id.

When the leading watcher's own node dies#

The leading watcher places tables from what its own node reports. If that node stays dead, the leader hands its role to another watcher after leader_step_down_after_ms (default 20 seconds), but only when another watcher can take over: most watchers still answer it, and at least one other watcher reports its own node reachable and is not down or in maintenance. Otherwise it keeps leading, so a cluster is never left without a leader (a single watcher always keeps leading). The watcher that stepped down does not stand for election again until its node has been reachable for health_up_after_ms, so the role does not bounce back and forth; its status page shows heldOff with the reason.

Reading the table#

curl -s http://127.0.0.1:<status_port>/v1/health

Each node has its state, since when (since, Unix seconds), the log position of the decision (epoch) and, in maintenance, its end (until). On the leading watcher ("complete":true) each node also shows whether it is suspect, which watchers cannot reach it now and for how long it has been silent.

Settings#

SettingMeaningDefault
health_down_after_msno report showing a node reachable for this long, confirmed by the other observers, makes it down5000
health_up_after_mscontinuous reports needed before a down node is up again10000
health_confirmobservers that must agree, the leader included; 1 lets the leader decide alone (two watchers)2
leader_step_down_after_msthe leading watcher hands over when its own node has been dead this long and another watcher can take over; 0 = never20000

Upgrade every watcher and node before relying on the table: older watchers do not know it, and older nodes refuse the placement map that lists a down node.

What is tested, and what is not built yet#

Tested with real watchers on one machine and scripted nodes: a dead node is down at every watcher after 5 seconds when two observers agree; a false suspicion, a broken link between two watchers, and a follower or the leader cut off from all the others never mark a live node down; a change of leader in the middle of a confirmation is finished by the new leader, and the next leader keeps the table; a node comes back only after the hold time and gets no primary role before; maintenance on, off and running out; the placement map carries the down node to every node. Leader hand-over (real watchers, scripted nodes): the leader's node killed, the role moves to another watcher a few seconds after the step-down time and does not come back while the node is dead, placement goes on past a minute and still handles a second dead node; a healthy leader never hands over; a leader that nobody can replace, and a single watcher, keep leading.

Servers (four real servers and watchers on a Linux machine, two runs): a holder killed with kill -9 is down about 5 seconds later and from about half a second after that no server names it to a client, as a holder or as the primary; it is not named while it is down, and is named again once it is up after its restart; a node in maintenance is not named while maintenance lasts.

Not built yet: the client libraries do not read the table themselves (they follow the servers' answers, which leave the node out).