Skip to content

Commit 07e467c

Browse files
author
Ajay Kannan
committed
modify default retry params to conform with datastore, storage, and bigquery sla
1 parent 982b808 commit 07e467c

File tree

4 files changed

+17
-46
lines changed

4 files changed

+17
-46
lines changed

gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/BigQueryOptions.java

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package com.google.gcloud.bigquery;
1818

1919
import com.google.common.collect.ImmutableSet;
20-
import com.google.gcloud.RetryParams;
2120
import com.google.gcloud.ServiceOptions;
2221
import com.google.gcloud.bigquery.spi.BigQueryRpc;
2322
import com.google.gcloud.bigquery.spi.BigQueryRpcFactory;
@@ -109,19 +108,6 @@ public static BigQueryOptions defaultInstance() {
109108
return builder().build();
110109
}
111110

112-
@Override
113-
protected RetryParams defaultRetryParams() {
114-
// See https://cloud.google.com/bigquery/sla for backoff requirements
115-
return RetryParams.builder()
116-
.retryMinAttempts(RetryParams.DEFAULT_RETRY_MIN_ATTEMPTS)
117-
.retryMaxAttempts(RetryParams.DEFAULT_RETRY_MAX_ATTEMPTS)
118-
.initialRetryDelayMillis(1000L)
119-
.maxRetryDelayMillis(32000L)
120-
.retryDelayBackoffFactor(2.0)
121-
.totalRetryPeriodMillis(80000L)
122-
.build();
123-
}
124-
125111
public static Builder builder() {
126112
return new Builder();
127113
}

gcloud-java-core/src/main/java/com/google/gcloud/RetryParams.java

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,16 @@ public final class RetryParams implements Serializable {
4848

4949
private static final long serialVersionUID = -8492751576749007700L;
5050

51+
/**
52+
* Note that App Engine Standard Environment front-end modules have a 60 second deadline for HTTP
53+
* requests. For that reason, we set the default total retry period to less than 60 seconds.
54+
*/
55+
public static final long DEFAULT_TOTAL_RETRY_PERIOD_MILLIS = 50_000L;
5156
public static final int DEFAULT_RETRY_MIN_ATTEMPTS = 3;
5257
public static final int DEFAULT_RETRY_MAX_ATTEMPTS = 6;
53-
public static final long DEFAULT_INITIAL_RETRY_DELAY_MILLIS = 250L;
54-
public static final long DEFAULT_MAX_RETRY_DELAY_MILLIS = 10_000L;
58+
public static final long DEFAULT_INITIAL_RETRY_DELAY_MILLIS = 1000L;
59+
public static final long DEFAULT_MAX_RETRY_DELAY_MILLIS = 32_000L;
5560
public static final double DEFAULT_RETRY_DELAY_BACKOFF_FACTOR = 2.0;
56-
public static final long DEFAULT_TOTAL_RETRY_PERIOD_MILLIS = 50_000L;
5761

5862
private final int retryMinAttempts;
5963
private final int retryMaxAttempts;
@@ -62,6 +66,9 @@ public final class RetryParams implements Serializable {
6266
private final double retryDelayBackoffFactor;
6367
private final long totalRetryPeriodMillis;
6468

69+
// Some services may have different backoff requirements listed in their SLAs. Be sure to override
70+
// ServiceOptions.defaultRetryParams() in options subclasses when the service's backoff
71+
// requirement differs from the default parameters used here.
6572
private static final RetryParams DEFAULT_INSTANCE = new RetryParams(new Builder());
6673
private static final RetryParams NO_RETRIES =
6774
builder().retryMaxAttempts(1).retryMinAttempts(1).build();
@@ -156,7 +163,9 @@ public Builder retryDelayBackoffFactor(double retryDelayBackoffFactor) {
156163
}
157164

158165
/**
159-
* Sets totalRetryPeriodMillis.
166+
* Sets totalRetryPeriodMillis. Note that App Engine Standard Environment front-end modules have
167+
* a 60 second deadline for HTTP requests. For that reason, you should set the total retry
168+
* period to under 60 seconds if you are using the App Engine front-end module.
160169
*
161170
* @param totalRetryPeriodMillis the totalRetryPeriodMillis to set
162171
* @return the Builder for chaining
@@ -295,4 +304,8 @@ public String toString() {
295304
public static Builder builder() {
296305
return new Builder();
297306
}
307+
308+
public Builder toBuilder() {
309+
return new Builder(this);
310+
}
298311
}

gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/DatastoreOptions.java

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import com.google.common.base.MoreObjects;
2222
import com.google.common.collect.ImmutableSet;
2323
import com.google.common.collect.Iterables;
24-
import com.google.gcloud.RetryParams;
2524
import com.google.gcloud.ServiceOptions;
2625
import com.google.gcloud.datastore.spi.DatastoreRpc;
2726
import com.google.gcloud.datastore.spi.DatastoreRpcFactory;
@@ -161,19 +160,6 @@ public String namespace() {
161160
return namespace;
162161
}
163162

164-
@Override
165-
protected RetryParams defaultRetryParams() {
166-
// See https://cloud.google.com/datastore/sla for backoff requirements
167-
return RetryParams.builder()
168-
.retryMinAttempts(RetryParams.DEFAULT_RETRY_MIN_ATTEMPTS)
169-
.retryMaxAttempts(RetryParams.DEFAULT_RETRY_MAX_ATTEMPTS)
170-
.initialRetryDelayMillis(1000L)
171-
.maxRetryDelayMillis(32000L)
172-
.retryDelayBackoffFactor(2.0)
173-
.totalRetryPeriodMillis(80000L)
174-
.build();
175-
}
176-
177163
/**
178164
* Returns a default {@code DatastoreOptions} instance.
179165
*/

gcloud-java-storage/src/main/java/com/google/gcloud/storage/StorageOptions.java

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package com.google.gcloud.storage;
1818

1919
import com.google.common.collect.ImmutableSet;
20-
import com.google.gcloud.RetryParams;
2120
import com.google.gcloud.ServiceOptions;
2221
import com.google.gcloud.storage.spi.DefaultStorageRpc;
2322
import com.google.gcloud.storage.spi.StorageRpc;
@@ -94,19 +93,6 @@ public static StorageOptions defaultInstance() {
9493
return builder().build();
9594
}
9695

97-
@Override
98-
protected RetryParams defaultRetryParams() {
99-
// See https://cloud.google.com/storage/sla for backoff requirements
100-
return RetryParams.builder()
101-
.retryMinAttempts(RetryParams.DEFAULT_RETRY_MIN_ATTEMPTS)
102-
.retryMaxAttempts(RetryParams.DEFAULT_RETRY_MAX_ATTEMPTS)
103-
.initialRetryDelayMillis(1000L)
104-
.maxRetryDelayMillis(32000L)
105-
.retryDelayBackoffFactor(2.0)
106-
.totalRetryPeriodMillis(80000L)
107-
.build();
108-
}
109-
11096
@SuppressWarnings("unchecked")
11197
@Override
11298
public Builder toBuilder() {

0 commit comments

Comments
 (0)