Internals

Watcher and error reports

What the raftdb-watch program checks and fixes, its quorum and resource control modules, and the rules of the raftdb-report fatal-error reports.

raftdb-watch#

raftdb-watch looks after a Raft DB server (decision D41). It is a separate program, so a bug in the server cannot take it down. Every few seconds it checks the server the way a client would (connect, log in, ping, write and read back a canary row, read the status page) and the machine (free disk space). When something stays wrong for several rounds it reports it, fixes it if the fix is basic and safe (restart the server, run a cleanup command written by the operator), and escalates when it cannot ("a person is needed", repeated as a reminder). It only runs commands the operator wrote into its configuration and never touches the data itself.

Modules of raftdb-watch:

ModuleRole
checks.rsThe checks: reachable, login, latency, write_probe, server, disk, replica:<addr>
engine.rsTurns check results into events, reports and fixes within a restart budget
notify.rs, shell.rsReports through a file, a command or a webhook; running operator commands
quorum.rs, control.rsThe control plane: a Raft group of watchers, decide and node_command
resources.rsResource control: sets compaction and replication rate limits
http.rs, config.rsStatus page and configuration keys

Control plane#

Switched on by cluster_peers in the watcher's configuration. Each watcher is the agent of one node and a member of a Raft group; the watcher quorum decides which node is primary (per table group with cluster_groups) and commands nodes through the control interface of the server (POST /v1/control/role). The watcher never touches the data.

Resource control#

The server enforces limits and reports its load (a foreground latency histogram with 20 power-of-two microsecond buckets, stalls, level-0 files, compaction bytes); the watcher decides the numbers and sets them with POST /v1/control/throttle (0 = no limit). The compaction RateLimiter of the LSM engine and a replication rate limit are the two controlled limits. D51 records that the watcher costs the data path no latency; the measurement is in the decision log (D51).

For configuration keys and operation see the administration chapter.

raftdb-report#

raftdb-report writes fatal-error reports (decision D53). It is installed by raftdb-server, raftdb-watch and raftdb-mysql: a chained panic hook plus explicit fatal(kind, place, message) calls at start-up failures. Its rules, taken from the crate's documentation:

  • A local copy always under <dir>/reports/, at most 50 kept.
  • Nothing leaves the machine unless the operator configured it: RAFTDB_ERROR_REPORT_URL (an http:// address) or RAFTDB_ERROR_REPORT_COMMAND (a program given the report's path, for https with curl or a mail command). The default is off. RAFTDB_ERROR_REPORT=off switches off even the local file.
  • No data in a report: the program and version, the operating system, the time, the kind of failure, the place in the code (file and line), function names of the stack and a message from which quoted text, paths and long numbers were removed (unless RAFTDB_ERROR_REPORT_DETAIL=full). No queries, rows, keys, passwords, tokens, host names or addresses.
  • No flood: the same failure is reported once in ten minutes and at most 20 reports are made in an hour.
  • No stall: sending runs in its own thread with short time limits and a crashing program waits at most three seconds for it.