Conversation

olavloite

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
@olavloiteolavloite requested a review from a team as a code owner November 11, 2020 13:15
@google-clagoogle-cla bot added the cla: yesThis human has signed the Contributor License Agreement.label Nov 11, 2020
@product-auto-labelproduct-auto-label bot added the api: spannerIssues related to the googleapis/java-spanner API.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
Collaborator Author

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
Collaborator Author

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
Collaborator Author

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

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 FilesCoverage ΔComplexity Δ
...gle/cloud/spanner/AsyncTransactionManagerImpl.java71.42% <0.00%> (+1.00%)12.00 <0.00> (ø)
...ud/spanner/SessionPoolAsyncTransactionManager.java85.36% <50.00%> (-1.19%)11.00 <0.00> (ø)
...le/cloud/spanner/TransactionContextFutureImpl.java91.57% <100.00%> (+0.08%)4.00 <0.00> (ø)
.../google/cloud/spanner/AbstractLazyInitializer.java92.85% <0.00%> (-7.15%)4.00% <0.00%> (-1.00%)
...ain/java/com/google/cloud/spanner/SessionImpl.java84.02% <0.00%> (-0.41%)29.00% <0.00%> (ø%)
...va/com/google/cloud/spanner/AbstractResultSet.java83.39% <0.00%> (-0.01%)28.00% <0.00%> (ø%)
...er/connection/ConnectionStatementExecutorImpl.java100.00% <0.00%> (ø)29.00% <0.00%> (ø%)
...om/google/cloud/spanner/TransactionRunnerImpl.java84.27% <0.00%> (+0.03%)9.00% <0.00%> (ø%)
...main/java/com/google/cloud/spanner/ResultSets.java97.02% <0.00%> (+0.06%)5.00% <0.00%> (ø%)
...oogle/cloud/spanner/connection/ConnectionImpl.java84.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.

@olavloiteolavloite merged commit 8a66d84 into master Nov 13, 2020
@olavloiteolavloite deleted the issue-605 branch November 13, 2020 07:08
rajatbhatta pushed a commit to rajatbhatta/java-spanner that referenced this pull request Nov 17, 2022
…ts (googleapis#616)

Removes the category from the base class for all integration tests so they are not excluded
from multiple builds, as the result is that both the category of the base class as well as
the concrete class are applied.
Sign up for free to join this conversation on . Already have an account? Sign in to comment
api: spannerIssues related to the googleapis/java-spanner API.cla: yesThis human has signed the Contributor License Agreement.
None yet

Successfully merging this pull request may close these issues.

RetryOnInvalidatedSessionTest seems to get stuck sometimes