-
Notifications
You must be signed in to change notification settings - Fork 11.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[8.x] Add support for MariaDB to skip locked rows with the database queue driver #39311
Conversation
…river As documented in https://mariadb.com/kb/en/select/#skip-locked since MariaDB 10.6 there is support for skipping locked rows when fetching from the database. This change adds support to it.
This update actually crashed our queue workers. We updated the framework/laravel version from v8.64.0 to v8.67.0 and suddenly all of our queue workers conflicted because of the FOR UPDATE SKIP LOCKED. Our MariaDB version is: 10.3.31-MariaDB-log - MariaDB Server. Rolling back to v8.64.0 solved the issue. |
Can you please show your result for: $databaseEngine = \DB::getPdo()->getAttribute(PDO::ATTR_DRIVER_NAME);
$databaseVersion = \DB::getPdo()->getAttribute(PDO::ATTR_SERVER_VERSION);
echo version_compare($databaseVersion, '8.0.1', '>='));
echo strpos($databaseVersion, 'MariaDB');
echo version_compare(\Str::after($databaseVersion, '-'), '10.6.0', '>='); Thanks |
It just returns 18 if I run your script. The 3 echo's are: |
I can confirm this same issues. I have been debugging for the past 3 days. I only just reaslised that the issue started after I upgraded. I am also on version 10.3.31-MariaDB-log-cll-lve - MariaDB Server and Laravel 8.67. Kindly look into it |
if (($databaseEngine === 'mysql' && ! strpos($databaseVersion, 'MariaDB') && version_compare($databaseVersion, '8.0.1', '>=')) ||
(strpos($databaseVersion, 'MariaDB') && version_compare(Str::after($databaseVersion, '5.5.5-'), '10.6.0', '>=')) ||
($databaseEngine === 'pgsql' && version_compare($databaseVersion, '9.5', '>='))) {
return 'FOR UPDATE SKIP LOCKED';
} |
Same me |
same here |
Revert it all. |
@antoniopaisfernandes please test your changes. I will be merging nothing else in this regard for a while. |
@taylorotwell Sorry for the mess I put you in :( I'll find out more scenarios and how to improve the code. |
@antoniopaisfernandes think it's best that we leave this be for now. |
Thank you and apologies. |
I did a new attempt for this at #39396 |
I just feel this is easier to read.. and change if (Str::of($databaseVersion)->contains('MariaDB')) {
$databaseEngine = 'MariaDB';
$databaseVersion = Str::of($databaseVersion)->match("/\d+\.\d+\.\d+/");
}
if (($databaseEngine === 'mysql' && version_compare($databaseVersion, '8.0.1', '>=')) ||
($databaseEngine === 'MariaDB' && version_compare($databaseVersion, '10.6.0', '>=')) ||
($databaseEngine === 'pgsql' && version_compare($databaseVersion, '9.5', '>='))) {
$result = 'FOR UPDATE SKIP LOCKED';
} |
Thanks @mxts, I added that suggestion, that looks indeed better. The regex wasn't correct though as it won't strip the |
Btw I'd greatly appreciate it if you all could try out #39396 to see if it passes for your systems. |
@driesvints Thank you so much for your care! 🦸♂️ With vanilla MariaDB 10.5:
With 10.6:
No errors running the workers! 🥳 |
Digress a bit here, how did you all manage to find the issue?
What I mean is, is there a "best" way to look out for/catch such exceptions? |
@mxts For the test I just activated MariaDB logging As for being aware of problems in the runners, our choice was Sentry https://sentry.io/for/laravel/ but there are a lot of solutions for it. |
@antoniopaisfernandes thanks I was hoping for something to appear when I run |
As documented in https://mariadb.com/kb/en/select/#skip-locked since MariaDB 10.6 there is support for skipping locked rows when fetching from the database.
This change adds support to it.