From e24409e081ee11a7fd75b692929ac061e976c731 Mon Sep 17 00:00:00 2001 From: Dries Vints Date: Thu, 28 Oct 2021 12:39:37 +0200 Subject: [PATCH 1/2] Add support for SKIP LOCKED to MariaDB These changes add support to add SKIP LOCKED functionality to the MariaDB (MySQL) engine. Implementation proof: https://3v4l.org/jShU9 Versioning sanitization: https://3v4l.org/2IqgH --- src/Illuminate/Queue/DatabaseQueue.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Illuminate/Queue/DatabaseQueue.php b/src/Illuminate/Queue/DatabaseQueue.php index 4259775d34cc..73980400a09d 100644 --- a/src/Illuminate/Queue/DatabaseQueue.php +++ b/src/Illuminate/Queue/DatabaseQueue.php @@ -8,6 +8,7 @@ use Illuminate\Queue\Jobs\DatabaseJob; use Illuminate\Queue\Jobs\DatabaseJobRecord; use Illuminate\Support\Carbon; +use Illuminate\Support\Str; use PDO; class DatabaseQueue extends Queue implements QueueContract, ClearableQueue @@ -253,8 +254,12 @@ protected function getLockForPopping() $databaseEngine = $this->database->getPdo()->getAttribute(PDO::ATTR_DRIVER_NAME); $databaseVersion = $this->database->getConfig('version') ?? $this->database->getPdo()->getAttribute(PDO::ATTR_SERVER_VERSION); - if (($databaseEngine === 'mysql' && ! strpos($databaseVersion, 'MariaDB') && version_compare($databaseVersion, '8.0.1', '>=')) || - ($databaseEngine === 'pgsql' && version_compare($databaseVersion, '9.5', '>='))) { + if (($databaseEngine === 'mysql' && ( + (! strpos($databaseVersion, 'MariaDB') && version_compare($databaseVersion, '8.0.1', '>=')) || + (strpos($databaseVersion, 'MariaDB') && version_compare(Str::before(Str::after($databaseVersion, '5.5.5-'), '-'), '10.6.0', '>=')) + )) || + ($databaseEngine === 'pgsql' && version_compare($databaseVersion, '9.5', '>=')) + ) { return 'FOR UPDATE SKIP LOCKED'; } From 80973a088c6b903f221d8e2bba7d49aa9eaed366 Mon Sep 17 00:00:00 2001 From: Dries Vints Date: Thu, 28 Oct 2021 14:58:01 +0200 Subject: [PATCH 2/2] Cleanup --- src/Illuminate/Queue/DatabaseQueue.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/Illuminate/Queue/DatabaseQueue.php b/src/Illuminate/Queue/DatabaseQueue.php index 73980400a09d..a1d3f085bea2 100644 --- a/src/Illuminate/Queue/DatabaseQueue.php +++ b/src/Illuminate/Queue/DatabaseQueue.php @@ -254,12 +254,14 @@ protected function getLockForPopping() $databaseEngine = $this->database->getPdo()->getAttribute(PDO::ATTR_DRIVER_NAME); $databaseVersion = $this->database->getConfig('version') ?? $this->database->getPdo()->getAttribute(PDO::ATTR_SERVER_VERSION); - if (($databaseEngine === 'mysql' && ( - (! strpos($databaseVersion, 'MariaDB') && version_compare($databaseVersion, '8.0.1', '>=')) || - (strpos($databaseVersion, 'MariaDB') && version_compare(Str::before(Str::after($databaseVersion, '5.5.5-'), '-'), '10.6.0', '>=')) - )) || - ($databaseEngine === 'pgsql' && version_compare($databaseVersion, '9.5', '>=')) - ) { + if (Str::of($databaseVersion)->contains('MariaDB')) { + $databaseEngine = 'mariadb'; + $databaseVersion = Str::before(Str::after($databaseVersion, '5.5.5-'), '-'); + } + + if (($databaseEngine === 'mysql' && version_compare($databaseVersion, '8.0.1', '>=')) || + ($databaseEngine === 'mariadb' && version_compare($databaseVersion, '10.6.0', '>=')) || + ($databaseEngine === 'pgsql' && version_compare($databaseVersion, '9.5', '>='))) { return 'FOR UPDATE SKIP LOCKED'; }