Skip to content

Commit

Permalink
Add default retry params that align with SLA
Browse files Browse the repository at this point in the history
  • Loading branch information
Ajay Kannan committed Apr 6, 2016
1 parent b29df66 commit 982b808
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
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 @@ -108,6 +109,19 @@ 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
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ protected ServiceOptions(Class<? extends ServiceFactory<ServiceT, OptionsT>> ser
authCredentials =
builder.authCredentials != null ? builder.authCredentials : defaultAuthCredentials();
authCredentialsState = authCredentials != null ? authCredentials.capture() : null;
retryParams = firstNonNull(builder.retryParams, RetryParams.defaultInstance());
retryParams = firstNonNull(builder.retryParams, defaultRetryParams());
serviceFactory = firstNonNull(builder.serviceFactory,
getFromServiceLoader(serviceFactoryClass, defaultServiceFactory()));
serviceFactoryClassName = serviceFactory.getClass().getName();
Expand Down Expand Up @@ -655,6 +655,10 @@ private static <T> T newInstance(String className) throws IOException, ClassNotF

public abstract <B extends Builder<ServiceT, ServiceRpcT, OptionsT, B>> B toBuilder();

protected RetryParams defaultRetryParams() {
return RetryParams.defaultInstance();
}

private static <T> T getFromServiceLoader(Class<? extends T> clazz, T defaultInstance) {
return Iterables.getFirst(ServiceLoader.load(clazz), defaultInstance);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
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 @@ -160,6 +161,19 @@ 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
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
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 @@ -93,6 +94,19 @@ 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 982b808

Please sign in to comment.