Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[backport to v1.40.x] retry changes: retry stats impl, bug fix, enable retry by default #8406

Merged
merged 4 commits into from Aug 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 28 additions & 2 deletions api/src/main/java/io/grpc/ClientStreamTracer.java
Expand Up @@ -97,11 +97,15 @@ public abstract static class InternalLimitedInfoFactory extends Factory {}
public static final class StreamInfo {
private final Attributes transportAttrs;
private final CallOptions callOptions;
private final int previousAttempts;
private final boolean isTransparentRetry;

StreamInfo(Attributes transportAttrs, CallOptions callOptions, boolean isTransparentRetry) {
StreamInfo(
Attributes transportAttrs, CallOptions callOptions, int previousAttempts,
boolean isTransparentRetry) {
this.transportAttrs = checkNotNull(transportAttrs, "transportAttrs");
this.callOptions = checkNotNull(callOptions, "callOptions");
this.previousAttempts = previousAttempts;
this.isTransparentRetry = isTransparentRetry;
}

Expand All @@ -124,6 +128,15 @@ public CallOptions getCallOptions() {
return callOptions;
}

/**
* Returns the number of preceding attempts for the RPC.
*
* @since 1.40.0
*/
public int getPreviousAttempts() {
return previousAttempts;
}

/**
* Whether the stream is a transparent retry.
*
Expand All @@ -142,6 +155,7 @@ public Builder toBuilder() {
return new Builder()
.setCallOptions(callOptions)
.setTransportAttrs(transportAttrs)
.setPreviousAttempts(previousAttempts)
.setIsTransparentRetry(isTransparentRetry);
}

Expand All @@ -159,6 +173,7 @@ public String toString() {
return MoreObjects.toStringHelper(this)
.add("transportAttrs", transportAttrs)
.add("callOptions", callOptions)
.add("previousAttempts", previousAttempts)
.add("isTransparentRetry", isTransparentRetry)
.toString();
}
Expand All @@ -171,6 +186,7 @@ public String toString() {
public static final class Builder {
private Attributes transportAttrs = Attributes.EMPTY;
private CallOptions callOptions = CallOptions.DEFAULT;
private int previousAttempts;
private boolean isTransparentRetry;

Builder() {
Expand All @@ -197,6 +213,16 @@ public Builder setCallOptions(CallOptions callOptions) {
return this;
}

/**
* Set the number of preceding attempts of the RPC.
*
* @since 1.40.0
*/
public Builder setPreviousAttempts(int previousAttempts) {
this.previousAttempts = previousAttempts;
return this;
}

/**
* Sets whether the stream is a transparent retry.
*
Expand All @@ -211,7 +237,7 @@ public Builder setIsTransparentRetry(boolean isTransparentRetry) {
* Builds a new StreamInfo.
*/
public StreamInfo build() {
return new StreamInfo(transportAttrs, callOptions, isTransparentRetry);
return new StreamInfo(transportAttrs, callOptions, previousAttempts, isTransparentRetry);
}
}
}
Expand Down
5 changes: 0 additions & 5 deletions api/src/main/java/io/grpc/ManagedChannelBuilder.java
Expand Up @@ -467,7 +467,6 @@ public T perRpcBufferLimit(long bytes) {
* @return this
* @since 1.11.0
*/
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/3982")
public T disableRetry() {
throw new UnsupportedOperationException();
}
Expand All @@ -479,13 +478,9 @@ public T disableRetry() {
* transparent retries, which are safe for non-idempotent RPCs. Service config is ideally provided
* by the name resolver, but may also be specified via {@link #defaultServiceConfig}.
*
* <p>For the current release, this method may have a side effect that disables Census stats and
* tracing.
*
* @return this
* @since 1.11.0
*/
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/3982")
public T enableRetry() {
throw new UnsupportedOperationException();
}
Expand Down