-
Notifications
You must be signed in to change notification settings - Fork 1.1k
PYTHON-4780 Implement fast path for server selection with Primary #2416
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
base: master
Are you sure you want to change the base?
Changes from all commits
ac12b55
f32a3a6
07e0dca
7dfc3f1
746e8d5
25fd1f2
e5a0c84
e478cf7
40794fe
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,7 +34,7 @@ | |
from bson.objectid import ObjectId | ||
from pymongo import common | ||
from pymongo.errors import ConfigurationError, PyMongoError | ||
from pymongo.read_preferences import ReadPreference, _AggWritePref, _ServerMode | ||
from pymongo.read_preferences import Primary, ReadPreference, _AggWritePref, _ServerMode | ||
from pymongo.server_description import ServerDescription | ||
from pymongo.server_selectors import Selection | ||
from pymongo.server_type import SERVER_TYPE | ||
|
@@ -324,6 +324,14 @@ def apply_selector( | |
description = self.server_descriptions().get(address) | ||
return [description] if description else [] | ||
|
||
# Primary selection fast path. | ||
if self.topology_type == TOPOLOGY_TYPE.ReplicaSetWithPrimary and type(selector) is Primary: | ||
for sd in self._server_descriptions.values(): | ||
if sd.server_type == SERVER_TYPE.RSPrimary: | ||
return [sd] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh one more thing, don't we have to call the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And add a test for it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll have to defer for now, working on a HELP ticket |
||
# No primary found, return an empty list. | ||
return [] | ||
|
||
selection = Selection.from_topology_description(self) | ||
# Ignore read preference for sharded clusters. | ||
if self.topology_type != TOPOLOGY_TYPE.Sharded: | ||
|
Uh oh!
There was an error while loading. Please reload this page.