Skip to content

Commit 4a1bcdb

Browse files
committed
fix(bigquery): selectively apply HTTP error retries to safe/idempotent RPCs
1 parent f195928 commit 4a1bcdb

2 files changed

Lines changed: 39 additions & 28 deletions

File tree

java-bigquery/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryImpl.java

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import com.google.api.core.BetaApi;
2424
import com.google.api.core.InternalApi;
2525
import com.google.api.gax.paging.Page;
26+
import com.google.api.gax.retrying.ResultRetryAlgorithm;
2627
import com.google.api.services.bigquery.model.ErrorProto;
2728
import com.google.api.services.bigquery.model.GetQueryResultsResponse;
2829
import com.google.api.services.bigquery.model.QueryRequest;
@@ -592,7 +593,7 @@ public com.google.api.services.bigquery.model.Dataset call() throws IOException
592593
}
593594
},
594595
getOptions().getRetrySettings(),
595-
getOptions().getResultRetryAlgorithm(),
596+
getHttpRetryAlgorithm(),
596597
getOptions().getClock(),
597598
EMPTY_RETRY_CONFIG,
598599
getOptions().isOpenTelemetryTracingEnabled(),
@@ -658,7 +659,7 @@ private static Page<Dataset> listDatasets(
658659
}
659660
},
660661
serviceOptions.getRetrySettings(),
661-
serviceOptions.getResultRetryAlgorithm(),
662+
BigQueryRetryHelper.getHttpRetryAlgorithm(serviceOptions.getResultRetryAlgorithm()),
662663
serviceOptions.getClock(),
663664
EMPTY_RETRY_CONFIG,
664665
serviceOptions.isOpenTelemetryTracingEnabled(),
@@ -710,7 +711,7 @@ public Boolean call() throws IOException {
710711
}
711712
},
712713
getOptions().getRetrySettings(),
713-
getOptions().getResultRetryAlgorithm(),
714+
getHttpRetryAlgorithm(),
714715
getOptions().getClock(),
715716
EMPTY_RETRY_CONFIG,
716717
getOptions().isOpenTelemetryTracingEnabled(),
@@ -761,7 +762,7 @@ public Boolean call() throws IOException {
761762
}
762763
},
763764
getOptions().getRetrySettings(),
764-
getOptions().getResultRetryAlgorithm(),
765+
getHttpRetryAlgorithm(),
765766
getOptions().getClock(),
766767
EMPTY_RETRY_CONFIG,
767768
getOptions().isOpenTelemetryTracingEnabled(),
@@ -807,7 +808,7 @@ public Boolean call() throws IOException {
807808
}
808809
},
809810
getOptions().getRetrySettings(),
810-
getOptions().getResultRetryAlgorithm(),
811+
getHttpRetryAlgorithm(),
811812
getOptions().getClock(),
812813
EMPTY_RETRY_CONFIG,
813814
getOptions().isOpenTelemetryTracingEnabled(),
@@ -853,7 +854,7 @@ public Boolean call() throws IOException {
853854
}
854855
},
855856
getOptions().getRetrySettings(),
856-
getOptions().getResultRetryAlgorithm(),
857+
getHttpRetryAlgorithm(),
857858
getOptions().getClock(),
858859
EMPTY_RETRY_CONFIG,
859860
getOptions().isOpenTelemetryTracingEnabled(),
@@ -897,7 +898,7 @@ public Boolean call() throws IOException {
897898
}
898899
},
899900
getOptions().getRetrySettings(),
900-
getOptions().getResultRetryAlgorithm(),
901+
getHttpRetryAlgorithm(),
901902
getOptions().getClock(),
902903
EMPTY_RETRY_CONFIG,
903904
getOptions().isOpenTelemetryTracingEnabled(),
@@ -938,7 +939,7 @@ public com.google.api.services.bigquery.model.Dataset call() throws IOException
938939
}
939940
},
940941
getOptions().getRetrySettings(),
941-
getOptions().getResultRetryAlgorithm(),
942+
getHttpRetryAlgorithm(),
942943
getOptions().getClock(),
943944
EMPTY_RETRY_CONFIG,
944945
getOptions().isOpenTelemetryTracingEnabled(),
@@ -985,7 +986,7 @@ public com.google.api.services.bigquery.model.Table call() throws IOException {
985986
}
986987
},
987988
getOptions().getRetrySettings(),
988-
getOptions().getResultRetryAlgorithm(),
989+
getHttpRetryAlgorithm(),
989990
getOptions().getClock(),
990991
EMPTY_RETRY_CONFIG,
991992
getOptions().isOpenTelemetryTracingEnabled(),
@@ -1031,7 +1032,7 @@ public com.google.api.services.bigquery.model.Model call() throws IOException {
10311032
}
10321033
},
10331034
getOptions().getRetrySettings(),
1034-
getOptions().getResultRetryAlgorithm(),
1035+
getHttpRetryAlgorithm(),
10351036
getOptions().getClock(),
10361037
EMPTY_RETRY_CONFIG,
10371038
getOptions().isOpenTelemetryTracingEnabled(),
@@ -1077,7 +1078,7 @@ public com.google.api.services.bigquery.model.Routine call() throws IOException
10771078
}
10781079
},
10791080
getOptions().getRetrySettings(),
1080-
getOptions().getResultRetryAlgorithm(),
1081+
getHttpRetryAlgorithm(),
10811082
getOptions().getClock(),
10821083
EMPTY_RETRY_CONFIG,
10831084
getOptions().isOpenTelemetryTracingEnabled(),
@@ -1131,7 +1132,7 @@ public com.google.api.services.bigquery.model.Table call() throws IOException {
11311132
}
11321133
},
11331134
getOptions().getRetrySettings(),
1134-
getOptions().getResultRetryAlgorithm(),
1135+
getHttpRetryAlgorithm(),
11351136
getOptions().getClock(),
11361137
EMPTY_RETRY_CONFIG,
11371138
getOptions().isOpenTelemetryTracingEnabled(),
@@ -1190,7 +1191,7 @@ public com.google.api.services.bigquery.model.Model call() throws IOException {
11901191
}
11911192
},
11921193
getOptions().getRetrySettings(),
1193-
getOptions().getResultRetryAlgorithm(),
1194+
getHttpRetryAlgorithm(),
11941195
getOptions().getClock(),
11951196
EMPTY_RETRY_CONFIG,
11961197
getOptions().isOpenTelemetryTracingEnabled(),
@@ -1249,7 +1250,7 @@ public com.google.api.services.bigquery.model.Routine call() throws IOException
12491250
}
12501251
},
12511252
getOptions().getRetrySettings(),
1252-
getOptions().getResultRetryAlgorithm(),
1253+
getHttpRetryAlgorithm(),
12531254
getOptions().getClock(),
12541255
EMPTY_RETRY_CONFIG,
12551256
getOptions().isOpenTelemetryTracingEnabled(),
@@ -1467,7 +1468,7 @@ public Tuple<String, Iterable<com.google.api.services.bigquery.model.Table>> cal
14671468
}
14681469
},
14691470
serviceOptions.getRetrySettings(),
1470-
serviceOptions.getResultRetryAlgorithm(),
1471+
BigQueryRetryHelper.getHttpRetryAlgorithm(serviceOptions.getResultRetryAlgorithm()),
14711472
serviceOptions.getClock(),
14721473
EMPTY_RETRY_CONFIG,
14731474
serviceOptions.isOpenTelemetryTracingEnabled(),
@@ -1508,7 +1509,7 @@ public Tuple<String, Iterable<com.google.api.services.bigquery.model.Model>> cal
15081509
}
15091510
},
15101511
serviceOptions.getRetrySettings(),
1511-
serviceOptions.getResultRetryAlgorithm(),
1512+
BigQueryRetryHelper.getHttpRetryAlgorithm(serviceOptions.getResultRetryAlgorithm()),
15121513
serviceOptions.getClock(),
15131514
EMPTY_RETRY_CONFIG,
15141515
serviceOptions.isOpenTelemetryTracingEnabled(),
@@ -1549,7 +1550,7 @@ private static Page<Routine> listRoutines(
15491550
}
15501551
},
15511552
serviceOptions.getRetrySettings(),
1552-
serviceOptions.getResultRetryAlgorithm(),
1553+
BigQueryRetryHelper.getHttpRetryAlgorithm(serviceOptions.getResultRetryAlgorithm()),
15531554
serviceOptions.getClock(),
15541555
EMPTY_RETRY_CONFIG,
15551556
serviceOptions.isOpenTelemetryTracingEnabled(),
@@ -1631,7 +1632,7 @@ public TableDataInsertAllResponse call() throws Exception {
16311632
}
16321633
},
16331634
getOptions().getRetrySettings(),
1634-
getOptions().getResultRetryAlgorithm(),
1635+
getHttpRetryAlgorithm(),
16351636
getOptions().getClock(),
16361637
EMPTY_RETRY_CONFIG,
16371638
getOptions().isOpenTelemetryTracingEnabled(),
@@ -1725,7 +1726,7 @@ public TableDataList call() throws IOException {
17251726
}
17261727
},
17271728
serviceOptions.getRetrySettings(),
1728-
serviceOptions.getResultRetryAlgorithm(),
1729+
BigQueryRetryHelper.getHttpRetryAlgorithm(serviceOptions.getResultRetryAlgorithm()),
17291730
serviceOptions.getClock(),
17301731
EMPTY_RETRY_CONFIG,
17311732
serviceOptions.isOpenTelemetryTracingEnabled(),
@@ -1802,7 +1803,7 @@ public com.google.api.services.bigquery.model.Job call() throws IOException {
18021803
}
18031804
},
18041805
getOptions().getRetrySettings(),
1805-
getOptions().getResultRetryAlgorithm(),
1806+
getHttpRetryAlgorithm(),
18061807
getOptions().getClock(),
18071808
EMPTY_RETRY_CONFIG,
18081809
getOptions().isOpenTelemetryTracingEnabled(),
@@ -1859,7 +1860,7 @@ public Tuple<String, Iterable<com.google.api.services.bigquery.model.Job>> call(
18591860
}
18601861
},
18611862
serviceOptions.getRetrySettings(),
1862-
serviceOptions.getResultRetryAlgorithm(),
1863+
BigQueryRetryHelper.getHttpRetryAlgorithm(serviceOptions.getResultRetryAlgorithm()),
18631864
serviceOptions.getClock(),
18641865
EMPTY_RETRY_CONFIG,
18651866
serviceOptions.isOpenTelemetryTracingEnabled(),
@@ -1914,7 +1915,7 @@ public Boolean call() throws IOException {
19141915
}
19151916
},
19161917
getOptions().getRetrySettings(),
1917-
getOptions().getResultRetryAlgorithm(),
1918+
getHttpRetryAlgorithm(),
19181919
getOptions().getClock(),
19191920
EMPTY_RETRY_CONFIG,
19201921
getOptions().isOpenTelemetryTracingEnabled(),
@@ -2169,7 +2170,7 @@ public GetQueryResultsResponse call() throws IOException {
21692170
}
21702171
},
21712172
serviceOptions.getRetrySettings(),
2172-
serviceOptions.getResultRetryAlgorithm(),
2173+
BigQueryRetryHelper.getHttpRetryAlgorithm(serviceOptions.getResultRetryAlgorithm()),
21732174
serviceOptions.getClock(),
21742175
DEFAULT_RETRY_CONFIG,
21752176
serviceOptions.isOpenTelemetryTracingEnabled(),
@@ -2240,7 +2241,7 @@ public com.google.api.services.bigquery.model.Policy call() throws IOException {
22402241
}
22412242
},
22422243
getOptions().getRetrySettings(),
2243-
getOptions().getResultRetryAlgorithm(),
2244+
getHttpRetryAlgorithm(),
22442245
getOptions().getClock(),
22452246
EMPTY_RETRY_CONFIG,
22462247
getOptions().isOpenTelemetryTracingEnabled(),
@@ -2334,7 +2335,7 @@ public com.google.api.services.bigquery.model.TestIamPermissionsResponse call()
23342335
}
23352336
},
23362337
getOptions().getRetrySettings(),
2337-
getOptions().getResultRetryAlgorithm(),
2338+
getHttpRetryAlgorithm(),
23382339
getOptions().getClock(),
23392340
EMPTY_RETRY_CONFIG,
23402341
getOptions().isOpenTelemetryTracingEnabled(),
@@ -2411,4 +2412,10 @@ private static boolean isRetryErrorCodeHttpNotFound(BigQueryRetryHelperException
24112412
}
24122413
return false;
24132414
}
2415+
2416+
@SuppressWarnings("unchecked")
2417+
private <V> ResultRetryAlgorithm<V> getHttpRetryAlgorithm() {
2418+
return BigQueryRetryHelper.getHttpRetryAlgorithm(
2419+
(ResultRetryAlgorithm<V>) getOptions().getResultRetryAlgorithm());
2420+
}
24142421
}

java-bigquery/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryRetryHelper.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,6 @@ public static <V> V runWithRetries(
7171
// implementation does not use response at all, so ignoring its type is ok.
7272
@SuppressWarnings("unchecked")
7373
ResultRetryAlgorithm<V> algorithm = (ResultRetryAlgorithm<V>) resultRetryAlgorithm;
74-
if (algorithm == BigQueryBaseService.DEFAULT_BIGQUERY_EXCEPTION_HANDLER) {
75-
algorithm = wrapDefaultAlgorithm(algorithm);
76-
}
7774
return run(
7875
callable,
7976
new ExponentialRetryAlgorithm(retrySettings, clock),
@@ -124,6 +121,13 @@ private static <V> V run(
124121
return retryingFuture.get();
125122
}
126123

124+
static <V> ResultRetryAlgorithm<V> getHttpRetryAlgorithm(ResultRetryAlgorithm<V> algorithm) {
125+
if (algorithm == BigQueryBaseService.DEFAULT_BIGQUERY_EXCEPTION_HANDLER) {
126+
return wrapDefaultAlgorithm(algorithm);
127+
}
128+
return algorithm;
129+
}
130+
127131
private static <V> ResultRetryAlgorithm<V> wrapDefaultAlgorithm(
128132
ResultRetryAlgorithm<V> defaultAlgorithm) {
129133
return new ResultRetryAlgorithm<V>() {

0 commit comments

Comments
 (0)