GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Spanner: Use generic retry helper for transaction retries by olavloite · Pull Request #5433 · googleapis/google-cloud-java

Conversation

@olavloite

@olavloite olavloite commented Jun 6, 2019

Copy link
Copy Markdown
Contributor

As discussed in PR #5412 we should move away from custom retry loops and use a generic retry helper. This PR changes the retry loop of read/write transactions from a custom loop to using the Gax RetryHelper.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@olavloite
use generic retry helper for transaction retries
63f51f2
@olavloite
olavloite requested a review from a team June 6, 2019 12:03
@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Jun 6, 2019
@olavloite olavloite added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Jun 6, 2019
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Jun 6, 2019
kolea2
kolea2 reviewed Jun 6, 2019
View reviewed changes
Comment thread ...ients/google-cloud-spanner/src/main/java/com/google/cloud/spanner/TransactionRunnerImpl.java
throw e;
}
}
private <T> T runInternal(final TransactionCallable<T> txCallable) {

@kolea2 kolea2 Jun 6, 2019

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind just briefly explaining what this change is? Hard to see from the diff. Is it mainly the return statement at the bottom?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@olavloite olavloite Jun 6, 2019

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The web diff view is indeed not very helpful in this case...

In general: Instead of using a while(true) {...} loop for retrying the transaction, the transaction is placed in a Callable that can be passed to the generic retry helper. The retry helper will handle the retries if the transaction aborts.

More specifically, the change is as follows:

  1. Everything inside the while(true) loop is moved into the call() method of the Callable retryCallable.
  2. The session.newTransaction() call is moved from the constructor and the backoff(...) method to inside the call() method to give each attempt a fresh transaction.
  3. The continue statement on line 354 is replaced with a throw statement in order to leave the method exceptionally.
  4. The Callable is passed in to the new method SpannerRetryHelper.runTxWithRetriesOnAborted(Callable) that handles the retries if the transaction is aborted.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

kolea2 reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
kolea2
kolea2 reviewed Jun 7, 2019
View reviewed changes
Comment thread ...ients/google-cloud-spanner/src/main/java/com/google/cloud/spanner/TransactionRunnerImpl.java
while (true) {
checkState(
isValid, "TransactionRunner has been invalidated by a new operation on the session");
SpannerImpl.checkContext(context);

@kolea2 kolea2 Jun 7, 2019

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if the context is cancelled now? Are the same error messages thrown for deadline exceeded and cancelled?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@olavloite olavloite Jun 19, 2019

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the initial version of this PR, the context was ignored. I've added a check for context cancellation to the generic retry helper, and it will now throw the same exceptions as previous retry loops.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@yoshi-automation yoshi-automation added the 🚨 critical P0 critical issue. Requires immediate fix label Jun 13, 2019
@olavloite
check context on retries
8205668
@codecov

codecov Bot commented Jun 17, 2019 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Codecov Report

Merging #5433 into master will increase coverage by 0.58%.
The diff coverage is n/a.

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #5433      +/-   ##
============================================
+ Coverage      50.5%   51.09%   +0.58%     
- Complexity    23903    24475     +572     
============================================
  Files          2259     2271      +12     
  Lines        227870   232042    +4172     
  Branches      24994    25064      +70     
============================================
+ Hits         115088   118552    +3464     
- Misses       104163   104838     +675     
- Partials       8619     8652      +33
Impacted Files Coverage Δ Complexity Δ
...atransfer/v1/stub/GrpcDataTransferServiceStub.java 94.17% <0%> (-1.71%) 28% <0%> (+8%)
.../com/google/cloud/pubsub/v1/MessageDispatcher.java 85.86% <0%> (-0.63%) 23% <0%> (+1%)
...ogle/cloud/dialogflow/v2beta1/stub/AgentsStub.java 7.14% <0%> (-0.55%) 2% <0%> (+1%)
...om/google/cloud/dialogflow/v2/stub/AgentsStub.java 7.14% <0%> (-0.55%) 2% <0%> (+1%)
...loud/kms/v1/stub/GrpcKeyManagementServiceStub.java 97.1% <0%> (-0.47%) 60% <0%> (+31%)
.../datatransfer/v1/stub/DataTransferServiceStub.java 5.12% <0%> (-0.43%) 2% <0%> (+1%)
...om/google/cloud/logging/spi/v2/GrpcLoggingRpc.java 42.72% <0%> (-0.4%) 1% <0%> (ø)
...gle/cloud/kms/v1/KeyManagementServiceSettings.java 9.48% <0%> (-0.24%) 3% <0%> (+1%)
...in/java/com/google/cloud/datastore/BaseEntity.java 91.51% <0%> (ø) 28% <0%> (ø) ⬇️
.../cloud/automl/v1beta1/PredictionServiceClient.java 44.64% <0%> (ø) 11% <0%> (ø) ⬇️
... and 44 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update bf84f6f...79803d8. Read the comment docs.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@kolea2 kolea2 added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Jun 18, 2019
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Jun 18, 2019
@olavloite
fixed reference to expected exception
79803d8
kolea2
kolea2 reviewed Jun 19, 2019
View reviewed changes
Comment thread ...-clients/google-cloud-spanner/src/main/java/com/google/cloud/spanner/SpannerRetryHelper.java
class SpannerRetryHelper {
private static final RetrySettings txRetrySettings =
RetrySettings.newBuilder()
.setInitialRetryDelay(Duration.ofMillis(1000L))

@kolea2 kolea2 Jun 19, 2019

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor - I would take these numbers and make them constants.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
kolea2
kolea2 approved these changes Jun 19, 2019
View reviewed changes
@kolea2
kolea2 merged commit d305770 into googleapis:master Jun 20, 2019
@kolea2 kolea2 mentioned this pull request Jun 20, 2019
Release google-cloud-java v0.97.0 #5528
Merged
olavloite added a commit to olavloite/google-cloud-java that referenced this pull request Sep 15, 2019
@olavloite
TransactionRunner did not use prepared transaction
2e245a9
A Spanner transaction runner that was given a session with a prepared
read/write transaction would not use that transaction, but instead
always start a new one, causing an extra unnecessary round-trip to the
server. This regression was introduced by commit
d305770 (PR googleapis#5433).
@olavloite olavloite mentioned this pull request Sep 15, 2019
Spanner: TransactionRunner should use prepared transaction #6275
Merged
skuruppu pushed a commit that referenced this pull request Sep 17, 2019
@olavloite @skuruppu
TransactionRunner did not use prepared transaction (#6275)
12e31c3
A Spanner transaction runner that was given a session with a prepared
read/write transaction would not use that transaction, but instead
always start a new one, causing an extra unnecessary round-trip to the
server. This regression was introduced by commit
d305770 (PR #5433).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

1 more reviewer
@kolea2 kolea2 kolea2 approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

cla: yes This human has signed the Contributor License Agreement. 🚨 critical P0 critical issue. Requires immediate fix

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

5 participants

@olavloite @kolea2 @googlebot @yoshi-automation @yoshi-kokoro
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.