Skip to content

PYTHON-2834 Direct read/write retries to another mongos if possible #1421

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 9 commits into from
Nov 14, 2023

Conversation

NoahStapp
Copy link
Contributor

No description provided.

@NoahStapp NoahStapp requested a review from a team as a code owner November 6, 2023 19:02
@NoahStapp NoahStapp requested review from blink1073 and removed request for a team November 6, 2023 19:02
@@ -1153,3 +1153,9 @@ def prepare_spec_arguments(spec, arguments, opname, entity_map, with_txn_callbac
raise AssertionError(f"Unsupported cursorType: {cursor_type}")
else:
arguments[c2s] = arguments.pop(arg_name)


def set_fail_point(client, command_args):
Copy link
Member

Choose a reason for hiding this comment

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

Can you use the with self.fail_point() helper instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We need to set the fail point on each individual mongos to ensure the failure occurs on every node. with self.fail_point() does not set the fail point correctly.

},
}

for mongos in client_context.mongos_seeds().split(","):
Copy link
Member

Choose a reason for hiding this comment

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

for mongos in client_context.mongoses:

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That change causes the following error:

h = ('localhost', 27017)

    def _connection_string(h):
>       if h.startswith(("mongodb://", "mongodb+srv://")):
E       AttributeError: 'tuple' object has no attribute 'startswith'

test/utils.py:544: AttributeError

@@ -2334,6 +2338,8 @@ def run(self) -> T:
raise
self._retrying = True
self._last_error = exc
if self._client.topology_description.topology_type == TOPOLOGY_TYPE.Sharded:
self._deprioritized_servers.append(self._server)
Copy link
Member

Choose a reason for hiding this comment

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

Since this logic is the same for reads and writes and we do it in one place?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch, thanks!

Copy link
Member

@ShaneHarvey ShaneHarvey left a comment

Choose a reason for hiding this comment

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

One more minor thing, otherwise LGTM

if len(servers) == 1:
return servers[0]
server1, server2 = random.sample(servers, 2)
filtered_servers = _filter_servers(servers, deprioritized_servers)
Copy link
Member

@ShaneHarvey ShaneHarvey Nov 13, 2023

Choose a reason for hiding this comment

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

Can we rename filtered_servers->servers so the rest of this code doesn't have to change?

Copy link
Member

@blink1073 blink1073 left a comment

Choose a reason for hiding this comment

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

LGTM!

@NoahStapp NoahStapp merged commit 5dc6034 into mongodb:master Nov 14, 2023
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