Skip to content

Commit 8f6ad67

Browse files
authored
all: remove deprecated internal attribute NAME_RESOLVER_SERVICE_CONFIG (#6705)
1 parent 0fd4975 commit 8f6ad67

File tree

7 files changed

+31
-212
lines changed

7 files changed

+31
-212
lines changed

core/src/main/java/io/grpc/internal/DnsNameResolver.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,8 +318,6 @@ public void run() {
318318
ConfigOrError parsedServiceConfig =
319319
serviceConfigParser.parseServiceConfig(verifiedRawServiceConfig);
320320
resultBuilder.setServiceConfig(parsedServiceConfig);
321-
attributesBuilder
322-
.set(GrpcAttributes.NAME_RESOLVER_SERVICE_CONFIG, verifiedRawServiceConfig);
323321
}
324322
} else {
325323
logger.log(Level.FINE, "No TXT records found for {0}", new Object[]{host});

core/src/main/java/io/grpc/internal/GrpcAttributes.java

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,11 @@
2222
import io.grpc.NameResolver;
2323
import io.grpc.SecurityLevel;
2424
import java.util.List;
25-
import java.util.Map;
2625

2726
/**
2827
* Special attributes that are only useful to gRPC.
2928
*/
3029
public final class GrpcAttributes {
31-
/**
32-
* Attribute key for service config.
33-
*
34-
* <p>Deprecated: all users should migrate to parsed config {@link ManagedChannelServiceConfig}.
35-
*/
36-
@Deprecated
37-
@NameResolver.ResolutionResultAttr
38-
public static final Attributes.Key<Map<String, ?>> NAME_RESOLVER_SERVICE_CONFIG =
39-
Attributes.Key.create("service-config");
40-
4130
/**
4231
* Attribute key for gRPC LB server addresses.
4332
*

core/src/main/java/io/grpc/internal/ManagedChannelImpl.java

Lines changed: 25 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727

2828
import com.google.common.annotations.VisibleForTesting;
2929
import com.google.common.base.MoreObjects;
30-
import com.google.common.base.Objects;
3130
import com.google.common.base.Stopwatch;
3231
import com.google.common.base.Supplier;
3332
import com.google.common.util.concurrent.ListenableFuture;
@@ -130,10 +129,8 @@ final class ManagedChannelImpl extends ManagedChannel implements
130129
static final Status SUBCHANNEL_SHUTDOWN_STATUS =
131130
Status.UNAVAILABLE.withDescription("Subchannel shutdown invoked");
132131

133-
private static final ServiceConfigHolder EMPTY_SERVICE_CONFIG =
134-
new ServiceConfigHolder(
135-
Collections.<String, Object>emptyMap(),
136-
ManagedChannelServiceConfig.empty());
132+
private static final ManagedChannelServiceConfig EMPTY_SERVICE_CONFIG =
133+
ManagedChannelServiceConfig.empty();
137134

138135
private final InternalLogId logId;
139136
private final String target;
@@ -254,9 +251,9 @@ public void uncaughtException(Thread t, Throwable e) {
254251
private ResolutionState lastResolutionState = ResolutionState.NO_RESOLUTION;
255252
// Must be mutated and read from constructor or syncContext
256253
// used for channel tracing when value changed
257-
private ServiceConfigHolder lastServiceConfig = EMPTY_SERVICE_CONFIG;
254+
private ManagedChannelServiceConfig lastServiceConfig = EMPTY_SERVICE_CONFIG;
258255
@Nullable
259-
private final ServiceConfigHolder defaultServiceConfig;
256+
private final ManagedChannelServiceConfig defaultServiceConfig;
260257
// Must be mutated and read from constructor or syncContext
261258
private boolean serviceConfigUpdated = false;
262259
private final boolean lookUpServiceConfig;
@@ -503,7 +500,7 @@ public <ReqT> ClientStream newRetriableStream(
503500
final Metadata headers,
504501
final Context context) {
505502
checkState(retryEnabled, "retry should be enabled");
506-
final Throttle throttle = lastServiceConfig.managedChannelServiceConfig.getRetryThrottling();
503+
final Throttle throttle = lastServiceConfig.getRetryThrottling();
507504
final class RetryStream extends RetriableStream<ReqT> {
508505
RetryStream() {
509506
super(
@@ -622,9 +619,7 @@ public void execute(Runnable command) {
622619
"Default config is invalid: %s",
623620
parsedDefaultServiceConfig.getError());
624621
this.defaultServiceConfig =
625-
new ServiceConfigHolder(
626-
builder.defaultServiceConfig,
627-
(ManagedChannelServiceConfig) parsedDefaultServiceConfig.getConfig());
622+
(ManagedChannelServiceConfig) parsedDefaultServiceConfig.getConfig();
628623
this.lastServiceConfig = this.defaultServiceConfig;
629624
} else {
630625
this.defaultServiceConfig = null;
@@ -683,7 +678,7 @@ public CallTracer create() {
683678
// May only be called in constructor or syncContext
684679
private void handleServiceConfigUpdate() {
685680
serviceConfigUpdated = true;
686-
serviceConfigInterceptor.handleUpdate(lastServiceConfig.managedChannelServiceConfig);
681+
serviceConfigInterceptor.handleUpdate(lastServiceConfig);
687682
}
688683

689684
@VisibleForTesting
@@ -1322,13 +1317,16 @@ private final class NameResolverListener extends NameResolver.Listener2 {
13221317
public void onResult(final ResolutionResult resolutionResult) {
13231318
final class NamesResolved implements Runnable {
13241319

1325-
@SuppressWarnings({"ReferenceEquality", "deprecation"})
1320+
@SuppressWarnings("ReferenceEquality")
13261321
@Override
13271322
public void run() {
1323+
13281324
List<EquivalentAddressGroup> servers = resolutionResult.getAddresses();
1329-
Attributes attrs = resolutionResult.getAttributes();
13301325
channelLogger.log(
1331-
ChannelLogLevel.DEBUG, "Resolved address: {0}, config={1}", servers, attrs);
1326+
ChannelLogLevel.DEBUG,
1327+
"Resolved address: {0}, config={1}",
1328+
servers,
1329+
resolutionResult.getAttributes());
13321330
ResolutionState lastResolutionStateCopy = lastResolutionState;
13331331

13341332
if (lastResolutionState != ResolutionState.SUCCESS) {
@@ -1338,19 +1336,13 @@ public void run() {
13381336

13391337
nameResolverBackoffPolicy = null;
13401338
ConfigOrError configOrError = resolutionResult.getServiceConfig();
1341-
ServiceConfigHolder validServiceConfig = null;
1342-
Status serviceConfigError = null;
1343-
if (configOrError != null) {
1344-
Map<String, ?> rawServiceConfig =
1345-
resolutionResult.getAttributes().get(GrpcAttributes.NAME_RESOLVER_SERVICE_CONFIG);
1346-
validServiceConfig = configOrError.getConfig() == null
1347-
? null
1348-
: new ServiceConfigHolder(
1349-
rawServiceConfig, (ManagedChannelServiceConfig) configOrError.getConfig());
1350-
serviceConfigError = configOrError.getError();
1351-
}
1339+
ManagedChannelServiceConfig validServiceConfig =
1340+
configOrError != null && configOrError.getConfig() != null
1341+
? (ManagedChannelServiceConfig) resolutionResult.getServiceConfig().getConfig()
1342+
: null;
1343+
Status serviceConfigError = configOrError != null ? configOrError.getError() : null;
13521344

1353-
ServiceConfigHolder effectiveServiceConfig;
1345+
ManagedChannelServiceConfig effectiveServiceConfig;
13541346
if (!lookUpServiceConfig) {
13551347
if (validServiceConfig != null) {
13561348
channelLogger.log(
@@ -1359,7 +1351,6 @@ public void run() {
13591351
}
13601352
effectiveServiceConfig =
13611353
defaultServiceConfig == null ? EMPTY_SERVICE_CONFIG : defaultServiceConfig;
1362-
attrs = attrs.toBuilder().discard(GrpcAttributes.NAME_RESOLVER_SERVICE_CONFIG).build();
13631354
} else {
13641355
// Try to use config if returned from name resolver
13651356
// Otherwise, try to use the default config if available
@@ -1405,31 +1396,24 @@ public void run() {
14051396
}
14061397
}
14071398

1399+
Attributes effectiveAttrs = resolutionResult.getAttributes();
14081400
// Call LB only if it's not shutdown. If LB is shutdown, lbHelper won't match.
14091401
if (NameResolverListener.this.helper == ManagedChannelImpl.this.lbHelper) {
1410-
Attributes effectiveAttrs = attrs;
14111402
if (effectiveServiceConfig != validServiceConfig) {
1412-
Attributes.Builder attrsBuilder = attrs.toBuilder();
1413-
attrsBuilder.set(
1414-
GrpcAttributes.NAME_RESOLVER_SERVICE_CONFIG,
1415-
effectiveServiceConfig.rawServiceConfig);
14161403
Map<String, ?> healthCheckingConfig =
1417-
effectiveServiceConfig
1418-
.managedChannelServiceConfig
1419-
.getHealthCheckingConfig();
1404+
effectiveServiceConfig.getHealthCheckingConfig();
14201405
if (healthCheckingConfig != null) {
1421-
attrsBuilder
1422-
.set(LoadBalancer.ATTR_HEALTH_CHECKING_CONFIG, healthCheckingConfig);
1406+
effectiveAttrs = effectiveAttrs.toBuilder()
1407+
.set(LoadBalancer.ATTR_HEALTH_CHECKING_CONFIG, healthCheckingConfig)
1408+
.build();
14231409
}
1424-
effectiveAttrs = attrsBuilder.build();
14251410
}
14261411

14271412
Status handleResult = helper.lb.tryHandleResolvedAddresses(
14281413
ResolvedAddresses.newBuilder()
14291414
.setAddresses(servers)
14301415
.setAttributes(effectiveAttrs)
1431-
.setLoadBalancingPolicyConfig(
1432-
effectiveServiceConfig.managedChannelServiceConfig.getLoadBalancingConfig())
1416+
.setLoadBalancingPolicyConfig(effectiveServiceConfig.getLoadBalancingConfig())
14331417
.build());
14341418

14351419
if (!handleResult.isOk()) {
@@ -1979,45 +1963,4 @@ enum ResolutionState {
19791963
SUCCESS,
19801964
ERROR
19811965
}
1982-
1983-
// TODO(creamsoup) remove this class when AutoConfiguredLoadBalancerFactory doesn't require raw
1984-
// service config.
1985-
private static final class ServiceConfigHolder {
1986-
Map<String, ?> rawServiceConfig;
1987-
ManagedChannelServiceConfig managedChannelServiceConfig;
1988-
1989-
ServiceConfigHolder(
1990-
Map<String, ?> rawServiceConfig, ManagedChannelServiceConfig managedChannelServiceConfig) {
1991-
this.rawServiceConfig = checkNotNull(rawServiceConfig, "rawServiceConfig");
1992-
this.managedChannelServiceConfig =
1993-
checkNotNull(managedChannelServiceConfig, "managedChannelServiceConfig");
1994-
}
1995-
1996-
@Override
1997-
public boolean equals(Object o) {
1998-
if (this == o) {
1999-
return true;
2000-
}
2001-
if (o == null || getClass() != o.getClass()) {
2002-
return false;
2003-
}
2004-
ServiceConfigHolder that = (ServiceConfigHolder) o;
2005-
return Objects.equal(rawServiceConfig, that.rawServiceConfig)
2006-
&& Objects
2007-
.equal(managedChannelServiceConfig, that.managedChannelServiceConfig);
2008-
}
2009-
2010-
@Override
2011-
public int hashCode() {
2012-
return Objects.hashCode(rawServiceConfig, managedChannelServiceConfig);
2013-
}
2014-
2015-
@Override
2016-
public String toString() {
2017-
return MoreObjects.toStringHelper(this)
2018-
.add("rawServiceConfig", rawServiceConfig)
2019-
.add("managedChannelServiceConfig", managedChannelServiceConfig)
2020-
.toString();
2021-
}
2022-
}
20231966
}

0 commit comments

Comments
 (0)