Skip to content

Commit 7d8f0c5

Browse files
authored
fix(spanner): ReadWriteStmtBasedTransaction would not remember options for retries (#11443)
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.
1 parent c9113dd commit 7d8f0c5

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

spanner/transaction.go

+1
Original file line numberDiff line numberDiff line change
@@ -1886,6 +1886,7 @@ func newReadWriteStmtBasedTransactionWithSessionHandle(ctx context.Context, c *C
18861886
return err
18871887
}
18881888

1889+
t.options = options
18891890
t.txOpts = c.txo.merge(options)
18901891
t.ct = c.ct
18911892
t.otConfig = c.otConfig

spanner/transaction_test.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -888,11 +888,14 @@ func testReadWriteStmtBasedTransaction(t *testing.T, executionTimes map[string]S
888888
if attempts > 1 {
889889
tx, err = tx.ResetForRetry(ctx)
890890
} else {
891-
tx, err = NewReadWriteStmtBasedTransaction(ctx, client)
891+
tx, err = NewReadWriteStmtBasedTransactionWithOptions(ctx, client, TransactionOptions{TransactionTag: "test"})
892892
}
893893
if err != nil {
894894
return 0, attempts, fmt.Errorf("failed to begin a transaction: %v", err)
895895
}
896+
if g, w := tx.options.TransactionTag, "test"; g != w {
897+
t.Errorf("transaction tag mismatch\n Got: %v\nWant: %v", g, w)
898+
}
896899
rowCount, err = f(tx)
897900
if err != nil && status.Code(err) != codes.Aborted {
898901
tx.Rollback(ctx)

0 commit comments

Comments
 (0)