feat(spanner): add ResetForRetry method for stmt-based transactions#10956
Merged
feat(spanner): add ResetForRetry method for stmt-based transactions#10956
Conversation
Read/write transactions that are aborted should preferably be retried using the same session as the original attempt. For this, statement-based transactions should have a ResetForRetry function. This was missing in the Go client library. This change adds this method, and re-uses the session when possible. If the aborted error happens during the Commit RPC, the session handle was already cleaned up by the original implementation. We will not change that now, as that could lead to breakage in existing code that depends on this. When the Go client is switched to multiplexed sessions for read/write transactions, then this implementation should be re-visited, and it should be made sure that ResetForRetry optimizes the retry attempt for an actual retry. Updates googleapis/go-sql-spanner#300
harshachinta
reviewed
Oct 9, 2024
spanner/transaction.go
Outdated
| // as this method will give the transaction a higher priority and thus a | ||
| // smaller probability of being aborted again by Spanner. | ||
| func (t *ReadWriteStmtBasedTransaction) ResetForRetry(ctx context.Context) (*ReadWriteStmtBasedTransaction, error) { | ||
| if t.state == txNew || t.state == txInit { |
Contributor
There was a problem hiding this comment.
Should we add a check whether the previous attempt failed with ABORTED, since
- for all the other errors (ex: session not found error) using the same session does not help during retry.
- This will prevent customers to use this only in case of ABORTED and not use it as retry mechanism for other errors.
Contributor
Author
There was a problem hiding this comment.
I've updated the PR to incorporate this. This makes the change slightly bigger, as we were not tracking Aborted as an actual transaction state, so this PR now also adds that.
harshachinta
approved these changes
Oct 9, 2024
harshachinta
approved these changes
Oct 22, 2024
gcf-merge-on-green bot
pushed a commit
that referenced
this pull request
Nov 14, 2024
🤖 I have created a release *beep* *boop* --- ## [1.73.0](https://togithub.com/googleapis/google-cloud-go/compare/spanner/v1.72.0...spanner/v1.73.0) (2024-11-14) ### Features * **spanner:** Add ResetForRetry method for stmt-based transactions ([#10956](https://togithub.com/googleapis/google-cloud-go/issues/10956)) ([02c191c](https://togithub.com/googleapis/google-cloud-go/commit/02c191c5dc13023857812217f63be2395bfcb382)) ### Bug Fixes * **spanner:** Add safecheck to avoid deadlock when creating multiplex session ([#11131](https://togithub.com/googleapis/google-cloud-go/issues/11131)) ([8ee5d05](https://togithub.com/googleapis/google-cloud-go/commit/8ee5d05e288c7105ddb1722071d6719933effea4)) * **spanner:** Allow non default service account only when direct path is enabled ([#11046](https://togithub.com/googleapis/google-cloud-go/issues/11046)) ([4250788](https://togithub.com/googleapis/google-cloud-go/commit/42507887523f41d0507ca8b1772235846947c3e0)) * **spanner:** Use spanner options when initializing monitoring exporter ([#11109](https://togithub.com/googleapis/google-cloud-go/issues/11109)) ([81413f3](https://togithub.com/googleapis/google-cloud-go/commit/81413f3647a0ea406f25d4159db19b7ad9f0682b)) --- This PR was generated with [Release Please](https://togithub.com/googleapis/release-please). See [documentation](https://togithub.com/googleapis/release-please#release-please).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Read/write transactions that are aborted should preferably be retried using the same session as the original attempt. For this, statement-based transactions should have a ResetForRetry function. This was missing in the Go client library.
This change adds this method, and re-uses the session when possible. If the aborted error happens during the Commit RPC, the session handle was already cleaned up by the original implementation. We will not change that now, as that could lead to breakage in existing code that depends on this. When the Go client is switched to multiplexed sessions for read/write transactions, then this implementation should be re-visited, and it should be made sure that ResetForRetry optimizes the retry attempt for an actual retry.
Updates googleapis/go-sql-spanner#300