Support multiple daily process locking backends with distributed polling (#11896)

* Implement locks in the file cache

* Replace custom locks

* implement restore lock
Used when re-hydrating

* remove legacy use statements

* Add class descriptions

* Fix style

* Default to database cache driver

* missed cache_locks table
prevent chicken-egg issue

* style fixes

* Remove custom file lock implementation

* missed items from file cache

* Update schema definition
hmm, other schema noise must be from manual modification as this is generated from a freshly migrated db.

* require predis, it is pure python, so no harm in adding

* and set predis as the default client
This commit is contained in:
Tony Murray
2020-10-07 07:36:35 -05:00
committed by GitHub
parent e52531fba4
commit 1e4702fa4f
17 changed files with 235 additions and 560 deletions

View File

@@ -16,13 +16,11 @@ use LibreNMS\Exceptions\HostIpExistsException;
use LibreNMS\Exceptions\HostUnreachableException;
use LibreNMS\Exceptions\HostUnreachablePingException;
use LibreNMS\Exceptions\InvalidPortAssocModeException;
use LibreNMS\Exceptions\LockException;
use LibreNMS\Exceptions\SnmpVersionUnsupportedException;
use LibreNMS\Fping;
use LibreNMS\Modules\Core;
use LibreNMS\Util\IPv4;
use LibreNMS\Util\IPv6;
use LibreNMS\Util\MemcacheLock;
use LibreNMS\Util\Time;
use PHPMailer\PHPMailer\PHPMailer;
use Symfony\Component\Process\Process;
@@ -2334,12 +2332,9 @@ function get_device_oid_limit($device)
*/
function lock_and_purge($table, $sql)
{
try {
$purge_name = $table . '_purge';
if (Config::get('distributed_poller')) {
MemcacheLock::lock($purge_name, 0, 86000);
}
$purge_name = $table . '_purge';
$lock = Cache::lock($purge_name, 86000);
if ($lock->get()) {
$purge_days = Config::get($purge_name);
$name = str_replace('_', ' ', ucfirst($table));
@@ -2348,13 +2343,12 @@ function lock_and_purge($table, $sql)
echo "$name cleared for entries over $purge_days days\n";
}
}
$lock->release();
return 0;
} catch (LockException $e) {
echo $e->getMessage() . PHP_EOL;
return -1;
}
return -1;
}
/**
@@ -2369,24 +2363,21 @@ function lock_and_purge_query($table, $sql, $msg)
{
$purge_name = $table . '_purge';
if (Config::get('distributed_poller')) {
MemcacheLock::lock($purge_name, 0, 86000);
}
$purge_duration = Config::get($purge_name);
if (! (is_numeric($purge_duration) && $purge_duration > 0)) {
return -2;
}
try {
$lock = Cache::lock($purge_name, 86000);
if ($lock->get()) {
if (dbQuery($sql, [$purge_duration])) {
printf($msg, $purge_duration);
}
} catch (LockException $e) {
echo $e->getMessage() . PHP_EOL;
$lock->release();
return -1;
return 0;
}
return 0;
return -1;
}
/**