-
Notifications
You must be signed in to change notification settings - Fork 1.1k
PYTHON-2554 Support $merge and $out executing on secondaries #774
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
4d0c7bb
to
76deede
Compare
76deede
to
627dc35
Compare
ef412a0
to
54159da
Compare
selection = Selection.from_topology_description(self) | ||
# Ignore read preference for sharded clusters. | ||
if self.topology_type != TOPOLOGY_TYPE.Sharded: | ||
selection = selector(selection) |
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 bit is just a small cleanup with no functional change.
@@ -263,21 +263,24 @@ def apply_selector(self, selector, address=None, custom_selector=None): | |||
selector.min_wire_version, | |||
common_wv)) | |||
|
|||
if isinstance(selector, _AggWritePref): | |||
selector.selection_hook(self) |
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.
Initially I was expecting to place the "selection_hook" logic inside _AggWritePref.__call__
but it turns out that we skip calling the selector in many cases. In fact the only time we actually do call the selector is for replica sets. I attempted to refactor this code to actually call the selector in all cases but that doesn't work either because read preference selectors are written to only work with replica sets.
So "selection_hook" is what I came up with instead.
@@ -1161,7 +1161,7 @@ def _secondaryok_for_server(self, read_preference, server, session): | |||
|
|||
with self._get_socket(server, session) as sock_info: | |||
secondary_ok = (single and not sock_info.is_mongos) or ( | |||
read_preference != ReadPreference.PRIMARY) | |||
read_preference.mode != ReadPreference.PRIMARY.mode) |
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 change is required because read_preference
might be a _AggWritePref.
I'll wait for @juliusgeo to review as well. |
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.
LGTM!
Implementation of https://github.com/mongodb/specifications/blob/master/source/crud/crud.rst#read-preferences-and-server-selection including the changes in DRIVERS-823 and DRIVERS-1969.