Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Messenger] support mysql 8.0 skip locked #51013

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

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Doctrine\DBAL\Exception as DBALException;
use Doctrine\DBAL\Exception\TableNotFoundException;
use Doctrine\DBAL\LockMode;
use Doctrine\DBAL\Platforms\MySQL80Platform;
use Doctrine\DBAL\Platforms\MySQLPlatform;
use Doctrine\DBAL\Platforms\OraclePlatform;
use Doctrine\DBAL\Query\QueryBuilder;
Expand Down Expand Up @@ -168,11 +169,12 @@ public function get(): ?array
get:
$this->driverConnection->beginTransaction();
try {
$databasePlatform = $this->driverConnection->getDatabasePlatform();
$query = $this->createAvailableMessagesQueryBuilder()
->orderBy('available_at', 'ASC')
->setMaxResults(1);

if ($this->driverConnection->getDatabasePlatform() instanceof OraclePlatform) {
if ($databasePlatform instanceof OraclePlatform) {
$query->select('m.id');
}

Expand All @@ -185,21 +187,27 @@ public function get(): ?array
$fromClause = sprintf('%s %s', $table, $alias);
$sql = str_replace(
sprintf('FROM %s WHERE', $fromClause),
sprintf('FROM %s WHERE', $this->driverConnection->getDatabasePlatform()->appendLockHint($fromClause, LockMode::PESSIMISTIC_WRITE)),
sprintf('FROM %s WHERE', $databasePlatform->appendLockHint($fromClause, LockMode::PESSIMISTIC_WRITE)),
$sql
);
}

// Wrap the rownum query in a sub-query to allow writelocks without ORA-02014 error
if ($this->driverConnection->getDatabasePlatform() instanceof OraclePlatform) {
if ($databasePlatform instanceof OraclePlatform) {
$sql = $this->createQueryBuilder('w')
->where('w.id IN ('.str_replace('SELECT a.* FROM', 'SELECT a.id FROM', $sql).')')
->getSQL();
}

// use SELECT ... FOR UPDATE to lock table
$sql .= ' '.$databasePlatform->getWriteLockSQL();

if ($databasePlatform instanceof MySQL80Platform) {
$sql .= ' SKIP LOCKED';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you write a teest for that please?

}

$stmt = $this->executeQuery(
$sql.' '.$this->driverConnection->getDatabasePlatform()->getWriteLockSQL(),
$sql,
$query->getParameters(),
$query->getParameterTypes()
);
Expand Down