@@ -54,8 +54,6 @@ type contextTransaction interface {
5454 AbortBatch () (driver.Result , error )
5555
5656 BufferWrite (ms []* spanner.Mutation ) error
57-
58- setRetryAbortsInternally (retry bool ) (driver.Result , error )
5957}
6058
6159type rowIterator interface {
@@ -205,11 +203,6 @@ func (tx *readOnlyTransaction) BufferWrite([]*spanner.Mutation) error {
205203 return spanner .ToSpannerError (status .Errorf (codes .FailedPrecondition , "read-only transactions cannot write" ))
206204}
207205
208- func (tx * readOnlyTransaction ) setRetryAbortsInternally (_ bool ) (driver.Result , error ) {
209- // no-op, ignore
210- return driver .ResultNoRows , nil
211- }
212-
213206// ErrAbortedDueToConcurrentModification is returned by a read/write transaction
214207// that was aborted by Cloud Spanner, and where the internal retry attempt
215208// failed because it detected that the results during the retry were different
@@ -244,7 +237,7 @@ type readWriteTransaction struct {
244237 close func (result txResult , commitResponse * spanner.CommitResponse , commitErr error )
245238 // retryAborts indicates whether this transaction will automatically retry
246239 // the transaction if it is aborted by Spanner. The default is true.
247- retryAborts bool
240+ retryAborts func () bool
248241
249242 // statements contains the list of statements that has been executed on this
250243 // transaction so far. These statements will be replayed on a new read write
@@ -415,7 +408,7 @@ func (tx *readWriteTransaction) Commit() (err error) {
415408 }
416409 var commitResponse spanner.CommitResponse
417410 if tx .rwTx != nil {
418- if ! tx .retryAborts {
411+ if ! tx .retryAborts () {
419412 ts , err := tx .rwTx .CommitWithReturnResp (tx .ctx )
420413 tx .close (txResultCommit , & ts , err )
421414 return err
@@ -471,7 +464,7 @@ func (tx *readWriteTransaction) Query(ctx context.Context, stmt spanner.Statemen
471464 }
472465 // If internal retries have been disabled, we don't need to keep track of a
473466 // running checksum for all results that we have seen.
474- if ! tx .retryAborts {
467+ if ! tx .retryAborts () {
475468 return & readOnlyRowIterator {tx .rwTx .QueryWithOptions (ctx , stmt , execOptions .QueryOptions )}, nil
476469 }
477470
@@ -509,7 +502,7 @@ func (tx *readWriteTransaction) ExecContext(ctx context.Context, stmt spanner.St
509502 return & result {rowsAffected : updateCount }, nil
510503 }
511504
512- if ! tx .retryAborts {
505+ if ! tx .retryAborts () {
513506 return execTransactionalDML (ctx , tx .rwTx , stmt , statementInfo , options )
514507 }
515508
@@ -608,7 +601,7 @@ func (tx *readWriteTransaction) runDmlBatch(ctx context.Context) (*result, error
608601 options := tx .batch .options
609602 tx .batch = nil
610603
611- if ! tx .retryAborts {
604+ if ! tx .retryAborts () {
612605 affected , err := tx .rwTx .BatchUpdateWithOptions (ctx , statements , options .QueryOptions )
613606 return & result {rowsAffected : sum (affected )}, err
614607 }
@@ -650,11 +643,3 @@ func errorsEqualForRetry(err1, err2 error) bool {
650643 }
651644 return false
652645}
653-
654- func (tx * readWriteTransaction ) setRetryAbortsInternally (retry bool ) (driver.Result , error ) {
655- if tx .active {
656- return nil , spanner .ToSpannerError (status .Error (codes .FailedPrecondition , "cannot change retry mode while a transaction is active" ))
657- }
658- tx .retryAborts = retry
659- return driver .ResultNoRows , nil
660- }
0 commit comments