Skip to content

Commit

Permalink
modify default retry params to conform with datastore, storage, and b…
Browse files Browse the repository at this point in the history
…igquery sla
  • Loading branch information
Ajay Kannan committed Apr 6, 2016
1 parent 982b808 commit 07e467c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 46 deletions.
Expand Up @@ -17,7 +17,6 @@
package com.google.gcloud.bigquery;

import com.google.common.collect.ImmutableSet;
import com.google.gcloud.RetryParams;
import com.google.gcloud.ServiceOptions;
import com.google.gcloud.bigquery.spi.BigQueryRpc;
import com.google.gcloud.bigquery.spi.BigQueryRpcFactory;
Expand Down Expand Up @@ -109,19 +108,6 @@ public static BigQueryOptions defaultInstance() {
return builder().build();
}

@Override
protected RetryParams defaultRetryParams() {
// See https://cloud.google.com/bigquery/sla for backoff requirements
return RetryParams.builder()
.retryMinAttempts(RetryParams.DEFAULT_RETRY_MIN_ATTEMPTS)
.retryMaxAttempts(RetryParams.DEFAULT_RETRY_MAX_ATTEMPTS)
.initialRetryDelayMillis(1000L)
.maxRetryDelayMillis(32000L)
.retryDelayBackoffFactor(2.0)
.totalRetryPeriodMillis(80000L)
.build();
}

public static Builder builder() {
return new Builder();
}
Expand Down
21 changes: 17 additions & 4 deletions gcloud-java-core/src/main/java/com/google/gcloud/RetryParams.java
Expand Up @@ -48,12 +48,16 @@ public final class RetryParams implements Serializable {

private static final long serialVersionUID = -8492751576749007700L;

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

private final int retryMinAttempts;
private final int retryMaxAttempts;
Expand All @@ -62,6 +66,9 @@ public final class RetryParams implements Serializable {
private final double retryDelayBackoffFactor;
private final long totalRetryPeriodMillis;

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

/**
* Sets totalRetryPeriodMillis.
* Sets totalRetryPeriodMillis. Note that App Engine Standard Environment front-end modules have
* a 60 second deadline for HTTP requests. For that reason, you should set the total retry
* period to under 60 seconds if you are using the App Engine front-end module.
*
* @param totalRetryPeriodMillis the totalRetryPeriodMillis to set
* @return the Builder for chaining
Expand Down Expand Up @@ -295,4 +304,8 @@ public String toString() {
public static Builder builder() {
return new Builder();
}

public Builder toBuilder() {
return new Builder(this);
}
}
Expand Up @@ -21,7 +21,6 @@
import com.google.common.base.MoreObjects;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.gcloud.RetryParams;
import com.google.gcloud.ServiceOptions;
import com.google.gcloud.datastore.spi.DatastoreRpc;
import com.google.gcloud.datastore.spi.DatastoreRpcFactory;
Expand Down Expand Up @@ -161,19 +160,6 @@ public String namespace() {
return namespace;
}

@Override
protected RetryParams defaultRetryParams() {
// See https://cloud.google.com/datastore/sla for backoff requirements
return RetryParams.builder()
.retryMinAttempts(RetryParams.DEFAULT_RETRY_MIN_ATTEMPTS)
.retryMaxAttempts(RetryParams.DEFAULT_RETRY_MAX_ATTEMPTS)
.initialRetryDelayMillis(1000L)
.maxRetryDelayMillis(32000L)
.retryDelayBackoffFactor(2.0)
.totalRetryPeriodMillis(80000L)
.build();
}

/**
* Returns a default {@code DatastoreOptions} instance.
*/
Expand Down
Expand Up @@ -17,7 +17,6 @@
package com.google.gcloud.storage;

import com.google.common.collect.ImmutableSet;
import com.google.gcloud.RetryParams;
import com.google.gcloud.ServiceOptions;
import com.google.gcloud.storage.spi.DefaultStorageRpc;
import com.google.gcloud.storage.spi.StorageRpc;
Expand Down Expand Up @@ -94,19 +93,6 @@ public static StorageOptions defaultInstance() {
return builder().build();
}

@Override
protected RetryParams defaultRetryParams() {
// See https://cloud.google.com/storage/sla for backoff requirements
return RetryParams.builder()
.retryMinAttempts(RetryParams.DEFAULT_RETRY_MIN_ATTEMPTS)
.retryMaxAttempts(RetryParams.DEFAULT_RETRY_MAX_ATTEMPTS)
.initialRetryDelayMillis(1000L)
.maxRetryDelayMillis(32000L)
.retryDelayBackoffFactor(2.0)
.totalRetryPeriodMillis(80000L)
.build();
}

@SuppressWarnings("unchecked")
@Override
public Builder toBuilder() {
Expand Down

0 comments on commit 07e467c

Please sign in to comment.