Skip to content

Commit 727b6c8

Browse files
authored
test(datastore): Update BeginLater test and resolve data race (#10489)
* test(datastore): Update BeginLater test * test(datastore): Resolve data race
1 parent 142b153 commit 727b6c8

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

datastore/integration_test.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -825,9 +825,10 @@ func TestIntegration_BeginLaterPerf(t *testing.T) {
825825
avgRunTimes[i] = sumRunTime / float64(numRepetitions)
826826
}
827827
improvement := ((avgRunTimes[1] - avgRunTimes[0]) / avgRunTimes[1]) * 100
828+
t.Logf("Run times:: with BeginLater: %.3fs, without BeginLater: %.3fs. improvement: %.2f%%", avgRunTimes[0], avgRunTimes[1], improvement)
828829
if improvement < 0 {
829-
t.Logf("Run times:: with BeginLater: %.3fs, without BeginLater: %.3fs. improvement: %.2f%%", avgRunTimes[0], avgRunTimes[1], improvement)
830-
t.Fatal("No perf improvement because of new transaction consistency type.")
830+
// Using BeginLater option involves a lot of mutex lock / unlock. So, it may / may not lead to performance improvements
831+
t.Logf("No perf improvement because of new transaction consistency type.")
831832
}
832833
}
833834

datastore/transaction.go

+7-9
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,10 @@ var (
4545
}
4646

4747
// Do not include codes.Unavailable here since client already retries for Unavailable error
48-
beginTxnRetryer = gax.OnCodes([]codes.Code{codes.DeadlineExceeded,
49-
codes.Internal}, txnBackoff)
50-
rollbackRetryer = gax.OnCodes([]codes.Code{codes.DeadlineExceeded,
51-
codes.Internal}, txnBackoff)
52-
txnRetryer = gax.OnCodes([]codes.Code{codes.Aborted, codes.Canceled, codes.Unknown, codes.DeadlineExceeded,
53-
codes.Internal, codes.Unauthenticated}, txnBackoff)
48+
beginTxnRetryCodes = []codes.Code{codes.DeadlineExceeded, codes.Internal}
49+
rollbackRetryCodes = []codes.Code{codes.DeadlineExceeded, codes.Internal}
50+
txnRetryCodes = []codes.Code{codes.Aborted, codes.Canceled, codes.Unknown, codes.DeadlineExceeded,
51+
codes.Internal, codes.Unauthenticated}
5452

5553
gaxSleep = gax.Sleep
5654
)
@@ -307,7 +305,7 @@ func (c *Client) newTransactionWithRetry(ctx context.Context, s *transactionSett
307305
return t, newTxnErr
308306
}
309307
// Check if BeginTransaction should be retried
310-
if backoffErr := backoffBeforeRetry(ctx, beginTxnRetryer, newTxnErr); backoffErr != nil {
308+
if backoffErr := backoffBeforeRetry(ctx, gax.OnCodes(beginTxnRetryCodes, txnBackoff), newTxnErr); backoffErr != nil {
311309
return nil, backoffErr
312310
}
313311
}
@@ -414,7 +412,7 @@ func (c *Client) RunInTransaction(ctx context.Context, f func(tx *Transaction) e
414412
}
415413
} else {
416414
// Check whether error other than ResourceExhausted should be retried
417-
backoffErr := backoffBeforeRetry(ctx, txnRetryer, retryErr)
415+
backoffErr := backoffBeforeRetry(ctx, gax.OnCodes(txnRetryCodes, txnBackoff), retryErr)
418416
if backoffErr != nil {
419417
return nil, err
420418
}
@@ -496,7 +494,7 @@ func (t *Transaction) rollbackWithRetry() error {
496494
}
497495

498496
// Check if Rollback should be retried
499-
if backoffErr := backoffBeforeRetry(t.ctx, rollbackRetryer, rollbackErr); backoffErr != nil {
497+
if backoffErr := backoffBeforeRetry(t.ctx, gax.OnCodes(rollbackRetryCodes, txnBackoff), rollbackErr); backoffErr != nil {
500498
return backoffErr
501499
}
502500
}

0 commit comments

Comments
 (0)