grpc 1.21.0 → 1.22.0.pre1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of grpc might be problematic. Click here for more details.

Files changed (141) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +422 -62
  3. data/include/grpc/grpc_security.h +61 -5
  4. data/include/grpc/grpc_security_constants.h +1 -1
  5. data/include/grpc/impl/codegen/gpr_types.h +1 -1
  6. data/include/grpc/slice.h +2 -2
  7. data/src/core/ext/filters/client_channel/backup_poller.cc +2 -3
  8. data/src/core/ext/filters/client_channel/backup_poller.h +5 -2
  9. data/src/core/ext/filters/client_channel/client_channel.cc +260 -122
  10. data/src/core/ext/filters/client_channel/client_channel.h +0 -8
  11. data/src/core/ext/filters/client_channel/client_channel_channelz.cc +3 -84
  12. data/src/core/ext/filters/client_channel/client_channel_channelz.h +2 -28
  13. data/src/core/ext/filters/client_channel/client_channel_plugin.cc +2 -8
  14. data/src/core/ext/filters/client_channel/health/health_check_client.cc +5 -4
  15. data/src/core/ext/filters/client_channel/lb_policy.cc +16 -2
  16. data/src/core/ext/filters/client_channel/lb_policy.h +92 -98
  17. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +63 -87
  18. data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.cc +6 -2
  19. data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc +35 -87
  20. data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc +18 -74
  21. data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +167 -217
  22. data/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc +216 -190
  23. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_load_balancer_api.cc +6 -2
  24. data/src/core/ext/filters/client_channel/lb_policy_factory.h +1 -1
  25. data/src/core/ext/filters/client_channel/lb_policy_registry.cc +1 -1
  26. data/src/core/ext/filters/client_channel/lb_policy_registry.h +1 -1
  27. data/src/core/ext/filters/client_channel/resolver.h +1 -1
  28. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +6 -3
  29. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_windows.cc +0 -1
  30. data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc +2 -0
  31. data/src/core/ext/filters/client_channel/resolver_result_parsing.cc +8 -8
  32. data/src/core/ext/filters/client_channel/resolver_result_parsing.h +7 -7
  33. data/src/core/ext/filters/client_channel/resolving_lb_policy.cc +28 -64
  34. data/src/core/ext/filters/client_channel/resolving_lb_policy.h +4 -12
  35. data/src/core/ext/filters/client_channel/server_address.cc +4 -6
  36. data/src/core/ext/filters/client_channel/server_address.h +1 -3
  37. data/src/core/ext/filters/client_channel/service_config.cc +20 -22
  38. data/src/core/ext/filters/client_channel/service_config.h +26 -28
  39. data/src/core/ext/filters/client_channel/subchannel.cc +261 -160
  40. data/src/core/ext/filters/client_channel/subchannel.h +97 -23
  41. data/src/core/ext/filters/client_channel/subchannel_interface.h +113 -0
  42. data/src/core/ext/filters/message_size/message_size_filter.cc +12 -12
  43. data/src/core/ext/filters/message_size/message_size_filter.h +2 -2
  44. data/src/core/ext/transport/chttp2/server/chttp2_server.cc +50 -2
  45. data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +2 -2
  46. data/src/core/ext/transport/chttp2/transport/frame_data.cc +31 -36
  47. data/src/core/ext/transport/chttp2/transport/frame_rst_stream.cc +3 -2
  48. data/src/core/ext/transport/chttp2/transport/hpack_encoder.cc +71 -52
  49. data/src/core/ext/transport/chttp2/transport/hpack_parser.cc +18 -3
  50. data/src/core/ext/transport/chttp2/transport/hpack_table.cc +5 -12
  51. data/src/core/ext/transport/chttp2/transport/hpack_table.h +10 -1
  52. data/src/core/ext/transport/chttp2/transport/internal.h +3 -3
  53. data/src/core/ext/transport/chttp2/transport/parsing.cc +39 -57
  54. data/src/core/lib/channel/channelz.cc +136 -19
  55. data/src/core/lib/channel/channelz.h +36 -40
  56. data/src/core/lib/channel/channelz_registry.cc +74 -106
  57. data/src/core/lib/channel/channelz_registry.h +10 -28
  58. data/src/core/lib/channel/context.h +1 -1
  59. data/src/core/lib/channel/handshaker.cc +6 -0
  60. data/src/core/lib/compression/compression.cc +13 -8
  61. data/src/core/lib/compression/compression_internal.cc +14 -10
  62. data/src/core/lib/compression/compression_internal.h +1 -1
  63. data/src/core/lib/compression/stream_compression.cc +3 -2
  64. data/src/core/lib/compression/stream_compression.h +2 -2
  65. data/src/core/lib/compression/stream_compression_gzip.cc +9 -9
  66. data/src/core/lib/gpr/env.h +1 -1
  67. data/src/core/lib/gpr/string.cc +8 -1
  68. data/src/core/lib/gpr/string.h +6 -1
  69. data/src/core/lib/gprpp/fork.cc +1 -1
  70. data/src/core/lib/gprpp/fork.h +5 -1
  71. data/src/core/lib/gprpp/global_config.h +9 -0
  72. data/src/core/lib/gprpp/global_config_custom.h +1 -1
  73. data/src/core/lib/gprpp/inlined_vector.h +8 -0
  74. data/src/core/lib/gprpp/map.h +38 -21
  75. data/src/core/lib/gprpp/memory.h +2 -2
  76. data/src/core/lib/gprpp/orphanable.h +1 -1
  77. data/src/core/lib/gprpp/ref_counted.h +9 -4
  78. data/src/core/lib/http/httpcli.cc +3 -3
  79. data/src/core/lib/iomgr/buffer_list.h +1 -1
  80. data/src/core/lib/iomgr/call_combiner.cc +1 -1
  81. data/src/core/lib/iomgr/call_combiner.h +1 -1
  82. data/src/core/lib/iomgr/cfstream_handle.cc +3 -2
  83. data/src/core/lib/iomgr/cfstream_handle.h +4 -0
  84. data/src/core/lib/iomgr/error.cc +3 -3
  85. data/src/core/lib/iomgr/error.h +9 -3
  86. data/src/core/lib/iomgr/error_internal.h +1 -1
  87. data/src/core/lib/iomgr/ev_epoll1_linux.cc +1 -1
  88. data/src/core/lib/iomgr/ev_posix.cc +3 -3
  89. data/src/core/lib/iomgr/ev_posix.h +3 -2
  90. data/src/core/lib/iomgr/ev_windows.cc +2 -2
  91. data/src/core/lib/iomgr/iomgr.cc +4 -4
  92. data/src/core/lib/iomgr/lockfree_event.cc +1 -1
  93. data/src/core/lib/iomgr/port.h +5 -1
  94. data/src/core/lib/iomgr/tcp_posix.cc +1 -3
  95. data/src/core/lib/iomgr/tcp_server.cc +5 -0
  96. data/src/core/lib/iomgr/tcp_server.h +24 -0
  97. data/src/core/lib/iomgr/tcp_server_custom.cc +11 -9
  98. data/src/core/lib/iomgr/tcp_server_posix.cc +72 -11
  99. data/src/core/lib/iomgr/tcp_server_utils_posix.h +3 -0
  100. data/src/core/lib/iomgr/tcp_server_windows.cc +11 -9
  101. data/src/core/lib/iomgr/tcp_uv.cc +5 -6
  102. data/src/core/lib/iomgr/timer.h +2 -1
  103. data/src/core/lib/iomgr/udp_server.cc +2 -2
  104. data/src/core/lib/security/credentials/plugin/plugin_credentials.cc +1 -1
  105. data/src/core/lib/security/credentials/ssl/ssl_credentials.cc +20 -2
  106. data/src/core/lib/security/credentials/ssl/ssl_credentials.h +2 -2
  107. data/src/core/lib/security/security_connector/security_connector.h +1 -1
  108. data/src/core/lib/security/security_connector/ssl/ssl_security_connector.cc +1 -1
  109. data/src/core/lib/security/transport/auth_filters.h +3 -0
  110. data/src/core/lib/security/transport/client_auth_filter.cc +13 -0
  111. data/src/core/lib/security/transport/security_handshaker.cc +7 -7
  112. data/src/core/lib/slice/b64.h +2 -2
  113. data/src/core/lib/slice/slice.cc +82 -10
  114. data/src/core/lib/slice/slice_buffer.cc +49 -21
  115. data/src/core/lib/slice/slice_hash_table.h +2 -2
  116. data/src/core/lib/slice/slice_intern.cc +15 -16
  117. data/src/core/lib/slice/slice_internal.h +52 -0
  118. data/src/core/lib/slice/slice_string_helpers.cc +10 -1
  119. data/src/core/lib/slice/slice_string_helpers.h +3 -1
  120. data/src/core/lib/slice/slice_utils.h +50 -0
  121. data/src/core/lib/slice/slice_weak_hash_table.h +2 -2
  122. data/src/core/lib/surface/call.cc +14 -8
  123. data/src/core/lib/surface/channel.cc +89 -97
  124. data/src/core/lib/surface/channel.h +60 -6
  125. data/src/core/lib/surface/completion_queue.cc +49 -36
  126. data/src/core/lib/surface/completion_queue.h +2 -1
  127. data/src/core/lib/surface/server.cc +8 -8
  128. data/src/core/lib/surface/validate_metadata.cc +14 -8
  129. data/src/core/lib/surface/validate_metadata.h +13 -2
  130. data/src/core/lib/surface/version.cc +1 -1
  131. data/src/core/lib/transport/metadata.cc +56 -26
  132. data/src/core/lib/transport/metadata.h +91 -75
  133. data/src/core/lib/transport/static_metadata.cc +262 -176
  134. data/src/core/lib/transport/static_metadata.h +272 -180
  135. data/src/core/lib/transport/transport.cc +1 -1
  136. data/src/core/lib/transport/transport.h +8 -2
  137. data/src/core/tsi/alts/handshaker/alts_shared_resource.h +1 -1
  138. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +2 -0
  139. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +5 -2
  140. data/src/ruby/lib/grpc/version.rb +1 -1
  141. metadata +37 -35
@@ -117,14 +117,16 @@ TraceFlag grpc_lb_xds_trace(false, "xds");
117
117
  namespace {
118
118
 
119
119
  constexpr char kXds[] = "xds_experimental";
120
- constexpr char kDefaultLocalityName[] = "xds_default_locality";
120
+ constexpr char kDefaultLocalityRegion[] = "xds_default_locality_region";
121
+ constexpr char kDefaultLocalityZone[] = "xds_default_locality_zone";
122
+ constexpr char kDefaultLocalitySubzone[] = "xds_default_locality_subzone";
121
123
  constexpr uint32_t kDefaultLocalityWeight = 3;
122
124
 
123
- class ParsedXdsConfig : public ParsedLoadBalancingConfig {
125
+ class ParsedXdsConfig : public LoadBalancingPolicy::Config {
124
126
  public:
125
127
  ParsedXdsConfig(const char* balancer_name,
126
- RefCountedPtr<ParsedLoadBalancingConfig> child_policy,
127
- RefCountedPtr<ParsedLoadBalancingConfig> fallback_policy)
128
+ RefCountedPtr<LoadBalancingPolicy::Config> child_policy,
129
+ RefCountedPtr<LoadBalancingPolicy::Config> fallback_policy)
128
130
  : balancer_name_(balancer_name),
129
131
  child_policy_(std::move(child_policy)),
130
132
  fallback_policy_(std::move(fallback_policy)) {}
@@ -133,18 +135,18 @@ class ParsedXdsConfig : public ParsedLoadBalancingConfig {
133
135
 
134
136
  const char* balancer_name() const { return balancer_name_; };
135
137
 
136
- RefCountedPtr<ParsedLoadBalancingConfig> child_policy() const {
138
+ RefCountedPtr<LoadBalancingPolicy::Config> child_policy() const {
137
139
  return child_policy_;
138
140
  }
139
141
 
140
- RefCountedPtr<ParsedLoadBalancingConfig> fallback_policy() const {
142
+ RefCountedPtr<LoadBalancingPolicy::Config> fallback_policy() const {
141
143
  return fallback_policy_;
142
144
  }
143
145
 
144
146
  private:
145
147
  const char* balancer_name_ = nullptr;
146
- RefCountedPtr<ParsedLoadBalancingConfig> child_policy_;
147
- RefCountedPtr<ParsedLoadBalancingConfig> fallback_policy_;
148
+ RefCountedPtr<LoadBalancingPolicy::Config> child_policy_;
149
+ RefCountedPtr<LoadBalancingPolicy::Config> fallback_policy_;
148
150
  };
149
151
 
150
152
  class XdsLb : public LoadBalancingPolicy {
@@ -155,9 +157,6 @@ class XdsLb : public LoadBalancingPolicy {
155
157
 
156
158
  void UpdateLocked(UpdateArgs args) override;
157
159
  void ResetBackoffLocked() override;
158
- void FillChildRefsForChannelz(
159
- channelz::ChildRefsList* child_subchannels,
160
- channelz::ChildRefsList* child_channels) override;
161
160
 
162
161
  private:
163
162
  struct LocalityServerlistEntry;
@@ -300,9 +299,7 @@ class XdsLb : public LoadBalancingPolicy {
300
299
  public:
301
300
  explicit PickerRef(UniquePtr<SubchannelPicker> picker)
302
301
  : picker_(std::move(picker)) {}
303
- PickResult Pick(PickArgs* pick, grpc_error** error) {
304
- return picker_->Pick(pick, error);
305
- }
302
+ PickResult Pick(PickArgs args) { return picker_->Pick(args); }
306
303
 
307
304
  private:
308
305
  UniquePtr<SubchannelPicker> picker_;
@@ -322,12 +319,11 @@ class XdsLb : public LoadBalancingPolicy {
322
319
  : client_stats_(std::move(client_stats)),
323
320
  pickers_(std::move(pickers)) {}
324
321
 
325
- PickResult Pick(PickArgs* pick, grpc_error** error) override;
322
+ PickResult Pick(PickArgs args) override;
326
323
 
327
324
  private:
328
325
  // Calls the picker of the locality that the key falls within
329
- PickResult PickFromLocality(const uint32_t key, PickArgs* pick,
330
- grpc_error** error);
326
+ PickResult PickFromLocality(const uint32_t key, PickArgs args);
331
327
  RefCountedPtr<XdsLbClientStats> client_stats_;
332
328
  PickerList pickers_;
333
329
  };
@@ -337,12 +333,16 @@ class XdsLb : public LoadBalancingPolicy {
337
333
  explicit FallbackHelper(RefCountedPtr<XdsLb> parent)
338
334
  : parent_(std::move(parent)) {}
339
335
 
340
- Subchannel* CreateSubchannel(const grpc_channel_args& args) override;
336
+ ~FallbackHelper() { parent_.reset(DEBUG_LOCATION, "FallbackHelper"); }
337
+
338
+ RefCountedPtr<SubchannelInterface> CreateSubchannel(
339
+ const grpc_channel_args& args) override;
341
340
  grpc_channel* CreateChannel(const char* target,
342
341
  const grpc_channel_args& args) override;
343
342
  void UpdateState(grpc_connectivity_state state,
344
343
  UniquePtr<SubchannelPicker> picker) override;
345
344
  void RequestReresolution() override;
345
+ void AddTraceEvent(TraceSeverity severity, const char* message) override;
346
346
 
347
347
  void set_child(LoadBalancingPolicy* child) { child_ = child; }
348
348
 
@@ -354,21 +354,61 @@ class XdsLb : public LoadBalancingPolicy {
354
354
  LoadBalancingPolicy* child_ = nullptr;
355
355
  };
356
356
 
357
+ class LocalityName : public RefCounted<LocalityName> {
358
+ public:
359
+ struct Less {
360
+ bool operator()(const RefCountedPtr<LocalityName>& lhs,
361
+ const RefCountedPtr<LocalityName>& rhs) {
362
+ int cmp_result = strcmp(lhs->region_.get(), rhs->region_.get());
363
+ if (cmp_result != 0) return cmp_result < 0;
364
+ cmp_result = strcmp(lhs->zone_.get(), rhs->zone_.get());
365
+ if (cmp_result != 0) return cmp_result < 0;
366
+ return strcmp(lhs->subzone_.get(), rhs->subzone_.get()) < 0;
367
+ }
368
+ };
369
+
370
+ LocalityName(UniquePtr<char> region, UniquePtr<char> zone,
371
+ UniquePtr<char> subzone)
372
+ : region_(std::move(region)),
373
+ zone_(std::move(zone)),
374
+ subzone_(std::move(subzone)) {}
375
+
376
+ bool operator==(const LocalityName& other) const {
377
+ return strcmp(region_.get(), other.region_.get()) == 0 &&
378
+ strcmp(zone_.get(), other.zone_.get()) == 0 &&
379
+ strcmp(subzone_.get(), other.subzone_.get()) == 0;
380
+ }
381
+
382
+ const char* AsHumanReadableString() {
383
+ if (human_readable_string_ == nullptr) {
384
+ char* tmp;
385
+ gpr_asprintf(&tmp, "{region=\"%s\", zone=\"%s\", subzone=\"%s\"}",
386
+ region_.get(), zone_.get(), subzone_.get());
387
+ human_readable_string_.reset(tmp);
388
+ }
389
+ return human_readable_string_.get();
390
+ }
391
+
392
+ private:
393
+ UniquePtr<char> region_;
394
+ UniquePtr<char> zone_;
395
+ UniquePtr<char> subzone_;
396
+ UniquePtr<char> human_readable_string_;
397
+ };
398
+
357
399
  class LocalityMap {
358
400
  public:
359
401
  class LocalityEntry : public InternallyRefCounted<LocalityEntry> {
360
402
  public:
361
- LocalityEntry(RefCountedPtr<XdsLb> parent, uint32_t locality_weight)
362
- : parent_(std::move(parent)), locality_weight_(locality_weight) {}
363
- ~LocalityEntry() = default;
403
+ LocalityEntry(RefCountedPtr<XdsLb> parent,
404
+ RefCountedPtr<LocalityName> name, uint32_t locality_weight);
405
+ ~LocalityEntry();
364
406
 
365
407
  void UpdateLocked(xds_grpclb_serverlist* serverlist,
366
- ParsedLoadBalancingConfig* child_policy_config,
408
+ LoadBalancingPolicy::Config* child_policy_config,
367
409
  const grpc_channel_args* args);
368
410
  void ShutdownLocked();
369
411
  void ResetBackoffLocked();
370
- void FillChildRefsForChannelz(channelz::ChildRefsList* child_subchannels,
371
- channelz::ChildRefsList* child_channels);
372
412
  void Orphan() override;
373
413
 
374
414
  private:
@@ -377,12 +417,17 @@ class XdsLb : public LoadBalancingPolicy {
377
417
  explicit Helper(RefCountedPtr<LocalityEntry> entry)
378
418
  : entry_(std::move(entry)) {}
379
419
 
380
- Subchannel* CreateSubchannel(const grpc_channel_args& args) override;
420
+ ~Helper() { entry_.reset(DEBUG_LOCATION, "Helper"); }
421
+
422
+ RefCountedPtr<SubchannelInterface> CreateSubchannel(
423
+ const grpc_channel_args& args) override;
381
424
  grpc_channel* CreateChannel(const char* target,
382
425
  const grpc_channel_args& args) override;
383
426
  void UpdateState(grpc_connectivity_state state,
384
427
  UniquePtr<SubchannelPicker> picker) override;
385
428
  void RequestReresolution() override;
429
+ void AddTraceEvent(TraceSeverity severity,
430
+ const char* message) override;
386
431
  void set_child(LoadBalancingPolicy* child) { child_ = child; }
387
432
 
388
433
  private:
@@ -398,40 +443,32 @@ class XdsLb : public LoadBalancingPolicy {
398
443
  grpc_channel_args* CreateChildPolicyArgsLocked(
399
444
  const grpc_channel_args* args);
400
445
 
446
+ RefCountedPtr<XdsLb> parent_;
447
+ RefCountedPtr<LocalityName> name_;
401
448
  OrphanablePtr<LoadBalancingPolicy> child_policy_;
402
449
  OrphanablePtr<LoadBalancingPolicy> pending_child_policy_;
403
- // Lock held when modifying the value of child_policy_ or
404
- // pending_child_policy_.
405
- Mutex child_policy_mu_;
406
- RefCountedPtr<XdsLb> parent_;
407
450
  RefCountedPtr<PickerRef> picker_ref_;
408
451
  grpc_connectivity_state connectivity_state_;
409
452
  uint32_t locality_weight_;
410
453
  };
411
454
 
412
455
  void UpdateLocked(const LocalityList& locality_list,
413
- ParsedLoadBalancingConfig* child_policy_config,
456
+ LoadBalancingPolicy::Config* child_policy_config,
414
457
  const grpc_channel_args* args, XdsLb* parent);
415
458
  void ShutdownLocked();
416
459
  void ResetBackoffLocked();
417
- void FillChildRefsForChannelz(channelz::ChildRefsList* child_subchannels,
418
- channelz::ChildRefsList* child_channels);
419
460
 
420
461
  private:
421
462
  void PruneLocalities(const LocalityList& locality_list);
422
- Map<UniquePtr<char>, OrphanablePtr<LocalityEntry>, StringLess> map_;
423
- // Lock held while filling child refs for all localities
424
- // inside the map
425
- Mutex child_refs_mu_;
463
+ Map<RefCountedPtr<LocalityName>, OrphanablePtr<LocalityEntry>,
464
+ LocalityName::Less>
465
+ map_;
426
466
  };
427
467
 
428
468
  struct LocalityServerlistEntry {
429
- ~LocalityServerlistEntry() {
430
- gpr_free(locality_name);
431
- xds_grpclb_destroy_serverlist(serverlist);
432
- }
469
+ ~LocalityServerlistEntry() { xds_grpclb_destroy_serverlist(serverlist); }
433
470
 
434
- char* locality_name;
471
+ RefCountedPtr<LocalityName> locality_name;
435
472
  uint32_t locality_weight;
436
473
  // The deserialized response from the balancer. May be nullptr until one
437
474
  // such response has arrived.
@@ -480,10 +517,6 @@ class XdsLb : public LoadBalancingPolicy {
480
517
  // The channel for communicating with the LB server.
481
518
  OrphanablePtr<BalancerChannelState> lb_chand_;
482
519
  OrphanablePtr<BalancerChannelState> pending_lb_chand_;
483
- // Mutex to protect the channel to the LB server. This is used when
484
- // processing a channelz request.
485
- // TODO(juanlishen): Replace this with atomic.
486
- Mutex lb_chand_mu_;
487
520
 
488
521
  // Timeout in milliseconds for the LB call. 0 means no deadline.
489
522
  int lb_call_timeout_ms_ = 0;
@@ -493,9 +526,8 @@ class XdsLb : public LoadBalancingPolicy {
493
526
  // 1. The fallback timer fires, we enter fallback mode.
494
527
  // 2. Before the fallback timer fires, the LB channel becomes
495
528
  // TRANSIENT_FAILURE or the LB call fails, we enter fallback mode.
496
- // 3. Before the fallback timer fires, we receive a response from the
497
- // balancer, we cancel the fallback timer and use the response to update the
498
- // locality map.
529
+ // 3. Before the fallback timer fires, if any child policy in the locality map
530
+ // becomes READY, we cancel the fallback timer.
499
531
  bool fallback_at_startup_checks_pending_ = false;
500
532
  // Timeout in milliseconds for before using fallback backend addresses.
501
533
  // 0 means not using fallback.
@@ -507,16 +539,13 @@ class XdsLb : public LoadBalancingPolicy {
507
539
  grpc_closure lb_on_fallback_;
508
540
 
509
541
  // The policy to use for the fallback backends.
510
- RefCountedPtr<ParsedLoadBalancingConfig> fallback_policy_config_;
511
- // Lock held when modifying the value of fallback_policy_ or
512
- // pending_fallback_policy_.
513
- Mutex fallback_policy_mu_;
542
+ RefCountedPtr<LoadBalancingPolicy::Config> fallback_policy_config_;
514
543
  // Non-null iff we are in fallback mode.
515
544
  OrphanablePtr<LoadBalancingPolicy> fallback_policy_;
516
545
  OrphanablePtr<LoadBalancingPolicy> pending_fallback_policy_;
517
546
 
518
547
  // The policy to use for the backends.
519
- RefCountedPtr<ParsedLoadBalancingConfig> child_policy_config_;
548
+ RefCountedPtr<LoadBalancingPolicy::Config> child_policy_config_;
520
549
  // Map of policies to use in the backend
521
550
  LocalityMap locality_map_;
522
551
  // TODO(mhaidry) : Add support for multiple maps of localities
@@ -531,25 +560,24 @@ class XdsLb : public LoadBalancingPolicy {
531
560
  // XdsLb::Picker
532
561
  //
533
562
 
534
- XdsLb::PickResult XdsLb::Picker::Pick(PickArgs* pick, grpc_error** error) {
563
+ XdsLb::PickResult XdsLb::Picker::Pick(PickArgs args) {
535
564
  // TODO(roth): Add support for drop handling.
536
565
  // Generate a random number between 0 and the total weight
537
566
  const uint32_t key =
538
567
  (rand() * pickers_[pickers_.size() - 1].first) / RAND_MAX;
539
568
  // Forward pick to whichever locality maps to the range in which the
540
569
  // random number falls in.
541
- PickResult result = PickFromLocality(key, pick, error);
570
+ PickResult result = PickFromLocality(key, args);
542
571
  // If pick succeeded, add client stats.
543
- if (result == PickResult::PICK_COMPLETE &&
544
- pick->connected_subchannel != nullptr && client_stats_ != nullptr) {
572
+ if (result.type == PickResult::PICK_COMPLETE &&
573
+ result.connected_subchannel != nullptr && client_stats_ != nullptr) {
545
574
  // TODO(roth): Add support for client stats.
546
575
  }
547
576
  return result;
548
577
  }
549
578
 
550
579
  XdsLb::PickResult XdsLb::Picker::PickFromLocality(const uint32_t key,
551
- PickArgs* pick,
552
- grpc_error** error) {
580
+ PickArgs args) {
553
581
  size_t mid = 0;
554
582
  size_t start_index = 0;
555
583
  size_t end_index = pickers_.size() - 1;
@@ -567,7 +595,7 @@ XdsLb::PickResult XdsLb::Picker::PickFromLocality(const uint32_t key,
567
595
  }
568
596
  if (index == 0) index = start_index;
569
597
  GPR_ASSERT(pickers_[index].first > key);
570
- return pickers_[index].second->Pick(pick, error);
598
+ return pickers_[index].second->Pick(args);
571
599
  }
572
600
 
573
601
  //
@@ -584,7 +612,7 @@ bool XdsLb::FallbackHelper::CalledByCurrentFallback() const {
584
612
  return child_ == parent_->fallback_policy_.get();
585
613
  }
586
614
 
587
- Subchannel* XdsLb::FallbackHelper::CreateSubchannel(
615
+ RefCountedPtr<SubchannelInterface> XdsLb::FallbackHelper::CreateSubchannel(
588
616
  const grpc_channel_args& args) {
589
617
  if (parent_->shutting_down_ ||
590
618
  (!CalledByPendingFallback() && !CalledByCurrentFallback())) {
@@ -619,7 +647,6 @@ void XdsLb::FallbackHelper::UpdateState(grpc_connectivity_state state,
619
647
  grpc_pollset_set_del_pollset_set(
620
648
  parent_->fallback_policy_->interested_parties(),
621
649
  parent_->interested_parties());
622
- MutexLock lock(&parent_->fallback_policy_mu_);
623
650
  parent_->fallback_policy_ = std::move(parent_->pending_fallback_policy_);
624
651
  } else if (!CalledByCurrentFallback()) {
625
652
  // This request is from an outdated fallback policy, so ignore it.
@@ -644,6 +671,15 @@ void XdsLb::FallbackHelper::RequestReresolution() {
644
671
  parent_->channel_control_helper()->RequestReresolution();
645
672
  }
646
673
 
674
+ void XdsLb::FallbackHelper::AddTraceEvent(TraceSeverity severity,
675
+ const char* message) {
676
+ if (parent_->shutting_down_ ||
677
+ (!CalledByPendingFallback() && !CalledByCurrentFallback())) {
678
+ return;
679
+ }
680
+ parent_->channel_control_helper()->AddTraceEvent(severity, message);
681
+ }
682
+
647
683
  //
648
684
  // serverlist parsing code
649
685
  //
@@ -723,7 +759,7 @@ ServerAddressList ProcessServerlist(const xds_grpclb_serverlist* serverlist) {
723
759
 
724
760
  XdsLb::BalancerChannelState::BalancerChannelState(
725
761
  const char* balancer_name, const grpc_channel_args& args,
726
- grpc_core::RefCountedPtr<grpc_core::XdsLb> parent_xdslb_policy)
762
+ RefCountedPtr<XdsLb> parent_xdslb_policy)
727
763
  : InternallyRefCounted<BalancerChannelState>(&grpc_lb_xds_trace),
728
764
  xdslb_policy_(std::move(parent_xdslb_policy)),
729
765
  lb_call_backoff_(
@@ -743,6 +779,7 @@ XdsLb::BalancerChannelState::BalancerChannelState(
743
779
  }
744
780
 
745
781
  XdsLb::BalancerChannelState::~BalancerChannelState() {
782
+ xdslb_policy_.reset(DEBUG_LOCATION, "BalancerChannelState");
746
783
  grpc_channel_destroy(channel_);
747
784
  }
748
785
 
@@ -1197,15 +1234,15 @@ void XdsLb::BalancerChannelState::BalancerCallState::
1197
1234
  xds_grpclb_destroy_serverlist(
1198
1235
  xdslb_policy->locality_serverlist_[0]->serverlist);
1199
1236
  } else {
1200
- // This is the first serverlist we've received, don't enter fallback
1201
- // mode.
1202
- xdslb_policy->MaybeCancelFallbackAtStartupChecks();
1203
1237
  // Initialize locality serverlist, currently the list only handles
1204
1238
  // one child.
1205
1239
  xdslb_policy->locality_serverlist_.emplace_back(
1206
1240
  MakeUnique<LocalityServerlistEntry>());
1207
1241
  xdslb_policy->locality_serverlist_[0]->locality_name =
1208
- static_cast<char*>(gpr_strdup(kDefaultLocalityName));
1242
+ MakeRefCounted<LocalityName>(
1243
+ UniquePtr<char>(gpr_strdup(kDefaultLocalityRegion)),
1244
+ UniquePtr<char>(gpr_strdup(kDefaultLocalityZone)),
1245
+ UniquePtr<char>(gpr_strdup(kDefaultLocalitySubzone)));
1209
1246
  xdslb_policy->locality_serverlist_[0]->locality_weight =
1210
1247
  kDefaultLocalityWeight;
1211
1248
  }
@@ -1336,21 +1373,29 @@ grpc_channel_args* BuildBalancerChannelArgs(const grpc_channel_args* args) {
1336
1373
  // treated as a stand-alone channel and not inherit this argument from the
1337
1374
  // args of the parent channel.
1338
1375
  GRPC_SSL_TARGET_NAME_OVERRIDE_ARG,
1376
+ // Don't want to pass down channelz node from parent; the balancer
1377
+ // channel will get its own.
1378
+ GRPC_ARG_CHANNELZ_CHANNEL_NODE,
1339
1379
  };
1340
1380
  // Channel args to add.
1341
- const grpc_arg args_to_add[] = {
1342
- // A channel arg indicating the target is a xds load balancer.
1343
- grpc_channel_arg_integer_create(
1344
- const_cast<char*>(GRPC_ARG_ADDRESS_IS_XDS_LOAD_BALANCER), 1),
1345
- // A channel arg indicating this is an internal channels, aka it is
1346
- // owned by components in Core, not by the user application.
1347
- grpc_channel_arg_integer_create(
1348
- const_cast<char*>(GRPC_ARG_CHANNELZ_CHANNEL_IS_INTERNAL_CHANNEL), 1),
1349
- };
1381
+ InlinedVector<grpc_arg, 2> args_to_add;
1382
+ // A channel arg indicating the target is a xds load balancer.
1383
+ args_to_add.emplace_back(grpc_channel_arg_integer_create(
1384
+ const_cast<char*>(GRPC_ARG_ADDRESS_IS_XDS_LOAD_BALANCER), 1));
1385
+ // The parent channel's channelz uuid.
1386
+ channelz::ChannelNode* channelz_node = nullptr;
1387
+ const grpc_arg* arg =
1388
+ grpc_channel_args_find(args, GRPC_ARG_CHANNELZ_CHANNEL_NODE);
1389
+ if (arg != nullptr && arg->type == GRPC_ARG_POINTER &&
1390
+ arg->value.pointer.p != nullptr) {
1391
+ channelz_node = static_cast<channelz::ChannelNode*>(arg->value.pointer.p);
1392
+ args_to_add.emplace_back(
1393
+ channelz::MakeParentUuidArg(channelz_node->uuid()));
1394
+ }
1350
1395
  // Construct channel args.
1351
1396
  grpc_channel_args* new_args = grpc_channel_args_copy_and_add_and_remove(
1352
- args, args_to_remove, GPR_ARRAY_SIZE(args_to_remove), args_to_add,
1353
- GPR_ARRAY_SIZE(args_to_add));
1397
+ args, args_to_remove, GPR_ARRAY_SIZE(args_to_remove), args_to_add.data(),
1398
+ args_to_add.size());
1354
1399
  // Make any necessary modifications for security.
1355
1400
  return grpc_lb_policy_xds_modify_lb_channel_args(new_args);
1356
1401
  }
@@ -1386,12 +1431,18 @@ XdsLb::XdsLb(Args args)
1386
1431
  }
1387
1432
 
1388
1433
  XdsLb::~XdsLb() {
1434
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_xds_trace)) {
1435
+ gpr_log(GPR_INFO, "[xdslb %p] destroying xds LB policy", this);
1436
+ }
1389
1437
  gpr_free((void*)server_name_);
1390
1438
  grpc_channel_args_destroy(args_);
1391
1439
  locality_serverlist_.clear();
1392
1440
  }
1393
1441
 
1394
1442
  void XdsLb::ShutdownLocked() {
1443
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_xds_trace)) {
1444
+ gpr_log(GPR_INFO, "[xdslb %p] shutting down", this);
1445
+ }
1395
1446
  shutting_down_ = true;
1396
1447
  if (fallback_at_startup_checks_pending_) {
1397
1448
  grpc_timer_cancel(&lb_fallback_timer_);
@@ -1405,18 +1456,12 @@ void XdsLb::ShutdownLocked() {
1405
1456
  grpc_pollset_set_del_pollset_set(
1406
1457
  pending_fallback_policy_->interested_parties(), interested_parties());
1407
1458
  }
1408
- {
1409
- MutexLock lock(&fallback_policy_mu_);
1410
- fallback_policy_.reset();
1411
- pending_fallback_policy_.reset();
1412
- }
1459
+ fallback_policy_.reset();
1460
+ pending_fallback_policy_.reset();
1413
1461
  // We reset the LB channels here instead of in our destructor because they
1414
1462
  // hold refs to XdsLb.
1415
- {
1416
- MutexLock lock(&lb_chand_mu_);
1417
- lb_chand_.reset();
1418
- pending_lb_chand_.reset();
1419
- }
1463
+ lb_chand_.reset();
1464
+ pending_lb_chand_.reset();
1420
1465
  }
1421
1466
 
1422
1467
  //
@@ -1439,40 +1484,6 @@ void XdsLb::ResetBackoffLocked() {
1439
1484
  }
1440
1485
  }
1441
1486
 
1442
- void XdsLb::FillChildRefsForChannelz(channelz::ChildRefsList* child_subchannels,
1443
- channelz::ChildRefsList* child_channels) {
1444
- // Delegate to the locality_map_ to fill the children subchannels.
1445
- locality_map_.FillChildRefsForChannelz(child_subchannels, child_channels);
1446
- {
1447
- // This must be done holding fallback_policy_mu_, since this method does not
1448
- // run in the combiner.
1449
- MutexLock lock(&fallback_policy_mu_);
1450
- if (fallback_policy_ != nullptr) {
1451
- fallback_policy_->FillChildRefsForChannelz(child_subchannels,
1452
- child_channels);
1453
- }
1454
- if (pending_fallback_policy_ != nullptr) {
1455
- pending_fallback_policy_->FillChildRefsForChannelz(child_subchannels,
1456
- child_channels);
1457
- }
1458
- }
1459
- MutexLock lock(&lb_chand_mu_);
1460
- if (lb_chand_ != nullptr) {
1461
- grpc_core::channelz::ChannelNode* channel_node =
1462
- grpc_channel_get_channelz_node(lb_chand_->channel());
1463
- if (channel_node != nullptr) {
1464
- child_channels->push_back(channel_node->uuid());
1465
- }
1466
- }
1467
- if (pending_lb_chand_ != nullptr) {
1468
- grpc_core::channelz::ChannelNode* channel_node =
1469
- grpc_channel_get_channelz_node(pending_lb_chand_->channel());
1470
- if (channel_node != nullptr) {
1471
- child_channels->push_back(channel_node->uuid());
1472
- }
1473
- }
1474
- }
1475
-
1476
1487
  void XdsLb::ProcessAddressesAndChannelArgsLocked(
1477
1488
  const ServerAddressList& addresses, const grpc_channel_args& args) {
1478
1489
  // Update fallback address list.
@@ -1498,8 +1509,9 @@ void XdsLb::ProcessAddressesAndChannelArgsLocked(
1498
1509
  }
1499
1510
  if (create_lb_channel) {
1500
1511
  OrphanablePtr<BalancerChannelState> lb_chand =
1501
- MakeOrphanable<BalancerChannelState>(balancer_name_.get(),
1502
- *lb_channel_args, Ref());
1512
+ MakeOrphanable<BalancerChannelState>(
1513
+ balancer_name_.get(), *lb_channel_args,
1514
+ Ref(DEBUG_LOCATION, "BalancerChannelState"));
1503
1515
  if (lb_chand_ == nullptr || !lb_chand_->HasActiveCall()) {
1504
1516
  GPR_ASSERT(pending_lb_chand_ == nullptr);
1505
1517
  // If we do not have a working LB channel yet, use the newly created one.
@@ -1662,14 +1674,10 @@ void XdsLb::UpdateFallbackPolicyLocked() {
1662
1674
  fallback_policy_ == nullptr ? "" : "pending ",
1663
1675
  fallback_policy_name);
1664
1676
  }
1665
- auto new_policy =
1666
- CreateFallbackPolicyLocked(fallback_policy_name, update_args.args);
1667
1677
  auto& lb_policy = fallback_policy_ == nullptr ? fallback_policy_
1668
1678
  : pending_fallback_policy_;
1669
- {
1670
- MutexLock lock(&fallback_policy_mu_);
1671
- lb_policy = std::move(new_policy);
1672
- }
1679
+ lb_policy =
1680
+ CreateFallbackPolicyLocked(fallback_policy_name, update_args.args);
1673
1681
  policy_to_update = lb_policy.get();
1674
1682
  } else {
1675
1683
  // Cases 2a and 3a: update an existing policy.
@@ -1692,7 +1700,8 @@ void XdsLb::UpdateFallbackPolicyLocked() {
1692
1700
 
1693
1701
  OrphanablePtr<LoadBalancingPolicy> XdsLb::CreateFallbackPolicyLocked(
1694
1702
  const char* name, const grpc_channel_args* args) {
1695
- FallbackHelper* helper = New<FallbackHelper>(Ref());
1703
+ FallbackHelper* helper =
1704
+ New<FallbackHelper>(Ref(DEBUG_LOCATION, "FallbackHelper"));
1696
1705
  LoadBalancingPolicy::Args lb_policy_args;
1697
1706
  lb_policy_args.combiner = combiner();
1698
1707
  lb_policy_args.args = args;
@@ -1734,12 +1743,12 @@ void XdsLb::LocalityMap::PruneLocalities(const LocalityList& locality_list) {
1734
1743
  for (auto iter = map_.begin(); iter != map_.end();) {
1735
1744
  bool found = false;
1736
1745
  for (size_t i = 0; i < locality_list.size(); i++) {
1737
- if (!gpr_stricmp(locality_list[i]->locality_name, iter->first.get())) {
1746
+ if (*locality_list[i]->locality_name == *iter->first) {
1738
1747
  found = true;
1748
+ break;
1739
1749
  }
1740
1750
  }
1741
1751
  if (!found) { // Remove entries not present in the locality list
1742
- MutexLock lock(&child_refs_mu_);
1743
1752
  iter = map_.erase(iter);
1744
1753
  } else
1745
1754
  iter++;
@@ -1748,18 +1757,19 @@ void XdsLb::LocalityMap::PruneLocalities(const LocalityList& locality_list) {
1748
1757
 
1749
1758
  void XdsLb::LocalityMap::UpdateLocked(
1750
1759
  const LocalityList& locality_serverlist,
1751
- ParsedLoadBalancingConfig* child_policy_config,
1760
+ LoadBalancingPolicy::Config* child_policy_config,
1752
1761
  const grpc_channel_args* args, XdsLb* parent) {
1753
1762
  if (parent->shutting_down_) return;
1754
1763
  for (size_t i = 0; i < locality_serverlist.size(); i++) {
1755
- UniquePtr<char> locality_name(
1756
- gpr_strdup(locality_serverlist[i]->locality_name));
1757
- auto iter = map_.find(locality_name);
1764
+ auto iter = map_.find(locality_serverlist[i]->locality_name);
1758
1765
  if (iter == map_.end()) {
1759
1766
  OrphanablePtr<LocalityEntry> new_entry = MakeOrphanable<LocalityEntry>(
1760
- parent->Ref(), locality_serverlist[i]->locality_weight);
1761
- MutexLock lock(&child_refs_mu_);
1762
- iter = map_.emplace(std::move(locality_name), std::move(new_entry)).first;
1767
+ parent->Ref(DEBUG_LOCATION, "LocalityEntry"),
1768
+ locality_serverlist[i]->locality_name,
1769
+ locality_serverlist[i]->locality_weight);
1770
+ iter = map_.emplace(locality_serverlist[i]->locality_name,
1771
+ std::move(new_entry))
1772
+ .first;
1763
1773
  }
1764
1774
  // Don't create new child policies if not directed to
1765
1775
  xds_grpclb_serverlist* serverlist =
@@ -1769,10 +1779,7 @@ void XdsLb::LocalityMap::UpdateLocked(
1769
1779
  PruneLocalities(locality_serverlist);
1770
1780
  }
1771
1781
 
1772
- void XdsLb::LocalityMap::ShutdownLocked() {
1773
- MutexLock lock(&child_refs_mu_);
1774
- map_.clear();
1775
- }
1782
+ void XdsLb::LocalityMap::ShutdownLocked() { map_.clear(); }
1776
1783
 
1777
1784
  void XdsLb::LocalityMap::ResetBackoffLocked() {
1778
1785
  for (auto& p : map_) {
@@ -1780,19 +1787,31 @@ void XdsLb::LocalityMap::ResetBackoffLocked() {
1780
1787
  }
1781
1788
  }
1782
1789
 
1783
- void XdsLb::LocalityMap::FillChildRefsForChannelz(
1784
- channelz::ChildRefsList* child_subchannels,
1785
- channelz::ChildRefsList* child_channels) {
1786
- MutexLock lock(&child_refs_mu_);
1787
- for (auto& p : map_) {
1788
- p.second->FillChildRefsForChannelz(child_subchannels, child_channels);
1789
- }
1790
- }
1791
-
1792
1790
  //
1793
1791
  // XdsLb::LocalityMap::LocalityEntry
1794
1792
  //
1795
1793
 
1794
+ XdsLb::LocalityMap::LocalityEntry::LocalityEntry(
1795
+ RefCountedPtr<XdsLb> parent, RefCountedPtr<LocalityName> name,
1796
+ uint32_t locality_weight)
1797
+ : parent_(std::move(parent)),
1798
+ name_(std::move(name)),
1799
+ locality_weight_(locality_weight) {
1800
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_xds_trace)) {
1801
+ gpr_log(GPR_INFO, "[xdslb %p] created LocalityEntry %p for %s",
1802
+ parent_.get(), this, name_->AsHumanReadableString());
1803
+ }
1804
+ }
1805
+
1806
+ XdsLb::LocalityMap::LocalityEntry::~LocalityEntry() {
1807
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_xds_trace)) {
1808
+ gpr_log(GPR_INFO,
1809
+ "[xdslb %p] LocalityEntry %p %s: destroying locality entry",
1810
+ parent_.get(), this, name_->AsHumanReadableString());
1811
+ }
1812
+ parent_.reset(DEBUG_LOCATION, "LocalityEntry");
1813
+ }
1814
+
1796
1815
  grpc_channel_args*
1797
1816
  XdsLb::LocalityMap::LocalityEntry::CreateChildPolicyArgsLocked(
1798
1817
  const grpc_channel_args* args_in) {
@@ -1814,7 +1833,7 @@ XdsLb::LocalityMap::LocalityEntry::CreateChildPolicyArgsLocked(
1814
1833
  OrphanablePtr<LoadBalancingPolicy>
1815
1834
  XdsLb::LocalityMap::LocalityEntry::CreateChildPolicyLocked(
1816
1835
  const char* name, const grpc_channel_args* args) {
1817
- Helper* helper = New<Helper>(this->Ref());
1836
+ Helper* helper = New<Helper>(this->Ref(DEBUG_LOCATION, "Helper"));
1818
1837
  LoadBalancingPolicy::Args lb_policy_args;
1819
1838
  lb_policy_args.combiner = parent_->combiner();
1820
1839
  lb_policy_args.args = args;
@@ -1824,13 +1843,16 @@ XdsLb::LocalityMap::LocalityEntry::CreateChildPolicyLocked(
1824
1843
  LoadBalancingPolicyRegistry::CreateLoadBalancingPolicy(
1825
1844
  name, std::move(lb_policy_args));
1826
1845
  if (GPR_UNLIKELY(lb_policy == nullptr)) {
1827
- gpr_log(GPR_ERROR, "[xdslb %p] Failure creating child policy %s", this,
1828
- name);
1846
+ gpr_log(GPR_ERROR,
1847
+ "[xdslb %p] LocalityEntry %p %s: failure creating child policy %s",
1848
+ parent_.get(), this, name_->AsHumanReadableString(), name);
1829
1849
  return nullptr;
1830
1850
  }
1831
1851
  helper->set_child(lb_policy.get());
1832
1852
  if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_xds_trace)) {
1833
- gpr_log(GPR_INFO, "[xdslb %p] Created new child policy %s (%p)", this, name,
1853
+ gpr_log(GPR_INFO,
1854
+ "[xdslb %p] LocalityEntry %p %s: Created new child policy %s (%p)",
1855
+ parent_.get(), this, name_->AsHumanReadableString(), name,
1834
1856
  lb_policy.get());
1835
1857
  }
1836
1858
  // Add the xDS's interested_parties pollset_set to that of the newly created
@@ -1843,7 +1865,7 @@ XdsLb::LocalityMap::LocalityEntry::CreateChildPolicyLocked(
1843
1865
 
1844
1866
  void XdsLb::LocalityMap::LocalityEntry::UpdateLocked(
1845
1867
  xds_grpclb_serverlist* serverlist,
1846
- ParsedLoadBalancingConfig* child_policy_config,
1868
+ LoadBalancingPolicy::Config* child_policy_config,
1847
1869
  const grpc_channel_args* args_in) {
1848
1870
  if (parent_->shutting_down_) return;
1849
1871
  // Construct update args.
@@ -1921,17 +1943,14 @@ void XdsLb::LocalityMap::LocalityEntry::UpdateLocked(
1921
1943
  // If child_policy_ is null, we set it (case 1), else we set
1922
1944
  // pending_child_policy_ (cases 2b and 3b).
1923
1945
  if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_xds_trace)) {
1924
- gpr_log(GPR_INFO, "[xdslb %p] Creating new %schild policy %s", this,
1946
+ gpr_log(GPR_INFO,
1947
+ "[xdslb %p] LocalityEntry %p %s: Creating new %schild policy %s",
1948
+ parent_.get(), this, name_->AsHumanReadableString(),
1925
1949
  child_policy_ == nullptr ? "" : "pending ", child_policy_name);
1926
1950
  }
1927
- auto new_policy =
1928
- CreateChildPolicyLocked(child_policy_name, update_args.args);
1929
1951
  auto& lb_policy =
1930
1952
  child_policy_ == nullptr ? child_policy_ : pending_child_policy_;
1931
- {
1932
- MutexLock lock(&child_policy_mu_);
1933
- lb_policy = std::move(new_policy);
1934
- }
1953
+ lb_policy = CreateChildPolicyLocked(child_policy_name, update_args.args);
1935
1954
  policy_to_update = lb_policy.get();
1936
1955
  } else {
1937
1956
  // Cases 2a and 3a: update an existing policy.
@@ -1944,7 +1963,9 @@ void XdsLb::LocalityMap::LocalityEntry::UpdateLocked(
1944
1963
  GPR_ASSERT(policy_to_update != nullptr);
1945
1964
  // Update the policy.
1946
1965
  if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_xds_trace)) {
1947
- gpr_log(GPR_INFO, "[xdslb %p] Updating %schild policy %p", this,
1966
+ gpr_log(GPR_INFO,
1967
+ "[xdslb %p] LocalityEntry %p %s: Updating %schild policy %p",
1968
+ parent_.get(), this, name_->AsHumanReadableString(),
1948
1969
  policy_to_update == pending_child_policy_.get() ? "pending " : "",
1949
1970
  policy_to_update);
1950
1971
  }
@@ -1952,18 +1973,20 @@ void XdsLb::LocalityMap::LocalityEntry::UpdateLocked(
1952
1973
  }
1953
1974
 
1954
1975
  void XdsLb::LocalityMap::LocalityEntry::ShutdownLocked() {
1976
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_xds_trace)) {
1977
+ gpr_log(GPR_INFO,
1978
+ "[xdslb %p] LocalityEntry %p %s: shutting down locality entry",
1979
+ parent_.get(), this, name_->AsHumanReadableString());
1980
+ }
1955
1981
  // Remove the child policy's interested_parties pollset_set from the
1956
1982
  // xDS policy.
1957
1983
  grpc_pollset_set_del_pollset_set(child_policy_->interested_parties(),
1958
1984
  parent_->interested_parties());
1985
+ child_policy_.reset();
1959
1986
  if (pending_child_policy_ != nullptr) {
1960
1987
  grpc_pollset_set_del_pollset_set(
1961
1988
  pending_child_policy_->interested_parties(),
1962
1989
  parent_->interested_parties());
1963
- }
1964
- {
1965
- MutexLock lock(&child_policy_mu_);
1966
- child_policy_.reset();
1967
1990
  pending_child_policy_.reset();
1968
1991
  }
1969
1992
  }
@@ -1975,17 +1998,6 @@ void XdsLb::LocalityMap::LocalityEntry::ResetBackoffLocked() {
1975
1998
  }
1976
1999
  }
1977
2000
 
1978
- void XdsLb::LocalityMap::LocalityEntry::FillChildRefsForChannelz(
1979
- channelz::ChildRefsList* child_subchannels,
1980
- channelz::ChildRefsList* child_channels) {
1981
- MutexLock lock(&child_policy_mu_);
1982
- child_policy_->FillChildRefsForChannelz(child_subchannels, child_channels);
1983
- if (pending_child_policy_ != nullptr) {
1984
- pending_child_policy_->FillChildRefsForChannelz(child_subchannels,
1985
- child_channels);
1986
- }
1987
- }
1988
-
1989
2001
  void XdsLb::LocalityMap::LocalityEntry::Orphan() {
1990
2002
  ShutdownLocked();
1991
2003
  Unref();
@@ -2005,7 +2017,8 @@ bool XdsLb::LocalityMap::LocalityEntry::Helper::CalledByCurrentChild() const {
2005
2017
  return child_ == entry_->child_policy_.get();
2006
2018
  }
2007
2019
 
2008
- Subchannel* XdsLb::LocalityMap::LocalityEntry::Helper::CreateSubchannel(
2020
+ RefCountedPtr<SubchannelInterface>
2021
+ XdsLb::LocalityMap::LocalityEntry::Helper::CreateSubchannel(
2009
2022
  const grpc_channel_args& args) {
2010
2023
  if (entry_->parent_->shutting_down_ ||
2011
2024
  (!CalledByPendingChild() && !CalledByCurrentChild())) {
@@ -2039,14 +2052,16 @@ void XdsLb::LocalityMap::LocalityEntry::Helper::UpdateState(
2039
2052
  grpc_pollset_set_del_pollset_set(
2040
2053
  entry_->child_policy_->interested_parties(),
2041
2054
  entry_->parent_->interested_parties());
2042
- MutexLock lock(&entry_->child_policy_mu_);
2043
2055
  entry_->child_policy_ = std::move(entry_->pending_child_policy_);
2044
2056
  } else if (!CalledByCurrentChild()) {
2045
2057
  // This request is from an outdated child, so ignore it.
2046
2058
  return;
2047
2059
  }
2048
2060
  // At this point, child_ must be the current child policy.
2049
- if (state == GRPC_CHANNEL_READY) entry_->parent_->MaybeExitFallbackMode();
2061
+ if (state == GRPC_CHANNEL_READY) {
2062
+ entry_->parent_->MaybeCancelFallbackAtStartupChecks();
2063
+ entry_->parent_->MaybeExitFallbackMode();
2064
+ }
2050
2065
  // If we are in fallback mode, ignore update request from the child policy.
2051
2066
  if (entry_->parent_->fallback_policy_ != nullptr) return;
2052
2067
  GPR_ASSERT(entry_->parent_->lb_chand_ != nullptr);
@@ -2106,11 +2121,13 @@ void XdsLb::LocalityMap::LocalityEntry::Helper::UpdateState(
2106
2121
  } else if (num_connecting > 0) {
2107
2122
  entry_->parent_->channel_control_helper()->UpdateState(
2108
2123
  GRPC_CHANNEL_CONNECTING,
2109
- UniquePtr<SubchannelPicker>(New<QueuePicker>(this->entry_->parent_)));
2124
+ UniquePtr<SubchannelPicker>(New<QueuePicker>(
2125
+ this->entry_->parent_->Ref(DEBUG_LOCATION, "QueuePicker"))));
2110
2126
  } else if (num_idle > 0) {
2111
2127
  entry_->parent_->channel_control_helper()->UpdateState(
2112
2128
  GRPC_CHANNEL_IDLE,
2113
- UniquePtr<SubchannelPicker>(New<QueuePicker>(this->entry_->parent_)));
2129
+ UniquePtr<SubchannelPicker>(New<QueuePicker>(
2130
+ this->entry_->parent_->Ref(DEBUG_LOCATION, "QueuePicker"))));
2114
2131
  } else {
2115
2132
  GPR_ASSERT(num_transient_failures == locality_map.size());
2116
2133
  grpc_error* error =
@@ -2146,6 +2163,15 @@ void XdsLb::LocalityMap::LocalityEntry::Helper::RequestReresolution() {
2146
2163
  }
2147
2164
  }
2148
2165
 
2166
+ void XdsLb::LocalityMap::LocalityEntry::Helper::AddTraceEvent(
2167
+ TraceSeverity severity, const char* message) {
2168
+ if (entry_->parent_->shutting_down_ ||
2169
+ (!CalledByPendingChild() && !CalledByCurrentChild())) {
2170
+ return;
2171
+ }
2172
+ entry_->parent_->channel_control_helper()->AddTraceEvent(severity, message);
2173
+ }
2174
+
2149
2175
  //
2150
2176
  // factory
2151
2177
  //
@@ -2159,7 +2185,7 @@ class XdsFactory : public LoadBalancingPolicyFactory {
2159
2185
 
2160
2186
  const char* name() const override { return kXds; }
2161
2187
 
2162
- RefCountedPtr<ParsedLoadBalancingConfig> ParseLoadBalancingConfig(
2188
+ RefCountedPtr<LoadBalancingPolicy::Config> ParseLoadBalancingConfig(
2163
2189
  const grpc_json* json, grpc_error** error) const override {
2164
2190
  GPR_DEBUG_ASSERT(error != nullptr && *error == GRPC_ERROR_NONE);
2165
2191
  if (json == nullptr) {
@@ -2175,8 +2201,8 @@ class XdsFactory : public LoadBalancingPolicyFactory {
2175
2201
 
2176
2202
  InlinedVector<grpc_error*, 3> error_list;
2177
2203
  const char* balancer_name = nullptr;
2178
- RefCountedPtr<ParsedLoadBalancingConfig> child_policy;
2179
- RefCountedPtr<ParsedLoadBalancingConfig> fallback_policy;
2204
+ RefCountedPtr<LoadBalancingPolicy::Config> child_policy;
2205
+ RefCountedPtr<LoadBalancingPolicy::Config> fallback_policy;
2180
2206
  for (const grpc_json* field = json->child; field != nullptr;
2181
2207
  field = field->next) {
2182
2208
  if (field->key == nullptr) continue;
@@ -2222,7 +2248,7 @@ class XdsFactory : public LoadBalancingPolicyFactory {
2222
2248
  "field:balancerName error:not found"));
2223
2249
  }
2224
2250
  if (error_list.empty()) {
2225
- return RefCountedPtr<ParsedLoadBalancingConfig>(New<ParsedXdsConfig>(
2251
+ return RefCountedPtr<LoadBalancingPolicy::Config>(New<ParsedXdsConfig>(
2226
2252
  balancer_name, std::move(child_policy), std::move(fallback_policy)));
2227
2253
  } else {
2228
2254
  *error = GRPC_ERROR_CREATE_FROM_VECTOR("Xds Parser", &error_list);