Merge pull request #1822 from f0o/mysql-lock-release

Release MySQL locks when they are not used anymore
This commit is contained in:
Neil Lathwood
2015-09-01 12:47:53 +01:00
3 changed files with 5 additions and 3 deletions

View File

@@ -108,6 +108,7 @@ if ($config['distributed_poller'] === true) {
foreach (dbFetch("SELECT * FROM `devices` WHERE status = 1 AND disabled = 0 $where ORDER BY device_id DESC") as $device) { 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'])) { if (dbGetLock('discovering.' . $device['device_id'])) {
discover_device($device, $options); discover_device($device, $options);
dbReleaseLock('discovering.' . $device['device_id']);
} }
} }

View File

@@ -96,6 +96,8 @@ if (!dbGetLock('schema_update')) {
exit(1); exit(1);
} //end if } //end if
register_shutdown_function('dbReleaseLock','schema_update');
do { do {
sleep(1); sleep(1);
} while (@dbFetchCell('SELECT COUNT(*) FROM `devices` WHERE NOT IS_FREE_LOCK(CONCAT("polling.", device_id)) OR NOT IS_FREE_LOCK(CONCAT("queued.", device_id)) OR NOT IS_FREE_LOCK(CONCAT("discovering.", device_id))') > 0); } while (@dbFetchCell('SELECT COUNT(*) FROM `devices` WHERE NOT IS_FREE_LOCK(CONCAT("polling.", device_id)) OR NOT IS_FREE_LOCK(CONCAT("queued.", device_id)) OR NOT IS_FREE_LOCK(CONCAT("discovering.", device_id))') > 0);
@@ -169,5 +171,3 @@ if ($updating) {
echo "-- Done\n"; echo "-- Done\n";
} }
dbReleaseLock('schema_update');

View File

@@ -114,6 +114,7 @@ foreach (dbFetch($query) as $device) {
poll_device($device, $options); poll_device($device, $options);
RunRules($device['device_id']); RunRules($device['device_id']);
echo "\r\n"; echo "\r\n";
dbReleaseLock('polling.' . $device['device_id']);
} }
$polled_devices++; $polled_devices++;
} }