grpc 1.18.0 → 1.19.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 (146) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +301 -33
  3. data/include/grpc/grpc_security.h +195 -0
  4. data/include/grpc/impl/codegen/grpc_types.h +17 -1
  5. data/include/grpc/impl/codegen/port_platform.h +36 -0
  6. data/include/grpc/impl/codegen/slice.h +1 -1
  7. data/src/core/ext/filters/client_channel/channel_connectivity.cc +2 -0
  8. data/src/core/ext/filters/client_channel/client_channel.cc +74 -69
  9. data/src/core/ext/filters/client_channel/client_channel.h +2 -2
  10. data/src/core/ext/filters/client_channel/client_channel_channelz.cc +5 -6
  11. data/src/core/ext/filters/client_channel/client_channel_channelz.h +5 -4
  12. data/src/core/ext/filters/client_channel/client_channel_factory.cc +2 -2
  13. data/src/core/ext/filters/client_channel/client_channel_factory.h +4 -4
  14. data/src/core/ext/filters/client_channel/client_channel_plugin.cc +3 -3
  15. data/src/core/ext/filters/client_channel/global_subchannel_pool.cc +176 -0
  16. data/src/core/ext/filters/client_channel/global_subchannel_pool.h +68 -0
  17. data/src/core/ext/filters/client_channel/health/health_check_client.cc +10 -8
  18. data/src/core/ext/filters/client_channel/health/health_check_client.h +1 -1
  19. data/src/core/ext/filters/client_channel/http_connect_handshaker.cc +146 -156
  20. data/src/core/ext/filters/client_channel/lb_policy.cc +30 -1
  21. data/src/core/ext/filters/client_channel/lb_policy.h +29 -1
  22. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +28 -30
  23. data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc +5 -8
  24. data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc +5 -8
  25. data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +23 -24
  26. data/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc +80 -15
  27. data/src/core/ext/filters/client_channel/lb_policy_factory.h +6 -1
  28. data/src/core/ext/filters/client_channel/lb_policy_registry.cc +2 -2
  29. data/src/core/ext/filters/client_channel/lb_policy_registry.h +1 -1
  30. data/src/core/ext/filters/client_channel/local_subchannel_pool.cc +96 -0
  31. data/src/core/ext/filters/client_channel/local_subchannel_pool.h +56 -0
  32. data/src/core/ext/filters/client_channel/parse_address.cc +24 -5
  33. data/src/core/ext/filters/client_channel/request_routing.cc +13 -3
  34. data/src/core/ext/filters/client_channel/request_routing.h +5 -1
  35. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +11 -6
  36. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc +2 -2
  37. data/src/core/ext/filters/client_channel/resolver_result_parsing.cc +7 -35
  38. data/src/core/ext/filters/client_channel/subchannel.cc +698 -791
  39. data/src/core/ext/filters/client_channel/subchannel.h +213 -123
  40. data/src/core/ext/filters/client_channel/subchannel_pool_interface.cc +97 -0
  41. data/src/core/ext/filters/client_channel/subchannel_pool_interface.h +94 -0
  42. data/src/core/ext/filters/http/client_authority_filter.cc +5 -2
  43. data/src/core/ext/filters/max_age/max_age_filter.cc +1 -1
  44. data/src/core/ext/transport/chttp2/client/chttp2_connector.cc +13 -12
  45. data/src/core/ext/transport/chttp2/client/insecure/channel_create.cc +5 -7
  46. data/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc +19 -27
  47. data/src/core/ext/transport/chttp2/server/chttp2_server.cc +18 -19
  48. data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +27 -6
  49. data/src/core/ext/transport/chttp2/transport/flow_control.cc +1 -1
  50. data/src/core/ext/transport/chttp2/transport/frame_window_update.cc +3 -2
  51. data/src/core/ext/transport/chttp2/transport/hpack_encoder.cc +1 -1
  52. data/src/core/ext/transport/chttp2/transport/writing.cc +8 -5
  53. data/src/core/lib/channel/handshaker.cc +141 -214
  54. data/src/core/lib/channel/handshaker.h +110 -101
  55. data/src/core/lib/channel/handshaker_factory.h +11 -19
  56. data/src/core/lib/channel/handshaker_registry.cc +64 -52
  57. data/src/core/lib/channel/handshaker_registry.h +21 -16
  58. data/src/core/lib/gpr/log_posix.cc +2 -1
  59. data/src/core/lib/gpr/time.cc +8 -0
  60. data/src/core/lib/gpr/time_posix.cc +8 -2
  61. data/src/core/lib/gprpp/optional.h +47 -0
  62. data/src/core/lib/http/httpcli_security_connector.cc +13 -14
  63. data/src/core/lib/iomgr/buffer_list.cc +182 -24
  64. data/src/core/lib/iomgr/buffer_list.h +70 -8
  65. data/src/core/lib/iomgr/combiner.cc +11 -3
  66. data/src/core/lib/iomgr/error.cc +9 -5
  67. data/src/core/lib/iomgr/ev_epoll1_linux.cc +3 -0
  68. data/src/core/lib/iomgr/ev_epollex_linux.cc +136 -162
  69. data/src/core/lib/iomgr/ev_poll_posix.cc +3 -0
  70. data/src/core/lib/iomgr/ev_posix.cc +4 -0
  71. data/src/core/lib/iomgr/ev_posix.h +4 -0
  72. data/src/core/lib/iomgr/exec_ctx.cc +1 -0
  73. data/src/core/lib/iomgr/exec_ctx.h +137 -8
  74. data/src/core/lib/iomgr/executor.cc +122 -87
  75. data/src/core/lib/iomgr/executor.h +53 -48
  76. data/src/core/lib/iomgr/fork_posix.cc +6 -4
  77. data/src/core/lib/iomgr/{network_status_tracker.cc → grpc_if_nametoindex.h} +8 -14
  78. data/src/core/lib/iomgr/grpc_if_nametoindex_posix.cc +42 -0
  79. data/src/core/lib/iomgr/{network_status_tracker.h → grpc_if_nametoindex_unsupported.cc} +15 -9
  80. data/src/core/lib/iomgr/internal_errqueue.h +105 -3
  81. data/src/core/lib/iomgr/iomgr.cc +6 -5
  82. data/src/core/lib/iomgr/iomgr.h +8 -0
  83. data/src/core/lib/iomgr/iomgr_custom.cc +6 -2
  84. data/src/core/lib/iomgr/iomgr_internal.cc +4 -0
  85. data/src/core/lib/iomgr/iomgr_internal.h +4 -0
  86. data/src/core/lib/iomgr/iomgr_posix.cc +10 -1
  87. data/src/core/lib/iomgr/iomgr_windows.cc +8 -1
  88. data/src/core/lib/iomgr/port.h +1 -0
  89. data/src/core/lib/iomgr/resolve_address_posix.cc +4 -3
  90. data/src/core/lib/iomgr/resolve_address_windows.cc +2 -1
  91. data/src/core/lib/iomgr/tcp_custom.cc +0 -4
  92. data/src/core/lib/iomgr/tcp_posix.cc +58 -44
  93. data/src/core/lib/iomgr/tcp_uv.cc +0 -1
  94. data/src/core/lib/iomgr/tcp_windows.cc +0 -4
  95. data/src/core/lib/iomgr/timer_manager.cc +8 -0
  96. data/src/core/lib/iomgr/udp_server.cc +6 -4
  97. data/src/core/lib/json/json.cc +1 -4
  98. data/src/core/lib/security/credentials/alts/alts_credentials.cc +1 -1
  99. data/src/core/lib/security/credentials/alts/check_gcp_environment_no_op.cc +2 -2
  100. data/src/core/lib/security/credentials/composite/composite_credentials.h +4 -0
  101. data/src/core/lib/security/credentials/credentials.h +9 -1
  102. data/src/core/lib/security/credentials/google_default/google_default_credentials.cc +15 -2
  103. data/src/core/lib/security/credentials/google_default/google_default_credentials.h +2 -0
  104. data/src/core/lib/security/credentials/jwt/json_token.cc +1 -1
  105. data/src/core/lib/security/credentials/jwt/jwt_credentials.cc +1 -0
  106. data/src/core/lib/security/credentials/jwt/jwt_verifier.cc +3 -2
  107. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc +2 -2
  108. data/src/core/lib/security/credentials/plugin/plugin_credentials.cc +1 -0
  109. data/src/core/lib/security/credentials/tls/grpc_tls_credentials_options.cc +192 -0
  110. data/src/core/lib/security/credentials/tls/grpc_tls_credentials_options.h +213 -0
  111. data/src/core/lib/security/security_connector/alts/alts_security_connector.cc +10 -8
  112. data/src/core/lib/security/security_connector/fake/fake_security_connector.cc +6 -10
  113. data/src/core/lib/security/security_connector/local/local_security_connector.cc +10 -8
  114. data/src/core/lib/security/security_connector/security_connector.h +2 -2
  115. data/src/core/lib/security/security_connector/ssl/ssl_security_connector.cc +4 -6
  116. data/src/core/lib/security/security_connector/ssl_utils.h +33 -0
  117. data/src/core/lib/security/transport/security_handshaker.cc +267 -300
  118. data/src/core/lib/security/transport/security_handshaker.h +11 -2
  119. data/src/core/lib/security/transport/server_auth_filter.cc +1 -0
  120. data/src/core/lib/surface/call.cc +5 -1
  121. data/src/core/lib/surface/channel_init.h +5 -0
  122. data/src/core/lib/surface/completion_queue.cc +4 -7
  123. data/src/core/lib/surface/init.cc +5 -3
  124. data/src/core/lib/surface/init_secure.cc +1 -1
  125. data/src/core/lib/surface/server.cc +19 -17
  126. data/src/core/lib/surface/version.cc +1 -1
  127. data/src/core/lib/transport/service_config.h +1 -0
  128. data/src/core/lib/transport/static_metadata.cc +279 -279
  129. data/src/core/lib/transport/transport.cc +5 -3
  130. data/src/core/tsi/ssl_transport_security.cc +10 -4
  131. data/src/ruby/ext/grpc/extconf.rb +12 -4
  132. data/src/ruby/ext/grpc/rb_call_credentials.c +8 -5
  133. data/src/ruby/ext/grpc/rb_channel.c +14 -10
  134. data/src/ruby/ext/grpc/rb_channel_credentials.c +8 -4
  135. data/src/ruby/ext/grpc/rb_compression_options.c +9 -7
  136. data/src/ruby/ext/grpc/rb_event_thread.c +2 -0
  137. data/src/ruby/ext/grpc/rb_grpc.c +22 -23
  138. data/src/ruby/ext/grpc/rb_grpc.h +4 -2
  139. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +18 -0
  140. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +27 -0
  141. data/src/ruby/ext/grpc/rb_server.c +8 -4
  142. data/src/ruby/lib/grpc/version.rb +1 -1
  143. metadata +46 -39
  144. data/src/core/ext/filters/client_channel/subchannel_index.cc +0 -248
  145. data/src/core/ext/filters/client_channel/subchannel_index.h +0 -76
  146. data/src/core/lib/channel/handshaker_factory.cc +0 -42
@@ -19,6 +19,8 @@
19
19
  #include <grpc/support/port_platform.h>
20
20
 
21
21
  #include "src/core/ext/filters/client_channel/lb_policy.h"
22
+
23
+ #include "src/core/ext/filters/client_channel/lb_policy_registry.h"
22
24
  #include "src/core/lib/iomgr/combiner.h"
23
25
 
24
26
  grpc_core::DebugOnlyTraceFlag grpc_trace_lb_policy_refcount(
@@ -26,10 +28,37 @@ grpc_core::DebugOnlyTraceFlag grpc_trace_lb_policy_refcount(
26
28
 
27
29
  namespace grpc_core {
28
30
 
29
- LoadBalancingPolicy::LoadBalancingPolicy(const Args& args)
31
+ grpc_json* LoadBalancingPolicy::ParseLoadBalancingConfig(
32
+ const grpc_json* lb_config_array) {
33
+ if (lb_config_array == nullptr || lb_config_array->type != GRPC_JSON_ARRAY) {
34
+ return nullptr;
35
+ }
36
+ // Find the first LB policy that this client supports.
37
+ for (const grpc_json* lb_config = lb_config_array->child;
38
+ lb_config != nullptr; lb_config = lb_config->next) {
39
+ if (lb_config->type != GRPC_JSON_OBJECT) return nullptr;
40
+ grpc_json* policy = nullptr;
41
+ for (grpc_json* field = lb_config->child; field != nullptr;
42
+ field = field->next) {
43
+ if (field->key == nullptr || field->type != GRPC_JSON_OBJECT)
44
+ return nullptr;
45
+ if (policy != nullptr) return nullptr; // Violate "oneof" type.
46
+ policy = field;
47
+ }
48
+ if (policy == nullptr) return nullptr;
49
+ // If we support this policy, then select it.
50
+ if (LoadBalancingPolicyRegistry::LoadBalancingPolicyExists(policy->key)) {
51
+ return policy;
52
+ }
53
+ }
54
+ return nullptr;
55
+ }
56
+
57
+ LoadBalancingPolicy::LoadBalancingPolicy(Args args)
30
58
  : InternallyRefCounted(&grpc_trace_lb_policy_refcount),
31
59
  combiner_(GRPC_COMBINER_REF(args.combiner, "lb_policy")),
32
60
  client_channel_factory_(args.client_channel_factory),
61
+ subchannel_pool_(std::move(args.subchannel_pool)),
33
62
  interested_parties_(grpc_pollset_set_create()),
34
63
  request_reresolution_(nullptr) {}
35
64
 
@@ -24,6 +24,7 @@
24
24
  #include "src/core/ext/filters/client_channel/client_channel_channelz.h"
25
25
  #include "src/core/ext/filters/client_channel/client_channel_factory.h"
26
26
  #include "src/core/ext/filters/client_channel/subchannel.h"
27
+ #include "src/core/ext/filters/client_channel/subchannel_pool_interface.h"
27
28
  #include "src/core/lib/gprpp/abstract.h"
28
29
  #include "src/core/lib/gprpp/orphanable.h"
29
30
  #include "src/core/lib/gprpp/ref_counted_ptr.h"
@@ -53,6 +54,8 @@ class LoadBalancingPolicy : public InternallyRefCounted<LoadBalancingPolicy> {
53
54
  grpc_combiner* combiner = nullptr;
54
55
  /// Used to create channels and subchannels.
55
56
  grpc_client_channel_factory* client_channel_factory = nullptr;
57
+ /// Subchannel pool.
58
+ RefCountedPtr<SubchannelPoolInterface> subchannel_pool;
56
59
  /// Channel args from the resolver.
57
60
  /// Note that the LB policy gets the set of addresses from the
58
61
  /// GRPC_ARG_SERVER_ADDRESS_LIST channel arg.
@@ -74,6 +77,19 @@ class LoadBalancingPolicy : public InternallyRefCounted<LoadBalancingPolicy> {
74
77
  /// Closure to run when pick is complete, if not completed synchronously.
75
78
  /// If null, pick will fail if a result is not available synchronously.
76
79
  grpc_closure* on_complete = nullptr;
80
+ // Callback set by lb policy to be notified of trailing metadata.
81
+ // The callback must be scheduled on grpc_schedule_on_exec_ctx.
82
+ grpc_closure* recv_trailing_metadata_ready = nullptr;
83
+ // The address that will be set to point to the original
84
+ // recv_trailing_metadata_ready callback, to be invoked by the LB
85
+ // policy's recv_trailing_metadata_ready callback when complete.
86
+ // Must be non-null if recv_trailing_metadata_ready is non-null.
87
+ grpc_closure** original_recv_trailing_metadata_ready = nullptr;
88
+ // If this is not nullptr, then the client channel will point it to the
89
+ // call's trailing metadata before invoking recv_trailing_metadata_ready.
90
+ // If this is nullptr, then the callback will still be called.
91
+ // The lb does not have ownership of the metadata.
92
+ grpc_metadata_batch** recv_trailing_metadata = nullptr;
77
93
  /// Will be set to the selected subchannel, or nullptr on failure or when
78
94
  /// the LB policy decides to drop the call.
79
95
  RefCountedPtr<ConnectedSubchannel> connected_subchannel;
@@ -163,6 +179,10 @@ class LoadBalancingPolicy : public InternallyRefCounted<LoadBalancingPolicy> {
163
179
  GRPC_ERROR_NONE);
164
180
  }
165
181
 
182
+ /// Returns the JSON node of policy (with both policy name and config content)
183
+ /// given the JSON node of a LoadBalancingConfig array.
184
+ static grpc_json* ParseLoadBalancingConfig(const grpc_json* lb_config_array);
185
+
166
186
  /// Sets the re-resolution closure to \a request_reresolution.
167
187
  void SetReresolutionClosureLocked(grpc_closure* request_reresolution) {
168
188
  GPR_ASSERT(request_reresolution_ == nullptr);
@@ -171,12 +191,18 @@ class LoadBalancingPolicy : public InternallyRefCounted<LoadBalancingPolicy> {
171
191
 
172
192
  grpc_pollset_set* interested_parties() const { return interested_parties_; }
173
193
 
194
+ // Callers that need their own reference can call the returned
195
+ // object's Ref() method.
196
+ SubchannelPoolInterface* subchannel_pool() const {
197
+ return subchannel_pool_.get();
198
+ }
199
+
174
200
  GRPC_ABSTRACT_BASE_CLASS
175
201
 
176
202
  protected:
177
203
  GPRC_ALLOW_CLASS_TO_USE_NON_PUBLIC_DELETE
178
204
 
179
- explicit LoadBalancingPolicy(const Args& args);
205
+ explicit LoadBalancingPolicy(Args args);
180
206
  virtual ~LoadBalancingPolicy();
181
207
 
182
208
  grpc_combiner* combiner() const { return combiner_; }
@@ -204,6 +230,8 @@ class LoadBalancingPolicy : public InternallyRefCounted<LoadBalancingPolicy> {
204
230
  grpc_combiner* combiner_;
205
231
  /// Client channel factory, used to create channels and subchannels.
206
232
  grpc_client_channel_factory* client_channel_factory_;
233
+ /// Subchannel pool.
234
+ RefCountedPtr<SubchannelPoolInterface> subchannel_pool_;
207
235
  /// Owned pointer to interested parties in load balancing decisions.
208
236
  grpc_pollset_set* interested_parties_;
209
237
  /// Callback to force a re-resolution.
@@ -85,7 +85,6 @@
85
85
  #include "src/core/ext/filters/client_channel/parse_address.h"
86
86
  #include "src/core/ext/filters/client_channel/resolver/fake/fake_resolver.h"
87
87
  #include "src/core/ext/filters/client_channel/server_address.h"
88
- #include "src/core/ext/filters/client_channel/subchannel_index.h"
89
88
  #include "src/core/lib/backoff/backoff.h"
90
89
  #include "src/core/lib/channel/channel_args.h"
91
90
  #include "src/core/lib/channel/channel_stack.h"
@@ -126,7 +125,7 @@ constexpr char kGrpclb[] = "grpclb";
126
125
 
127
126
  class GrpcLb : public LoadBalancingPolicy {
128
127
  public:
129
- explicit GrpcLb(const Args& args);
128
+ explicit GrpcLb(Args args);
130
129
 
131
130
  const char* name() const override { return kGrpclb; }
132
131
 
@@ -274,7 +273,7 @@ class GrpcLb : public LoadBalancingPolicy {
274
273
  // Methods for dealing with the RR policy.
275
274
  void CreateOrUpdateRoundRobinPolicyLocked();
276
275
  grpc_channel_args* CreateRoundRobinPolicyArgsLocked();
277
- void CreateRoundRobinPolicyLocked(const Args& args);
276
+ void CreateRoundRobinPolicyLocked(Args args);
278
277
  bool PickFromRoundRobinPolicyLocked(bool force_async, PendingPick* pp,
279
278
  grpc_error** error);
280
279
  void UpdateConnectivityStateFromRoundRobinPolicyLocked(
@@ -297,9 +296,8 @@ class GrpcLb : public LoadBalancingPolicy {
297
296
 
298
297
  // The channel for communicating with the LB server.
299
298
  grpc_channel* lb_channel_ = nullptr;
300
- // Mutex to protect the channel to the LB server. This is used when
301
- // processing a channelz request.
302
- gpr_mu lb_channel_mu_;
299
+ // Uuid of the lb channel. Used for channelz.
300
+ gpr_atm lb_channel_uuid_ = 0;
303
301
  grpc_connectivity_state lb_channel_connectivity_;
304
302
  grpc_closure lb_channel_on_connectivity_changed_;
305
303
  // Are we already watching the LB channel's connectivity?
@@ -919,6 +917,9 @@ grpc_channel_args* BuildBalancerChannelArgs(
919
917
  // LB policy name, since we want to use the default (pick_first) in
920
918
  // the LB channel.
921
919
  GRPC_ARG_LB_POLICY_NAME,
920
+ // Strip out the service config, since we don't want the LB policy
921
+ // config specified for the parent channel to affect the LB channel.
922
+ GRPC_ARG_SERVICE_CONFIG,
922
923
  // The channel arg for the server URI, since that will be different for
923
924
  // the LB channel than for the parent channel. The client channel
924
925
  // factory will re-add this arg with the right value.
@@ -930,7 +931,7 @@ grpc_channel_args* BuildBalancerChannelArgs(
930
931
  // resolver will have is_balancer=false, whereas our own addresses have
931
932
  // is_balancer=true. We need the LB channel to return addresses with
932
933
  // is_balancer=false so that it does not wind up recursively using the
933
- // grpclb LB policy, as per the special case logic in client_channel.c.
934
+ // grpclb LB policy.
934
935
  GRPC_ARG_SERVER_ADDRESS_LIST,
935
936
  // The fake resolver response generator, because we are replacing it
936
937
  // with the one from the grpclb policy, used to propagate updates to
@@ -975,8 +976,8 @@ grpc_channel_args* BuildBalancerChannelArgs(
975
976
  // ctor and dtor
976
977
  //
977
978
 
978
- GrpcLb::GrpcLb(const LoadBalancingPolicy::Args& args)
979
- : LoadBalancingPolicy(args),
979
+ GrpcLb::GrpcLb(LoadBalancingPolicy::Args args)
980
+ : LoadBalancingPolicy(std::move(args)),
980
981
  response_generator_(MakeRefCounted<FakeResolverResponseGenerator>()),
981
982
  lb_call_backoff_(
982
983
  BackOff::Options()
@@ -987,8 +988,6 @@ GrpcLb::GrpcLb(const LoadBalancingPolicy::Args& args)
987
988
  .set_max_backoff(GRPC_GRPCLB_RECONNECT_MAX_BACKOFF_SECONDS *
988
989
  1000)) {
989
990
  // Initialization.
990
- gpr_mu_init(&lb_channel_mu_);
991
- grpc_subchannel_index_ref();
992
991
  GRPC_CLOSURE_INIT(&lb_channel_on_connectivity_changed_,
993
992
  &GrpcLb::OnBalancerChannelConnectivityChangedLocked, this,
994
993
  grpc_combiner_scheduler(args.combiner));
@@ -1025,14 +1024,12 @@ GrpcLb::GrpcLb(const LoadBalancingPolicy::Args& args)
1025
1024
 
1026
1025
  GrpcLb::~GrpcLb() {
1027
1026
  GPR_ASSERT(pending_picks_ == nullptr);
1028
- gpr_mu_destroy(&lb_channel_mu_);
1029
1027
  gpr_free((void*)server_name_);
1030
1028
  grpc_channel_args_destroy(args_);
1031
1029
  grpc_connectivity_state_destroy(&state_tracker_);
1032
1030
  if (serverlist_ != nullptr) {
1033
1031
  grpc_grpclb_destroy_serverlist(serverlist_);
1034
1032
  }
1035
- grpc_subchannel_index_unref();
1036
1033
  }
1037
1034
 
1038
1035
  void GrpcLb::ShutdownLocked() {
@@ -1052,10 +1049,9 @@ void GrpcLb::ShutdownLocked() {
1052
1049
  // OnBalancerChannelConnectivityChangedLocked(), and we need to be
1053
1050
  // alive when that callback is invoked.
1054
1051
  if (lb_channel_ != nullptr) {
1055
- gpr_mu_lock(&lb_channel_mu_);
1056
1052
  grpc_channel_destroy(lb_channel_);
1057
1053
  lb_channel_ = nullptr;
1058
- gpr_mu_unlock(&lb_channel_mu_);
1054
+ gpr_atm_no_barrier_store(&lb_channel_uuid_, 0);
1059
1055
  }
1060
1056
  grpc_connectivity_state_set(&state_tracker_, GRPC_CHANNEL_SHUTDOWN,
1061
1057
  GRPC_ERROR_REF(error), "grpclb_shutdown");
@@ -1210,14 +1206,12 @@ void GrpcLb::FillChildRefsForChannelz(
1210
1206
  channelz::ChildRefsList* child_subchannels,
1211
1207
  channelz::ChildRefsList* child_channels) {
1212
1208
  // delegate to the RoundRobin to fill the children subchannels.
1213
- rr_policy_->FillChildRefsForChannelz(child_subchannels, child_channels);
1214
- MutexLock lock(&lb_channel_mu_);
1215
- if (lb_channel_ != nullptr) {
1216
- grpc_core::channelz::ChannelNode* channel_node =
1217
- grpc_channel_get_channelz_node(lb_channel_);
1218
- if (channel_node != nullptr) {
1219
- child_channels->push_back(channel_node->uuid());
1220
- }
1209
+ if (rr_policy_ != nullptr) {
1210
+ rr_policy_->FillChildRefsForChannelz(child_subchannels, child_channels);
1211
+ }
1212
+ gpr_atm uuid = gpr_atm_no_barrier_load(&lb_channel_uuid_);
1213
+ if (uuid != 0) {
1214
+ child_channels->push_back(uuid);
1221
1215
  }
1222
1216
  }
1223
1217
 
@@ -1277,12 +1271,15 @@ void GrpcLb::ProcessChannelArgsLocked(const grpc_channel_args& args) {
1277
1271
  if (lb_channel_ == nullptr) {
1278
1272
  char* uri_str;
1279
1273
  gpr_asprintf(&uri_str, "fake:///%s", server_name_);
1280
- gpr_mu_lock(&lb_channel_mu_);
1281
1274
  lb_channel_ = grpc_client_channel_factory_create_channel(
1282
1275
  client_channel_factory(), uri_str,
1283
1276
  GRPC_CLIENT_CHANNEL_TYPE_LOAD_BALANCING, lb_channel_args);
1284
- gpr_mu_unlock(&lb_channel_mu_);
1285
1277
  GPR_ASSERT(lb_channel_ != nullptr);
1278
+ grpc_core::channelz::ChannelNode* channel_node =
1279
+ grpc_channel_get_channelz_node(lb_channel_);
1280
+ if (channel_node != nullptr) {
1281
+ gpr_atm_no_barrier_store(&lb_channel_uuid_, channel_node->uuid());
1282
+ }
1286
1283
  gpr_free(uri_str);
1287
1284
  }
1288
1285
  // Propagate updates to the LB channel (pick_first) through the fake
@@ -1594,10 +1591,10 @@ bool GrpcLb::PickFromRoundRobinPolicyLocked(bool force_async, PendingPick* pp,
1594
1591
  return pick_done;
1595
1592
  }
1596
1593
 
1597
- void GrpcLb::CreateRoundRobinPolicyLocked(const Args& args) {
1594
+ void GrpcLb::CreateRoundRobinPolicyLocked(Args args) {
1598
1595
  GPR_ASSERT(rr_policy_ == nullptr);
1599
1596
  rr_policy_ = LoadBalancingPolicyRegistry::CreateLoadBalancingPolicy(
1600
- "round_robin", args);
1597
+ "round_robin", std::move(args));
1601
1598
  if (GPR_UNLIKELY(rr_policy_ == nullptr)) {
1602
1599
  gpr_log(GPR_ERROR, "[grpclb %p] Failure creating a RoundRobin policy",
1603
1600
  this);
@@ -1699,7 +1696,8 @@ void GrpcLb::CreateOrUpdateRoundRobinPolicyLocked() {
1699
1696
  lb_policy_args.combiner = combiner();
1700
1697
  lb_policy_args.client_channel_factory = client_channel_factory();
1701
1698
  lb_policy_args.args = args;
1702
- CreateRoundRobinPolicyLocked(lb_policy_args);
1699
+ lb_policy_args.subchannel_pool = subchannel_pool()->Ref();
1700
+ CreateRoundRobinPolicyLocked(std::move(lb_policy_args));
1703
1701
  }
1704
1702
  grpc_channel_args_destroy(args);
1705
1703
  }
@@ -1807,7 +1805,7 @@ void GrpcLb::OnRoundRobinConnectivityChangedLocked(void* arg,
1807
1805
  class GrpcLbFactory : public LoadBalancingPolicyFactory {
1808
1806
  public:
1809
1807
  OrphanablePtr<LoadBalancingPolicy> CreateLoadBalancingPolicy(
1810
- const LoadBalancingPolicy::Args& args) const override {
1808
+ LoadBalancingPolicy::Args args) const override {
1811
1809
  /* Count the number of gRPC-LB addresses. There must be at least one. */
1812
1810
  const ServerAddressList* addresses =
1813
1811
  FindServerAddressListChannelArg(args.args);
@@ -1820,7 +1818,7 @@ class GrpcLbFactory : public LoadBalancingPolicyFactory {
1820
1818
  }
1821
1819
  }
1822
1820
  if (!found_balancer) return nullptr;
1823
- return OrphanablePtr<LoadBalancingPolicy>(New<GrpcLb>(args));
1821
+ return OrphanablePtr<LoadBalancingPolicy>(New<GrpcLb>(std::move(args)));
1824
1822
  }
1825
1823
 
1826
1824
  const char* name() const override { return kGrpclb; }
@@ -26,7 +26,6 @@
26
26
  #include "src/core/ext/filters/client_channel/lb_policy_registry.h"
27
27
  #include "src/core/ext/filters/client_channel/server_address.h"
28
28
  #include "src/core/ext/filters/client_channel/subchannel.h"
29
- #include "src/core/ext/filters/client_channel/subchannel_index.h"
30
29
  #include "src/core/lib/channel/channel_args.h"
31
30
  #include "src/core/lib/gprpp/mutex_lock.h"
32
31
  #include "src/core/lib/iomgr/combiner.h"
@@ -47,7 +46,7 @@ constexpr char kPickFirst[] = "pick_first";
47
46
 
48
47
  class PickFirst : public LoadBalancingPolicy {
49
48
  public:
50
- explicit PickFirst(const Args& args);
49
+ explicit PickFirst(Args args);
51
50
 
52
51
  const char* name() const override { return kPickFirst; }
53
52
 
@@ -80,7 +79,7 @@ class PickFirst : public LoadBalancingPolicy {
80
79
  PickFirstSubchannelData(
81
80
  SubchannelList<PickFirstSubchannelList, PickFirstSubchannelData>*
82
81
  subchannel_list,
83
- const ServerAddress& address, grpc_subchannel* subchannel,
82
+ const ServerAddress& address, Subchannel* subchannel,
84
83
  grpc_combiner* combiner)
85
84
  : SubchannelData(subchannel_list, address, subchannel, combiner) {}
86
85
 
@@ -155,7 +154,7 @@ class PickFirst : public LoadBalancingPolicy {
155
154
  channelz::ChildRefsList child_channels_;
156
155
  };
157
156
 
158
- PickFirst::PickFirst(const Args& args) : LoadBalancingPolicy(args) {
157
+ PickFirst::PickFirst(Args args) : LoadBalancingPolicy(std::move(args)) {
159
158
  GPR_ASSERT(args.client_channel_factory != nullptr);
160
159
  gpr_mu_init(&child_refs_mu_);
161
160
  grpc_connectivity_state_init(&state_tracker_, GRPC_CHANNEL_IDLE,
@@ -164,7 +163,6 @@ PickFirst::PickFirst(const Args& args) : LoadBalancingPolicy(args) {
164
163
  gpr_log(GPR_INFO, "Pick First %p created.", this);
165
164
  }
166
165
  UpdateLocked(*args.args, args.lb_config);
167
- grpc_subchannel_index_ref();
168
166
  }
169
167
 
170
168
  PickFirst::~PickFirst() {
@@ -176,7 +174,6 @@ PickFirst::~PickFirst() {
176
174
  GPR_ASSERT(latest_pending_subchannel_list_ == nullptr);
177
175
  GPR_ASSERT(pending_picks_ == nullptr);
178
176
  grpc_connectivity_state_destroy(&state_tracker_);
179
- grpc_subchannel_index_unref();
180
177
  }
181
178
 
182
179
  void PickFirst::HandOffPendingPicksLocked(LoadBalancingPolicy* new_policy) {
@@ -622,8 +619,8 @@ void PickFirst::PickFirstSubchannelData::
622
619
  class PickFirstFactory : public LoadBalancingPolicyFactory {
623
620
  public:
624
621
  OrphanablePtr<LoadBalancingPolicy> CreateLoadBalancingPolicy(
625
- const LoadBalancingPolicy::Args& args) const override {
626
- return OrphanablePtr<LoadBalancingPolicy>(New<PickFirst>(args));
622
+ LoadBalancingPolicy::Args args) const override {
623
+ return OrphanablePtr<LoadBalancingPolicy>(New<PickFirst>(std::move(args)));
627
624
  }
628
625
 
629
626
  const char* name() const override { return kPickFirst; }
@@ -33,7 +33,6 @@
33
33
  #include "src/core/ext/filters/client_channel/lb_policy/subchannel_list.h"
34
34
  #include "src/core/ext/filters/client_channel/lb_policy_registry.h"
35
35
  #include "src/core/ext/filters/client_channel/subchannel.h"
36
- #include "src/core/ext/filters/client_channel/subchannel_index.h"
37
36
  #include "src/core/lib/channel/channel_args.h"
38
37
  #include "src/core/lib/debug/trace.h"
39
38
  #include "src/core/lib/gprpp/mutex_lock.h"
@@ -57,7 +56,7 @@ constexpr char kRoundRobin[] = "round_robin";
57
56
 
58
57
  class RoundRobin : public LoadBalancingPolicy {
59
58
  public:
60
- explicit RoundRobin(const Args& args);
59
+ explicit RoundRobin(Args args);
61
60
 
62
61
  const char* name() const override { return kRoundRobin; }
63
62
 
@@ -95,7 +94,7 @@ class RoundRobin : public LoadBalancingPolicy {
95
94
  RoundRobinSubchannelData(
96
95
  SubchannelList<RoundRobinSubchannelList, RoundRobinSubchannelData>*
97
96
  subchannel_list,
98
- const ServerAddress& address, grpc_subchannel* subchannel,
97
+ const ServerAddress& address, Subchannel* subchannel,
99
98
  grpc_combiner* combiner)
100
99
  : SubchannelData(subchannel_list, address, subchannel, combiner) {}
101
100
 
@@ -211,7 +210,7 @@ class RoundRobin : public LoadBalancingPolicy {
211
210
  channelz::ChildRefsList child_channels_;
212
211
  };
213
212
 
214
- RoundRobin::RoundRobin(const Args& args) : LoadBalancingPolicy(args) {
213
+ RoundRobin::RoundRobin(Args args) : LoadBalancingPolicy(std::move(args)) {
215
214
  GPR_ASSERT(args.client_channel_factory != nullptr);
216
215
  gpr_mu_init(&child_refs_mu_);
217
216
  grpc_connectivity_state_init(&state_tracker_, GRPC_CHANNEL_IDLE,
@@ -221,7 +220,6 @@ RoundRobin::RoundRobin(const Args& args) : LoadBalancingPolicy(args) {
221
220
  gpr_log(GPR_INFO, "[RR %p] Created with %" PRIuPTR " subchannels", this,
222
221
  subchannel_list_->num_subchannels());
223
222
  }
224
- grpc_subchannel_index_ref();
225
223
  }
226
224
 
227
225
  RoundRobin::~RoundRobin() {
@@ -233,7 +231,6 @@ RoundRobin::~RoundRobin() {
233
231
  GPR_ASSERT(latest_pending_subchannel_list_ == nullptr);
234
232
  GPR_ASSERT(pending_picks_ == nullptr);
235
233
  grpc_connectivity_state_destroy(&state_tracker_);
236
- grpc_subchannel_index_unref();
237
234
  }
238
235
 
239
236
  void RoundRobin::HandOffPendingPicksLocked(LoadBalancingPolicy* new_policy) {
@@ -700,8 +697,8 @@ void RoundRobin::UpdateLocked(const grpc_channel_args& args,
700
697
  class RoundRobinFactory : public LoadBalancingPolicyFactory {
701
698
  public:
702
699
  OrphanablePtr<LoadBalancingPolicy> CreateLoadBalancingPolicy(
703
- const LoadBalancingPolicy::Args& args) const override {
704
- return OrphanablePtr<LoadBalancingPolicy>(New<RoundRobin>(args));
700
+ LoadBalancingPolicy::Args args) const override {
701
+ return OrphanablePtr<LoadBalancingPolicy>(New<RoundRobin>(std::move(args)));
705
702
  }
706
703
 
707
704
  const char* name() const override { return kRoundRobin; }
@@ -88,7 +88,7 @@ class SubchannelData {
88
88
  }
89
89
 
90
90
  // Returns a pointer to the subchannel.
91
- grpc_subchannel* subchannel() const { return subchannel_; }
91
+ Subchannel* subchannel() const { return subchannel_; }
92
92
 
93
93
  // Returns the connected subchannel. Will be null if the subchannel
94
94
  // is not connected.
@@ -103,8 +103,8 @@ class SubchannelData {
103
103
  // ProcessConnectivityChangeLocked()).
104
104
  grpc_connectivity_state CheckConnectivityStateLocked(grpc_error** error) {
105
105
  GPR_ASSERT(!connectivity_notification_pending_);
106
- pending_connectivity_state_unsafe_ = grpc_subchannel_check_connectivity(
107
- subchannel(), error, subchannel_list_->inhibit_health_checking());
106
+ pending_connectivity_state_unsafe_ = subchannel()->CheckConnectivity(
107
+ error, subchannel_list_->inhibit_health_checking());
108
108
  UpdateConnectedSubchannelLocked();
109
109
  return pending_connectivity_state_unsafe_;
110
110
  }
@@ -142,7 +142,7 @@ class SubchannelData {
142
142
  protected:
143
143
  SubchannelData(
144
144
  SubchannelList<SubchannelListType, SubchannelDataType>* subchannel_list,
145
- const ServerAddress& address, grpc_subchannel* subchannel,
145
+ const ServerAddress& address, Subchannel* subchannel,
146
146
  grpc_combiner* combiner);
147
147
 
148
148
  virtual ~SubchannelData();
@@ -170,7 +170,7 @@ class SubchannelData {
170
170
  SubchannelList<SubchannelListType, SubchannelDataType>* subchannel_list_;
171
171
 
172
172
  // The subchannel and connected subchannel.
173
- grpc_subchannel* subchannel_;
173
+ Subchannel* subchannel_;
174
174
  RefCountedPtr<ConnectedSubchannel> connected_subchannel_;
175
175
 
176
176
  // Notification that connectivity has changed on subchannel.
@@ -203,7 +203,7 @@ class SubchannelList : public InternallyRefCounted<SubchannelListType> {
203
203
  for (size_t i = 0; i < subchannels_.size(); ++i) {
204
204
  if (subchannels_[i].subchannel() != nullptr) {
205
205
  grpc_core::channelz::SubchannelNode* subchannel_node =
206
- grpc_subchannel_get_channelz_node(subchannels_[i].subchannel());
206
+ subchannels_[i].subchannel()->channelz_node();
207
207
  if (subchannel_node != nullptr) {
208
208
  refs_list->push_back(subchannel_node->uuid());
209
209
  }
@@ -276,7 +276,7 @@ class SubchannelList : public InternallyRefCounted<SubchannelListType> {
276
276
  template <typename SubchannelListType, typename SubchannelDataType>
277
277
  SubchannelData<SubchannelListType, SubchannelDataType>::SubchannelData(
278
278
  SubchannelList<SubchannelListType, SubchannelDataType>* subchannel_list,
279
- const ServerAddress& address, grpc_subchannel* subchannel,
279
+ const ServerAddress& address, Subchannel* subchannel,
280
280
  grpc_combiner* combiner)
281
281
  : subchannel_list_(subchannel_list),
282
282
  subchannel_(subchannel),
@@ -317,7 +317,7 @@ template <typename SubchannelListType, typename SubchannelDataType>
317
317
  void SubchannelData<SubchannelListType,
318
318
  SubchannelDataType>::ResetBackoffLocked() {
319
319
  if (subchannel_ != nullptr) {
320
- grpc_subchannel_reset_backoff(subchannel_);
320
+ subchannel_->ResetBackoff();
321
321
  }
322
322
  }
323
323
 
@@ -337,8 +337,8 @@ void SubchannelData<SubchannelListType,
337
337
  GPR_ASSERT(!connectivity_notification_pending_);
338
338
  connectivity_notification_pending_ = true;
339
339
  subchannel_list()->Ref(DEBUG_LOCATION, "connectivity_watch").release();
340
- grpc_subchannel_notify_on_state_change(
341
- subchannel_, subchannel_list_->policy()->interested_parties(),
340
+ subchannel_->NotifyOnStateChange(
341
+ subchannel_list_->policy()->interested_parties(),
342
342
  &pending_connectivity_state_unsafe_, &connectivity_changed_closure_,
343
343
  subchannel_list_->inhibit_health_checking());
344
344
  }
@@ -357,8 +357,8 @@ void SubchannelData<SubchannelListType,
357
357
  grpc_connectivity_state_name(pending_connectivity_state_unsafe_));
358
358
  }
359
359
  GPR_ASSERT(connectivity_notification_pending_);
360
- grpc_subchannel_notify_on_state_change(
361
- subchannel_, subchannel_list_->policy()->interested_parties(),
360
+ subchannel_->NotifyOnStateChange(
361
+ subchannel_list_->policy()->interested_parties(),
362
362
  &pending_connectivity_state_unsafe_, &connectivity_changed_closure_,
363
363
  subchannel_list_->inhibit_health_checking());
364
364
  }
@@ -391,9 +391,9 @@ void SubchannelData<SubchannelListType, SubchannelDataType>::
391
391
  subchannel_, reason);
392
392
  }
393
393
  GPR_ASSERT(connectivity_notification_pending_);
394
- grpc_subchannel_notify_on_state_change(
395
- subchannel_, nullptr, nullptr, &connectivity_changed_closure_,
396
- subchannel_list_->inhibit_health_checking());
394
+ subchannel_->NotifyOnStateChange(nullptr, nullptr,
395
+ &connectivity_changed_closure_,
396
+ subchannel_list_->inhibit_health_checking());
397
397
  }
398
398
 
399
399
  template <typename SubchannelListType, typename SubchannelDataType>
@@ -401,8 +401,7 @@ bool SubchannelData<SubchannelListType,
401
401
  SubchannelDataType>::UpdateConnectedSubchannelLocked() {
402
402
  // If the subchannel is READY, take a ref to the connected subchannel.
403
403
  if (pending_connectivity_state_unsafe_ == GRPC_CHANNEL_READY) {
404
- connected_subchannel_ =
405
- grpc_subchannel_get_connected_subchannel(subchannel_);
404
+ connected_subchannel_ = subchannel_->connected_subchannel();
406
405
  // If the subchannel became disconnected between the time that READY
407
406
  // was reported and the time we got here (e.g., between when a
408
407
  // notification callback is scheduled and when it was actually run in
@@ -509,15 +508,16 @@ SubchannelList<SubchannelListType, SubchannelDataType>::SubchannelList(
509
508
  GRPC_ARG_SERVER_ADDRESS_LIST,
510
509
  GRPC_ARG_INHIBIT_HEALTH_CHECKING};
511
510
  // Create a subchannel for each address.
512
- grpc_subchannel_args sc_args;
513
511
  for (size_t i = 0; i < addresses.size(); i++) {
514
512
  // If there were any balancer addresses, we would have chosen grpclb
515
513
  // policy, which does not use a SubchannelList.
516
514
  GPR_ASSERT(!addresses[i].IsBalancer());
517
- memset(&sc_args, 0, sizeof(grpc_subchannel_args));
518
515
  InlinedVector<grpc_arg, 4> args_to_add;
519
516
  args_to_add.emplace_back(
520
- grpc_create_subchannel_address_arg(&addresses[i].address()));
517
+ SubchannelPoolInterface::CreateChannelArg(policy_->subchannel_pool()));
518
+ const size_t subchannel_address_arg_index = args_to_add.size();
519
+ args_to_add.emplace_back(
520
+ Subchannel::CreateSubchannelAddressArg(&addresses[i].address()));
521
521
  if (addresses[i].args() != nullptr) {
522
522
  for (size_t j = 0; j < addresses[i].args()->num_args; ++j) {
523
523
  args_to_add.emplace_back(addresses[i].args()->args[j]);
@@ -526,10 +526,9 @@ SubchannelList<SubchannelListType, SubchannelDataType>::SubchannelList(
526
526
  grpc_channel_args* new_args = grpc_channel_args_copy_and_add_and_remove(
527
527
  &args, keys_to_remove, GPR_ARRAY_SIZE(keys_to_remove),
528
528
  args_to_add.data(), args_to_add.size());
529
- gpr_free(args_to_add[0].value.string);
530
- sc_args.args = new_args;
531
- grpc_subchannel* subchannel = grpc_client_channel_factory_create_subchannel(
532
- client_channel_factory, &sc_args);
529
+ gpr_free(args_to_add[subchannel_address_arg_index].value.string);
530
+ Subchannel* subchannel = grpc_client_channel_factory_create_subchannel(
531
+ client_channel_factory, new_args);
533
532
  grpc_channel_args_destroy(new_args);
534
533
  if (subchannel == nullptr) {
535
534
  // Subchannel could not be created.