Skip to content

Two processing masters can run at once on a database cluster because the process registry is node-local #502

Backlog

Description

@somethingwithproof

Describe the bug

On a database cluster, two Syslog processing masters can run at the same time. #495 replaced the GET_LOCK() processing lock with register_process_start('syslog', 'master', ...), which removed the worker check that failed in #479, but the registry cannot guarantee a single master when the database has more than one node. I noted this as a caveat in #495; this issue tracks it.

@TheWitness for your call on timing. This can wait until the release settles unless a cluster user reports overlapping runs sooner.

Why it happens

  • Cacti's processes table is ENGINE=MEMORY on both 1.2.x and develop. Galera replicates InnoDB only; MariaDB's known limitations say writes to tables of other engines are not replicated. A master's registration therefore exists only on the node that took the insert.
  • Cacti's install documentation already describes this for Galera: the MEMORY tables are not replicated among nodes, and it does not apply when Cacti connects to one node only. It lists the tables to convert to InnoDB otherwise, processes among them (develop, 1.2.x).
  • register_process_start() decides whether a master is running with a SELECT on that table. If the read is routed to another node, it finds no row and registers a second master.
  • The primary key is (pid, tasktype, taskname, taskid), so a second registration with a different pid does not collide with the first, even on the same node.
  • develop wraps the check in the InnoDB process_locks mutex. That stops two starters racing each other, but the check still reads the node-local processes table. 1.2.x has no process_locks, and INFO declares compat = 1.2.23, so the plugin cannot rely on it.

This is from reading the code. I have not reproduced it on a cluster, and whether a proxy sends that SELECT to another node depends on its routing rules.

When it matters

A second master starts only if a run is still going when the next one is launched, or if two Cacti hosts process the same Syslog database. Workers are not affected: they are started by the master on the same host and check that the master process is alive locally.

Expected behavior

Only one master, partition rebuild or table repair runs against a Syslog database at a time, whichever node a connection lands on.

Fix direction

Per the maintainer comments below: move the core processes table to InnoDB, and remove entries whose process is gone, in poller_maintenance.php and on cactid restart. That makes the registration visible on every node.

Points to settle in that change:

  • A process id can only be checked on the host that started it. With the table replicated, each row needs the host recorded, so a host removes only its own dead entries and never another host's live ones.
  • The registration check is a SELECT followed by an INSERT. On 1.2.x nothing serialises the two, and on a cluster the read can also be stale on another node. One conditional write, with a key that does not include the pid, would close both.
  • Syslog supports core back to 1.2.23. On a core that still has the MEMORY table, the plugin needs its own guard or has to document single-node routing as a requirement.

Plugin-only alternative, if the core change has to wait: a lease row in an InnoDB table in the Syslog database (owner, host, pid, an epoch that increases on each takeover, and an expiry taken from the database clock), acquired and renewed with a single conditional UPDATE and an affected-rows check. cli/upgrade_partitioning.php and the on-demand repair in includes/schema.php would take the same lease.

Related: named locks still in the plugin

#495 removed only the processing lock. GET_LOCK() is still called on develop in syslog_pipeline_health_check(), syslog_partition_create(), syslog_partition_remove(), syslog_threshold_deliver_recoveries(), syslog_replace_data() and syslog_dashboard_seed_default(). MariaDB lists GET_LOCK() as unsupported explicit locking under Galera. The lock belongs to one server, so these guards only hold when every connection reaches the same node.

Versions

Syslog develop after #495. Seen as a risk for MariaDB Galera behind MaxScale read/write split (the setup reported in #479).

Edited 2026-12-03: added documentation references, the maintainer's fix direction and the remaining named locks, and corrected the first paragraph, which said #495 fixed #479. That is not yet confirmed by the reporters.

Activity

  1. somethingwithproof commented on Dec 3, 2026

    @somethingwithproof
    MemberAuthor

    Workaround until the registry is cluster-safe: send all Cacti and Syslog connections to one node

    Use the cluster for failover, not for spreading Cacti's queries. Cacti keeps state that lives on one database node and assumes its next query lands on the same node:

    • MEMORY tables such as processes, which Galera does not replicate.
    • Named locks (GET_LOCK()), which belong to one server and are listed by MariaDB as unsupported under Galera.
    • Checks that read right after a write, which can miss the row on another node even for replicated InnoDB tables.

    Cacti's install documentation gives the same two choices for Galera: connect Cacti to one node only, or convert the listed MEMORY tables to InnoDB (develop, 1.2.x). The table lists differ between the two branches.

    Recommended setup:

    • Proxy routing: one writer, with reads on the same node. With MaxScale that is a readconnroute service with router_options=master, not readwritesplit. Its documentation says a session stays on one backend and is closed if that backend connection breaks, so Cacti reconnects after a failover. It does not say what happens to open sessions when the primary role moves.
    • Licence: MaxScale 25.01 and later is closed-source and needs a subscription. HAProxy in TCP mode with a Galera health check and the other nodes marked backup is an open alternative; I have only read the documentation for the pieces, not run that layout.
    • One writer: treat the Galera cluster as single-writer for Cacti. The other nodes are standbys.
    • One processing host: only one Cacti host runs Syslog processing against a given Syslog database.
    • After failover: the MEMORY tables are empty on the new primary. Stale registrations disappearing is the safe direction for the process registry.

    With everything on one node, the check and the registration hit the same node, so the second-master case described above mostly goes away.

    This follows from the documentation and from how the code behaves. I have not tested it on a cluster.

    Edited 2026-12-03: the first version said read/write split breaks all three kinds of state. MaxScale's readwritesplit documentation says GET_LOCK(), RELEASE_LOCK() and IS_USED_LOCK() are always routed to the primary, so the named-lock case does not follow from read/write split alone. Also added the Cacti documentation references and the MaxScale licence note.

  2. TheWitness commented on Dec 3, 2026

    @TheWitness
    Member

    You can move the process table to innodb but upon say for example a cactid restart, we may want to check the status of pid's and eliminate things that are gone. Make it so.

  3. TheWitness commented on Dec 3, 2026

    @TheWitness
    Member

    For people using cron maybe we do that in poller_maintenance.php. do it there regardless of course but if you do it inside of cactid it's also very convenient.

  4. somethingwithproof commented on Dec 3, 2026

    @somethingwithproof
    MemberAuthor

    I tested this on a real cluster: three MariaDB 10.6.24 Galera nodes, MaxScale 24.02.9 and HAProxy 2.8, Cacti 1.2.32 from 1.2.x, Syslog develop at 369b859, two workers, 12,000 to 30,000 generated messages per run. Two masters were started one second apart unless noted.

    Route Registry engine Result
    MaxScale readconnroute, router_options=master MEMORY Second master did not run. One registry row.
    MaxScale readwritesplit MEMORY Both masters ran. Two registry rows on the primary, none visible on the replicas. The first master logged Syslog worker(s) exited without recording completion: 1, 2 and One or more transfer workers failed.
    Two Galera nodes directly MEMORY Both masters ran. Each node held only its own registry row.
    MaxScale readwritesplit InnoDB Second master did not run (one run). Syslog worker PID N is no longer running, removing its stale process entry was logged for a worker that had just finished.
    Two Galera nodes directly InnoDB Second master did not run, 2 of 2 runs.
    Two Galera nodes directly, both started at the same instant InnoDB Both masters ran in 1 of 3 runs.

    So the report is confirmed, and moving processes to InnoDB fixes the case where the starts are apart in time. It does not close the race when two masters start together: register_process_start() reads and then inserts, and the primary key includes the pid, so two rows for the same job are both accepted. The core change needs a unique key on (tasktype, taskname, taskid), or an insert that fails for the second caller, as well as the engine change.

    In every overlapping run the number of rows added to syslog equalled the number injected. I would not read that as safe: no alerts, reports or removal rules were configured.

    Two more things showed up through readwritesplit that the engine change does not fix:

    • The master's own checks are plain SELECTs, so they are answered by replicas. With the MEMORY registry the master saw no worker rows, stopped waiting, and reported the workers as failed while they were still running.
    • Named locks are per node. Two sessions on two nodes both got GET_LOCK('same_name', 0) = 1. The six GET_LOCK() calls still in the plugin give no protection across nodes.

    On a single-writer route none of this happens, and that is what I have written up for the manual in Cacti/documentation#334 (develop) and Cacti/documentation#335 (1.2.x).

    Unrelated to the plugin but worth knowing: through readwritesplit with the stock tables the core poller reported RRDsProcessed:0 on every cycle and logged no error, because poller_output was written on the primary and read on a replica.

  5. somethingwithproof commented on Dec 3, 2026

    @somethingwithproof
    MemberAuthor

    Following the test results above, this is what I think has to change for Syslog to be correct on a cluster that is not behind a single-writer route. Line numbers are develop at 369b859. Nothing here is written or tested yet; it is a proposal to agree on before any PR.

    On a single-writer route (MaxScale readconnroute with router_options=master, or HAProxy with backup servers) the current code already works and needs none of this.

    1. Make the master registration exclusive

    syslog_process.php:243 calls register_process_start('syslog', 'master', <poller_id>, 1200). In core that function reads processes and then inserts, and the primary key is (pid, tasktype, taskname, taskid), so two masters with different pids both get a row. That is what happened in 1 of 3 simultaneous starts with the table already on InnoDB.

    Two ways to fix it:

    • In core, as part of the change to move processes to InnoDB: add a unique key on (tasktype, taskname, taskid) so the second insert fails, and treat a duplicate-key error (and a Galera deadlock, error 1213) as "not acquired". Syslog needs no change beyond handling the return value it already checks.
    • In the plugin, if the core change cannot go into 1.2.x: a small InnoDB table with one row per job, taken with a single conditional UPDATE ... WHERE holder IS NULL OR expires < NOW(6) and checked by affected rows, with the expiry taken from the database clock.

    I prefer the core change. It fixes every caller of the registry and not just Syslog.

    2. Replace the remaining named locks

    Named locks are local to one node. In the test, two sessions on two Galera nodes both got GET_LOCK('same_name', 0) = 1. Six calls remain:

    Location Purpose
    includes/functions.php:2196 syslog_pipeline_health_check()
    includes/functions.php:3555 syslog_partition_create()
    includes/functions.php:3764 syslog_partition_remove()
    includes/functions.php:6019 syslog_threshold_deliver_recoveries()
    includes/processing.php:165 syslog_replace_data()
    setup.php:1252 syslog_dashboard_seed_default()

    These should use the same mechanism as item 1, with a task name per job. The partition ones matter most, because DDL is replicated to every node whichever node ran it.

    3. Run the master's coordination reads on the writer

    The master tracks its workers with plain SELECTs on processes (syslog_workers_running_ids(), includes/functions.php:3254) and on the per-worker statistics settings. A read/write splitting proxy sends those to a replica. In the two-master run through readwritesplit, one master logged Syslog worker(s) exited without recording completion: 1, 2 and One or more transfer workers failed while its workers were still running and went on to finish.

    The same function deletes a worker's registry row when it thinks the pid is gone, so a stale read can remove a live worker's row.

    Options: wrap these reads in a transaction, which MaxScale routes to the primary, or read them with SELECT ... FOR UPDATE. On a multi-writer Galera setup the session would also need wsrep_sync_wait=1 for these reads. This is the item I am least sure how to do cleanly, because the reads go through core db_fetch_* helpers.

    4. No change needed: worker liveness

    syslog_processing_master_alive() checks a local pid (syslog_process.php:600). That is correct as long as the master and its workers run on the same host, which they do.

    What I would not do

    Try to support writes on several nodes at once. Items 1 to 3 make Syslog safe if a proxy misroutes a statement or two masters start during a failover. They do not make an active-active setup a good idea for Cacti: the core poller has the same dependencies, and through readwritesplit with the stock tables it wrote no graphs at all.

    Suggested order

    1. Core: processes to InnoDB, unique key, dead-pid cleanup in poller_maintenance.php and on cactid restart. Separate issue and PRs in Cacti/cacti for 1.2.x and develop.
    2. Syslog: move the six named locks onto the registry.
    3. Syslog: writer-side reads for worker tracking.

    @TheWitness does this match what you had in mind for the core side?

  6. somethingwithproof commented on Dec 3, 2026

    @somethingwithproof
    MemberAuthor

    Related tickets, so the history is in one place:

    Same failure family

    Where the remaining named locks came from

    Design tracking

    • Cacti Syslog v2 — Design Principles (discussion / tracking) #317: the v2 design principles list the same cases under "Replication and HA" (replication lag, failover during maintenance, "leader election or advisory-lock strategy tied to active primary") and item 18 (two workers racing to create a partition). The proposal above is the 1.2.x-sized version of those items.

    Outside this repository

  7. TheWitness commented on Dec 3, 2026

    @TheWitness
    Member

    Yes. Maybe we find a way to tone it down, the turns, since we will only manually do thing in 1.2.31. A migration should be fine for develop and 1.2.32. However, there are not a ton of turns to register, etc.

  8. somethingwithproof commented on Dec 4, 2026

    @somethingwithproof
    MemberAuthor

    Status after the maintainer's go-ahead on moving the remaining named locks onto the process registry (item 2 of the proposal above):

    • Item 1 (core): on 1.2.x, fix(poller): [1.2.x] let only one process register a task cacti#9156 made processes an InnoDB table with a unique key on (tasktype, taskname, taskid), and register_process() now returns false when another holder exists. The develop port is still in review.
    • Item 2 (this plugin): in progress. The six GET_LOCK() call sites listed above move to the registry with one task name per job. Because INFO declares compat = 1.2.23, the pull request will say how the plugin behaves on a core that still has the old table.
    • Item 3 (writer-side reads for worker tracking): not started; it stays open after item 2.

    I will link the pull request here when it is open.

  9. somethingwithproof commented on Dec 4, 2026

    @somethingwithproof
    MemberAuthor

    Item 2 is up as #503: the six remaining named locks move onto the process registry when the core has the cluster-safe registry (1.2.32 and later), and keep the named lock on older cores. It has not been run on a Galera cluster. Item 3 and the develop port of Cacti/cacti#9156 remain open here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions