Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Lock] Add MysqlStore that use GET_LOCK #25578

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 10 commits into from
Prev Previous commit
Check if lock still exists with a db query
  • Loading branch information
GromNaN committed Jan 19, 2018
commit 3ae4cceea667cbdc2ccff4a122be52d8bbc4f04c
21 changes: 16 additions & 5 deletions 21 src/Symfony/Component/Lock/Store/MysqlStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function __construct($connection, $waitTimeout = 0)
}

$this->connection = $connection;
$this->waitTimeout = (int) $waitTimeout;
$this->waitTimeout = $waitTimeout;
}

/**
Expand Down Expand Up @@ -130,9 +130,9 @@ public function delete(Key $key)

$storedKey = $key->getState(__CLASS__);

$releaseStmt = $this->connection->prepare('DO RELEASE_LOCK(:key)');
$releaseStmt->bindValue(':key', $storedKey, \PDO::PARAM_STR);
$releaseStmt->execute();
$stmt = $this->connection->prepare('DO RELEASE_LOCK(:key)');
$stmt->bindValue(':key', $storedKey, \PDO::PARAM_STR);
$stmt->execute();

$key->removeState(__CLASS__);
}
Expand All @@ -142,6 +142,17 @@ public function delete(Key $key)
*/
public function exists(Key $key)
{
return $key->hasState(__CLASS__);
if (!$key->hasState(__CLASS__)) {
return false;
}

$storedKey = $key->getState(__CLASS__);

$stmt = $this->connection->prepare('SELECT IF(IS_USED_LOCK(:key) = CONNECTION_ID(), 1, 0)');
Copy link
Member Author

@GromNaN GromNaN Jan 19, 2018

Choose a reason for hiding this comment

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

@jderusse This query insure that: 1. the connection is still alive & 2. the lock is still assigned to the current connection.

$stmt->bindValue(':key', $storedKey, \PDO::PARAM_STR);
$stmt->setFetchMode(\PDO::FETCH_COLUMN, 0);
$stmt->execute();

return '1' === $stmt->fetchColumn();
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.