Skip to content

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

Merged
merged 7 commits into from
Dec 8, 2021

Conversation

ShaneHarvey
Copy link
Member

@ShaneHarvey ShaneHarvey commented Nov 3, 2021

@ShaneHarvey ShaneHarvey marked this pull request as ready for review December 4, 2021 00:32
selection = Selection.from_topology_description(self)
# Ignore read preference for sharded clusters.
if self.topology_type != TOPOLOGY_TYPE.Sharded:
selection = selector(selection)
Copy link
Member Author

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)
Copy link
Member Author

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)
Copy link
Member Author

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.

@ShaneHarvey ShaneHarvey requested a review from blink1073 December 7, 2021 20:38
@ShaneHarvey
Copy link
Member Author

I'll wait for @juliusgeo to review as well.

Copy link
Contributor

@juliusgeo juliusgeo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@ShaneHarvey ShaneHarvey merged commit bf992c2 into mongodb:master Dec 8, 2021
@ShaneHarvey ShaneHarvey deleted the PYTHON-2554 branch December 8, 2021 00:26
juliusgeo pushed a commit to juliusgeo/mongo-python-driver that referenced this pull request Apr 5, 2022
juliusgeo pushed a commit to juliusgeo/mongo-python-driver that referenced this pull request Apr 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants