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

perf: only capture the call stack if the call is actually async #2471

Merged
merged 3 commits into from
May 31, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ implementation 'com.google.cloud:google-cloud-spanner'
If you are using Gradle without BOM, add this to your dependencies:

```Groovy
implementation 'com.google.cloud:google-cloud-spanner:6.42.1'
implementation 'com.google.cloud:google-cloud-spanner:6.42.2'
```

If you are using SBT, add this to your dependencies:

```Scala
libraryDependencies += "com.google.cloud" % "google-cloud-spanner" % "6.42.1"
libraryDependencies += "com.google.cloud" % "google-cloud-spanner" % "6.42.2"
```
<!-- {x-version-update-end} -->

Expand Down Expand Up @@ -412,7 +412,7 @@ Java is a registered trademark of Oracle and/or its affiliates.
[kokoro-badge-link-5]: http://storage.googleapis.com/cloud-devrel-public/java/badges/java-spanner/java11.html
[stability-image]: https://img.shields.io/badge/stability-stable-green
[maven-version-image]: https://img.shields.io/maven-central/v/com.google.cloud/google-cloud-spanner.svg
[maven-version-link]: https://central.sonatype.com/artifact/com.google.cloud/google-cloud-spanner/6.42.1
[maven-version-link]: https://central.sonatype.com/artifact/com.google.cloud/google-cloud-spanner/6.42.2
[authentication]: https://github.com/googleapis/google-cloud-java#authentication
[auth-scopes]: https://developers.google.com/identity/protocols/oauth2/scopes
[predefined-iam-roles]: https://cloud.google.com/iam/docs/understanding-roles#predefined_roles
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,12 @@ public void cancel() {
}

<T> ApiFuture<T> executeStatementAsync(
CallType callType,
ParsedStatement statement,
Callable<T> callable,
@Nullable MethodDescriptor<?, ?> applyStatementTimeoutToMethod) {
return executeStatementAsync(
callType,
statement,
callable,
InterceptorsUsage.INVOKE_INTERCEPTORS,
Expand All @@ -190,11 +192,16 @@ <T> ApiFuture<T> executeStatementAsync(
}

<T> ApiFuture<T> executeStatementAsync(
CallType callType,
ParsedStatement statement,
Callable<T> callable,
Collection<MethodDescriptor<?, ?>> applyStatementTimeoutToMethods) {
return executeStatementAsync(
statement, callable, InterceptorsUsage.INVOKE_INTERCEPTORS, applyStatementTimeoutToMethods);
callType,
statement,
callable,
InterceptorsUsage.INVOKE_INTERCEPTORS,
applyStatementTimeoutToMethods);
}

<ResponseT, MetadataT> ResponseT getWithStatementTimeout(
Expand Down Expand Up @@ -237,6 +244,7 @@ <ResponseT, MetadataT> ResponseT getWithStatementTimeout(
}

<T> ApiFuture<T> executeStatementAsync(
CallType callType,
ParsedStatement statement,
Callable<T> callable,
InterceptorsUsage interceptorUsage,
Expand Down Expand Up @@ -268,13 +276,17 @@ public <ReqT, RespT> ApiCallContext configure(
}
ApiFuture<T> f = statementExecutor.submit(context.wrap(callable));
final SpannerAsyncExecutionException caller =
new SpannerAsyncExecutionException(statement.getStatement());
callType == CallType.ASYNC
? new SpannerAsyncExecutionException(statement.getStatement())
: null;
final ApiFuture<T> future =
ApiFutures.catching(
f,
Throwable.class,
input -> {
input.addSuppressed(caller);
if (caller != null) {
input.addSuppressed(caller);
}
throw SpannerExceptionFactory.asSpannerException(input);
},
MoreExecutors.directExecutor());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,18 +102,21 @@ public boolean isActive() {
* Check that the current transaction actually has a valid underlying transaction. If not, the
* method will throw a {@link SpannerException}.
*/
abstract void checkValidTransaction();
abstract void checkValidTransaction(CallType callType);

/** Returns the {@link ReadContext} that can be used for queries on this transaction. */
abstract ReadContext getReadContext();

@Override
public ApiFuture<ResultSet> executeQueryAsync(
final CallType callType,
final ParsedStatement statement,
final AnalyzeMode analyzeMode,
final QueryOption... options) {
Preconditions.checkArgument(statement.isQuery(), "Statement is not a query");
checkValidTransaction();
checkValidTransaction(callType);
return executeStatementAsync(
callType,
statement,
() -> {
checkAborted();
Expand All @@ -133,7 +136,7 @@ ResultSet internalExecuteQuery(
}

@Override
public ApiFuture<long[]> runBatchAsync() {
public ApiFuture<long[]> runBatchAsync(CallType callType) {
throw SpannerExceptionFactory.newSpannerException(
ErrorCode.FAILED_PRECONDITION, "Run batch is not supported for transactions");
}
Expand Down
Loading