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

fix: session retry could cause infinite wait #616

Merged
merged 1 commit into from Nov 13, 2020
Merged

fix: session retry could cause infinite wait #616

merged 1 commit into from Nov 13, 2020

Conversation

olavloite
Copy link
Contributor

@olavloite olavloite commented Nov 11, 2020

A "Session not found" when using an AsyncTransactionManager could cause an infinite wait for an ApiFuture that would never be done.

Fixes #605

A "Session not found" when using an AsyncTransactionManager could cause an
infinite wait for an ApiFuture that would never be done.

Fixes #605
@olavloite olavloite requested a review from thiagotnunes Nov 11, 2020
@olavloite olavloite requested a review from as a code owner Nov 11, 2020
@google-cla google-cla bot added the cla: yes label Nov 11, 2020
@product-auto-label product-auto-label bot added the api: spanner label Nov 11, 2020
@@ -109,6 +109,7 @@ public Timestamp get(long timeout, TimeUnit unit)
@Override
public void onFailure(Throwable t) {
mgr.onError(t);
statementResult.setException(t);
Copy link
Contributor Author

@olavloite olavloite Nov 11, 2020

Choose a reason for hiding this comment

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

This missing statement was what could cause the infinite wait. The result of this specific statement would never be done if the previous statement (input) would fail.

@@ -174,10 +176,6 @@ public void onSuccess(Timestamp result) {

@Override
public TransactionContextFuture resetForRetryAsync() {
if (txn == null || (!txn.isAborted() && txnState != TransactionState.ABORTED)) {
Copy link
Contributor Author

@olavloite olavloite Nov 11, 2020

Choose a reason for hiding this comment

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

This check is no longer needed here as it is checked in the SessionPoolAsyncTransactionManager.

"commit can only be invoked if the transaction is in progress. Current state: "
+ txnState);
if (txnState == TransactionState.ABORTED) {
Copy link
Contributor Author

@olavloite olavloite Nov 11, 2020

Choose a reason for hiding this comment

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

This makes sure that the AsyncTransactionManager will return an ApiFuture with exception Aborted if the transaction has already been aborted by an asynchronous statement that has not yet been checked by the application, e.g. (simplified):

txn.updateAsync(...); // This aborts the transaction, but the status of the returned ApiFuture is not checked by the application.
...
txn.commitAsync();

@codecov
Copy link

@codecov codecov bot commented Nov 11, 2020

Codecov Report

Merging #616 (730d678) into master (35cc56c) will increase coverage by 0.24%.
The diff coverage is 50.00%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #616      +/-   ##
============================================
+ Coverage     83.79%   84.04%   +0.24%     
- Complexity     2500     2502       +2     
============================================
  Files           141      141              
  Lines         13770    13810      +40     
  Branches       1278     1318      +40     
============================================
+ Hits          11538    11606      +68     
- Misses         1655     1657       +2     
+ Partials        577      547      -30     
Impacted Files Coverage Δ Complexity Δ
...gle/cloud/spanner/AsyncTransactionManagerImpl.java 71.42% <0.00%> (+1.00%) 12.00 <0.00> (ø)
...ud/spanner/SessionPoolAsyncTransactionManager.java 85.36% <50.00%> (-1.19%) 11.00 <0.00> (ø)
...le/cloud/spanner/TransactionContextFutureImpl.java 91.57% <100.00%> (+0.08%) 4.00 <0.00> (ø)
.../google/cloud/spanner/AbstractLazyInitializer.java 92.85% <0.00%> (-7.15%) 4.00% <0.00%> (-1.00%)
...ain/java/com/google/cloud/spanner/SessionImpl.java 84.02% <0.00%> (-0.41%) 29.00% <0.00%> (ø%)
...va/com/google/cloud/spanner/AbstractResultSet.java 83.39% <0.00%> (-0.01%) 28.00% <0.00%> (ø%)
...er/connection/ConnectionStatementExecutorImpl.java 100.00% <0.00%> (ø) 29.00% <0.00%> (ø%)
...om/google/cloud/spanner/TransactionRunnerImpl.java 84.27% <0.00%> (+0.03%) 9.00% <0.00%> (ø%)
...main/java/com/google/cloud/spanner/ResultSets.java 97.02% <0.00%> (+0.06%) 5.00% <0.00%> (ø%)
...oogle/cloud/spanner/connection/ConnectionImpl.java 84.84% <0.00%> (+0.09%) 175.00% <0.00%> (ø%)
... and 13 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 35cc56c...730d678. Read the comment docs.

@olavloite olavloite merged commit 8a66d84 into master Nov 13, 2020
20 of 21 checks passed
@olavloite olavloite deleted the issue-605 branch Nov 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: spanner cla: yes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants