Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/grpc/grpc-java into healt…
Browse files Browse the repository at this point in the history
…h-experiment
  • Loading branch information
YifeiZhuang committed Nov 9, 2023
2 parents fb97e94 + dfdd50b commit 1b71001
Show file tree
Hide file tree
Showing 109 changed files with 2,058 additions and 1,290 deletions.
3 changes: 2 additions & 1 deletion SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,8 @@ grpc-netty version | netty-handler version | netty-tcnative-boringssl-static ver
1.54.x-1.55.x | 4.1.87.Final | 2.0.56.Final
1.56.x | 4.1.87.Final | 2.0.61.Final
1.57.x-1.58.x | 4.1.93.Final | 2.0.61.Final
1.59.x- | 4.1.97.Final | 2.0.61.Final
1.59.x | 4.1.97.Final | 2.0.61.Final
1.60.x- | 4.1.100.Final | 2.0.61.Final

_(grpc-netty-shaded avoids issues with keeping these versions in sync.)_

Expand Down
4 changes: 0 additions & 4 deletions alts/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,6 @@ configureProtoCompilation()
import net.ltgt.gradle.errorprone.CheckSeverity

[tasks.named("compileJava"), tasks.named("compileTestJava")]*.configure {
// protobuf calls valueof. Will be fixed in next release (google/protobuf#4046)
options.compilerArgs += [
"-Xlint:-deprecation"
]
// ALTS returns a lot of futures that we mostly don't care about.
options.errorprone.check("FutureReturnValueIgnored", CheckSeverity.OFF)
}
Expand Down
4 changes: 2 additions & 2 deletions alts/src/main/java/io/grpc/alts/AltsChannelBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import com.google.common.annotations.VisibleForTesting;
import io.grpc.ExperimentalApi;
import io.grpc.ForwardingChannelBuilder;
import io.grpc.ForwardingChannelBuilder2;
import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder;
import io.grpc.internal.GrpcUtil;
Expand All @@ -32,7 +32,7 @@
* commmunication between two cloud VMs using ALTS.
*/
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/4151")
public final class AltsChannelBuilder extends ForwardingChannelBuilder<AltsChannelBuilder> {
public final class AltsChannelBuilder extends ForwardingChannelBuilder2<AltsChannelBuilder> {
private final NettyChannelBuilder delegate;
private final AltsChannelCredentials.Builder credentialsBuilder =
new AltsChannelCredentials.Builder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public static ComputeEngineChannelBuilder forAddress(String name, int port) {
}

@Override
@SuppressWarnings("deprecation") // Not extending ForwardingChannelBuilder2 to preserve ABI.
protected NettyChannelBuilder delegate() {
return delegate;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public static GoogleDefaultChannelBuilder forAddress(String name, int port) {
}

@Override
@SuppressWarnings("deprecation") // Not extending ForwardingChannelBuilder2 to preserve ABI.
protected NettyChannelBuilder delegate() {
return delegate;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioSocketChannel;
import io.netty.util.concurrent.DefaultThreadFactory;
import java.net.InetSocketAddress;
import java.util.concurrent.TimeUnit;

/**
Expand Down Expand Up @@ -57,7 +58,7 @@ public Channel create() {
EventLoopGroup eventGroup =
new NioEventLoopGroup(1, new DefaultThreadFactory("handshaker pool", true));
ManagedChannel channel = NettyChannelBuilder.forTarget(target)
.channelType(NioSocketChannel.class)
.channelType(NioSocketChannel.class, InetSocketAddress.class)
.directExecutor()
.eventLoopGroup(eventGroup)
.usePlaintext()
Expand Down
24 changes: 18 additions & 6 deletions alts/src/main/java/io/grpc/alts/internal/AltsHandshakerStub.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class AltsHandshakerStub {
private final HandshakerServiceStub serviceStub;
private final ArrayBlockingQueue<Optional<HandshakerResp>> responseQueue =
new ArrayBlockingQueue<>(1);
private final AtomicReference<String> exceptionMessage = new AtomicReference<>();
private final AtomicReference<ThrowableInfo> exceptionMessage = new AtomicReference<>();

private static final long HANDSHAKE_RPC_DEADLINE_SECS = 20;

Expand Down Expand Up @@ -72,7 +72,7 @@ public HandshakerResp send(HandshakerReq req) throws InterruptedException, IOExc
}

if (exceptionMessage.get() != null) {
throw new IOException(exceptionMessage.get());
throw new IOException(exceptionMessage.get().info, exceptionMessage.get().throwable);
} else {
throw new IOException("No handshaker response received");
}
Expand All @@ -89,7 +89,7 @@ private void createWriterIfNull() {
/** Throw exception if there is an outstanding exception. */
private void maybeThrowIoException() throws IOException {
if (exceptionMessage.get() != null) {
throw new IOException(exceptionMessage.get());
throw new IOException(exceptionMessage.get().info, exceptionMessage.get().throwable);
}
}

Expand All @@ -108,7 +108,7 @@ public void onNext(HandshakerResp resp) {
AltsHandshakerStub.this.responseQueue.add(Optional.of(resp));
} catch (IllegalStateException e) {
AltsHandshakerStub.this.exceptionMessage.compareAndSet(
null, "Received an unexpected response.");
null, new ThrowableInfo(e, "Received an unexpected response."));
AltsHandshakerStub.this.close();
}
}
Expand All @@ -117,7 +117,7 @@ public void onNext(HandshakerResp resp) {
@Override
public void onError(Throwable t) {
AltsHandshakerStub.this.exceptionMessage.compareAndSet(
null, "Received a terminating error: " + t.toString());
null, new ThrowableInfo(t, "Received a terminating error."));
// Trigger the release of any blocked send.
Optional<HandshakerResp> result = Optional.absent();
AltsHandshakerStub.this.responseQueue.offer(result);
Expand All @@ -126,10 +126,22 @@ public void onError(Throwable t) {
/** Receive the closing message from the server. */
@Override
public void onCompleted() {
AltsHandshakerStub.this.exceptionMessage.compareAndSet(null, "Response stream closed.");
AltsHandshakerStub.this.exceptionMessage.compareAndSet(
null, new ThrowableInfo(null, "Response stream closed."));
// Trigger the release of any blocked send.
Optional<HandshakerResp> result = Optional.absent();
AltsHandshakerStub.this.responseQueue.offer(result);
}
}

private static class ThrowableInfo {

private final Throwable throwable;
private final String info;

private ThrowableInfo(Throwable throwable, String info) {
this.throwable = throwable;
this.info = info;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ private void sendAndExpectError() throws InterruptedException {
fail("Exception expected");
} catch (IOException ex) {
assertThat(ex).hasMessageThat().contains("Received a terminating error");
assertThat(ex.getCause()).hasMessageThat().contains("Root cause message");
}
}

Expand Down Expand Up @@ -152,7 +153,7 @@ public void onNext(final HandshakerReq req) {
reader.onNext(resp.setOutFrames(req.getNext().getInBytes()).build());
break;
case ERROR:
reader.onError(new RuntimeException());
reader.onError(new RuntimeException("Root cause message"));
break;
case COMPLETE:
reader.onCompleted();
Expand Down
2 changes: 1 addition & 1 deletion android-interop-testing/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ android {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
compileSdkVersion 33
compileSdkVersion 34

defaultConfig {
applicationId "io.grpc.android.integrationtest"
Expand Down
3 changes: 1 addition & 2 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ android {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
compileSdkVersion 33
compileSdkVersion 34
defaultConfig {
consumerProguardFiles "proguard-rules.txt"
minSdkVersion 21
targetSdkVersion 33
versionCode 1
Expand Down
6 changes: 0 additions & 6 deletions android/proguard-rules.txt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ public AndroidChannelBuilder context(Context context) {
}

@Override
@SuppressWarnings("deprecation") // Not extending ForwardingChannelBuilder2 to preserve ABI.
protected ManagedChannelBuilder<?> delegate() {
return delegateBuilder;
}
Expand Down
21 changes: 18 additions & 3 deletions api/src/main/java/io/grpc/ForwardingChannelBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
* A {@link ManagedChannelBuilder} that delegates all its builder methods to another builder by
* default.
*
* <p>Important! Use {@link ForwardingChannelBuilder2} instead!
* <p>DEPRECATED: Use {@link ForwardingChannelBuilder2} instead!
*
* <p>This class mistakenly used {@code <T extends ForwardingChannelBuilder<T>>} which causes
* return types to be {@link ForwardingChannelBuilder} instead of {@link ManagedChannelBuilder}.
Expand All @@ -38,14 +38,29 @@
*/
public abstract class ForwardingChannelBuilder<T extends ForwardingChannelBuilder<T>>
extends ForwardingChannelBuilder2<T> {
// TODO(sergiitk): deprecate after stabilizing

/**
* The default constructor.
*/
protected ForwardingChannelBuilder() {
}


/**
* Returns the delegated {@code ManagedChannelBuilder}.
*
* <p>NOTE: this method is marked deprecated instead the class itself, so that classes extending
* {@link ForwardingChannelBuilder2} won't need class-level
* {@code @SuppressWarnings("deprecation")} annotation. Such annotation would suppress all
* deprecation warnings in all methods, inadvertently hiding any real deprecation warnings needing
* to be addressed. However, each child class is expected to implement {@code delegate()}.
* Therefore, the {@code @Deprecated} annotation is added to this method, and not to the class.
*
* @deprecated As of 1.60.0, use {@link ForwardingChannelBuilder2} instead.
*/
@Override
@Deprecated
protected abstract ManagedChannelBuilder<?> delegate();

@Override
public T directExecutor() {
delegate().directExecutor();
Expand Down
13 changes: 7 additions & 6 deletions api/src/main/java/io/grpc/LoadBalancer.java
Original file line number Diff line number Diff line change
Expand Up @@ -170,20 +170,21 @@ public void handleResolvedAddresses(ResolvedAddresses resolvedAddresses) {
* @return {@code true} if the resolved addresses were accepted. {@code false} if rejected.
* @since 1.49.0
*/
public boolean acceptResolvedAddresses(ResolvedAddresses resolvedAddresses) {
public Status acceptResolvedAddresses(ResolvedAddresses resolvedAddresses) {
if (resolvedAddresses.getAddresses().isEmpty()
&& !canHandleEmptyAddressListFromNameResolution()) {
handleNameResolutionError(Status.UNAVAILABLE.withDescription(
"NameResolver returned no usable address. addrs=" + resolvedAddresses.getAddresses()
+ ", attrs=" + resolvedAddresses.getAttributes()));
return false;
Status unavailableStatus = Status.UNAVAILABLE.withDescription(
"NameResolver returned no usable address. addrs=" + resolvedAddresses.getAddresses()
+ ", attrs=" + resolvedAddresses.getAttributes());
handleNameResolutionError(unavailableStatus);
return unavailableStatus;
} else {
if (recursionCount++ == 0) {
handleResolvedAddresses(resolvedAddresses);
}
recursionCount = 0;

return true;
return Status.OK;
}
}

Expand Down
6 changes: 3 additions & 3 deletions api/src/main/java/io/grpc/ManagedChannelRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,13 @@ ManagedChannelBuilder<?> newChannelBuilder(NameResolverRegistry nameResolverRegi
NameResolverProvider nameResolverProvider = null;
try {
URI uri = new URI(target);
nameResolverProvider = nameResolverRegistry.providers().get(uri.getScheme());
nameResolverProvider = nameResolverRegistry.getProviderForScheme(uri.getScheme());
} catch (URISyntaxException ignore) {
// bad URI found, just ignore and continue
}
if (nameResolverProvider == null) {
nameResolverProvider = nameResolverRegistry.providers().get(
nameResolverRegistry.asFactory().getDefaultScheme());
nameResolverProvider = nameResolverRegistry.getProviderForScheme(
nameResolverRegistry.getDefaultScheme());
}
Collection<Class<? extends SocketAddress>> nameResolverSocketAddressTypes
= (nameResolverProvider != null)
Expand Down
2 changes: 1 addition & 1 deletion api/src/main/java/io/grpc/NameResolverProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ protected String getScheme() {
*
* @return the {@link SocketAddress} types this provider's name-resolver is capable of producing.
*/
protected Collection<Class<? extends SocketAddress>> getProducedSocketAddressTypes() {
public Collection<Class<? extends SocketAddress>> getProducedSocketAddressTypes() {
return Collections.singleton(InetSocketAddress.class);
}
}
20 changes: 12 additions & 8 deletions api/src/main/java/io/grpc/NameResolverRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,16 @@ public final class NameResolverRegistry {
@GuardedBy("this")
private ImmutableMap<String, NameResolverProvider> effectiveProviders = ImmutableMap.of();

public synchronized String getDefaultScheme() {
return defaultScheme;
}

public NameResolverProvider getProviderForScheme(String scheme) {
if (scheme == null) {
return null;
}
return providers().get(scheme.toLowerCase(Locale.US));
}

/**
* Register a provider.
Expand Down Expand Up @@ -163,19 +173,13 @@ private final class NameResolverFactory extends NameResolver.Factory {
@Override
@Nullable
public NameResolver newNameResolver(URI targetUri, NameResolver.Args args) {
String scheme = targetUri.getScheme();
if (scheme == null) {
return null;
}
NameResolverProvider provider = providers().get(scheme.toLowerCase(Locale.US));
NameResolverProvider provider = getProviderForScheme(targetUri.getScheme());
return provider == null ? null : provider.newNameResolver(targetUri, args);
}

@Override
public String getDefaultScheme() {
synchronized (NameResolverRegistry.this) {
return defaultScheme;
}
return NameResolverRegistry.this.getDefaultScheme();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public class ForwardingChannelBuilderTest {

private final class TestBuilder extends ForwardingChannelBuilder<TestBuilder> {
@Override
@SuppressWarnings("deprecation")
protected ManagedChannelBuilder<?> delegate() {
return mockDelegate;
}
Expand Down
4 changes: 2 additions & 2 deletions api/src/test/java/io/grpc/LoadBalancerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,9 @@ public void handleResolvedAddresses_delegatesToAcceptResolvedAddresses() {

LoadBalancer balancer = new LoadBalancer() {
@Override
public boolean acceptResolvedAddresses(ResolvedAddresses resolvedAddresses) {
public Status acceptResolvedAddresses(ResolvedAddresses resolvedAddresses) {
resultCapture.set(resolvedAddresses);
return true;
return Status.OK;
}

@Override
Expand Down
Loading

0 comments on commit 1b71001

Please sign in to comment.