123456789101112131415161718192021222324252627282930313233343536373839 |
- <?php
- declare(strict_types=1);
- /**
- * This file is part of Hyperf.
- *
- * @link https://www.hyperf.io
- * @document https://hyperf.wiki
- * @contact group@hyperf.io
- * @license https://github.com/hyperf/hyperf/blob/master/LICENSE
- */
- namespace Hyperf\Database;
- use Exception;
- use Hyperf\Stringable\Str;
- trait DetectsDeadlocks
- {
- /**
- * Determine if the given exception was caused by a deadlock.
- */
- protected function causedByDeadlock(Exception $e): bool
- {
- $message = $e->getMessage();
- return Str::contains($message, [
- 'Deadlock found when trying to get lock',
- 'deadlock detected',
- 'The database file is locked',
- 'database is locked',
- 'database table is locked',
- 'A table in the database is locked',
- 'has been chosen as the deadlock victim',
- 'Lock wait timeout exceeded; try restarting transaction',
- 'WSREP detected deadlock/conflict and aborted the transaction. Try restarting the transaction',
- ]);
- }
- }
|