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

test(datastore): Update BeginLater test and resolve data race #10489

Merged
merged 4 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions datastore/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -825,9 +825,10 @@ func TestIntegration_BeginLaterPerf(t *testing.T) {
avgRunTimes[i] = sumRunTime / float64(numRepetitions)
}
improvement := ((avgRunTimes[1] - avgRunTimes[0]) / avgRunTimes[1]) * 100
t.Logf("Run times:: with BeginLater: %.3fs, without BeginLater: %.3fs. improvement: %.2f%%", avgRunTimes[0], avgRunTimes[1], improvement)
if improvement < 0 {
t.Logf("Run times:: with BeginLater: %.3fs, without BeginLater: %.3fs. improvement: %.2f%%", avgRunTimes[0], avgRunTimes[1], improvement)
t.Fatal("No perf improvement because of new transaction consistency type.")
// Using BeginLater option involves a lot of mutex lock / unlock. So, it may / may not lead to performance improvements
t.Logf("No perf improvement because of new transaction consistency type.")
}
}

Expand Down
16 changes: 7 additions & 9 deletions datastore/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,10 @@ var (
}

// Do not include codes.Unavailable here since client already retries for Unavailable error
beginTxnRetryer = gax.OnCodes([]codes.Code{codes.DeadlineExceeded,
codes.Internal}, txnBackoff)
rollbackRetryer = gax.OnCodes([]codes.Code{codes.DeadlineExceeded,
codes.Internal}, txnBackoff)
txnRetryer = gax.OnCodes([]codes.Code{codes.Aborted, codes.Canceled, codes.Unknown, codes.DeadlineExceeded,
codes.Internal, codes.Unauthenticated}, txnBackoff)
beginTxnRetryCodes = []codes.Code{codes.DeadlineExceeded, codes.Internal}
rollbackRetryCodes = []codes.Code{codes.DeadlineExceeded, codes.Internal}
txnRetryCodes = []codes.Code{codes.Aborted, codes.Canceled, codes.Unknown, codes.DeadlineExceeded,
codes.Internal, codes.Unauthenticated}

gaxSleep = gax.Sleep
)
Expand Down Expand Up @@ -307,7 +305,7 @@ func (c *Client) newTransactionWithRetry(ctx context.Context, s *transactionSett
return t, newTxnErr
}
// Check if BeginTransaction should be retried
if backoffErr := backoffBeforeRetry(ctx, beginTxnRetryer, newTxnErr); backoffErr != nil {
if backoffErr := backoffBeforeRetry(ctx, gax.OnCodes(beginTxnRetryCodes, txnBackoff), newTxnErr); backoffErr != nil {
return nil, backoffErr
}
}
Expand Down Expand Up @@ -414,7 +412,7 @@ func (c *Client) RunInTransaction(ctx context.Context, f func(tx *Transaction) e
}
} else {
// Check whether error other than ResourceExhausted should be retried
backoffErr := backoffBeforeRetry(ctx, txnRetryer, retryErr)
backoffErr := backoffBeforeRetry(ctx, gax.OnCodes(txnRetryCodes, txnBackoff), retryErr)
if backoffErr != nil {
return nil, err
}
Expand Down Expand Up @@ -496,7 +494,7 @@ func (t *Transaction) rollbackWithRetry() error {
}

// Check if Rollback should be retried
if backoffErr := backoffBeforeRetry(t.ctx, rollbackRetryer, rollbackErr); backoffErr != nil {
if backoffErr := backoffBeforeRetry(t.ctx, gax.OnCodes(rollbackRetryCodes, txnBackoff), rollbackErr); backoffErr != nil {
return backoffErr
}
}
Expand Down
Loading