From da9e071d7dddfe008da0cf8d9b67f85342558424 Mon Sep 17 00:00:00 2001 From: f0o Date: Wed, 2 Sep 2015 14:46:42 +0100 Subject: [PATCH 1/2] Revert all PHP-Based MySQL Locks introduced in #1584 --- discovery.php | 13 +------------ includes/dbFacile.mysql.php | 30 ------------------------------ includes/dbFacile.mysqli.php | 29 ----------------------------- includes/sql-schema/update.php | 8 -------- poller.php | 17 +++-------------- 5 files changed, 4 insertions(+), 93 deletions(-) diff --git a/discovery.php b/discovery.php index c72013ec7..3006399ff 100755 --- a/discovery.php +++ b/discovery.php @@ -105,19 +105,8 @@ if ($config['distributed_poller'] === true) { $where .= ' AND poller_group IN('.$config['distributed_poller_group'].')'; } -echo 'Checking for MySQL Locks:'; -while (!dbCheckLock('schema_update')) { - echo '.'; - sleep(1); -} -echo PHP_EOL; - foreach (dbFetch("SELECT * FROM `devices` WHERE status = 1 AND disabled = 0 $where ORDER BY device_id DESC") as $device) { - if (dbGetLock('discovering.' . $device['device_id'])) { - register_shutdown_function('dbReleaseLock','discovering.'.$device['device_id']); - discover_device($device, $options); - dbReleaseLock('discovering.' . $device['device_id']); - } + discover_device($device, $options); } $end = utime(); diff --git a/includes/dbFacile.mysql.php b/includes/dbFacile.mysql.php index 7b75aa9fb..0d1d7150c 100644 --- a/includes/dbFacile.mysql.php +++ b/includes/dbFacile.mysql.php @@ -59,36 +59,6 @@ function dbQuery($sql, $parameters=array()) { }//end dbQuery() -/* - * Aquire a lock on a string - * */ -function dbGetLock($data, $timeout = 0) { - $sql = 'SELECT GET_LOCK(\'' . $data . '\',' . $timeout . ')'; - $result = dbFetchCell($sql); - return $result; -} - - -/* - * Check a lock on a string - * */ -function dbCheckLock($data) { - $sql = 'SELECT IS_FREE_LOCK(\'' . $data . '\')'; - $result = dbFetchCell($sql); - return $result; -} - - -/* - * Release a lock on a string - * */ -function dbReleaseLock($data) { - $sql = 'SELECT RELEASE_LOCK(\'' . $data . '\')'; - $result = dbFetchCell($sql); - return $result; -} - - /* * Passed an array and a table name, it attempts to insert the data into the table. * Check for boolean false to determine whether insert failed diff --git a/includes/dbFacile.mysqli.php b/includes/dbFacile.mysqli.php index d7016368d..2408ca990 100644 --- a/includes/dbFacile.mysqli.php +++ b/includes/dbFacile.mysqli.php @@ -59,35 +59,6 @@ function dbQuery($sql, $parameters=array()) { }//end dbQuery() -/* - * Aquire a lock on a string - * */ -function dbGetLock($data, $timeout = 0) { - $sql = 'SELECT GET_LOCK(\'' . $data . '\',' . $timeout . ')'; - $result = dbFetchCell($sql); - return $result; -} - - -/* - * Check a lock on a string - * */ -function dbCheckLock($data) { - $sql = 'SELECT IS_FREE_LOCK(\'' . $data . '\')'; - $result = dbFetchCell($sql); - return $result; -} - - -/* - * Release a lock on a string - * */ -function dbReleaseLock($data) { - $sql = 'SELECT RELEASE_LOCK(\'' . $data . '\')'; - $result = dbFetchCell($sql); - return $result; -} - /* * Passed an array and a table name, it attempts to insert the data into the table. * Check for boolean false to determine whether insert failed diff --git a/includes/sql-schema/update.php b/includes/sql-schema/update.php index 93fe7eb6b..505082615 100644 --- a/includes/sql-schema/update.php +++ b/includes/sql-schema/update.php @@ -91,13 +91,6 @@ if ($tmp[0] <= $db_rev) { return; } -if (!dbGetLock('schema_update')) { - echo "Schema update already in progress. Exiting\n"; - exit(1); -} //end if - -register_shutdown_function('dbReleaseLock','schema_update'); - foreach ($filelist as $file) { list($filename,$extension) = explode('.', $file, 2); if ($filename > $db_rev) { @@ -168,4 +161,3 @@ if ($updating) { echo "-- Done\n"; } -dbReleaseLock('schema_update'); diff --git a/poller.php b/poller.php index 265486b2a..6412c37be 100755 --- a/poller.php +++ b/poller.php @@ -100,13 +100,6 @@ if (isset($options['r'])) { $config['norrd'] = true; } -echo 'Checking for MySQL Locks:'; -while (!dbCheckLock('schema_update')) { - echo '.'; - sleep(1); -} -echo PHP_EOL; - rrdtool_pipe_open($rrd_process, $rrd_pipes); echo "Starting polling run:\n\n"; @@ -117,13 +110,9 @@ if (!isset($query)) { foreach (dbFetch($query) as $device) { $device = dbFetchRow("SELECT * FROM `devices` WHERE `device_id` = '".$device['device_id']."'"); - if (dbGetLock('polling.' . $device['device_id'])) { - register_shutdown_function('dbReleaseLock','polling.'.$device['device_id']); - poll_device($device, $options); - RunRules($device['device_id']); - echo "\r\n"; - dbReleaseLock('polling.' . $device['device_id']); - } + poll_device($device, $options); + RunRules($device['device_id']); + echo "\r\n"; $polled_devices++; } From e85a140d468b591cde77582a7be872f88f2aa3e9 Mon Sep 17 00:00:00 2001 From: f0o Date: Wed, 2 Sep 2015 15:01:00 +0100 Subject: [PATCH 2/2] Adjusted docs --- doc/Extensions/Poller-Service.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/doc/Extensions/Poller-Service.md b/doc/Extensions/Poller-Service.md index ab5461ca6..6d33e27b9 100644 --- a/doc/Extensions/Poller-Service.md +++ b/doc/Extensions/Poller-Service.md @@ -1,4 +1,7 @@ # Poller Service + +# WARNING: THIS IS HIGHLY EXPERIMENTAL AND MAY NOT WORK + The Poller service is an alternative to polling and discovery cron jobs and provides support for distributed polling without memcache. It is multi-threaded and runs continuously discovering and polling devices with the oldest data attempting to honor the polling frequency configured in `config.php`. This service replaces all the required cron jobs except for `/opt/librenms/daily.sh` and `/opt/librenms/alerts.php`. Configure the maximum number of threads for the service in `$config['poller_service_workers']`. Configure the minimum desired polling frequency in `$config['poller_service_poll_frequency']` and the minimum desired discovery frequency in `$config['poller_service_discover_frequency']`. The service will not poll or discover devices which have data newer than this this configured age in seconds. Configure how frequently the service will attempt to poll devices which are down in `$config['poller_service_down_retry']`.