@@ -201,6 +201,10 @@ private void checkValidState() {
201201 + "or "
202202 + UnitOfWorkState .ABORTED
203203 + " is allowed." );
204+ checkTimedOut ();
205+ }
206+
207+ private void checkTimedOut () {
204208 ConnectionPreconditions .checkState (
205209 !timedOutOrCancelled ,
206210 "The last statement of this transaction timed out or was cancelled. "
@@ -313,34 +317,35 @@ public ApiFuture<ResultSet> executeQueryAsync(
313317 res =
314318 executeStatementAsync (
315319 statement ,
316- () ->
317- runWithRetry (
318- () -> {
319- try {
320- getStatementExecutor ()
321- .invokeInterceptors (
322- statement ,
323- StatementExecutionStep .EXECUTE_STATEMENT ,
324- ReadWriteTransaction .this );
325- ResultSet delegate =
326- DirectExecuteResultSet .ofResultSet (
327- internalExecuteQuery (statement , analyzeMode , options ));
328- return createAndAddRetryResultSet (
329- delegate , statement , analyzeMode , options );
330- } catch (AbortedException e ) {
331- throw e ;
332- } catch (SpannerException e ) {
333- createAndAddFailedQuery (e , statement , analyzeMode , options );
334- throw e ;
335- }
336- }),
320+ () -> {
321+ checkTimedOut ();
322+ return runWithRetry (
323+ () -> {
324+ try {
325+ getStatementExecutor ()
326+ .invokeInterceptors (
327+ statement ,
328+ StatementExecutionStep .EXECUTE_STATEMENT ,
329+ ReadWriteTransaction .this );
330+ ResultSet delegate =
331+ DirectExecuteResultSet .ofResultSet (
332+ internalExecuteQuery (statement , analyzeMode , options ));
333+ return createAndAddRetryResultSet (
334+ delegate , statement , analyzeMode , options );
335+ } catch (AbortedException e ) {
336+ throw e ;
337+ } catch (SpannerException e ) {
338+ createAndAddFailedQuery (e , statement , analyzeMode , options );
339+ throw e ;
340+ }
341+ });
342+ },
337343 // ignore interceptors here as they are invoked in the Callable.
338344 InterceptorsUsage .IGNORE_INTERCEPTORS ,
339345 ImmutableList .<MethodDescriptor <?, ?>>of (SpannerGrpc .getExecuteStreamingSqlMethod ()));
340346 } else {
341347 res = super .executeQueryAsync (statement , analyzeMode , options );
342348 }
343-
344349 ApiFutures .addCallback (
345350 res ,
346351 new ApiFutureCallback <ResultSet >() {
@@ -368,26 +373,28 @@ public ApiFuture<Long> executeUpdateAsync(final ParsedStatement update) {
368373 res =
369374 executeStatementAsync (
370375 update ,
371- () ->
372- runWithRetry (
373- () -> {
374- try {
375- getStatementExecutor ()
376- .invokeInterceptors (
377- update ,
378- StatementExecutionStep .EXECUTE_STATEMENT ,
379- ReadWriteTransaction .this );
380- long updateCount =
381- get (txContextFuture ).executeUpdate (update .getStatement ());
382- createAndAddRetriableUpdate (update , updateCount );
383- return updateCount ;
384- } catch (AbortedException e ) {
385- throw e ;
386- } catch (SpannerException e ) {
387- createAndAddFailedUpdate (e , update );
388- throw e ;
389- }
390- }),
376+ () -> {
377+ checkTimedOut ();
378+ return runWithRetry (
379+ () -> {
380+ try {
381+ getStatementExecutor ()
382+ .invokeInterceptors (
383+ update ,
384+ StatementExecutionStep .EXECUTE_STATEMENT ,
385+ ReadWriteTransaction .this );
386+ long updateCount =
387+ get (txContextFuture ).executeUpdate (update .getStatement ());
388+ createAndAddRetriableUpdate (update , updateCount );
389+ return updateCount ;
390+ } catch (AbortedException e ) {
391+ throw e ;
392+ } catch (SpannerException e ) {
393+ createAndAddFailedUpdate (e , update );
394+ throw e ;
395+ }
396+ });
397+ },
391398 // ignore interceptors here as they are invoked in the Callable.
392399 InterceptorsUsage .IGNORE_INTERCEPTORS ,
393400 ImmutableList .<MethodDescriptor <?, ?>>of (SpannerGrpc .getExecuteSqlMethod ()));
@@ -396,6 +403,7 @@ public ApiFuture<Long> executeUpdateAsync(final ParsedStatement update) {
396403 executeStatementAsync (
397404 update ,
398405 () -> {
406+ checkTimedOut ();
399407 checkAborted ();
400408 return get (txContextFuture ).executeUpdate (update .getStatement ());
401409 },
@@ -449,25 +457,27 @@ public ApiFuture<long[]> executeBatchUpdateAsync(Iterable<ParsedStatement> updat
449457 res =
450458 executeStatementAsync (
451459 EXECUTE_BATCH_UPDATE_STATEMENT ,
452- () ->
453- runWithRetry (
454- () -> {
455- try {
456- getStatementExecutor ()
457- .invokeInterceptors (
458- EXECUTE_BATCH_UPDATE_STATEMENT ,
459- StatementExecutionStep .EXECUTE_STATEMENT ,
460- ReadWriteTransaction .this );
461- long [] updateCounts = get (txContextFuture ).batchUpdate (updateStatements );
462- createAndAddRetriableBatchUpdate (updateStatements , updateCounts );
463- return updateCounts ;
464- } catch (AbortedException e ) {
465- throw e ;
466- } catch (SpannerException e ) {
467- createAndAddFailedBatchUpdate (e , updateStatements );
468- throw e ;
469- }
470- }),
460+ () -> {
461+ checkTimedOut ();
462+ return runWithRetry (
463+ () -> {
464+ try {
465+ getStatementExecutor ()
466+ .invokeInterceptors (
467+ EXECUTE_BATCH_UPDATE_STATEMENT ,
468+ StatementExecutionStep .EXECUTE_STATEMENT ,
469+ ReadWriteTransaction .this );
470+ long [] updateCounts = get (txContextFuture ).batchUpdate (updateStatements );
471+ createAndAddRetriableBatchUpdate (updateStatements , updateCounts );
472+ return updateCounts ;
473+ } catch (AbortedException e ) {
474+ throw e ;
475+ } catch (SpannerException e ) {
476+ createAndAddFailedBatchUpdate (e , updateStatements );
477+ throw e ;
478+ }
479+ });
480+ },
471481 // ignore interceptors here as they are invoked in the Callable.
472482 InterceptorsUsage .IGNORE_INTERCEPTORS ,
473483 ImmutableList .<MethodDescriptor <?, ?>>of (SpannerGrpc .getExecuteBatchDmlMethod ()));
@@ -476,12 +486,12 @@ public ApiFuture<long[]> executeBatchUpdateAsync(Iterable<ParsedStatement> updat
476486 executeStatementAsync (
477487 EXECUTE_BATCH_UPDATE_STATEMENT ,
478488 () -> {
489+ checkTimedOut ();
479490 checkAborted ();
480491 return get (txContextFuture ).batchUpdate (updateStatements );
481492 },
482493 SpannerGrpc .getExecuteBatchDmlMethod ());
483494 }
484-
485495 ApiFutures .addCallback (
486496 res ,
487497 new ApiFutureCallback <long []>() {
@@ -546,6 +556,7 @@ public ApiFuture<Void> commitAsync() {
546556 executeStatementAsync (
547557 COMMIT_STATEMENT ,
548558 () -> {
559+ checkTimedOut ();
549560 try {
550561 return runWithRetry (
551562 () -> {
@@ -574,6 +585,7 @@ public ApiFuture<Void> commitAsync() {
574585 executeStatementAsync (
575586 COMMIT_STATEMENT ,
576587 () -> {
588+ checkTimedOut ();
577589 try {
578590 return commitCallable .call ();
579591 } catch (Throwable t ) {
0 commit comments