File tree Expand file tree Collapse file tree
java-spanner/google-cloud-spanner/src
main/java/com/google/cloud/spanner/spi/v1
test/java/com/google/cloud/spanner/spi/v1 Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -127,6 +127,7 @@ public void recordError(Duration penalty) {
127127 private double calculateTimeBasedAlpha (long nowNanos ) {
128128 long deltaNanos = nowNanos - lastUpdatedAtNanos ;
129129 if (deltaNanos <= 0L ) {
130+ // concurrent or future samples get full weight.
130131 return 1.0 ;
131132 }
132133 double alpha = 1.0 - Math .exp (-(double ) deltaNanos / (double ) tauNanos );
Original file line number Diff line number Diff line change @@ -447,8 +447,15 @@ public GapicSpannerRpc(final SpannerOptions options) {
447447 : streamingReadRetryableCodes ;
448448 this .executeQueryRetrySettings =
449449 options .getSpannerStubSettings ().executeStreamingSqlSettings ().getRetrySettings ();
450- this . executeQueryRetryableCodes =
450+ Set < Code > executeStreamingSqlRetryableCodes =
451451 options .getSpannerStubSettings ().executeStreamingSqlSettings ().getRetryableCodes ();
452+ this .executeQueryRetryableCodes =
453+ enableLocationApi
454+ ? ImmutableSet .<Code >builder ()
455+ .addAll (executeStreamingSqlRetryableCodes )
456+ .add (Code .RESOURCE_EXHAUSTED )
457+ .build ()
458+ : executeStreamingSqlRetryableCodes ;
452459 this .commitRetrySettings =
453460 options .getSpannerStubSettings ().commitSettings ().getRetrySettings ();
454461 partitionedDmlRetrySettings =
Original file line number Diff line number Diff line change @@ -1081,6 +1081,27 @@ public boolean isEnableLocationApi() {
10811081 }
10821082 }
10831083
1084+ @ Test
1085+ public void testExecuteQueryRetryableCodesIncludeResourceExhaustedWhenLocationApiEnabled () {
1086+ try {
1087+ SpannerOptions .useEnvironment (
1088+ new SpannerOptions .SpannerEnvironment () {
1089+ @ Override
1090+ public boolean isEnableLocationApi () {
1091+ return true ;
1092+ }
1093+ });
1094+ GapicSpannerRpc rpc = new GapicSpannerRpc (createSpannerOptions (), true );
1095+ try {
1096+ assertThat (rpc .getExecuteQueryRetryableCodes ()).contains (Code .RESOURCE_EXHAUSTED );
1097+ } finally {
1098+ rpc .shutdown ();
1099+ }
1100+ } finally {
1101+ SpannerOptions .useDefaultEnvironment ();
1102+ }
1103+ }
1104+
10841105 @ Test
10851106 public void testReadRetryableCodesDoNotAddResourceExhaustedWhenLocationApiDisabled () {
10861107 try {
@@ -1107,6 +1128,32 @@ public boolean isEnableLocationApi() {
11071128 }
11081129 }
11091130
1131+ @ Test
1132+ public void testExecuteQueryRetryableCodesDoNotAddResourceExhaustedWhenLocationApiDisabled () {
1133+ try {
1134+ SpannerOptions .useEnvironment (
1135+ new SpannerOptions .SpannerEnvironment () {
1136+ @ Override
1137+ public boolean isEnableLocationApi () {
1138+ return false ;
1139+ }
1140+ });
1141+ GapicSpannerRpc rpc = new GapicSpannerRpc (createSpannerOptions (), true );
1142+ try {
1143+ assertThat (rpc .getExecuteQueryRetryableCodes ())
1144+ .isEqualTo (
1145+ createSpannerOptions ()
1146+ .getSpannerStubSettings ()
1147+ .executeStreamingSqlSettings ()
1148+ .getRetryableCodes ());
1149+ } finally {
1150+ rpc .shutdown ();
1151+ }
1152+ } finally {
1153+ SpannerOptions .useDefaultEnvironment ();
1154+ }
1155+ }
1156+
11101157 @ Test
11111158 public void testGrpcGcpExtensionPreservesChannelConfigurator () throws Exception {
11121159 InstantiatingGrpcChannelProvider .Builder channelProviderBuilder =
You can’t perform that action at this time.
0 commit comments