Describe the single-writer layout Cacti needs on a MariaDB Galera cluster or a primary and replica, with tested MaxScale and HAProxy configuration, failover behaviour, the effect of converting MEMORY tables to InnoDB, Syslog plugin behaviour, and the limits of the tests. Refs #333 Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
15 KiB
Database High Availability
This page describes how to place the Cacti database on a MariaDB Galera cluster or a replicated primary and replica without breaking polling or plugin processing. It records which layouts were tested, what each one did, and what remains untested.
The short version: Cacti must talk to exactly one database server at a time. Use the other servers as standbys and let a proxy move Cacti to a standby when the active server fails. Do not split reads and writes across servers.
Summary
- Route every Cacti connection, including plugin connections, to one writable server. This is called a single-writer layout.
- Do not use a read/write splitting router such as the MaxScale
readwritesplitrouter for Cacti. It sends lock functions and other statements of one session to different servers. On Galera with the stock tables, polling stopped updating graphs without logging an error. - Do not let two Cacti processes connect to different cluster nodes directly.
- Decide what happens when a failed server returns. Either stay on the standby until a planned change, or make the proxy close standby sessions when it moves back. Otherwise two servers can hold Cacti sessions at once.
- Converting the
MEMORYtables to InnoDB removes one cause of failure. It does not make read/write splitting or multiple writers safe.
Why Cacti needs one database server
Cacti keeps short-lived working state in the database and expects every connection to see that state immediately. Three mechanisms depend on it.
MEMORYtables. The poller writes collected values topoller_outputand the main poller reads them back to update RRD files. Background jobs record themselves in theprocessestable so that a second copy does not start. Both tables use theMEMORYstorage engine. Galera replicates InnoDB tables only, so a row written on one node does not exist on the others. See the Galera known limitations page listed under References.- Named locks. Cacti and several plugins call
GET_LOCK()to stop two jobs from running together. A named lock belongs to one connection on one server. In testing, two sessions on two Galera nodes both obtained the same lock name. - Reading back what was just written. Cacti writes a row and reads it on the next statement, sometimes from a different process. A replica can answer before the row arrives. In testing on a primary and replica, a count taken through a read/write splitting router immediately after an insert returned zero, and the next read returned one. This happened once and replica lag was not measured. No stale InnoDB read was seen on Galera in these tests, but Galera does not rule one out with its default settings.
The list of MEMORY tables for this branch is in
General Installing Instructions.
What was tested
The results below come from one test run on 3 December 2026 with small cloud virtual machines on a private network.
| Component | Version |
|---|---|
| Cacti | 1.2.32 from the 1.2.x branch |
| Syslog plugin | 5.0 from the plugin's develop branch |
| MariaDB with Galera | 10.6.24, three nodes |
| MaxScale | 24.02.9 |
| HAProxy | 2.8 |
Cacti 1.2.32 is the release line this manual documents. The development branch was not run on a cluster.
Each run used the command line installer, one device with five data sources, forced poller cycles, and 2,000 to 30,000 generated Syslog messages processed by two Syslog workers. That is a functional test. It says nothing about performance at production size.
Results on a three-node Galera cluster
| Route from Cacti to the cluster | Poller | Syslog processing |
|---|---|---|
MaxScale readconnroute, router_options=master |
Graphs updated | All messages processed |
HAProxy, one active server and two backup servers |
Graphs updated | All messages processed |
MaxScale readwritesplit, stock tables |
No graphs updated in 5 cycles across three runs, no error logged | One master: all messages processed. Two masters: both ran |
MaxScale readwritesplit, MEMORY tables converted to InnoDB |
Graphs updated in 8 of 8 cycles | Tested with two masters only: one ran and processed all messages, and logged stale worker warnings |
With readwritesplit and the stock tables, each poller cycle reported
RRDsProcessed:0 and exited normally. The collected values stayed in
poller_output on the node that received the writes, and they accumulated
with each cycle. The table was empty on the other two nodes, and the routing
test below shows that reads of a MEMORY table went to those nodes.
Statement routing observed through MaxScale
One client session through readwritesplit ran these statements in order.
| Statement | Answered by |
|---|---|
SELECT @@hostname |
A replica |
SELECT GET_LOCK('name', 0) |
The primary |
SELECT CONNECTION_ID() |
A replica |
SELECT IS_USED_LOCK('name') |
The primary |
SELECT COUNT(*) on a MEMORY table just written |
A replica, returned 0 |
SELECT COUNT(*) on an InnoDB table just written |
A replica, returned 1 |
CONNECTION_ID() returned 83 and IS_USED_LOCK() returned 87 in the same
client session, because the two statements ran on different servers. Code
that compares the two values cannot confirm that it holds its own lock.
The same session through readconnroute or HAProxy returned one server name
and one connection ID throughout.
The MaxScale routing rules are described in the router references listed under References.
Recommended layout
Run three Galera nodes so the cluster keeps quorum when one node is lost. Put
a proxy between Cacti and the cluster and configure it to send all
connections to one node. Point $database_hostname and $database_port in
include/config.php at the proxy. If a plugin has its own database settings,
point those at the same proxy listener.
The proxy is itself a single point of failure unless you run two of them behind a virtual IP address. That part was not tested.
MaxScale
Use the readconnroute router with router_options=master. The galeramon
monitor chooses one node as the master. Set use_priority so the choice is
predictable and disable_master_failback so a returning node does not take
the role back.
[db1]
type=server
address=192.0.2.11
port=3306
priority=1
[db2]
type=server
address=192.0.2.12
port=3306
priority=2
[db3]
type=server
address=192.0.2.13
port=3306
priority=3
[galera-monitor]
type=monitor
module=galeramon
servers=db1,db2,db3
user=maxscale_monitor
password=<monitor password>
monitor_interval=1s
use_priority=true
disable_master_failback=true
[cacti-single-writer]
type=service
router=readconnroute
router_options=master
servers=db1,db2,db3
user=maxscale_monitor
password=<monitor password>
[cacti-listener]
type=listener
service=cacti-single-writer
port=3306
Replace the addresses, account name, and password placeholders with your own values. Check the licence terms of the MaxScale version you deploy before you depend on it; the terms differ between release series.
HAProxy
HAProxy in TCP mode gives the same single-writer behaviour with open source
software. Mark every server except one as backup. HAProxy needs a health
check that knows whether the node is synced, because a node that accepts TCP
connections is not necessarily usable. Run a small HTTP responder on each
node that returns status 200 only when wsrep_local_state is 4, for example
the clustercheck script distributed with Percona XtraDB Cluster.
listen cacti-single-writer
bind *:3306
mode tcp
option httpchk GET /
http-check expect status 200
timeout client 30m
timeout server 30m
default-server port 9200 inter 1s fall 2 rise 2 on-marked-down shutdown-sessions
server db1 192.0.2.11:3306 check on-marked-up shutdown-backup-sessions
server db2 192.0.2.12:3306 check backup
server db3 192.0.2.13:3306 check backup
option httpchk GET / makes HAProxy send an HTTP request to the responder.
The responder must read the whole request before it replies. The first
responder used in testing replied without reading it. HAProxy logged
Connection reset by peer for each check, marked every node down, and
refused client connections. The tests used a short script written for the
purpose, not the Percona script.
on-marked-up shutdown-backup-sessions matters. Without it, HAProxy sent new
connections back to db1 as soon as it returned, while a session opened
during the outage stayed on db2. Two nodes then held client sessions until
that session ended. The test clients only read, so no conflicting writes
were made. With the option set, HAProxy closed the session on db2 when
db1 returned, and all connections were on one node again.
HAProxy always returns to the first server when it recovers. If you would
rather stay on the standby until a planned change, use MaxScale with
disable_master_failback or manage the HAProxy server state yourself.
What happens during a failover
The active node was stopped while one client held a session open and another opened a new connection every second.
| Event | MaxScale readconnroute |
HAProxy with backup servers |
|---|---|---|
| Session open on the failed node | Closed with error 2013 | Closed with error 2013 |
| New connections reach the next node | About 3 seconds | About 3 seconds |
| Failed node returns | Stayed on the new node | Returned to the first node |
Each case was run once, with a client that sampled once per second. Both proxies checked node health once per second; other intervals were not tested. After the MaxScale run, MaxScale listed the returned node as synced and kept the standby as master.
A Cacti process that loses its connection in the middle of a poller cycle was not tested. Expect that cycle to be incomplete and the next cycle to run normally. After the failover in testing, the next poller cycle and Syslog run completed against the new node with no change to Cacti.
A MEMORY table is emptied when its server restarts, and its rows exist only
on the node that received them. Unprocessed poller_output rows on a failed
node are therefore expected to be lost, and InnoDB tables are expected to
keep them. This follows from how the engine works and was not tested.
Converting MEMORY tables to InnoDB
General Installing Instructions lists
the ALTER TABLE statements. In testing the conversion had these effects.
- Polling through
readwritesplitwrote graphs again in 8 of 8 cycles. - A second Syslog master started one second after the first did not run.
This was one run through
readwritesplitand two runs with the masters connected to different nodes directly. - When two Syslog masters were started at the same instant on different
nodes, both ran in 1 of 3 attempts and the registry held two rows for the
same job. In the Cacti source,
register_process_start()reads the table and then inserts, and the table's primary key includes the process ID, so a second row is accepted.
Convert the tables if a standby must take over without losing queued poller output. Do not treat the conversion as permission to split reads from writes or to write on several nodes. Named locks remain local to one node, and reads can still be answered by a different server than the last write.
These tests did not include a Cacti upgrade. Check the table engines after each upgrade, and convert again if any have changed back:
SELECT TABLE_NAME, ENGINE
FROM information_schema.TABLES
WHERE TABLE_SCHEMA = 'cacti' AND ENGINE = 'MEMORY';
Syslog plugin
The Syslog plugin runs one master process that starts worker processes. The master must be unique, and each worker checks that its master is still running.
- Development builds of the plugin from before the fix for
plugin_syslog issue 479
used a named lock for that check. Through
readwritesplit, every worker loggedthe processing run that launched it no longer holds the processing lockand exited, and no messages were transferred. The same build worked through a single-writer route. - Current builds use the Cacti process registry. Through a single-writer
route a second master did not run. Through
readwritesplita single master processed all messages. With two masters throughreadwritesplit, or on different nodes, both ran at the same time while the registry was aMEMORYtable, and one loggedOne or more transfer workers failedwhile its workers were still running. See plugin_syslog issue 502.
In the runs where two masters overlapped, the number of rows added to the
syslog table matched the number of messages injected. That is not evidence
that overlapping masters are safe. Alerts, reports, and removal rules were
not configured in these tests.
If the plugin uses its own database, as set in the plugin's config.php,
send that connection through the same single-writer listener.
Primary and replica replication
Two of the test servers were reconfigured as a primary and one replica with
standard binary log replication, monitored by the MaxScale mariadbmon
monitor.
MEMORYtable rows did reach the replica. Polling throughreadwritesplitwrote graphs in 8 of 8 cycles.GET_LOCK(),CONNECTION_ID()andIS_USED_LOCK()were routed as on Galera.CONNECTION_ID()andIS_USED_LOCK()ran on different servers, and the older Syslog build failed in the same way.- A read of an InnoDB table through
readwritesplitimmediately after an insert returned stale data once in the routing test. - Through
readconnroutewithrouter_options=master, polling and Syslog processing completed normally.
The recommendation is the same: one writer, reached through a route that never sends Cacti statements to a replica. Automatic promotion of the replica was configured but not exercised.
Limits of these tests
- One small installation, one device, five data sources. No load testing.
- Cacti 1.2.32 only. The development branch was not run.
- MariaDB 10.6.24 and MaxScale 24.02.9 only. Other versions may route or lock differently.
- Remote data collectors, Boost, Spine, and plugins other than Syslog were not exercised.
- ProxySQL was not tested.
- Network partitions, loss of quorum, and state transfers during polling were not tested. Only a clean stop and start of the active node was, once per proxy, with a read-only test client and not with Cacti running.
- Loss of the database connection in the middle of a poller cycle was not tested.
- Proxy redundancy was not tested.
- Sample sizes are small. The HAProxy route was polled for one cycle. The simultaneous-start result is three attempts, not a rate. Poller cycle counts combine several runs, and the poller also starts its own Syslog run in the background.
- The primary and replica pair had one replica, and replication lag was not measured.
References
| Topic | Source |
|---|---|
| What Galera replicates | MariaDB Galera Cluster known limitations |
| Read/write split routing | MaxScale readwritesplit |
| Single-server routing | MaxScale readconnroute |
Health checks and backup servers |
HAProxy 2.8 configuration manual |