Skip to content

syslog: fix device purge and Status cards, harden partition rebuilds, add hourly partitioning - #473

Merged
TheWitness merged 12 commits into
developfrom
fix/472-purge-devices-and-rebuild
Nov 20, 2026
Merged

TheWitness merged 12 commits into
developfrom
fix/472-purge-devices-and-rebuild

Conversation

@TheWitness

@TheWitness TheWitness commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

Description

Purge Syslog Devices crash (#472). Cacti loads only includes/utilities.php for the
utilities_action hook. The purge called syslog_db_execute() without syslog_connect(),
so includes/database.php was never loaded, the request died with
Call to undefined function syslog_db_execute(), and Cacti disabled the plugin. The purge
now connects first. A failed connection is logged and reported, and nothing is purged.
The deletes now name the configured Syslog database explicitly. They also use NOT EXISTS
instead of NOT IN (SELECT DISTINCT … UNION …): one NULL host_id in the message tables
made NOT IN purge nothing, and NOT EXISTS probes the host_id indexes instead of
running DISTINCT over every message.

Partition rebuild hardening (review of #471). cli/upgrade_partitioning.php:

  • Writers. The command refuses to start while Syslog Enabled is set. It then takes
    the syslog processing lock (GET_LOCK(syslog_processing_lock_name(), 0)), which
    syslog_process.php also takes, and holds it for the whole rebuild. A poller cycle
    therefore cannot start processing partway through. Neither side waits on or terminates
    the other: the rebuild refuses to start, and the processor logs a NOTE and skips the cycle.
    The server releases the lock if the connection drops. The processor holds the lock on a
    connection of its own (syslog_processing_lock_acquire()). On MySQL before 5.7.5, a
    session keeps only one named lock, so the nested GET_LOCK calls that maintenance and
    alert delivery make on the Syslog connection could otherwise release it. That idle
    connection's wait_timeout is raised to at least a day (and read back) so the server
    cannot drop it, and the lock, during a long run.
  • Transfer workers. The master passes each worker its lock session
    (--lock-owner=<CONNECTION_ID>). A worker registers, then exits without writing unless that
    session still holds the processing lock, so workers that are delayed, standalone, or
    orphaned by a killed master never write during a rebuild. Once the rebuild holds the lock, it
    refuses while live syslog/child processes remain registered (stale rows from crashed
    workers are ignored). Every worker is therefore either seen by the rebuild or sees its lock.
  • Schema repair. syslog_process.php and the rebuild connect without automatic repair
    (SYSLOG_DEFER_SCHEMA_REPAIR); the processor repairs only once it holds the lock. Any other
    caller, such as a page load, takes the lock on a separate connection before recreating a
    missing table, and skips the repair while a run or rebuild holds it. A table the rebuild has
    renamed away is never recreated underneath it. Repair sizes a recreated table from the
    current retention and refuses, before any DDL, a plan above the partition limit.
  • No seq in INSERT … SELECT. Stored and removed messages are copied without seq,
    in their original (seq, logtime) order. This matches how the plugin already moves rows
    between syslog_incoming, syslog and syslog_removed. The replacement's
    AUTO_INCREMENT is set above the original high-water mark (GREATEST(MAX(seq) + 1, AUTO_INCREMENT)) before the first row is copied. Sequence values are therefore never
    reused, and copied rows cannot collide with live inserts, which was the 128-duplicate
    failure in the review. The command refuses to start if too few sequence values remain
    above the high-water mark.
  • Verification and resume. Each batch (50,000 rows by default) is compared with its source range by
    row count and two MD5-based aggregates covering every copied column. The comparison is
    binary-exact, and logtime is normalized to %f. A matching batch is recorded in
    syslog_rebuild_progress. A retry deletes replacement rows above the last checkpoint and
    resumes after it. An empty replacement left by an interrupted setup is recreated. The
    original is dropped only after every batch and the total counts match.
  • syslog_incoming is widened in place with ALTER TABLE … MODIFY under --convert-ms.
    Its seq is an identity, stored as replication_source_event_id and used to deduplicate
    archival, so it is not renumbered. The outbox is widened in place, as before.
  • Legacy DATETIME is not supported. It is detected before anything is renamed. A
    preserving rebuild refuses with no changes; --discard-data may replace such a table.
    This removes the DST gap/overlap failure mode (review item 1). The README documents a
    manual conversion that checks the values first, and how to roll back an abandoned rebuild.

Related Issue

Fixes #472. Addresses @somethingwithproof's review of #471.

Hourly and Daily partitioning

  • Settings: the spacer is renamed Data Retention and Partitioning. It gains a
    Partitioning Level dropdown (syslog_partition_granularity): Daily (default) or Hourly.
    There is no Disabled level, because partitioned tables are the only supported architecture.
  • Switching works like MacTrack: choose the level in Settings, or run
    cli/upgrade_partitioning.php --partition=hourly|daily, which saves it once confirmed. The
    utility rebuilds both tables to that level, preserving data.
  • The setting applies only when the utility runs: saving it changes nothing on its own.
    Poller maintenance keeps following the size the tables actually have (hYYYYMMDDHH /
    dYYYYMMDD names). Settings and the Status tab show the change as pending until both
    syslog and syslog_removed use the selected level; if a rebuild finishes only one of them,
    Status shows each table's level. This part deliberately differs from MacTrack.
  • Install: the advisor's unused "Partitions per Day" dropdown is replaced by the level, and
    silent installs take $syslog_install_options['partitioning'] = 'day'|'hour'.
  • Partition limits: saving settings is refused with an error giving the required and
    permitted partition counts. The required count is (retention + today + pre-create window) ×
    24 for Hourly, + dMaxValue. The limit is 8192, or 1024 on MariaDB < 10.0.4 and MySQL < 5.7.
    Hourly with Indefinite retention is also refused.
    • The check runs in the config_settings hook, before Cacti's settings.php writes
      anything, on both 1.2.x and 1.3.
    • It covers the selected level and every level the tables still use. Otherwise hourly tables
      could be given Indefinite retention by selecting Daily before the rebuild runs.
    • The installer and the utility apply the same check. Repair recreates a missing table from
      the current retention, and refuses before any DDL if that plan exceeds the limit.
    • If the Syslog server's version or table layouts can't be read, the save is refused. It is
      never checked against fallback data.
  • Advance window: hourly tables keep at least 2 days of partitions ahead, matching
    MacTrack's MACTRACK_PARTITION_AHEAD = 2 * 86400, or the configured window if larger. New
    partitions are therefore always split from an empty dMaxValue, which is instant.
    • While the horizon exists, recovery does one check, not 73 hourly probes.
    • A gap is found with a binary search and healed in bounded runs.
  • Query pruning: get_syslog_messages() always adds logtime < FROM_UNIXTIME(now + 1),
    whatever the filter says. This covers both search modes, grouped and UNION views, export, and
    group detail pages. Empty future partitions are therefore always pruned; this was verified
    with EXPLAIN PARTITIONS on MariaDB. Messages with future timestamps are hidden until that
    time; that tradeoff was chosen deliberately.

Syslog Status page

  • Add card did nothing: Cacti develop wraps every plain select in select2. Select2
    reports a choice with jQuery's .trigger('change'), which never reaches the native
    addEventListener('change') in the card controller (cards.js, the same code as core's
    include/js/cards.js). The Status adapter now binds the add select with jQuery. It
    appends and binds the chosen card at the end, saves the layout, and keeps the select2
    display in sync. Core's cards.js has the same latent issue for any other addControl
    user.
  • Refresh did a full page load: changing the interval set window.location, and the
    Status tab also registered Cacti's page refresh. The interval is now saved per user
    through a CSRF-protected status_refresh callback. A client timer refreshes the cards in
    place, through the same path as the Refresh button, and stops once the grid leaves the
    page.
  • Tests: tests/browser/status_cards.cjs applies select2 the way Cacti does. It fails on
    develop and passes here, with no page navigation. StatusRefreshCallbackTest covers the
    endpoint's validation and CSRF checks.

Copy batch-size sweep (10M rows, 2 GiB buffer pool)

Each row is a full preserving rebuild of the same 10M-row, 4.8 GiB table on MariaDB 10.5
(96 MiB redo log, binlog off). Run-to-run noise is about ±7%: two 10,000 runs took 511 s
and 550 s.

Batch Total Rows/s Copy Verify Checkpoint + boundary lookup Slowest statement
1,000 783 s 12,769 434 s 180 s 140 s 2.1 s
2,500 658 s 15,202 391 s 157 s 85 s 1.4 s
5,000 605 s 16,540 368 s 146 s 66 s 3.2 s
10,000 511–550 s 18–19.6k 326–345 s 135–138 s 36–40 s 2.8 s
25,000 544 s 18,377 — — — 4.0 s
50,000 (new default) 473 s 21,154 293 s 134 s 23 s 3.1 s
65,536 525 s 19,039 341 s 136 s 22 s 6.0 s
  • Small batches: below 10,000, the per-batch checkpoint and boundary query dominate.
  • 10,000 and above: the curve is flat within noise, so the sweep stopped at 65,536.
  • Memory and I/O: buffer-pool disk reads (about 115k) and redo written (about 4.8 GiB)
    were the same at every size.
  • Default: the copy now uses 50,000-row batches (the fastest measured). The batch size is a
    syslog_upart_rebuild() parameter; the regression test passes 10,000 to keep multi-batch
    resume covered on a small table.

The boundary lookup is the indexed ORDER BY seq, logtime LIMIT 1 OFFSET N-1, not a server
cursor. Replacing it with fixed seq BETWEEN windows computed in PHP removed the lookup,
but the copy got slower by about the same amount:

Batch With lookup Without lookup
10,000 511–550 s 499 s
50,000 473 s 529 s
65,536 525 s 522 s

The lookup is kept, because it also handles gaps in seq; empty windows would otherwise
fail verification.

Motivation and Context

  • The purge utility crashed and disabled the plugin.
  • The rebuild could leave live tables empty or unfinishable, with duplicate seq values,
    when writers ran or DATETIME history crossed a DST change.

Impact assessment and timings

Setup. WSL2 (AlmaLinux 9), MariaDB 10.5.29, InnoDB, 2 GiB buffer pool (raised from
128 MiB for these runs), binlog off, innodb_flush_log_at_trx_commit=1. Tables use the
production syslog schema with seven secondary indexes and 30 days of daily partitions.
The 10M-row table is 4.9 GiB (data + indexes).

Operation (10M rows) Time Notes
This PR, TIMESTAMP rebuild, preserve 494 s copy 312 s, per-batch verify 131 s, checkpoints 19 s
develop tool, TIMESTAMP rebuild, preserve (seq copied) 471 s copy 378 s (anti-join on seq), final verify join 43 s
This PR, --convert-ms (TIMESTAMP→TIMESTAMP(3)) 551 s +11% over TIMESTAMP
This PR, --discard-data 17 s DDL only
develop tool, batched DATETIME→TIMESTAMP copy 483 s +2.6% over its TIMESTAMP copy
DATETIME DST round-trip pre-flight scan 8 s FROM_UNIXTIME(UNIX_TIMESTAMP(logtime)) <> logtime
In-place ALTER DATETIME→TIMESTAMP + epoch repartition 331 s single blocking statement, no verification or resume
  • Conversion speed. Converting DATETIME→TIMESTAMP costs almost nothing in speed (+2.6%);
    its risk is correctness. A detect-and-convert-only-when-needed path would save about 3%.
  • The new copy. It costs about 5% more than the develop tool. Dropping the seq
    anti-join makes the copy statements 17% faster, which pays for most of the per-batch
    verification and checkpointing that make a resume safe.
  • Projection to 100M rows (~49 GiB) on this hardware. About 80–85 minutes per table
    (TIMESTAMP); syslog_removed is extra. About 55 minutes for the in-place DATETIME ALTER.
    Allow at least the reported database size in free space. The 100M-row confirmation run was
    stopped at the maintainer's request, because the 10M results extrapolate linearly.

Partition granularity. This PR adds Hourly alongside Daily (see above). Any existing
RANGE layout can be rebuilt to either level. The MariaDB regression test rebuilds daily →
hourly → daily, preserving every row.

How Has This Been Tested?

  • Pest, full suite: 852 passed (3620 assertions). Changed-line coverage: 100%
    with tests/bin/patch-coverage.php. The one warning is the existing xdebug coverage notice in
    QueryBuilderGuardTest. New tests:
    • PartitionGranularityTest covers server limits by version, projected counts, the
      settings-save gate (including hourly tables with Daily selected, and an unavailable Syslog
      database), layout detection and lookup failures, and bounded hourly recovery where the
      steady state reads the horizon once.
    • ProcessingLockTest covers the processor's separate lock connection on Cacti 1.2 and 1.3
      connection details, the raised wait_timeout (and refusal when the server keeps it
      short), release, and the worker ownership check. It was also checked live against MariaDB
      with both Cacti versions' db_connect_real().
    • cli_schema_upgrade_test checks that a missing table is repaired only under the
      processing lock and is left alone while another session holds it.
    • An hourly pre-create case, hourly observability, and the --partition CLI paths.
  • MariaDB 10.5 regressions:
    • review_fixes_database_test installs hourly, checks there are at least 2 days ahead, merges
      six future hours into dMaxValue, and confirms maintenance heals them while Settings
      already asks for Daily. It also checks that repair recreates a missing hourly table from the
      current retention, and that it creates nothing for a refused plan.
    • partition_rebuild_database_test (71 checks) adds the daily → hourly → daily rebuilds, an
      EXPLAIN PARTITIONS proof of pruning, and a check that an hourly plan above the limit is
      refused.
    • incoming_preservation_database_test hangs on this local MariaDB 10.5 even on unmodified
      develop, so it was not used here.
  • Syslog 5 Develop version, Utilities -> Purge Syslog Devices, crash syslog plugin #472 and rebuild hardening:
    • CsrfPurgeTest drives the purge through the real syslog_connect() and
      includes/database.php, stubbing only Cacti's db_* layer. It fails on develop
      with the exact Syslog 5 Develop version, Utilities -> Purge Syslog Devices, crash syslog plugin #472 fatal, and covers a Syslog database that cannot be reached.
    • PartitionRebuildTest covers the refusal while Syslog is enabled, the processing lock held
      elsewhere, releasing the lock after a refusal, live transfer workers (live, stale and
      other-user pids), the DATETIME refusal before any change, and widening incoming in place.
  • Further partition_rebuild_database_test checks:
    • An injected copy failure, then an injected unverified row, then an injected case-only
      corruption are each detected or discarded, and the resume finishes.
    • Every row is copied exactly once, in the original order. Repeated seq values get
      distinct new ones, and none is at or below the old high-water mark. Binary, zero-date
      and NULL values survive.
    • Too little sequence headroom is refused before any change.
    • A failed create, and a failed setup before the checkpoint, both recover.
    • Aria, DATETIME refusal and DATETIME discard; the Syslog Enabled refusal; refusal while
      another connection holds the processing lock.
    • The --convert-ms pipeline keeps incoming seq identities and outbox instants, and
      restores the session and lock after a failure.
  • check-i18n-pot.php passes; locales/po/cacti.pot was regenerated with the
    build_gettext.sh xgettext invocation (.po/.mo files untouched).

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

The rebuild now renumbers seq in rebuilt stored/removed tables. No code reads old values:
syslog_logs.logseq is written but never queried.

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation repository accordingly.
    Not applicable: README and CHANGELOG are updated in this PR. The CHANGELOG now keeps only
    security, issue and feature entries, ordered by category, then ascending issue/PR
    number, then alphabetically; bug:/compat: became issue: and dev:/docs:/test:
    lines were dropped.

Copilot AI balanced review requested due to automatic review settings November 20, 2026 14:00

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Unresolved defects can let rebuilds overlap active processing, block --discard-data with invalid SQL, and cause the documented rollback to delete the only surviving copy of a completed table.

3 open issues
What changed in this PR

This PR addresses the Purge Syslog Devices crash reported in #472 and strengthens the partition rebuild utility introduced in #471.

Changes:

  • Connect before purging, report connection failures, and use database-qualified, NULL-safe deletion queries.
  • Add rebuild writer checks, sequence renumbering, batch verification and recovery checkpoints; preserve incoming identities through in-place conversion.
  • Expand regression coverage and document maintenance, legacy DATETIME handling, and recovery.
File Description
tests/​Unit/​PartitionRebuildTest.php Covers processing guards, DATETIME refusal, incoming conversion, and help output.
tests/​Security/​CsrfPurgeTest.php Exercises real connection setup and failed-connection handling.
tests/​regression/​partition_rebuild_database_test.php Tests batch verification, interrupted rebuild recovery, and identity preservation.
README.md Documents rebuild behavior, maintenance requirements, and recovery procedures.
locales/​po/​cacti.pot Adds the purge connection-failure message.
includes/​utilities.php Initializes the database connection and updates purge queries.
cli/​upgrade_partitioning.php Adds rebuild guards, checkpoints, verification, and in-place queue conversion.
CHANGELOG.md Records the purge fix and partition rebuild hardening.

Review effort: Balanced

Comment thread cli/upgrade_partitioning.php Resolved
Comment thread cli/upgrade_partitioning.php Resolved
Comment thread README.md Resolved
@TheWitness

Copy link
Copy Markdown
Member Author

More changes coming. This is draft.

@TheWitness
TheWitness marked this pull request as draft November 20, 2026 14:27
TheWitness and others added 3 commits November 20, 2026 10:16
Purge Syslog Devices called syslog_db_execute() from the utilities hook
without ever connecting, so includes/database.php was never loaded and the
plugin was disabled (#472). Connect first, report a failed connection,
qualify the Syslog database, and use NOT EXISTS so a NULL host_id cannot
silently prevent purging.

Address the #471 review of cli/upgrade_partitioning.php:

- Refuse to start while Syslog processing is enabled, and hold the
  syslog/master process slot for the duration.
- Copy stored and removed messages without seq. The replacement's
  AUTO_INCREMENT is set above the original high-water mark before the
  first row, so sequence values are never reused and copied rows cannot
  collide with live inserts.
- Verify each 10,000-row batch by count and MD5 checksum against its
  source range, then checkpoint it in syslog_rebuild_progress. A retry
  deletes unverified rows above the checkpoint and resumes.
- Widen syslog_incoming in place; its seq is an archival identity.
- Drop legacy DATETIME conversion: refuse such history before any
  change unless --discard-data is used, and document manual conversion
  and rollback.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add a Partitioning Level of Daily (default) or Hourly for syslog and
syslog_removed, matching MacTrack's partition-size workflow:

- Settings: rename "Data Retention Settings" to "Data Retention and
  Partitioning" and add the Partitioning Level dropdown. The level is
  applied only by cli/upgrade_partitioning.php, or by its new
  --partition=hourly|daily option, which saves it once confirmed. Until
  then maintenance follows the tables' existing layout, and Settings and
  Status show the change as pending.
- Install: replace the unused "Partitions per Day" advisor option with the
  level, and add $syslog_install_options['partitioning'].
- Limits: refuse to save settings, install, or rebuild when retention,
  today, the pre-create window and dMaxValue need more partitions than
  the server allows (8192; 1024 before MariaDB 10.0.4 and MySQL 5.7), or
  when Hourly is combined with Indefinite retention. Cacti runs the
  config_settings hook before settings.php saves, on 1.2 and 1.3.
- Hourly maintenance creates hYYYYMMDDHH partitions and keeps at least two
  days ahead, as MacTrack does, so dMaxValue splits stay instant. Recovery
  checks only the horizon in the steady state and binary-searches a gap.
- Queries: get_syslog_messages() always bounds logtime at now, so empty
  future partitions are pruned whatever the filter says.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Maintenance keeps the tables' existing partitioning level until
cli/upgrade_partitioning.php rebuilds them, so a settings save or upgrade
is also checked against every level the syslog and syslog_removed tables
currently use. This refuses, for example, Indefinite retention while
the tables are still hourly, even when Daily is selected.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@TheWitness
TheWitness force-pushed the fix/472-purge-devices-and-rebuild branch from b80da8e to 69ca410 Compare November 20, 2026 15:17
@TheWitness TheWitness changed the title syslog: fix Purge Syslog Devices crash and harden partition rebuilds syslog: fix Purge Syslog Devices crash, harden partition rebuilds, add hourly partitioning Nov 20, 2026
TheWitness and others added 2 commits November 20, 2026 10:19
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Cacti develop wraps every plain select in select2, which reports a change
through jQuery's trigger. The card controller listens with a native
addEventListener, so choosing a card under "Add card" did nothing. Bind
the add select with jQuery in the Status adapter, append and bind the
card, save the layout, and keep the select2 display in sync.

Changing the Refresh interval assigned window.location, a full page
load, and the Status tab also registered Cacti's page refresh. The
interval is now saved per user through a CSRF-protected status_refresh
callback, and a client timer refreshes the cards in place, through the
same path as the Refresh button. The timer stops once the grid leaves
the page.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@TheWitness TheWitness changed the title syslog: fix Purge Syslog Devices crash, harden partition rebuilds, add hourly partitioning syslog: fix device purge and Status cards, harden partition rebuilds, add hourly partitioning Nov 20, 2026
Comment thread tests/browser/status_cards.cjs Fixed
Comment thread tests/browser/status_cards.cjs Fixed
TheWitness and others added 2 commits November 20, 2026 12:46
… fixture

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
A 10M-row sweep on a 2 GiB buffer pool found batches of 10,000 to 65,536
rows within measurement noise of each other, with 50,000 fastest. The
batch size is now a parameter so the regression test can keep exercising
multi-batch resume on a small table.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@TheWitness

TheWitness commented Nov 20, 2026 •

Copy link
Copy Markdown
Member Author

Partition rebuild: analysis summary

Copy design (review of #471). seq is no longer part of INSERT … SELECT. Rows are copied in their original (seq, logtime) order into a replacement table. Its AUTO_INCREMENT is set above the original high-water mark before the first row, so sequence values are never reused and cannot collide with live inserts. Writers are refused up front: the command will not start while Syslog Enabled is set, and it holds the Syslog processing lock that syslog_process.php and its transfer workers also honor, refusing while live workers remain. Each batch is checksummed against its source range and checkpointed, so a crash resumes safely.

DATETIME → TIMESTAMP (10M rows, MariaDB 10.5, 2 GiB buffer pool):

Operation 10M rows
Batched TIMESTAMP→TIMESTAMP copy (develop tool) 471 s
Batched DATETIME→TIMESTAMP copy (develop tool) 483 s (+2.6%)
DST round-trip pre-flight scan 8 s
In-place ALTER DATETIME→TIMESTAMP + repartition 331 s

Conversion costs almost nothing in speed; its risk is correctness (values in the DST gap fail or shift, and the repeated hour is ambiguous). Legacy DATETIME history is therefore refused before any change; --discard-data replaces it, and the README documents a manual conversion that checks the values first. At 100M rows (~49 GiB), expect about 80–85 minutes per table for a preserving rebuild on comparable hardware, extrapolated linearly from 10M.

Batch size (10M rows, 2 GiB buffer pool, full preserving rebuild each run):

Batch Total Rows/s Slowest statement
1,000 783 s 12,769 2.1 s
2,500 658 s 15,202 1.4 s
5,000 605 s 16,540 3.2 s
10,000 511–550 s 18–19.6k 2.8 s
25,000 544 s 18,377 4.0 s
50,000 473 s 21,154 3.1 s
65,536 525 s 19,039 6.0 s
  • Below 10,000: per-batch overhead (the checkpoint write and the boundary query) dominates.
  • 10,000 and above: flat within run-to-run noise of about ±7%.
  • Buffer pool: disk reads and redo log written were the same at every size, so the 2 GiB pool was never the limit.
  • Boundary query: replacing the indexed boundary lookup with fixed seq BETWEEN windows gave the same totals (499–529 s), so the lookup stays; it also handles gaps in seq.

The default is now 50,000 rows per batch.

@TheWitness
TheWitness marked this pull request as ready for review November 20, 2026 17:59
@TheWitness
TheWitness requested a balanced review from Copilot November 20, 2026 17:59

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The rebuild CLI’s process-registration check does not enforce mutual exclusion across PHP entrypoints, allowing table rebuilds to overlap a still-running Syslog writer.

6 open issues

Review effort: Balanced

Comment thread js/syslog_dashboard.js Resolved
Comment thread setup.php Resolved
Comment thread setup.php Resolved
…imer

- Rebuild locking: cli/upgrade_partitioning.php and syslog_process.php now
  share one database lock (syslog_processing_lock_name()) instead of the
  Cacti process registry, which on 1.2.x can treat another PHP script as
  stale and takes over expired slots. GET_LOCK never waits for or
  terminates the other side, and is released when its connection closes.
  A single lock also avoids old servers dropping a first GET_LOCK when a
  second is taken.
- --discard-data with no incoming/outbox widening no longer issues
  "TABLE_NAME IN ()".
- README rollback restores only tables that still have a <table>_rebuild
  original and leaves completed tables untouched.
- Status auto-refresh: a late callback from a grid replaced by ajax
  navigation no longer resets the current grid's shared timer.
- Installer limit check (syslog_partition_install_error()): a submitted
  Daily level wins over the saved one, and truncate ignores the old
  layouts of both tables, which it drops and recreates.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread includes/schema.php Resolved
Comment thread includes/settings.php Resolved
Comment thread syslog_process.php Resolved
Comment thread README.md Resolved
…ttings checks

- syslog_process.php takes the processing lock through the new
  syslog_processing_lock_acquire(), on a separate connection to the same
  server as $syslog_cnn, opened from the details Cacti recorded for it
  (bypassing the cached session and persistent handles). MySQL before
  5.7.5 keeps one named lock per session, so the GET_LOCK calls made by
  partition maintenance and alert delivery on the Syslog connection
  could otherwise release it mid-run and let a rebuild overlap.
- Repair (automatic and cli/syslog_schema.php) recreates a missing
  syslog table from the current retention rather than the install-time
  days, and checks the plan against the server partition limit before
  any DDL.
- The Syslog settings save is refused when the Syslog server's version
  or table layouts cannot be read, rather than validating against the
  Cacti server's version and no layouts. The installer check refuses
  likewise when the existing layouts cannot be read.
- README: the DATETIME round-trip check counts values UNIX_TIMESTAMP()
  cannot convert (NULL-safe comparison).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…order

Every release section now lists security, then issue, then feature
entries. Numbered entries come first in ascending issue or pull number,
then unnumbered entries alphabetically. bug: and compat: entries become
issue:, and issue#N - / issue#N separators become issue#N:. A single
trailing "(issue #N)" or "(#N)" reference moves into the prefix. dev:,
docs: and test: entries are dropped. This PR's entries are tagged #473,
and the rebuild entries now describe the shared processing lock and
50,000-row batches.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The idle lock connection can time out during ingestion, releasing the lock and allowing a rebuild to overlap processing because lock ownership is neither maintained nor monitored.

1 open issue
4 resolved since last review

Review effort: Balanced

Comment thread includes/functions.php Resolved
The processor's lock connection is idle after GET_LOCK, so the server
would close it, and release the lock, once wait_timeout elapsed during a
long processing run. Raise its session wait_timeout to at least a day
before taking the lock and skip processing if the server does not
accept it.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Critical locking gaps allow processor schema repair and transfer-worker writes to overlap partition rebuilds, leaving table modifications unprotected.

4 open issues
1 resolved since last review

Review effort: Balanced

Comment thread cli/upgrade_partitioning.php Resolved
Comment thread syslog_process.php Resolved
Comment thread includes/settings.php Resolved
Comment thread syslog.php Resolved
- Transfer workers receive the master's lock session (--lock-owner) and
  exit without writing unless that session still holds the processing
  lock. The rebuild, once it holds the lock, refuses while live workers
  remain registered in Cacti's process table (stale rows of crashed
  workers are ignored). Registration precedes the worker's check, so
  every worker is either seen by the rebuild or sees the rebuild's lock.
- syslog_process.php and cli/upgrade_partitioning.php connect without
  schema repair (SYSLOG_DEFER_SCHEMA_REPAIR); the processor repairs only
  after taking the processing lock. Recreating a missing table from any
  other caller first takes the lock on a separate connection, so a page
  load can never recreate a table a rebuild has renamed away.
- Settings and Status report a pending partitioning level whenever
  either message table differs from the selected level, and Status
  shows both tables' levels when they differ.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@TheWitness
TheWitness requested a balanced review from Copilot November 20, 2026 19:14
@sonarqubecloud

sonarqubecloud Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
0.1% Duplication on New Code

See analysis details on SonarQube Cloud

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Human assessment is needed to weigh unpublished findings about Never-refresh timer overflow and database lock failures being masked as ordinary contention.

No open issues 🎉

4 resolved since last review

Review effort: Balanced

@TheWitness
TheWitness merged commit d36843b into develop Nov 20, 2026
12 checks passed
@TheWitness
TheWitness deleted the fix/472-purge-devices-and-rebuild branch November 20, 2026 19:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Syslog 5 Develop version, Utilities -> Purge Syslog Devices, crash syslog plugin

4 participants