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

Commit ebf7eaf

Browse filesBrowse files
Joe Bennettfabpot
Joe Bennett
authored andcommitted
[Lock] Fixed reading locks from replica set secondary nodes
1 parent 5de548b commit ebf7eaf
Copy full SHA for ebf7eaf

File tree

1 file changed

+5
-24
lines changed
Filter options

1 file changed

+5
-24
lines changed

‎src/Symfony/Component/Lock/Store/MongoDbStore.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Lock/Store/MongoDbStore.php
+5-24Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
use MongoDB\BSON\UTCDateTime;
1515
use MongoDB\Client;
1616
use MongoDB\Collection;
17-
use MongoDB\Driver\Command;
1817
use MongoDB\Driver\Exception\WriteException;
18+
use MongoDB\Driver\ReadPreference;
1919
use MongoDB\Exception\DriverRuntimeException;
2020
use MongoDB\Exception\InvalidArgumentException as MongoInvalidArgumentException;
2121
use MongoDB\Exception\UnsupportedException;
@@ -54,8 +54,6 @@ class MongoDbStore implements BlockingStoreInterface
5454
private $options;
5555
private $initialTtl;
5656

57-
private $databaseVersion;
58-
5957
use ExpiringStoreTrait;
6058

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

@@ -315,25 +315,6 @@ private function isDuplicateKeyException(WriteException $e): bool
315315
return 11000 === $code;
316316
}
317317

318-
private function getDatabaseVersion(): string
319-
{
320-
if (null !== $this->databaseVersion) {
321-
return $this->databaseVersion;
322-
}
323-
324-
$command = new Command([
325-
'buildinfo' => 1,
326-
]);
327-
$cursor = $this->getCollection()->getManager()->executeReadCommand(
328-
$this->getCollection()->getDatabaseName(),
329-
$command
330-
);
331-
$buildInfo = $cursor->toArray()[0];
332-
$this->databaseVersion = $buildInfo->version;
333-
334-
return $this->databaseVersion;
335-
}
336-
337318
private function getCollection(): Collection
338319
{
339320
if (null !== $this->collection) {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.