-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Lock] Fixed reading locks from replica set secondary nodes #37140
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
Conversation
In order to add a CI test for this we would need a replicaSet in CI. Not sure this is worth doing? |
3b04eac
to
a0e4f1f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In order to add a CI test for this we would need a replicaSet in CI. Not sure this is worth doing?
Unless there is a docker image that would allow doing that easily by using GitHub Actions, I agree.
I can't find anything that appears maintained. There's https://github.com/marketplace/actions/mongodb-in-github-actions#with-a-replica-set however their replica set is single instance (there is no secondary so we therefore can't test against it). I don't really want to create and maintain our own github action for this but might make sense in the future if we want to also test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just sharing a few comments after I was pinged in #37139. Feel free to take or leave my suggestions as you wish.
); | ||
$buildInfo = $cursor->toArray()[0]; | ||
$this->databaseVersion = $buildInfo->version; | ||
$this->readPreference = new ReadPreference(ReadPreference::RP_PRIMARY); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: ReadPreference
can be constructed with a string since driver version 1.3.0 (September 2017). I didn't find any reference to the mongodb
extension or PHP library in composer.json
so perhaps there's no minimum requirement and that's the reason for preferring the deprecated numeric constants (we hope to remove these in 2.0, per PHPC-1021).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
symfony doesn't require ext-mongodb
, the closest it comes is "require-dev": { "mongodb/mongodb": "~1.1" }
since "mongodb/mongodb": "1.1.0"
requires ext-mongodb: ^1.2.0
i think we should probably support pre ext-mongodb: 1.3.0
(needs to support ints).
I've added detection for string const vs int const to allow both forwards and backwards compatibility with the shift from int
to string
constructed ReadPreference
I'm assuming in https://jira.mongodb.org/browse/PHPC-1021 you're planning to just remove ReadPreference::RP_PRIMARY
and ReadPreference::PRIMARY
will remain in ext-mongodb: 2.0
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
symfony doesn't require ext-mongodb, the closest it comes is "require-dev": { "mongodb/mongodb": "~1.1" }
Where is this? I didn't find any reference to mongodb
in https://github.com/symfony/symfony/blob/5.1/composer.json
I'm assuming in https://jira.mongodb.org/browse/PHPC-1021 you're planning to just remove ReadPreference::RP_PRIMARY and ReadPreference::PRIMARY will remain in ext-mongodb: 2.0?
Correct. The new constants would stay. The old, integer constants happen to be tied to internal libmongoc constants, which is why we want to remove them (and why the values seemingly make no sense, since they're bitmasks IIRC).
In any event, I think the ternary you have in the current diff is future-proof. 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where is this? I didn't find any reference to mongodb in https://github.com/symfony/symfony/blob/5.1/composer.json
in the Component\Lock
- src/Symfony/Component/Lock/composer.json
@@ -315,23 +317,15 @@ private function isDuplicateKeyException(WriteException $e): bool | |||
return 11000 === $code; | |||
} | |||
|
|||
private function getDatabaseVersion(): string | |||
private function getReadPreference(): ReadPreference |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This appears to be called exactly once in exists()
. ReadPreference is a very light value object, so I'd propose just removing this method (and cached class property) in favor of constructing it inline.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed
Side note: while looking at
collection option in the MongoDB connection string. Likewise, this adapter parses a default database name from the authentication database. I realize this likely needs to remain in 5.x for BC at this point, but I'd argue against having this behavior for two reasons:
IMO, both |
regarding the use of
|
Indeed, the MongoDB shell does use this as its default database since its REPL always has a From the driver's perspective, the root context is always the client object and applications explicitly select a database or collection. The connection string spec for drivers only defines this as a default auth database and makes no mention of it having any other purpose. The server manual for connection strings says the same. Given that Some libraries built atop drivers also use the database component as their default database (e.g. default DB for storing models in the Mongoose ODM for Node.js); however, I have the same objections about that since it could also clash with authentication. Having said all that, I imagine none of this can be changed in 5.x. If you'd like to preemptively open a ticket to address this in 6.0, I would still suggest addressing both |
@jmikola Thanks heaps for your insight to the usage of I'll make sure all of this also filters down to |
46def68
to
ebf7eaf
Compare
Thank you @kralos. |
…eadPreference (kralos) This PR was merged into the 5.1 branch. Discussion ---------- [Lock] #37139 Updated Lock MongoDbStore note on readPreference Fixed documentation around `readPreference` for `MongoDbStore` in `Lock` component. See symfony/symfony#37140 Commits ------- 98574f5 #37139 Updated Lock MongoDbStore note on readPreference
Force lock existence query to use
readPreference=primary
in case the given mongo connection is using any of the followingreadPreference
s:Any of the above would fail if a secondary node is queried during a lock release.