-
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
Merged
+42
−8
Merged
Changes from 10 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
ac12b55
PYTHON-4780 Implement fast path for server selection with Primary
blink1073 f32a3a6
PYTHON-4780 Implement fast path for server selection with Primary
blink1073 07e0dca
fix zizmor
blink1073 7dfc3f1
fix zizmor
blink1073 746e8d5
update test
blink1073 25fd1f2
Merge branch 'master' of github.com:mongodb/mongo-python-driver into …
blink1073 e5a0c84
update readme
blink1073 e478cf7
address review
blink1073 40794fe
address review
blink1073 ee955f1
address review
blink1073 fd194f2
address review
blink1073 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,7 +30,7 @@ | |
from pymongo import common | ||
from pymongo.errors import AutoReconnect, ConfigurationError, ConnectionFailure | ||
from pymongo.hello import Hello, HelloCompat | ||
from pymongo.read_preferences import ReadPreference, Secondary | ||
from pymongo.read_preferences import Primary, ReadPreference, Secondary | ||
from pymongo.server_description import ServerDescription | ||
from pymongo.server_selectors import any_server_selector, writable_server_selector | ||
from pymongo.server_type import SERVER_TYPE | ||
|
@@ -51,7 +51,10 @@ def get_topology_type(self): | |
|
||
|
||
def create_mock_topology( | ||
seeds=None, replica_set_name=None, monitor_class=DummyMonitor, direct_connection=False | ||
seeds=None, | ||
replica_set_name=None, | ||
monitor_class=DummyMonitor, | ||
direct_connection=False, | ||
): | ||
partitioned_seeds = list(map(common.partition_node, seeds or ["a"])) | ||
topology_settings = TopologySettings( | ||
|
@@ -123,6 +126,25 @@ def test_timeout_configuration(self): | |
# The monitor, not its pool, is responsible for calling hello. | ||
self.assertTrue(monitor._pool.is_sdam) | ||
|
||
def test_selector_fast_path(self): | ||
topology = create_mock_topology(seeds=["a", "b:27018"], replica_set_name="foo") | ||
description = topology.description | ||
description._topology_type = TOPOLOGY_TYPE.ReplicaSetWithPrimary | ||
|
||
# There is no primary yet, so it should give an empty list. | ||
self.assertEqual(description.apply_selector(Primary()), []) | ||
|
||
# If we set a primary server, we should get it back. | ||
sd = list(description._server_descriptions.values())[0] | ||
sd._server_type = SERVER_TYPE.RSPrimary | ||
self.assertEqual(description.apply_selector(Primary()), [sd]) | ||
|
||
# If there is a custom selector, it should be applied. | ||
def custom_selector(servers): | ||
return [] | ||
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. Neat trick. |
||
|
||
self.assertEqual(description.apply_selector(Primary(), custom_selector=custom_selector), []) | ||
|
||
|
||
class TestSingleServerTopology(TopologyTest): | ||
def test_direct_connection(self): | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Is the
custom_selector is None
check supposed to be here?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.
No, I forgot to back that change out