Files
cacti/tests/Unit/Core/Boost/BoostFailedDataSourceIsolationTest.php
T
Thomas Vincent 658b320f75 fix(boost): acknowledge exact keys and isolate repeatedly failing data sources (#8351)
* Stop Boost retries at failed writes and metadata reads

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>

* Retain Boost archives when temporary copies fail

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>

* Reuse Boost cleanup after failed temporary copies

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>

* Acknowledge exact Boost keys without deleting late arrivals

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>

* test(boost): cover native acknowledgement and archive handoff

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>

* fix(boost): match acknowledged keys by epoch, not session-local time

Staging fetched keys with FROM_UNIXTIME() converts each epoch through the
session time zone. On MySQL in a DST zone both instants of the fall-back
hour render as the same local time and are stored back as the first one,
so INSERT IGNORE collapses them and the second row is never deleted. It
is then fetched, skipped by --skip-past-updates and retained on every run.

Stage the epoch integers and compare them with UNIX_TIMESTAMP(time),
which reads the TIMESTAMP column's stored value without a time zone
conversion. Verified on MySQL 8.4 and MariaDB 11.8 with the session in
America/New_York.

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>

* fix(boost): stop bulk drain writes after a rejected flush

The bulk drain kept writing a data source's later timestamps after one of
its mid-stream flushes failed. That advanced the RRD past the rejected
samples, so --skip-past-updates dropped them when the retained shard was
retried. Skip the remaining rows of that data source instead.

Match the on-demand update result exactly against OK. An error that only
contains the letters, for example in an RRD file name such as BOOK_7.rrd,
was counted as success and its rows were acknowledged without being
written.

Describe the acknowledgement DELETE's index use accurately and note why
the fall-back fixture shifts only int parameters.

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>

* test(boost): publish bulk drain probe evidence to the changed-line gate

The bulk drain changes in poller_boost.php are exercised only by
BoostBulkDrainFailureProbe.php, which compiles the drain in a child
process from a temporary file. Xdebug credited those hits to the
temporary file, so the changed-line gate saw none of the drain's nine
changed statements and the pull request measured 66.7 percent.

Keep each loaded function at its original line numbers and map the copy
back to its source file, let the drain probe publish request coverage,
and run both drain scenarios from a request-coverage fixture whenever
poller_boost.php or the probe changes.

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>

* fix(boost): isolate a failing data source instead of its whole shard

One data source whose RRD update always fails, for example a corrupt RRD,
an unwritable file or a template mismatch, made its pass return -1. The
child abandoned its remaining passes and the parent kept every archive
table. Each later run added another archive table, re-read all of them,
and failed at the same data source again, so data sources after it in
that child were never written and work and disk use grew without bound.

Park the data sources whose update was rejected on process handler 0 and
acknowledge the rest of the shard, so the child carries on. Once every
child has finished, the parent copies the parked data sources' samples
into poller_output_boost and drops the archive tables as usual. Samples
older than one day are discarded with a warning, so a data source that
never succeeds cannot grow the queue forever. If parking or the copy
fails, the shard or the archive tables are retained as before.

Database and metadata failures still fail the whole shard.

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>

* test(boost): expect a rejected flush to park the data source and acknowledge the shard

A rejected mid-stream flush still stops further writes to its data source so
a later timestamp cannot advance the RRD past the rejected samples. The data
source is now parked for the parent to carry forward instead of retaining the
whole shard, so the bulk drain probe expects the shard to be acknowledged.

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>

* test(boost): run the Boost probes in the changed-line coverage gate

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>

---------

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
2026-11-17 13:36:34 -05:00

81 lines
3.6 KiB
PHP

<?php
// Copyright (C) 2026 The Cacti Group. GPL-2.0-or-later.
require_once dirname(__DIR__, 3) . '/Helpers/IsolatedProbe.php';
beforeAll(function () {
$GLOBALS['boost_isolation_verdict'] = cacti_test_isolated_probe(dirname(__DIR__, 3) . '/fixtures/Core/Boost/FailedDataSourceIsolation.php');
});
test('a rejected data source is parked and the rest of its shard is acknowledged', function () {
$r = $GLOBALS['boost_isolation_verdict']['isolate'];
// Data source 2 is written in full, and the shard still returns its row
// count so the child goes on to its remaining passes.
expect($r['result'])->toBe(6)
->and($r['writes'])->toContain('2@1700000000:42', '2@1700000060:42', '2@1700000120:42')
->and($r['statements'][0])->toBe([
'UPDATE poller_output_boost_local_data_ids SET process_handler = 0 WHERE process_handler = ? AND local_data_id IN (1)',
[3]
])
->and($r['statements'][1])->toBe([
'DELETE FROM poller_output_boost_local_data_ids WHERE local_data_id <= ? AND process_handler = ?',
[2, 3]
]);
});
test('a rejected final flush parks the shard\'s last data source', function () {
$r = $GLOBALS['boost_isolation_verdict']['isolate_last'];
expect($r['result'])->toBe(6)
->and($r['statements'][0][0])->toEndWith('AND local_data_id IN (2)');
});
test('a shard with no rejected update parks nothing', function () {
$r = $GLOBALS['boost_isolation_verdict']['clean'];
expect($r['result'])->toBe(6)
->and($r['statements'])->toHaveCount(1)
->and($r['statements'][0][0])->toStartWith('DELETE FROM poller_output_boost_local_data_ids');
});
test('a shard whose failed data source cannot be parked is retained', function () {
$r = $GLOBALS['boost_isolation_verdict']['park_fails'];
expect($r['result'])->toBe(-1)
->and(array_filter($r['statements'], fn ($s) => str_starts_with($s[0], 'DELETE')))->toBeEmpty();
});
test('parked data sources are carried into the live table within the age cap', function () {
$r = $GLOBALS['boost_isolation_verdict']['carry_some'];
// The table that is not a Boost archive is never read.
expect($r['result'])->toBeTrue()
->and($r['statements'])->toHaveCount(1)
->and($r['statements'][0][0])->toStartWith('INSERT IGNORE INTO poller_output_boost (local_data_id, rrd_name, time, output)')
->and($r['statements'][0][0])->toContain('FROM `poller_output_boost_arch_1` AS at')
->and($r['statements'][0][0])->toContain('bpt.process_handler = 0')
->and($r['statements'][0][1][0])->toBeGreaterThanOrEqual($r['before'] - 86400)
->and($r['statements'][0][1][0])->toBeLessThanOrEqual($r['before'] - 86400 + 5)
->and($r['logs'])->toContain('WARNING: Boost discarded 3 sample(s) older than 86400 seconds from data sources whose RRD update keeps failing.');
});
test('nothing is copied when no data source failed', function () {
$r = $GLOBALS['boost_isolation_verdict']['carry_none'];
expect($r['result'])->toBeTrue()->and($r['statements'])->toBeEmpty();
});
test('a failed carry-forward read or copy keeps the archive tables', function (string $scenario) {
expect($GLOBALS['boost_isolation_verdict'][$scenario]['result'])->toBeFalse();
})->with(['carry_count_fails', 'carry_expiry_fails', 'carry_insert_fails']);
test('the parent drops archive tables only after the failed data sources are carried forward', function () {
$v = $GLOBALS['boost_isolation_verdict'];
expect($v['parent_drops']['dropped'])->toBe(['DROP TABLE IF EXISTS `poller_output_boost_arch_1`'])
->and($v['parent_keeps']['dropped'])->toBeEmpty()
->and($v['parent_keeps']['logs'])->toContain('WARNING: Boost could not carry failed data sources forward; leaving archive tables in place for the next run to pick up.')
->and($v['parent_incomplete']['dropped'])->toBeEmpty();
});