Skip to content
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

[Lock] Fixed reading locks from replica set secondary nodes #37140

Merged
merged 1 commit into from Jun 10, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 5 additions & 24 deletions src/Symfony/Component/Lock/Store/MongoDbStore.php
Expand Up @@ -14,8 +14,8 @@
use MongoDB\BSON\UTCDateTime;
use MongoDB\Client;
use MongoDB\Collection;
use MongoDB\Driver\Command;
use MongoDB\Driver\Exception\WriteException;
use MongoDB\Driver\ReadPreference;
use MongoDB\Exception\DriverRuntimeException;
use MongoDB\Exception\InvalidArgumentException as MongoInvalidArgumentException;
use MongoDB\Exception\UnsupportedException;
Expand Down Expand Up @@ -54,8 +54,6 @@ class MongoDbStore implements BlockingStoreInterface
private $options;
private $initialTtl;

private $databaseVersion;

use ExpiringStoreTrait;

/**
Expand Down Expand Up @@ -87,8 +85,8 @@ class MongoDbStore implements BlockingStoreInterface
* to 0.0 and optionally leverage
* self::createTtlIndex(int $expireAfterSeconds = 0).
*
* writeConcern, readConcern and readPreference are not specified by
* MongoDbStore meaning the collection's settings will take effect.
* writeConcern and readConcern are not specified by MongoDbStore meaning the connection's settings will take effect.
* readPreference is primary for all queries.
* @see https://docs.mongodb.com/manual/applications/replication/
*/
public function __construct($mongo, array $options = [], float $initialTtl = 300.0)
Expand Down Expand Up @@ -262,6 +260,8 @@ public function exists(Key $key): bool
'expires_at' => [
'$gt' => $this->createMongoDateTime(microtime(true)),
],
], [
'readPreference' => new ReadPreference(\defined(ReadPreference::PRIMARY) ? ReadPreference::PRIMARY : ReadPreference::RP_PRIMARY),
]);
}

Expand Down Expand Up @@ -315,25 +315,6 @@ private function isDuplicateKeyException(WriteException $e): bool
return 11000 === $code;
}

private function getDatabaseVersion(): string
{
if (null !== $this->databaseVersion) {
return $this->databaseVersion;
}

$command = new Command([
'buildinfo' => 1,
]);
$cursor = $this->getCollection()->getManager()->executeReadCommand(
$this->getCollection()->getDatabaseName(),
$command
);
$buildInfo = $cursor->toArray()[0];
$this->databaseVersion = $buildInfo->version;

return $this->databaseVersion;
}

private function getCollection(): Collection
{
if (null !== $this->collection) {
Expand Down