Skip to content

Commit 9e09a8c

Browse files
refactor: align partition maintenance with dMaxValue fallback
1 parent 2ad33f0 commit 9e09a8c

2 files changed

Lines changed: 11 additions & 12 deletions

File tree

functions.php

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -242,11 +242,10 @@ function syslog_partition_manage() {
242242
$time = time() + 3600;
243243

244244
/*
245-
* Only run the retention prune when the new partition was created
246-
* successfully. Otherwise a hard failure in syslog_partition_create
247-
* (unknown partition expression, empty SHOW CREATE, invalid $time)
248-
* would combine with syslog_partition_remove to silently drop old
249-
* partitions on every poller cycle without adding a replacement.
245+
* Only run the retention prune when the next partition is ready.
246+
* If maintenance cannot safely create it, leave dMaxValue in place
247+
* as the write-path safety net and avoid dropping old partitions
248+
* without a replacement.
250249
*/
251250
if (syslog_partition_check('syslog', $time)) {
252251
if (syslog_partition_create('syslog', $time)) {
@@ -357,7 +356,7 @@ function syslog_partition_create($table, $time = null) {
357356
$boundary_epoch = ((int)($time / 86400) + 1) * 86400;
358357

359358
if ($boundary_epoch <= 0 || $boundary_epoch <= $time) {
360-
cacti_log("SYSLOG ERROR: Boundary epoch computation overflow for '$table' (time=$time); rotation aborted", false, 'SYSLOG');
359+
cacti_log("SYSLOG ERROR: Boundary epoch computation failed for '$table' (time=$time); leaving writes in dMaxValue until maintenance recovers", false, 'SYSLOG');
361360

362361
return false;
363362
}
@@ -366,7 +365,7 @@ function syslog_partition_create($table, $time = null) {
366365
$boundary_date = gmdate('Y-m-d', $boundary_epoch);
367366

368367
if (!preg_match('/^d\d{8}$/', $cformat) || !preg_match('/^\d{4}-\d{2}-\d{2}$/', $boundary_date)) {
369-
cacti_log("SYSLOG ERROR: Derived partition values failed format validation for '$table'; rotation aborted", false, 'SYSLOG');
368+
cacti_log("SYSLOG ERROR: Derived partition values failed format validation for '$table'; leaving writes in dMaxValue until maintenance recovers", false, 'SYSLOG');
370369

371370
return false;
372371
}
@@ -395,7 +394,7 @@ function syslog_partition_create($table, $time = null) {
395394
$create_syntax = syslog_db_fetch_row_prepared("SHOW CREATE TABLE `$syslogdb_default`.`$table`");
396395

397396
if (!cacti_sizeof($create_syntax) || empty($create_syntax['Create Table'])) {
398-
cacti_log("SYSLOG ERROR: SHOW CREATE TABLE returned no rows for '$table'; partition rotation aborted", false, 'SYSLOG');
397+
cacti_log("SYSLOG ERROR: SHOW CREATE TABLE returned no rows for '$table'; leaving writes in dMaxValue until maintenance recovers", false, 'SYSLOG');
399398

400399
return false;
401400
}
@@ -411,7 +410,7 @@ function syslog_partition_create($table, $time = null) {
411410
PARTITION $cformat VALUES LESS THAN ($boundary_epoch),
412411
PARTITION dMaxValue VALUES LESS THAN MAXVALUE)");
413412
} else {
414-
cacti_log("SYSLOG ERROR: Unable to determine partition expression (neither TO_DAYS nor UNIX_TIMESTAMP) for '$table'; rotation aborted", false, 'SYSLOG');
413+
cacti_log("SYSLOG ERROR: Unable to determine partition expression (neither TO_DAYS nor UNIX_TIMESTAMP) for '$table'; leaving writes in dMaxValue until maintenance recovers", false, 'SYSLOG');
415414

416415
return false;
417416
}

tests/regression/issue254_partition_table_locking_test.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,10 +234,10 @@
234234
exit(1);
235235
}
236236

237-
// ---- syslog_partition_create must hard-fail when the partition expression cannot be detected ----
237+
// ---- syslog_partition_create must fall back to dMaxValue when the expression cannot be detected ----
238238

239-
if (!preg_match('/SHOW CREATE TABLE.*Unable to determine partition expression/s', $functions)) {
240-
fwrite(STDERR, "syslog_partition_create does not hard-fail on unknown partition expression.\n");
239+
if (!preg_match('/SHOW CREATE TABLE.*Unable to determine partition expression.*dMaxValue/s', $functions)) {
240+
fwrite(STDERR, "syslog_partition_create does not preserve dMaxValue fallback on unknown partition expression.\n");
241241
exit(1);
242242
}
243243

0 commit comments

Comments
 (0)