Replication and clustering

Changing the configuration of a running cluster

Set a configuration item once on the watchers, see per node who applied it, refused it or still waits, and go back to the previous set. What works today and what does not yet.

A cluster's watchers keep one configuration set in their replicated log: lines key = value, or node N: key = value for one node only. You write it once, on any machine's watcher, and every watcher applies it; the leading watcher keeps a table of which node has applied which version.

What this version applies: the watcher settings below take effect on every watcher at once, and the live server settings take effect on every server with its next write, read or query, without a restart. A server keeps the set it applied in its data folder and applies it again when it starts. A server of an earlier version has no such route: its row says refused with that reason, and the rest of the cluster goes on.

Writing#

On the status port of a watcher (this machine only), with the cluster secret:

curl -s http://127.0.0.1:<status_port>/v1/config                      # the set, its version, the table per node, the history
curl -X PUT -H "Authorization: Bearer <cluster_secret>" --data-binary "health_up_after_ms = 20000" "http://127.0.0.1:<status_port>/v1/config?expected=N"
curl -X PUT -H "Authorization: Bearer <cluster_secret>" "http://127.0.0.1:<status_port>/v1/config?expected=N&revert=1"
curl -X DELETE -H "Authorization: Bearer <cluster_secret>" "http://127.0.0.1:<status_port>/v1/config/health_up_after_ms?expected=N"

expected is the version you read (0 the first time), so two people cannot overwrite each other (409 with the current version). The lines you send are merged into the set; DELETE removes one key (add &node=N for a node line), and the process goes back to the value in its own file; revert=1 writes the set before the current one as a new version. Ask the leading watcher: another answers 503 with the leader's id.

A bad write changes nothing. An unknown key, a value out of range, a node that is not a member, or a key that can never change on a running cluster is refused with the reason (400, or 409 for those fixed keys), and nothing is stored or sent anywhere.

Kinds of settings#

KindSettingsWhat happens
live, watcherhealth_down_after_ms, health_up_after_ms, health_confirm, placement_down_after_ms, placement_max_jobs, placement_max_jobs_per_node, sync_replicasapplied by every watcher at once
live, serversync-timeout-ms, lag-beacon-ms, read-wait-ms, gather-timeout-ms, gather-max-take, gather-max-groups, gather-max-inflightsent to each node by its watcher and applied at once; a server refuses a whole set it cannot take (for example a value out of its range), with the key and the reason
restart, serverlabels, ship-early, alloc-cache, lsm-l0-triggersent to each node and kept by the server for its next start; a rolling restart (below) applies them one node at a time
restart, otheraddr, dir, profile, lease_ms, control_fail_after_msstored and shown per node as needing a restart; applied only when you restart that program with the changed file
fixedgroups, shards, engine, cluster_groups, cluster_peersrefused

Who applied what#

GET /v1/config on the leading watcher lists every node with applied, pending (not yet; for example the node is stopped: it gets the set when it returns), refused (with the node's own reason; it is not sent again until the set changes), declined (that node's watcher has config_mode = off) or unknown (never heard), the restart items that concern it, and how old its report is. Every change is logged by the watchers with its version.

config_mode = off in a watcher's file makes that watcher and its node ignore the cluster set.

sync_replicas#

sync_replicas is one item for the watchers and the servers. It is changed in two steps so that the watchers never count on more confirmations than the servers wait for: when raising it the servers' value goes up first, when lowering it the watchers' value goes down first; the leading watcher writes the second step itself once every node has applied the first. It cannot be more than the members less one, nor more than copies - 1 of a placement rule. A server that has not applied the first step (stopped, or of an earlier version) holds the second step back.

What is tested, and what is not built yet#

Tested with three real watchers on one machine and scripted nodes that apply the server settings: a live item reaches all three nodes and the table shows all applied; a node that refuses is named with its reason; nine kinds of bad writes are refused and change nothing; a stopped node gets the set when it returns; revert and delete; the set kept across a change of leader and a watcher restart; config_mode = off; sync_replicas raised and lowered in the safe order; a node that answers like a server without the live route is sent nothing for watcher settings and is shown refused, with the reason, for a server setting.

Tested with three real servers and watchers on a Linux machine, under continuous writes: live server settings reached all three servers and the table showed them applied; sync_replicas raised and lowered with the watchers never counting on more confirmations than the servers waited for; a server that was killed got the set when it came back; revert; a server of an earlier version shown refused with its reason; every acknowledged write read back afterwards.

Applying restart settings: a rolling restart#

After the set is applied everywhere, give the leading watcher an update plan with action = restart (no target):

PUT /v1/update/plan?expected=N      action = restart
                                    mode = apply
                                    window = any

The watchers restart the nodes that have such settings one at a time, as an upgrade does: a node that leads a group hands it over first, is put in maintenance, drains, stops, starts again with the same version and is checked; the next node goes only when it is back and caught up. If a node fails its checks it is started again and the roll stops there. A server shows the settings it started with from the cluster as config_restart and those waiting for a restart as config_restart_pending. A value given on a server's command line or in its environment still wins.

Not built yet: an automatic revert when a node fails its checks after a change.