Skip to content

Commit

Permalink
[Lock] Fixed reading locks from replica set secondary nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
Joe Bennett authored and fabpot committed Jun 10, 2020
1 parent 5de548b commit ebf7eaf
Showing 1 changed file with 5 additions and 24 deletions.
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

0 comments on commit ebf7eaf

Please sign in to comment.