Skip to content

Commit 589df4e

Browse files
authored
xds: Avoid default bootstrap when global override in XdsNameResolver
This fixes a regression with an internal API from 27d1508 where overridding the global bootstrap didn't impact parsing the default bootstrap. So if no global bootstrap was available XdsNameResolver would fail to start even though an override was in place in SharedXdsClientPoolProvider. Instead of dealing with the override in SharedXdsClientPoolProvider, do it in GrpcBootstrapperImpl so XdsNameResolver is ignorant of the source of the default bootstrap. We want all of this to go away in favor of XDS_CLIENT_SUPPLIER injection, but there needs to be some overlap for migration. cl/826085025
1 parent 89d77e0 commit 589df4e

File tree

3 files changed

+19
-16
lines changed

3 files changed

+19
-16
lines changed

xds/src/main/java/io/grpc/xds/GrpcBootstrapperImpl.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,22 @@ protected Object getImplSpecificConfig(Map<String, ?> serverConfig, String serve
100100
return getChannelCredentials(serverConfig, serverUri);
101101
}
102102

103+
@GuardedBy("GrpcBootstrapperImpl.class")
104+
private static Map<String, ?> defaultBootstrapOverride;
103105
@GuardedBy("GrpcBootstrapperImpl.class")
104106
private static BootstrapInfo defaultBootstrap;
105107

108+
static synchronized void setDefaultBootstrapOverride(Map<String, ?> rawBootstrap) {
109+
defaultBootstrapOverride = rawBootstrap;
110+
}
111+
106112
static synchronized BootstrapInfo defaultBootstrap() throws XdsInitializationException {
107113
if (defaultBootstrap == null) {
108-
defaultBootstrap = new GrpcBootstrapperImpl().bootstrap();
114+
if (defaultBootstrapOverride == null) {
115+
defaultBootstrap = new GrpcBootstrapperImpl().bootstrap();
116+
} else {
117+
defaultBootstrap = new GrpcBootstrapperImpl().bootstrap(defaultBootstrapOverride);
118+
}
109119
}
110120
return defaultBootstrap;
111121
}

xds/src/main/java/io/grpc/xds/InternalSharedXdsClientPoolProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ private InternalSharedXdsClientPoolProvider() {}
4141
*/
4242
@Deprecated
4343
public static void setDefaultProviderBootstrapOverride(Map<String, ?> bootstrap) {
44-
SharedXdsClientPoolProvider.getDefaultProvider().setBootstrapOverride(bootstrap);
44+
GrpcBootstrapperImpl.setDefaultBootstrapOverride(bootstrap);
4545
}
4646

4747
/**

xds/src/main/java/io/grpc/xds/SharedXdsClientPoolProvider.java

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
import java.util.Map;
3838
import java.util.concurrent.ConcurrentHashMap;
3939
import java.util.concurrent.ScheduledExecutorService;
40-
import java.util.concurrent.atomic.AtomicReference;
4140
import java.util.logging.Level;
4241
import java.util.logging.Logger;
4342
import javax.annotation.Nullable;
@@ -55,29 +54,24 @@ final class SharedXdsClientPoolProvider implements XdsClientPoolFactory {
5554
private static final ExponentialBackoffPolicy.Provider BACKOFF_POLICY_PROVIDER =
5655
new ExponentialBackoffPolicy.Provider();
5756

57+
@Nullable
5858
private final Bootstrapper bootstrapper;
5959
private final Object lock = new Object();
60-
private final AtomicReference<Map<String, ?>> bootstrapOverride = new AtomicReference<>();
6160
private final Map<String, ObjectPool<XdsClient>> targetToXdsClientMap = new ConcurrentHashMap<>();
6261

6362
SharedXdsClientPoolProvider() {
64-
this(new GrpcBootstrapperImpl());
63+
this(null);
6564
}
6665

6766
@VisibleForTesting
68-
SharedXdsClientPoolProvider(Bootstrapper bootstrapper) {
69-
this.bootstrapper = checkNotNull(bootstrapper, "bootstrapper");
67+
SharedXdsClientPoolProvider(@Nullable Bootstrapper bootstrapper) {
68+
this.bootstrapper = bootstrapper;
7069
}
7170

7271
static SharedXdsClientPoolProvider getDefaultProvider() {
7372
return SharedXdsClientPoolProviderHolder.instance;
7473
}
7574

76-
@Deprecated
77-
public void setBootstrapOverride(Map<String, ?> bootstrap) {
78-
bootstrapOverride.set(bootstrap);
79-
}
80-
8175
@Override
8276
@Nullable
8377
public ObjectPool<XdsClient> get(String target) {
@@ -89,11 +83,10 @@ public ObjectPool<XdsClient> getOrCreate(
8983
String target, MetricRecorder metricRecorder, CallCredentials transportCallCredentials)
9084
throws XdsInitializationException {
9185
BootstrapInfo bootstrapInfo;
92-
Map<String, ?> rawBootstrap = bootstrapOverride.get();
93-
if (rawBootstrap != null) {
94-
bootstrapInfo = bootstrapper.bootstrap(rawBootstrap);
95-
} else {
86+
if (bootstrapper != null) {
9687
bootstrapInfo = bootstrapper.bootstrap();
88+
} else {
89+
bootstrapInfo = GrpcBootstrapperImpl.defaultBootstrap();
9790
}
9891
return getOrCreate(target, bootstrapInfo, metricRecorder, transportCallCredentials);
9992
}

0 commit comments

Comments
 (0)