Repository navigation
fix: move the remaining named locks onto the process registry - #503
Open
somethingwithproof wants to merge 21 commits into
Open
somethingwithproof wants to merge 21 commits into
somethingwithproof wants to merge 21 commits into
Conversation
Each site is run while another process holds its lock, and to success, an early failure return and an exception, so a change of lock mechanism for Cacti#502 can be checked against the current behaviour: the wait each lock uses, what the caller returns and logs when it is busy, and that the lock is released on every exit path. Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
Refs Cacti#502. GET_LOCK() is granted per database server, so two Galera nodes can both hand out the same lock. syslog_task_lock() registers the task through register_process(), whose insert admits one holder once Cacti 1.2.32 keeps the registry in InnoDB with a unique task key. It waits up to a given number of seconds, retires an entry older than its timeout, and never signals a holder. On a Cacti without that registry it returns null so the caller keeps its named lock. The unit bootstrap stubs the three core registry functions; the registry reports itself unavailable unless a test opts in. Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
…egistry Refs Cacti#502. The per-collector health check tries once for task ('syslog', 'health', <poller id>) and skips the run when another process holds it, as it did with GET_LOCK(..., 0). An entry left by a holder that died expires after 300 seconds; the check itself makes a few queries and sends at most one mail. Cacti before 1.2.32 keeps the named lock. Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
Refs Cacti#502. syslog_partition_create() now holds task ('syslog', 'partition_create_<table>', <poller id>). It waits up to 10 seconds for another holder, as GET_LOCK(..., 10) did, and logs the same 'Unable to acquire' line when it gives up. Partition maintenance runs inside the processing master, whose own registration expires after 1200 seconds, so an abandoned entry expires after 1200 seconds too; until then writes stay in dMaxValue. Cacti before 1.2.32 keeps the named lock. Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
Refs Cacti#502. syslog_partition_remove() now holds task ('syslog', 'partition_remove_<table>', <poller id>), waits up to 10 seconds as before, and returns 0 with the same log line when another process holds it. An abandoned entry expires after 1200 seconds, which delays retention pruning by at most that long. Cacti before 1.2.32 keeps the named lock. Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
Refs Cacti#502. After retiring an expired entry the task lock retried at once, without a bound, for as long as the sweep reported a removed row. It now makes one immediate retry per sweep and otherwise waits for the deadline. The lock tests also reset their overrides afterwards, so the registry they enable no longer reaches tests in later files. Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
Refs Cacti#502. syslog_threshold_deliver_recoveries() tries once for task ('syslog', 'recovery', <source poller id>) and skips delivery when another process holds it, as with GET_LOCK(..., 0). Recovery commands run through exec() with no time limit inside the processing master, which the next master replaces after 1200 seconds, so an abandoned entry expires after 1200 seconds. Cacti before 1.2.32 keeps the named lock. Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
…gistry Refs Cacti#502. syslog_replace_data() holds task ('syslog', 'rules_<table>', <collector>) where the collector owns the target database: the remote collector for syslog_replicate_out(), this collector for syslog_replicate_in(). Publishing to two collectors at once stays independent, as it was with a lock on each target server. It waits up to 5 seconds as before and returns false when another process holds the task. Copying a rule table takes seconds, so an abandoned entry expires after 300 seconds. Cacti before 1.2.32 keeps the named lock on the target connection. Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
…egistry Refs Cacti#502. syslog_dashboard_seed_default() holds task ('syslog', 'dashboard', <poller id>), waits up to 5 seconds as before, and leaves seeding to the holder when it cannot get the task. Seeding inserts six rows; an entry left by a web request that ended without releasing it stays until it expires after 300 seconds, because the web server process keeps running. Cacti before 1.2.32 keeps the named lock. Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
Refs Cacti#502. With Cacti's lib/poller.php the script starts from the MEMORY processes table older Cacti created and checks that the first lock has Cacti convert it, that a second process on another connection is refused or waits, that recovery delivery is skipped while another process holds its task and runs after release, that a live holder is not signalled, that only an entry past its timeout is retired, and that one of two callers starting together wins in each of 20 rounds. Run with the argument 'main named', it checks that without that core the named lock still decides. Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
The contended unit tests slept through every configured wait, about 32 seconds in all. syslog_task_lock() now pauses and reads the time through syslog_task_lock_clock(), or through a callable in $GLOBALS['syslog_task_lock_clock'] when one is set, so the unit tests assert the exact wait on a fake clock without sleeping. The real-time wait stays covered by the MariaDB regression script. Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
The task lock retired a registry entry once started + timeout had passed, whether or not its process was still running. A recovery command that blocked in exec() past 1200 seconds let the next processing run take the task and deliver the same pending recoveries a second time, and a second partition ALTER could queue behind the first and fail with a duplicate partition name. syslog_task_lock() takes a $pid_is_local flag. With it, an expired entry is retired only if its pid is no longer running on this host, probed as cacti_process_registry_prune() does: a bare signal-0 probe, EPERM counted as running, and without posix_kill() every holder counted as running. The pipeline health check, partition create and remove, and recovery delivery pass it: they run only from the command line and their task id is the local poller id, so the entry's pid belongs to this host. Rule snapshot publishing and dashboard seeding can run in a web request, whose PHP-FPM worker pid outlives the request, so they keep the expiry on age alone. The comment that said the processing master is replaced after 1200 seconds is corrected. Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
The MariaDB regression script passed with two mutations of the task lock: a release that drops the pid and so deletes another process's entry, and an acquire that reports success after an expiry sweep although its own insert affected no rows. It now checks that a release by another process leaves the holder's entry and the task held, and, through a hook that runs another process's insert right after the sweep, that such an acquire reports busy with and without the process check. Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
The REORGANIZE and DROP PARTITION statements in syslog_partition_create() and syslog_partition_remove() waited for a metadata lock up to the server's lock_wait_timeout, 86400 seconds by default on MariaDB, while holding the partition task. syslog_partition_alter() sets the session value to 30 seconds around each ALTER and restores it afterwards, the idiom cli/upgrade_partitioning.php uses for its own DDL. A failed restore is logged. When the session value cannot be read or set, the ALTER runs as before, and when the lock is free nothing else changes. On MariaDB 11.8 a partition ALTER behind a held metadata lock failed after twice the setting, so the cap is about a minute. Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
The health, recovery and dashboard lock names were rebuilt in the test with the same hash calls as the code under test, so a change to how a name is derived could pass. Older plugin versions take these exact names; spell them out byte for byte instead. Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
The regression script spliced its database name into CREATE DATABASE, USE and DROP DATABASE, and the holder pid into a COUNT query. A name cannot be bound, so run those statements through one helper that accepts only [A-Za-z0-9_] and backticks the name, and bind the COUNT query's values. The child takes its database name from argv, so the check is not only cosmetic. Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
The named lock for the pipeline health check is unchanged, so its line no longer shows as modified. Behaviour and the lock name are identical. Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
…ait cap Mutation testing of the task lock helpers left three changes unnoticed by the suite: syslog_task_lock_clock() without its pause or returning whole seconds, the replacement registry entry taken after an expired holder was retired carrying the wait in place of its timeout, and the TO_DAYS REORGANIZE running without the capped lock wait. Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
The regression script rebuilt the named lock's name with its own hash call. It now asks the database for the same value, so the script has no hash call for the static analysis to report. Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Problem
GET_LOCK()is granted per database server. On a Galera cluster that is not behind a single-writer route, two nodes can both grant the same named lock (test results are in #502). Six places in the plugin still rely on one: the pipeline health check, partition create and remove, threshold recovery delivery, rule snapshot publishing and default dashboard seeding.Fix
syslog_task_lock()/syslog_task_unlock()register the task with Cacti'sregister_process(). From Cacti 1.2.32 (fix(poller): [1.2.x] let only one process register a task cacti#9156) the registry is InnoDB with a unique task key, so its insert admits one holder across the cluster.finally.register_process_start()is deliberately not used here: it treats a holder running a different script as dead, and it sends SIGTERM to a holder that outlives its timeout, which for the health check would bepoller.phpand for a web caller a web server worker.$pid_is_local = true: the pipeline health check, partition create, partition remove and recovery delivery. Their task id is the local poller id, so the entry's pid belongs to this host. For them an entry past its 1200 or 300 second expiry is retired only if its pid is no longer running, probed the way core'scacti_process_registry_prune()does: a bare signal-0 probe, EPERM counted as running, and without the posix extension every holder counted as running. A slow holder, such as a recovery command blocked inexec(), is therefore never replaced, so pending recoveries are not delivered twice and a second partition ALTER cannot queue behind the first. Rule snapshot publishing and dashboard seeding can run in a web request, where a PHP-FPM worker's pid outlives the request, so they keep the expiry on age alone (300 seconds).lock_wait_timeoutset to 30 seconds and restored afterwards, the idiomcli/upgrade_partitioning.phpuses. Before, they could wait up to the server's default of 86400 seconds while holding the task. When the session value cannot be read or set, the ALTER runs as before; when the lock is free nothing else changes. On MariaDB 11.8 a partition ALTER behind a held metadata lock failed after twice the setting, so the cap is about a minute.cacti_process_registry_ensure_table()(1.2.23 to 1.2.31, anddevelopuntil #9156 is ported) each site keeps its named lock, unchanged.compatstays at 1.2.23.syslog_replace_data()takes the target collector's id, so pushes to different collectors do not block each other.syslog, ...)syslog_pipeline_health_check()health, poller idsyslog_partition_create()partition_create_<table>, poller idsyslog_partition_remove()partition_remove_<table>, poller idsyslog_threshold_deliver_recoveries()recovery, source poller idsyslog_replace_data()rules_<table>, target collector idsyslog_dashboard_seed_default()dashboard, poller idVerification
Tests were written first at each site: the named-lock behaviour was pinned on the unchanged code (busy; released after success, an early failure return and an exception), then a failing test for the registry path, then the change. The review fixes followed the same order.
tests/Unit/TaskLockTest.phpcovers both paths at all six sites and the helper, including an expired entry whose process still runs (kept at the four command line sites, which skip or wait and report busy as before), an expired entry whose process has exited (retired), and age-based expiry at the two web sites. Waits run on an overridable clock, so the configured wait is asserted exactly without sleeping.tests/Unit/PartitionLockWaitTest.phpcovers the 30 second cap and its restore around both partition ALTERs, a failed ALTER, a failed restore, and the unchanged path when the session value cannot be read or set.tests/regression/task_lock_database_test.phpruns core 1.2.x's ownlib/poller.phpagainst MariaDB 11.8: two processes on separate connections, 20 rounds of two simultaneous starts with exactly one winner each, a holder still running past its expiry while a second process arrives (no delivery by the second process), retirement of an expired entry whose process has exited, a release by another process leaving the holder's entry, an acquire whose insert after an expiry sweep affected no rows reporting busy, a live holder not being signalled, real-time waits, conversion of an old MEMORY table on first use, and the named-lock fallback without the new core. The last two new checks were confirmed to fail against the corresponding mutations (unlock without the pid; ignoring the insert result after a sweep).php -lclean on 8.2 for the changed files; changed-line coverage 100% (62/62); no translatable string changes; the task lock regression script passes (47 registry checks, 6 named-lock checks), and the seven existing MariaDB regression scripts pass.Notes for review
finally, so its row stays until core's maintenance prune removes it, normally within one poller cycle. A web request that dies holds its task for the 300 second expiry, and a dashboard seed skipped that way is not retried until the next install or upgrade.Refs #502. Still open there: porting Cacti/cacti#9156 to
develop(this change picks it up automatically), and reading worker-tracking state from the writer (item 3 of the proposal).