-
Notifications
You must be signed in to change notification settings - Fork 1.1k
PYTHON-5528 & PYTHON-5651 Add exponential backoff to operation retry loop for server overloaded errors #2635
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: backpressure
Are you sure you want to change the base?
PYTHON-5528 & PYTHON-5651 Add exponential backoff to operation retry loop for server overloaded errors #2635
Conversation
…r overloaded errors (cherry picked from commit 95948d3def875f1efb4d912ab8f507f518604ef5)
(cherry picked from commit ebf65519f12d160da6d2088c22f6c69fad5a37d0)
(cherry picked from commit 3093a7c)
| await change_stream._initialize_cursor() | ||
| return change_stream | ||
|
|
||
| async def _conn_for_writes( |
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.
What's the motivation behind the change from this centralized method to a bunch of def inner closures?
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.
Because we needed to pass a function to the retry helper class, and the logic for backpressure is centralized there
| # If we need to apply backpressure to the first command, | ||
| # we will need to revert back to starting state. | ||
| if self._session is not None and self._session.in_transaction: | ||
| self._session._transaction.has_completed_command = True |
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.
How does being in a transaction here imply that the transaction has completed a command?
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.
Because we've just recorded a successful read
pymongo/asynchronous/mongo_client.py
Outdated
| always_retryable = exc.has_error_label( | ||
| "RetryableError" | ||
| ) and exc.has_error_label("SystemOverloadedError") | ||
| overloaded = exc.has_error_label("SystemOverloadedError") |
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.
minor thought but it might be a smidge easier to read if it was like:
overloaded = exc.has_error_label("SystemOverloadedError")
always_retryable = exc.has_error_label("RetryableError") and overloaded
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.
Good call, done!
…-python-driver into PYTHON-5528-backpressure
PYTHON-5528
PYTHON-5651
Summary
Adds unified and prose tests from mongodb/specifications#1862 and replaces the use of the
_retry_overloadwith the retry helper method calls to ensure that servers are properly deprioritized. They needed to be done together to verify that the unified tests still work.Changes in this PR
_retry_overloadwith the retry helper method calls to ensure that servers are properly deprioritizedTesting Plan
Added unified and prose tests, testing as part of PR.
Screenshots (optional)
N/A
Checklist
Checklist for Author
Checklist for Reviewer {@primary_reviewer}
Focus Areas for Reviewer (optional)