-
Notifications
You must be signed in to change notification settings - Fork 92
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
fix: update retry strategy for mutation calls to handle aborted transactions #1270
Conversation
google/cloud/spanner_v1/batch.py
Outdated
method, | ||
allowed_exceptions={InternalServerError: _check_rst_stream_error}, | ||
) | ||
response = self._session.run_in_transaction(method) |
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.
Hmmm.... Now that I see this, I realize that this cannot use run_in_transaction
directly. The reason is that:
- This method
batch.commit()
in its original form (so without the changes in this pull request) creates and commits a single-use read/write transaction. run_in_transaction
however creates a new read/write transaction and then executes the given method in the scope of that transaction.
So what happens now is that you create two transactions:
run_in_transaction
creates a transaction that is not being used.method
that is passed in torun_in_transaction
executes aCommit
in a single-use read/write transaction.
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.
Thank you for pointing that out. I've updated the PR with a new retry strategy, replicating the same retry behavior as in the run_in_transaction method.
tests/unit/test_batch.py
Outdated
except Aborted: | ||
pass | ||
|
||
# Verify that commit was called more than once (due to retry) |
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.
You should verify the exact number. Based on my comment above, my guess is that you are getting 1 more commit than you would expect, as run_in_transaction
also creates a read/write transaction.
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.
Thank you for the clarification. I’ve added updated assertions to track the number of times api.commit
is called with the next revision
b4effdc
to
c4362d0
Compare
A new PR has been created to fix the commit history. Please refer to the new PR for the updated changes. This PR will be closed to keep the commit history clean and in line with the intended changes. |
Updating retry strategy for mutation calls to handle aborted transactions
Test Results:
Fixes #<1133> 🦕