Skip to content

Commit 1b39e8c

Browse files
committed
Merge branch 'main' into batch-read-connection-api
2 parents ed6a34e + c34d51e commit 1b39e8c

15 files changed

+1342
-66
lines changed

.github/blunderbuss.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Configuration for the Blunderbuss GitHub app. For more info see
22
# https://github.com/googleapis/repo-automation-bots/tree/main/packages/blunderbuss
33
assign_issues:
4-
- rajatbhatta
4+
- arpan14
55
assign_prs_by:
66
- labels:
77
- samples

google-cloud-spanner/clirr-ignored-differences.xml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@
374374
<difference>
375375
<differenceType>7012</differenceType>
376376
<className>com/google/cloud/spanner/connection/Connection</className>
377-
<method>boolean isAlwaysUsePartitionedQueries()</method>
377+
<method>boolean isAutoPartitionMode()</method>
378378
</difference>
379379
<difference>
380380
<differenceType>7012</differenceType>
@@ -399,7 +399,7 @@
399399
<difference>
400400
<differenceType>7012</differenceType>
401401
<className>com/google/cloud/spanner/connection/Connection</className>
402-
<method>void setAlwaysUsePartitionedQueries(boolean)</method>
402+
<method>void setAutoPartitionMode(boolean)</method>
403403
</difference>
404404
<difference>
405405
<differenceType>7012</differenceType>
@@ -416,4 +416,10 @@
416416
<className>com/google/cloud/spanner/connection/Connection</className>
417417
<method>void setMaxPartitions(int)</method>
418418
</difference>
419+
<!-- (Internal change, use stream timeout) -->
420+
<difference>
421+
<differenceType>7012</differenceType>
422+
<className>com/google/cloud/spanner/spi/v1/SpannerRpc$StreamingCall</className>
423+
<method>com.google.api.gax.rpc.ApiCallContext getCallContext()</method>
424+
</difference>
419425
</differences>

google-cloud-spanner/src/main/java/com/google/cloud/spanner/AbstractResultSet.java

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import com.google.api.client.util.BackOff;
2626
import com.google.api.client.util.ExponentialBackOff;
2727
import com.google.api.gax.retrying.RetrySettings;
28+
import com.google.api.gax.rpc.ApiCallContext;
2829
import com.google.cloud.ByteArray;
2930
import com.google.cloud.Date;
3031
import com.google.cloud.Timestamp;
@@ -74,6 +75,7 @@
7475
import java.util.stream.Collectors;
7576
import javax.annotation.Nonnull;
7677
import javax.annotation.Nullable;
78+
import org.threeten.bp.Duration;
7779

7880
/** Implementation of {@link ResultSet}. */
7981
abstract class AbstractResultSet<R> extends AbstractStructReader implements ResultSet {
@@ -944,6 +946,8 @@ static class GrpcStreamIterator extends AbstractIterator<PartialResultSet>
944946

945947
private SpannerRpc.StreamingCall call;
946948
private volatile boolean withBeginTransaction;
949+
private TimeUnit streamWaitTimeoutUnit;
950+
private long streamWaitTimeoutValue;
947951
private SpannerException error;
948952

949953
@VisibleForTesting
@@ -965,6 +969,22 @@ protected final SpannerRpc.ResultStreamConsumer consumer() {
965969
public void setCall(SpannerRpc.StreamingCall call, boolean withBeginTransaction) {
966970
this.call = call;
967971
this.withBeginTransaction = withBeginTransaction;
972+
ApiCallContext callContext = call.getCallContext();
973+
Duration streamWaitTimeout = callContext == null ? null : callContext.getStreamWaitTimeout();
974+
if (streamWaitTimeout != null) {
975+
// Determine the timeout unit to use. This reduces the precision to seconds if the timeout
976+
// value is more than 1 second, which is lower than the precision that would normally be
977+
// used by the stream watchdog (which uses a precision of 10 seconds by default).
978+
if (streamWaitTimeout.getSeconds() > 0L) {
979+
streamWaitTimeoutValue = streamWaitTimeout.getSeconds();
980+
streamWaitTimeoutUnit = TimeUnit.SECONDS;
981+
} else if (streamWaitTimeout.getNano() > 0) {
982+
streamWaitTimeoutValue = streamWaitTimeout.getNano();
983+
streamWaitTimeoutUnit = TimeUnit.NANOSECONDS;
984+
}
985+
// Note that if the stream-wait-timeout is zero, we won't set a timeout at all.
986+
// That is consistent with ApiCallContext#withStreamWaitTimeout(Duration.ZERO).
987+
}
968988
}
969989

970990
@Override
@@ -983,11 +1003,15 @@ public boolean isWithBeginTransaction() {
9831003
protected final PartialResultSet computeNext() {
9841004
PartialResultSet next;
9851005
try {
986-
// TODO: Ideally honor io.grpc.Context while blocking here. In practice,
987-
// cancellation/deadline results in an error being delivered to "stream", which
988-
// should mean that we do not block significantly longer afterwards, but it would
989-
// be more robust to use poll() with a timeout.
990-
next = stream.take();
1006+
if (streamWaitTimeoutUnit != null) {
1007+
next = stream.poll(streamWaitTimeoutValue, streamWaitTimeoutUnit);
1008+
if (next == null) {
1009+
throw SpannerExceptionFactory.newSpannerException(
1010+
ErrorCode.DEADLINE_EXCEEDED, "stream wait timeout");
1011+
}
1012+
} else {
1013+
next = stream.take();
1014+
}
9911015
} catch (InterruptedException e) {
9921016
// Treat interrupt as a request to cancel the read.
9931017
throw SpannerExceptionFactory.propagateInterrupt(e);

0 commit comments

Comments
 (0)