Skip to content

Commit

Permalink
fix(spanner): ReadWriteStmtBasedTransaction would not remember option…
Browse files Browse the repository at this point in the history
…s for retries

Any TransactionOptions that had been set for a ReadWriteStmtBasedTransaction
would not be remember and carried over if the transaction was retried. This
would cause the retry to for example miss the transaction tag.
  • Loading branch information
olavloite committed Jan 13, 2025
1 parent c9113dd commit d892073
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
1 change: 1 addition & 0 deletions spanner/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -1886,6 +1886,7 @@ func newReadWriteStmtBasedTransactionWithSessionHandle(ctx context.Context, c *C
return err
}

t.options = options
t.txOpts = c.txo.merge(options)
t.ct = c.ct
t.otConfig = c.otConfig
Expand Down
5 changes: 4 additions & 1 deletion spanner/transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -888,11 +888,14 @@ func testReadWriteStmtBasedTransaction(t *testing.T, executionTimes map[string]S
if attempts > 1 {
tx, err = tx.ResetForRetry(ctx)
} else {
tx, err = NewReadWriteStmtBasedTransaction(ctx, client)
tx, err = NewReadWriteStmtBasedTransactionWithOptions(ctx, client, TransactionOptions{TransactionTag: "test"})
}
if err != nil {
return 0, attempts, fmt.Errorf("failed to begin a transaction: %v", err)
}
if g, w := tx.options.TransactionTag, "test"; g != w {
t.Errorf("transaction tag mismatch\n Got: %v\nWant: %v", g, w)
}
rowCount, err = f(tx)
if err != nil && status.Code(err) != codes.Aborted {
tx.Rollback(ctx)
Expand Down

0 comments on commit d892073

Please sign in to comment.