-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
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
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 { |
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.
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.
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.
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.
🤖 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).
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