Skip to content
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

Merged
merged 6 commits into from
Nov 12, 2024

Conversation

olavloite
Copy link
Contributor

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

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
// 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 {
Copy link
Contributor

@harshachinta harshachinta Oct 9, 2024

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

  1. for all the other errors (ex: session not found error) using the same session does not help during retry.
  2. This will prevent customers to use this only in case of ABORTED and not use it as retry mechanism for other errors.

Copy link
Contributor Author

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.

@olavloite olavloite merged commit 02c191c into main Nov 12, 2024
9 checks passed
@olavloite olavloite deleted the spanner-add-reset-for-retry branch November 12, 2024 15:33
gcf-merge-on-green bot pushed a commit that referenced this pull request Nov 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: spanner Issues related to the Spanner API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants