27
27
28
28
import com .google .common .annotations .VisibleForTesting ;
29
29
import com .google .common .base .MoreObjects ;
30
- import com .google .common .base .Objects ;
31
30
import com .google .common .base .Stopwatch ;
32
31
import com .google .common .base .Supplier ;
33
32
import com .google .common .util .concurrent .ListenableFuture ;
@@ -130,10 +129,8 @@ final class ManagedChannelImpl extends ManagedChannel implements
130
129
static final Status SUBCHANNEL_SHUTDOWN_STATUS =
131
130
Status .UNAVAILABLE .withDescription ("Subchannel shutdown invoked" );
132
131
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 ();
137
134
138
135
private final InternalLogId logId ;
139
136
private final String target ;
@@ -254,9 +251,9 @@ public void uncaughtException(Thread t, Throwable e) {
254
251
private ResolutionState lastResolutionState = ResolutionState .NO_RESOLUTION ;
255
252
// Must be mutated and read from constructor or syncContext
256
253
// used for channel tracing when value changed
257
- private ServiceConfigHolder lastServiceConfig = EMPTY_SERVICE_CONFIG ;
254
+ private ManagedChannelServiceConfig lastServiceConfig = EMPTY_SERVICE_CONFIG ;
258
255
@ Nullable
259
- private final ServiceConfigHolder defaultServiceConfig ;
256
+ private final ManagedChannelServiceConfig defaultServiceConfig ;
260
257
// Must be mutated and read from constructor or syncContext
261
258
private boolean serviceConfigUpdated = false ;
262
259
private final boolean lookUpServiceConfig ;
@@ -503,7 +500,7 @@ public <ReqT> ClientStream newRetriableStream(
503
500
final Metadata headers ,
504
501
final Context context ) {
505
502
checkState (retryEnabled , "retry should be enabled" );
506
- final Throttle throttle = lastServiceConfig .managedChannelServiceConfig . getRetryThrottling ();
503
+ final Throttle throttle = lastServiceConfig .getRetryThrottling ();
507
504
final class RetryStream extends RetriableStream <ReqT > {
508
505
RetryStream () {
509
506
super (
@@ -622,9 +619,7 @@ public void execute(Runnable command) {
622
619
"Default config is invalid: %s" ,
623
620
parsedDefaultServiceConfig .getError ());
624
621
this .defaultServiceConfig =
625
- new ServiceConfigHolder (
626
- builder .defaultServiceConfig ,
627
- (ManagedChannelServiceConfig ) parsedDefaultServiceConfig .getConfig ());
622
+ (ManagedChannelServiceConfig ) parsedDefaultServiceConfig .getConfig ();
628
623
this .lastServiceConfig = this .defaultServiceConfig ;
629
624
} else {
630
625
this .defaultServiceConfig = null ;
@@ -683,7 +678,7 @@ public CallTracer create() {
683
678
// May only be called in constructor or syncContext
684
679
private void handleServiceConfigUpdate () {
685
680
serviceConfigUpdated = true ;
686
- serviceConfigInterceptor .handleUpdate (lastServiceConfig . managedChannelServiceConfig );
681
+ serviceConfigInterceptor .handleUpdate (lastServiceConfig );
687
682
}
688
683
689
684
@ VisibleForTesting
@@ -1322,13 +1317,16 @@ private final class NameResolverListener extends NameResolver.Listener2 {
1322
1317
public void onResult (final ResolutionResult resolutionResult ) {
1323
1318
final class NamesResolved implements Runnable {
1324
1319
1325
- @ SuppressWarnings ({ "ReferenceEquality" , "deprecation" } )
1320
+ @ SuppressWarnings ("ReferenceEquality" )
1326
1321
@ Override
1327
1322
public void run () {
1323
+
1328
1324
List <EquivalentAddressGroup > servers = resolutionResult .getAddresses ();
1329
- Attributes attrs = resolutionResult .getAttributes ();
1330
1325
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 ());
1332
1330
ResolutionState lastResolutionStateCopy = lastResolutionState ;
1333
1331
1334
1332
if (lastResolutionState != ResolutionState .SUCCESS ) {
@@ -1338,19 +1336,13 @@ public void run() {
1338
1336
1339
1337
nameResolverBackoffPolicy = null ;
1340
1338
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 ;
1352
1344
1353
- ServiceConfigHolder effectiveServiceConfig ;
1345
+ ManagedChannelServiceConfig effectiveServiceConfig ;
1354
1346
if (!lookUpServiceConfig ) {
1355
1347
if (validServiceConfig != null ) {
1356
1348
channelLogger .log (
@@ -1359,7 +1351,6 @@ public void run() {
1359
1351
}
1360
1352
effectiveServiceConfig =
1361
1353
defaultServiceConfig == null ? EMPTY_SERVICE_CONFIG : defaultServiceConfig ;
1362
- attrs = attrs .toBuilder ().discard (GrpcAttributes .NAME_RESOLVER_SERVICE_CONFIG ).build ();
1363
1354
} else {
1364
1355
// Try to use config if returned from name resolver
1365
1356
// Otherwise, try to use the default config if available
@@ -1405,31 +1396,24 @@ public void run() {
1405
1396
}
1406
1397
}
1407
1398
1399
+ Attributes effectiveAttrs = resolutionResult .getAttributes ();
1408
1400
// Call LB only if it's not shutdown. If LB is shutdown, lbHelper won't match.
1409
1401
if (NameResolverListener .this .helper == ManagedChannelImpl .this .lbHelper ) {
1410
- Attributes effectiveAttrs = attrs ;
1411
1402
if (effectiveServiceConfig != validServiceConfig ) {
1412
- Attributes .Builder attrsBuilder = attrs .toBuilder ();
1413
- attrsBuilder .set (
1414
- GrpcAttributes .NAME_RESOLVER_SERVICE_CONFIG ,
1415
- effectiveServiceConfig .rawServiceConfig );
1416
1403
Map <String , ?> healthCheckingConfig =
1417
- effectiveServiceConfig
1418
- .managedChannelServiceConfig
1419
- .getHealthCheckingConfig ();
1404
+ effectiveServiceConfig .getHealthCheckingConfig ();
1420
1405
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 ();
1423
1409
}
1424
- effectiveAttrs = attrsBuilder .build ();
1425
1410
}
1426
1411
1427
1412
Status handleResult = helper .lb .tryHandleResolvedAddresses (
1428
1413
ResolvedAddresses .newBuilder ()
1429
1414
.setAddresses (servers )
1430
1415
.setAttributes (effectiveAttrs )
1431
- .setLoadBalancingPolicyConfig (
1432
- effectiveServiceConfig .managedChannelServiceConfig .getLoadBalancingConfig ())
1416
+ .setLoadBalancingPolicyConfig (effectiveServiceConfig .getLoadBalancingConfig ())
1433
1417
.build ());
1434
1418
1435
1419
if (!handleResult .isOk ()) {
@@ -1979,45 +1963,4 @@ enum ResolutionState {
1979
1963
SUCCESS ,
1980
1964
ERROR
1981
1965
}
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
- }
2023
1966
}
0 commit comments