grpc 1.22.0 → 1.23.0

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 (176) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +487 -649
  3. data/include/grpc/grpc_security.h +25 -0
  4. data/include/grpc/impl/codegen/grpc_types.h +11 -2
  5. data/include/grpc/impl/codegen/port_platform.h +12 -0
  6. data/src/core/ext/filters/client_channel/backup_poller.cc +4 -2
  7. data/src/core/ext/filters/client_channel/client_channel.cc +477 -182
  8. data/src/core/ext/filters/client_channel/client_channel_channelz.cc +25 -16
  9. data/src/core/ext/filters/client_channel/client_channel_channelz.h +11 -6
  10. data/src/core/ext/filters/client_channel/connector.h +10 -2
  11. data/src/core/ext/filters/client_channel/health/health_check_client.cc +3 -3
  12. data/src/core/ext/filters/client_channel/http_proxy.cc +9 -10
  13. data/src/core/ext/filters/client_channel/lb_policy.cc +2 -17
  14. data/src/core/ext/filters/client_channel/lb_policy.h +36 -8
  15. data/src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.cc +22 -8
  16. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +86 -52
  17. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.h +7 -0
  18. data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc +73 -72
  19. data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc +8 -12
  20. data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +25 -101
  21. data/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc +5 -5
  22. data/src/core/ext/filters/client_channel/parse_address.cc +29 -26
  23. data/src/core/ext/filters/client_channel/resolver.h +3 -11
  24. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +5 -3
  25. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_windows.cc +405 -82
  26. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc +44 -51
  27. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_libuv.cc +0 -1
  28. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_windows.cc +0 -1
  29. data/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc +11 -6
  30. data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc +130 -65
  31. data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.h +8 -3
  32. data/src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.cc +31 -14
  33. data/src/core/ext/filters/client_channel/resolver_factory.h +4 -0
  34. data/src/core/ext/filters/client_channel/resolver_registry.cc +11 -0
  35. data/src/core/ext/filters/client_channel/resolver_registry.h +3 -0
  36. data/src/core/ext/filters/client_channel/resolving_lb_policy.cc +10 -49
  37. data/src/core/ext/filters/client_channel/resolving_lb_policy.h +1 -14
  38. data/src/core/ext/filters/client_channel/retry_throttle.h +2 -3
  39. data/src/core/ext/filters/client_channel/subchannel.cc +65 -58
  40. data/src/core/ext/filters/client_channel/subchannel.h +65 -45
  41. data/src/core/ext/filters/client_channel/subchannel_interface.h +15 -30
  42. data/src/core/ext/filters/client_idle/client_idle_filter.cc +262 -0
  43. data/src/core/ext/filters/http/client/http_client_filter.cc +4 -5
  44. data/src/core/ext/filters/http/client_authority_filter.cc +2 -2
  45. data/src/core/ext/filters/http/message_compress/message_compress_filter.cc +140 -152
  46. data/src/core/ext/filters/max_age/max_age_filter.cc +3 -3
  47. data/src/core/ext/transport/chttp2/client/chttp2_connector.cc +3 -4
  48. data/src/core/ext/transport/chttp2/server/chttp2_server.cc +7 -6
  49. data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +63 -38
  50. data/src/core/ext/transport/chttp2/transport/context_list.cc +3 -1
  51. data/src/core/ext/transport/chttp2/transport/frame_data.cc +4 -4
  52. data/src/core/ext/transport/chttp2/transport/frame_goaway.cc +1 -1
  53. data/src/core/ext/transport/chttp2/transport/frame_ping.cc +1 -0
  54. data/src/core/ext/transport/chttp2/transport/frame_rst_stream.cc +8 -0
  55. data/src/core/ext/transport/chttp2/transport/frame_rst_stream.h +7 -0
  56. data/src/core/ext/transport/chttp2/transport/frame_settings.cc +1 -0
  57. data/src/core/ext/transport/chttp2/transport/hpack_encoder.cc +37 -22
  58. data/src/core/ext/transport/chttp2/transport/hpack_parser.cc +136 -81
  59. data/src/core/ext/transport/chttp2/transport/hpack_parser.h +8 -0
  60. data/src/core/ext/transport/chttp2/transport/hpack_table.cc +7 -166
  61. data/src/core/ext/transport/chttp2/transport/hpack_table.h +41 -15
  62. data/src/core/ext/transport/chttp2/transport/internal.h +13 -2
  63. data/src/core/ext/transport/chttp2/transport/parsing.cc +35 -22
  64. data/src/core/ext/transport/chttp2/transport/stream_map.cc +28 -18
  65. data/src/core/ext/transport/chttp2/transport/writing.cc +1 -0
  66. data/src/core/ext/transport/inproc/inproc_transport.cc +1 -1
  67. data/src/core/lib/channel/channelz.cc +80 -33
  68. data/src/core/lib/channel/channelz.h +28 -13
  69. data/src/core/lib/compression/compression.cc +1 -2
  70. data/src/core/lib/compression/compression_args.cc +13 -6
  71. data/src/core/lib/compression/compression_args.h +3 -2
  72. data/src/core/lib/compression/compression_internal.cc +1 -1
  73. data/src/core/lib/gpr/env_linux.cc +10 -21
  74. data/src/core/lib/gpr/env_posix.cc +0 -5
  75. data/src/core/lib/gpr/string.cc +7 -2
  76. data/src/core/lib/gpr/string.h +1 -0
  77. data/src/core/lib/gpr/sync_posix.cc +0 -129
  78. data/src/core/lib/gprpp/debug_location.h +3 -2
  79. data/src/core/lib/gprpp/fork.cc +14 -21
  80. data/src/core/lib/gprpp/fork.h +15 -4
  81. data/src/core/lib/gprpp/host_port.cc +118 -0
  82. data/src/core/lib/{gpr → gprpp}/host_port.h +27 -11
  83. data/src/core/lib/gprpp/map.h +25 -0
  84. data/src/core/lib/gprpp/memory.h +26 -9
  85. data/src/core/lib/gprpp/ref_counted.h +63 -21
  86. data/src/core/lib/gprpp/string_view.h +143 -0
  87. data/src/core/lib/gprpp/thd.h +10 -1
  88. data/src/core/lib/gprpp/thd_posix.cc +25 -0
  89. data/src/core/lib/gprpp/thd_windows.cc +9 -1
  90. data/src/core/lib/http/httpcli_security_connector.cc +3 -1
  91. data/src/core/lib/iomgr/cfstream_handle.cc +6 -1
  92. data/src/core/lib/iomgr/cfstream_handle.h +8 -2
  93. data/src/core/lib/iomgr/combiner.cc +4 -4
  94. data/src/core/lib/iomgr/error.cc +18 -8
  95. data/src/core/lib/iomgr/error.h +2 -0
  96. data/src/core/lib/iomgr/ev_posix.cc +4 -2
  97. data/src/core/lib/iomgr/executor.cc +4 -1
  98. data/src/core/lib/iomgr/executor/mpmcqueue.cc +183 -0
  99. data/src/core/lib/iomgr/executor/mpmcqueue.h +178 -0
  100. data/src/core/lib/iomgr/executor/threadpool.cc +138 -0
  101. data/src/core/lib/iomgr/executor/threadpool.h +153 -0
  102. data/src/core/lib/iomgr/fork_posix.cc +4 -2
  103. data/src/core/lib/iomgr/iocp_windows.cc +2 -2
  104. data/src/core/lib/iomgr/iomgr_posix_cfstream.cc +14 -0
  105. data/src/core/lib/iomgr/iomgr_uv.cc +3 -0
  106. data/src/core/lib/iomgr/lockfree_event.cc +3 -3
  107. data/src/core/lib/iomgr/resolve_address_custom.cc +16 -20
  108. data/src/core/lib/iomgr/resolve_address_posix.cc +8 -10
  109. data/src/core/lib/iomgr/resolve_address_windows.cc +6 -8
  110. data/src/core/lib/iomgr/sockaddr_utils.cc +5 -3
  111. data/src/core/lib/iomgr/socket_utils_common_posix.cc +0 -1
  112. data/src/core/lib/iomgr/socket_windows.h +1 -1
  113. data/src/core/lib/iomgr/tcp_client_cfstream.cc +7 -6
  114. data/src/core/lib/iomgr/tcp_client_custom.cc +1 -0
  115. data/src/core/lib/iomgr/tcp_custom.cc +4 -0
  116. data/src/core/lib/iomgr/tcp_posix.cc +8 -2
  117. data/src/core/lib/iomgr/tcp_server_custom.cc +1 -0
  118. data/src/core/lib/iomgr/tcp_server_windows.cc +1 -1
  119. data/src/core/lib/iomgr/tcp_windows.cc +7 -7
  120. data/src/core/lib/iomgr/timer_custom.cc +1 -0
  121. data/src/core/lib/iomgr/timer_manager.cc +0 -29
  122. data/src/core/lib/security/credentials/credentials.cc +84 -0
  123. data/src/core/lib/security/credentials/credentials.h +58 -2
  124. data/src/core/lib/security/credentials/jwt/json_token.cc +6 -2
  125. data/src/core/lib/security/credentials/jwt/json_token.h +1 -1
  126. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc +245 -24
  127. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.h +16 -0
  128. data/src/core/lib/security/security_connector/alts/alts_security_connector.cc +3 -2
  129. data/src/core/lib/security/security_connector/fake/fake_security_connector.cc +21 -25
  130. data/src/core/lib/security/security_connector/local/local_security_connector.cc +3 -2
  131. data/src/core/lib/security/security_connector/security_connector.cc +1 -1
  132. data/src/core/lib/security/security_connector/security_connector.h +1 -1
  133. data/src/core/lib/security/security_connector/ssl/ssl_security_connector.cc +19 -19
  134. data/src/core/lib/security/security_connector/ssl_utils.cc +26 -31
  135. data/src/core/lib/security/security_connector/ssl_utils.h +11 -8
  136. data/src/core/lib/security/security_connector/tls/spiffe_security_connector.cc +16 -20
  137. data/src/core/lib/security/security_connector/tls/spiffe_security_connector.h +4 -3
  138. data/src/core/lib/security/transport/client_auth_filter.cc +1 -2
  139. data/src/core/lib/security/util/json_util.cc +19 -5
  140. data/src/core/lib/security/util/json_util.h +3 -1
  141. data/src/core/lib/slice/slice.cc +69 -50
  142. data/src/core/lib/slice/slice_buffer.cc +6 -5
  143. data/src/core/lib/slice/slice_hash_table.h +3 -7
  144. data/src/core/lib/slice/slice_intern.cc +130 -39
  145. data/src/core/lib/slice/slice_internal.h +8 -0
  146. data/src/core/lib/slice/slice_utils.h +120 -0
  147. data/src/core/lib/slice/slice_weak_hash_table.h +2 -7
  148. data/src/core/lib/surface/call.cc +8 -3
  149. data/src/core/lib/surface/channel.cc +31 -8
  150. data/src/core/lib/surface/completion_queue.cc +17 -7
  151. data/src/core/lib/surface/init_secure.cc +4 -1
  152. data/src/core/lib/surface/lame_client.cc +2 -2
  153. data/src/core/lib/surface/server.cc +34 -35
  154. data/src/core/lib/surface/server.h +8 -17
  155. data/src/core/lib/surface/version.cc +1 -1
  156. data/src/core/lib/transport/byte_stream.cc +3 -5
  157. data/src/core/lib/transport/byte_stream.h +1 -2
  158. data/src/core/lib/transport/error_utils.cc +10 -1
  159. data/src/core/lib/transport/metadata.cc +202 -35
  160. data/src/core/lib/transport/metadata.h +81 -6
  161. data/src/core/lib/transport/static_metadata.cc +1257 -465
  162. data/src/core/lib/transport/static_metadata.h +190 -347
  163. data/src/core/lib/transport/timeout_encoding.cc +7 -0
  164. data/src/core/lib/transport/timeout_encoding.h +3 -2
  165. data/src/core/plugin_registry/grpc_plugin_registry.cc +4 -0
  166. data/src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc +0 -1
  167. data/src/core/tsi/ssl/session_cache/ssl_session_cache.h +2 -7
  168. data/src/core/tsi/ssl_transport_security.cc +35 -43
  169. data/src/core/tsi/ssl_transport_security.h +2 -1
  170. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +2 -0
  171. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +3 -0
  172. data/src/ruby/lib/grpc/generic/rpc_server.rb +1 -1
  173. data/src/ruby/lib/grpc/grpc.rb +1 -1
  174. data/src/ruby/lib/grpc/version.rb +1 -1
  175. metadata +39 -33
  176. data/src/core/lib/gpr/host_port.cc +0 -98
@@ -32,5 +32,12 @@
32
32
  #define GRPC_ARG_ADDRESS_IS_BACKEND_FROM_GRPCLB_LOAD_BALANCER \
33
33
  "grpc.address_is_backend_from_grpclb_load_balancer"
34
34
 
35
+ namespace grpc_core {
36
+
37
+ extern const char kGrpcLbClientStatsMetadataKey[];
38
+ extern const char kGrpcLbLbTokenMetadataKey[];
39
+
40
+ } // namespace grpc_core
41
+
35
42
  #endif /* GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_LB_POLICY_GRPCLB_GRPCLB_H \
36
43
  */
@@ -28,7 +28,6 @@
28
28
  #include "src/core/ext/filters/client_channel/subchannel.h"
29
29
  #include "src/core/lib/channel/channel_args.h"
30
30
  #include "src/core/lib/gprpp/sync.h"
31
- #include "src/core/lib/iomgr/combiner.h"
32
31
  #include "src/core/lib/iomgr/sockaddr_utils.h"
33
32
  #include "src/core/lib/transport/connectivity_state.h"
34
33
 
@@ -85,9 +84,8 @@ class PickFirst : public LoadBalancingPolicy {
85
84
  public:
86
85
  PickFirstSubchannelList(PickFirst* policy, TraceFlag* tracer,
87
86
  const ServerAddressList& addresses,
88
- grpc_combiner* combiner,
89
87
  const grpc_channel_args& args)
90
- : SubchannelList(policy, tracer, addresses, combiner,
88
+ : SubchannelList(policy, tracer, addresses,
91
89
  policy->channel_control_helper(), args) {
92
90
  // Need to maintain a ref to the LB policy as long as we maintain
93
91
  // any references to subchannels, since the subchannels'
@@ -111,23 +109,26 @@ class PickFirst : public LoadBalancingPolicy {
111
109
 
112
110
  class Picker : public SubchannelPicker {
113
111
  public:
114
- explicit Picker(
115
- RefCountedPtr<ConnectedSubchannelInterface> connected_subchannel)
116
- : connected_subchannel_(std::move(connected_subchannel)) {}
112
+ explicit Picker(RefCountedPtr<SubchannelInterface> subchannel)
113
+ : subchannel_(std::move(subchannel)) {}
117
114
 
118
115
  PickResult Pick(PickArgs args) override {
119
116
  PickResult result;
120
117
  result.type = PickResult::PICK_COMPLETE;
121
- result.connected_subchannel = connected_subchannel_;
118
+ result.subchannel = subchannel_;
122
119
  return result;
123
120
  }
124
121
 
125
122
  private:
126
- RefCountedPtr<ConnectedSubchannelInterface> connected_subchannel_;
123
+ RefCountedPtr<SubchannelInterface> subchannel_;
127
124
  };
128
125
 
129
126
  void ShutdownLocked() override;
130
127
 
128
+ void AttemptToConnectUsingLatestUpdateArgsLocked();
129
+
130
+ // Lateset update args.
131
+ UpdateArgs latest_update_args_;
131
132
  // All our subchannels.
132
133
  OrphanablePtr<PickFirstSubchannelList> subchannel_list_;
133
134
  // Latest pending subchannel list.
@@ -166,59 +167,41 @@ void PickFirst::ShutdownLocked() {
166
167
  void PickFirst::ExitIdleLocked() {
167
168
  if (shutdown_) return;
168
169
  if (idle_) {
169
- idle_ = false;
170
- if (subchannel_list_ == nullptr ||
171
- subchannel_list_->num_subchannels() == 0) {
172
- grpc_error* error = grpc_error_set_int(
173
- GRPC_ERROR_CREATE_FROM_STATIC_STRING("No addresses to connect to"),
174
- GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_UNAVAILABLE);
175
- channel_control_helper()->UpdateState(
176
- GRPC_CHANNEL_TRANSIENT_FAILURE,
177
- UniquePtr<SubchannelPicker>(New<TransientFailurePicker>(error)));
178
- } else {
179
- subchannel_list_->subchannel(0)
180
- ->CheckConnectivityStateAndStartWatchingLocked();
170
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_pick_first_trace)) {
171
+ gpr_log(GPR_INFO, "Pick First %p exiting idle", this);
181
172
  }
173
+ idle_ = false;
174
+ AttemptToConnectUsingLatestUpdateArgsLocked();
182
175
  }
183
176
  }
184
177
 
185
178
  void PickFirst::ResetBackoffLocked() {
186
- subchannel_list_->ResetBackoffLocked();
179
+ if (subchannel_list_ != nullptr) subchannel_list_->ResetBackoffLocked();
187
180
  if (latest_pending_subchannel_list_ != nullptr) {
188
181
  latest_pending_subchannel_list_->ResetBackoffLocked();
189
182
  }
190
183
  }
191
184
 
192
- void PickFirst::UpdateLocked(UpdateArgs args) {
193
- if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_pick_first_trace)) {
194
- gpr_log(GPR_INFO,
195
- "Pick First %p received update with %" PRIuPTR " addresses", this,
196
- args.addresses.size());
197
- }
198
- grpc_arg new_arg = grpc_channel_arg_integer_create(
199
- const_cast<char*>(GRPC_ARG_INHIBIT_HEALTH_CHECKING), 1);
200
- grpc_channel_args* new_args =
201
- grpc_channel_args_copy_and_add(args.args, &new_arg, 1);
185
+ void PickFirst::AttemptToConnectUsingLatestUpdateArgsLocked() {
186
+ // Create a subchannel list from the latest_update_args_.
202
187
  auto subchannel_list = MakeOrphanable<PickFirstSubchannelList>(
203
- this, &grpc_lb_pick_first_trace, args.addresses, combiner(), *new_args);
204
- grpc_channel_args_destroy(new_args);
188
+ this, &grpc_lb_pick_first_trace, latest_update_args_.addresses,
189
+ *latest_update_args_.args);
190
+ // Empty update or no valid subchannels.
205
191
  if (subchannel_list->num_subchannels() == 0) {
206
- // Empty update or no valid subchannels. Unsubscribe from all current
207
- // subchannels.
192
+ // Unsubscribe from all current subchannels.
208
193
  subchannel_list_ = std::move(subchannel_list); // Empty list.
209
194
  selected_ = nullptr;
210
195
  // If not idle, put the channel in TRANSIENT_FAILURE.
211
196
  // (If we are idle, then this will happen in ExitIdleLocked() if we
212
197
  // haven't gotten a non-empty update by the time the application tries
213
198
  // to start a new call.)
214
- if (!idle_) {
215
- grpc_error* error = grpc_error_set_int(
216
- GRPC_ERROR_CREATE_FROM_STATIC_STRING("Empty update"),
217
- GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_UNAVAILABLE);
218
- channel_control_helper()->UpdateState(
219
- GRPC_CHANNEL_TRANSIENT_FAILURE,
220
- UniquePtr<SubchannelPicker>(New<TransientFailurePicker>(error)));
221
- }
199
+ grpc_error* error =
200
+ grpc_error_set_int(GRPC_ERROR_CREATE_FROM_STATIC_STRING("Empty update"),
201
+ GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_UNAVAILABLE);
202
+ channel_control_helper()->UpdateState(
203
+ GRPC_CHANNEL_TRANSIENT_FAILURE,
204
+ UniquePtr<SubchannelPicker>(New<TransientFailurePicker>(error)));
222
205
  return;
223
206
  }
224
207
  // If one of the subchannels in the new list is already in state
@@ -226,8 +209,6 @@ void PickFirst::UpdateLocked(UpdateArgs args) {
226
209
  // currently selected subchannel is also present in the update. It
227
210
  // can also happen if one of the subchannels in the update is already
228
211
  // in the global subchannel pool because it's in use by another channel.
229
- // TODO(roth): If we're in IDLE state, we should probably defer this
230
- // check and instead do it in ExitIdleLocked().
231
212
  for (size_t i = 0; i < subchannel_list->num_subchannels(); ++i) {
232
213
  PickFirstSubchannelData* sd = subchannel_list->subchannel(i);
233
214
  grpc_connectivity_state state = sd->CheckConnectivityStateLocked();
@@ -239,10 +220,6 @@ void PickFirst::UpdateLocked(UpdateArgs args) {
239
220
  // not have contained the currently selected subchannel), drop
240
221
  // it, so that it doesn't override what we've done here.
241
222
  latest_pending_subchannel_list_.reset();
242
- // Make sure that subsequent calls to ExitIdleLocked() don't cause
243
- // us to start watching a subchannel other than the one we've
244
- // selected.
245
- idle_ = false;
246
223
  return;
247
224
  }
248
225
  }
@@ -252,13 +229,11 @@ void PickFirst::UpdateLocked(UpdateArgs args) {
252
229
  subchannel_list_ = std::move(subchannel_list);
253
230
  // If we're not in IDLE state, start trying to connect to the first
254
231
  // subchannel in the new list.
255
- if (!idle_) {
256
- // Note: No need to use CheckConnectivityStateAndStartWatchingLocked()
257
- // here, since we've already checked the initial connectivity
258
- // state of all subchannels above.
259
- subchannel_list_->subchannel(0)->StartConnectivityWatchLocked();
260
- subchannel_list_->subchannel(0)->subchannel()->AttemptToConnect();
261
- }
232
+ // Note: No need to use CheckConnectivityStateAndStartWatchingLocked()
233
+ // here, since we've already checked the initial connectivity
234
+ // state of all subchannels above.
235
+ subchannel_list_->subchannel(0)->StartConnectivityWatchLocked();
236
+ subchannel_list_->subchannel(0)->subchannel()->AttemptToConnect();
262
237
  } else {
263
238
  // We do have a selected subchannel (which means it's READY), so keep
264
239
  // using it until one of the subchannels in the new list reports READY.
@@ -274,16 +249,35 @@ void PickFirst::UpdateLocked(UpdateArgs args) {
274
249
  latest_pending_subchannel_list_ = std::move(subchannel_list);
275
250
  // If we're not in IDLE state, start trying to connect to the first
276
251
  // subchannel in the new list.
277
- if (!idle_) {
278
- // Note: No need to use CheckConnectivityStateAndStartWatchingLocked()
279
- // here, since we've already checked the initial connectivity
280
- // state of all subchannels above.
281
- latest_pending_subchannel_list_->subchannel(0)
282
- ->StartConnectivityWatchLocked();
283
- latest_pending_subchannel_list_->subchannel(0)
284
- ->subchannel()
285
- ->AttemptToConnect();
286
- }
252
+ // Note: No need to use CheckConnectivityStateAndStartWatchingLocked()
253
+ // here, since we've already checked the initial connectivity
254
+ // state of all subchannels above.
255
+ latest_pending_subchannel_list_->subchannel(0)
256
+ ->StartConnectivityWatchLocked();
257
+ latest_pending_subchannel_list_->subchannel(0)
258
+ ->subchannel()
259
+ ->AttemptToConnect();
260
+ }
261
+ }
262
+
263
+ void PickFirst::UpdateLocked(UpdateArgs args) {
264
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_pick_first_trace)) {
265
+ gpr_log(GPR_INFO,
266
+ "Pick First %p received update with %" PRIuPTR " addresses", this,
267
+ args.addresses.size());
268
+ }
269
+ // Update the latest_update_args_
270
+ grpc_arg new_arg = grpc_channel_arg_integer_create(
271
+ const_cast<char*>(GRPC_ARG_INHIBIT_HEALTH_CHECKING), 1);
272
+ const grpc_channel_args* new_args =
273
+ grpc_channel_args_copy_and_add(args.args, &new_arg, 1);
274
+ GPR_SWAP(const grpc_channel_args*, new_args, args.args);
275
+ grpc_channel_args_destroy(new_args);
276
+ latest_update_args_ = std::move(args);
277
+ // If we are not in idle, start connection attempt immediately.
278
+ // Otherwise, we defer the attempt into ExitIdleLocked().
279
+ if (!idle_) {
280
+ AttemptToConnectUsingLatestUpdateArgsLocked();
287
281
  }
288
282
  }
289
283
 
@@ -338,10 +332,12 @@ void PickFirst::PickFirstSubchannelData::ProcessConnectivityChangeLocked(
338
332
  // also set the channel state to IDLE. The reason is that if the new
339
333
  // state is TRANSIENT_FAILURE due to a GOAWAY reception we don't want
340
334
  // to connect to the re-resolved backends until we leave IDLE state.
335
+ // TODO(qianchengz): We may want to request re-resolution in
336
+ // ExitIdleLocked().
341
337
  p->idle_ = true;
342
338
  p->channel_control_helper()->RequestReresolution();
343
339
  p->selected_ = nullptr;
344
- CancelConnectivityWatchLocked("selected subchannel failed; going IDLE");
340
+ p->subchannel_list_.reset();
345
341
  p->channel_control_helper()->UpdateState(
346
342
  GRPC_CHANNEL_IDLE, UniquePtr<SubchannelPicker>(New<QueuePicker>(
347
343
  p->Ref(DEBUG_LOCATION, "QueuePicker"))));
@@ -351,8 +347,8 @@ void PickFirst::PickFirstSubchannelData::ProcessConnectivityChangeLocked(
351
347
  // some connectivity state notifications.
352
348
  if (connectivity_state == GRPC_CHANNEL_READY) {
353
349
  p->channel_control_helper()->UpdateState(
354
- GRPC_CHANNEL_READY, UniquePtr<SubchannelPicker>(New<Picker>(
355
- connected_subchannel()->Ref())));
350
+ GRPC_CHANNEL_READY,
351
+ UniquePtr<SubchannelPicker>(New<Picker>(subchannel()->Ref())));
356
352
  } else { // CONNECTING
357
353
  p->channel_control_helper()->UpdateState(
358
354
  connectivity_state, UniquePtr<SubchannelPicker>(New<QueuePicker>(
@@ -447,12 +443,17 @@ void PickFirst::PickFirstSubchannelData::ProcessUnselectedReadyLocked() {
447
443
  p->subchannel_list_ = std::move(p->latest_pending_subchannel_list_);
448
444
  }
449
445
  // Cases 1 and 2.
446
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_pick_first_trace)) {
447
+ gpr_log(GPR_INFO, "Pick First %p selected subchannel %p", p, subchannel());
448
+ }
450
449
  p->selected_ = this;
451
450
  p->channel_control_helper()->UpdateState(
452
451
  GRPC_CHANNEL_READY,
453
- UniquePtr<SubchannelPicker>(New<Picker>(connected_subchannel()->Ref())));
454
- if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_pick_first_trace)) {
455
- gpr_log(GPR_INFO, "Pick First %p selected subchannel %p", p, subchannel());
452
+ UniquePtr<SubchannelPicker>(New<Picker>(subchannel()->Ref())));
453
+ for (size_t i = 0; i < subchannel_list()->num_subchannels(); ++i) {
454
+ if (i != Index()) {
455
+ subchannel_list()->subchannel(i)->ShutdownLocked();
456
+ }
456
457
  }
457
458
  }
458
459
 
@@ -38,7 +38,6 @@
38
38
  #include "src/core/lib/debug/trace.h"
39
39
  #include "src/core/lib/gprpp/ref_counted_ptr.h"
40
40
  #include "src/core/lib/gprpp/sync.h"
41
- #include "src/core/lib/iomgr/combiner.h"
42
41
  #include "src/core/lib/iomgr/sockaddr_utils.h"
43
42
  #include "src/core/lib/transport/connectivity_state.h"
44
43
  #include "src/core/lib/transport/static_metadata.h"
@@ -106,9 +105,8 @@ class RoundRobin : public LoadBalancingPolicy {
106
105
  public:
107
106
  RoundRobinSubchannelList(RoundRobin* policy, TraceFlag* tracer,
108
107
  const ServerAddressList& addresses,
109
- grpc_combiner* combiner,
110
108
  const grpc_channel_args& args)
111
- : SubchannelList(policy, tracer, addresses, combiner,
109
+ : SubchannelList(policy, tracer, addresses,
112
110
  policy->channel_control_helper(), args) {
113
111
  // Need to maintain a ref to the LB policy as long as we maintain
114
112
  // any references to subchannels, since the subchannels'
@@ -155,7 +153,7 @@ class RoundRobin : public LoadBalancingPolicy {
155
153
  RoundRobin* parent_;
156
154
 
157
155
  size_t last_picked_index_;
158
- InlinedVector<RefCountedPtr<ConnectedSubchannelInterface>, 10> subchannels_;
156
+ InlinedVector<RefCountedPtr<SubchannelInterface>, 10> subchannels_;
159
157
  };
160
158
 
161
159
  void ShutdownLocked() override;
@@ -180,10 +178,9 @@ RoundRobin::Picker::Picker(RoundRobin* parent,
180
178
  RoundRobinSubchannelList* subchannel_list)
181
179
  : parent_(parent) {
182
180
  for (size_t i = 0; i < subchannel_list->num_subchannels(); ++i) {
183
- auto* connected_subchannel =
184
- subchannel_list->subchannel(i)->connected_subchannel();
185
- if (connected_subchannel != nullptr) {
186
- subchannels_.push_back(connected_subchannel->Ref());
181
+ RoundRobinSubchannelData* sd = subchannel_list->subchannel(i);
182
+ if (sd->connectivity_state() == GRPC_CHANNEL_READY) {
183
+ subchannels_.push_back(sd->subchannel()->Ref());
187
184
  }
188
185
  }
189
186
  // For discussion on why we generate a random starting index for
@@ -204,14 +201,13 @@ RoundRobin::PickResult RoundRobin::Picker::Pick(PickArgs args) {
204
201
  last_picked_index_ = (last_picked_index_ + 1) % subchannels_.size();
205
202
  if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_round_robin_trace)) {
206
203
  gpr_log(GPR_INFO,
207
- "[RR %p picker %p] returning index %" PRIuPTR
208
- ", connected_subchannel=%p",
204
+ "[RR %p picker %p] returning index %" PRIuPTR ", subchannel=%p",
209
205
  parent_, this, last_picked_index_,
210
206
  subchannels_[last_picked_index_].get());
211
207
  }
212
208
  PickResult result;
213
209
  result.type = PickResult::PICK_COMPLETE;
214
- result.connected_subchannel = subchannels_[last_picked_index_];
210
+ result.subchannel = subchannels_[last_picked_index_];
215
211
  return result;
216
212
  }
217
213
 
@@ -424,7 +420,7 @@ void RoundRobin::UpdateLocked(UpdateArgs args) {
424
420
  }
425
421
  }
426
422
  latest_pending_subchannel_list_ = MakeOrphanable<RoundRobinSubchannelList>(
427
- this, &grpc_lb_round_robin_trace, args.addresses, combiner(), *args.args);
423
+ this, &grpc_lb_round_robin_trace, args.addresses, *args.args);
428
424
  if (latest_pending_subchannel_list_->num_subchannels() == 0) {
429
425
  // If the new list is empty, immediately promote the new list to the
430
426
  // current list and transition to TRANSIENT_FAILURE.
@@ -39,7 +39,6 @@
39
39
  #include "src/core/lib/gprpp/ref_counted.h"
40
40
  #include "src/core/lib/gprpp/ref_counted_ptr.h"
41
41
  #include "src/core/lib/iomgr/closure.h"
42
- #include "src/core/lib/iomgr/combiner.h"
43
42
  #include "src/core/lib/iomgr/sockaddr_utils.h"
44
43
  #include "src/core/lib/transport/connectivity_state.h"
45
44
 
@@ -64,8 +63,7 @@ class MySubchannelList
64
63
  };
65
64
 
66
65
  */
67
- // All methods with a Locked() suffix must be called from within the
68
- // client_channel combiner.
66
+ // All methods will be called from within the client_channel combiner.
69
67
 
70
68
  namespace grpc_core {
71
69
 
@@ -93,20 +91,13 @@ class SubchannelData {
93
91
  // Returns a pointer to the subchannel.
94
92
  SubchannelInterface* subchannel() const { return subchannel_.get(); }
95
93
 
96
- // Returns the connected subchannel. Will be null if the subchannel
97
- // is not connected.
98
- ConnectedSubchannelInterface* connected_subchannel() const {
99
- return connected_subchannel_.get();
100
- }
101
-
102
94
  // Synchronously checks the subchannel's connectivity state.
103
95
  // Must not be called while there is a connectivity notification
104
96
  // pending (i.e., between calling StartConnectivityWatchLocked() and
105
97
  // calling CancelConnectivityWatchLocked()).
106
98
  grpc_connectivity_state CheckConnectivityStateLocked() {
107
99
  GPR_ASSERT(pending_watcher_ == nullptr);
108
- connectivity_state_ =
109
- subchannel()->CheckConnectivityState(&connected_subchannel_);
100
+ connectivity_state_ = subchannel_->CheckConnectivityState();
110
101
  return connectivity_state_;
111
102
  }
112
103
 
@@ -144,7 +135,8 @@ class SubchannelData {
144
135
 
145
136
  private:
146
137
  // Watcher for subchannel connectivity state.
147
- class Watcher : public SubchannelInterface::ConnectivityStateWatcher {
138
+ class Watcher
139
+ : public SubchannelInterface::ConnectivityStateWatcherInterface {
148
140
  public:
149
141
  Watcher(
150
142
  SubchannelData<SubchannelListType, SubchannelDataType>* subchannel_data,
@@ -154,42 +146,13 @@ class SubchannelData {
154
146
 
155
147
  ~Watcher() { subchannel_list_.reset(DEBUG_LOCATION, "Watcher dtor"); }
156
148
 
157
- void OnConnectivityStateChange(grpc_connectivity_state new_state,
158
- RefCountedPtr<ConnectedSubchannelInterface>
159
- connected_subchannel) override;
149
+ void OnConnectivityStateChange(grpc_connectivity_state new_state) override;
160
150
 
161
151
  grpc_pollset_set* interested_parties() override {
162
152
  return subchannel_list_->policy()->interested_parties();
163
153
  }
164
154
 
165
155
  private:
166
- // A fire-and-forget class that bounces into the combiner to process
167
- // a connectivity state update.
168
- class Updater {
169
- public:
170
- Updater(
171
- SubchannelData<SubchannelListType, SubchannelDataType>*
172
- subchannel_data,
173
- RefCountedPtr<SubchannelList<SubchannelListType, SubchannelDataType>>
174
- subchannel_list,
175
- grpc_connectivity_state state,
176
- RefCountedPtr<ConnectedSubchannelInterface> connected_subchannel);
177
-
178
- ~Updater() {
179
- subchannel_list_.reset(DEBUG_LOCATION, "Watcher::Updater dtor");
180
- }
181
-
182
- private:
183
- static void OnUpdateLocked(void* arg, grpc_error* error);
184
-
185
- SubchannelData<SubchannelListType, SubchannelDataType>* subchannel_data_;
186
- RefCountedPtr<SubchannelList<SubchannelListType, SubchannelDataType>>
187
- subchannel_list_;
188
- const grpc_connectivity_state state_;
189
- RefCountedPtr<ConnectedSubchannelInterface> connected_subchannel_;
190
- grpc_closure closure_;
191
- };
192
-
193
156
  SubchannelData<SubchannelListType, SubchannelDataType>* subchannel_data_;
194
157
  RefCountedPtr<SubchannelListType> subchannel_list_;
195
158
  };
@@ -202,10 +165,10 @@ class SubchannelData {
202
165
  // The subchannel.
203
166
  RefCountedPtr<SubchannelInterface> subchannel_;
204
167
  // Will be non-null when the subchannel's state is being watched.
205
- SubchannelInterface::ConnectivityStateWatcher* pending_watcher_ = nullptr;
168
+ SubchannelInterface::ConnectivityStateWatcherInterface* pending_watcher_ =
169
+ nullptr;
206
170
  // Data updated by the watcher.
207
171
  grpc_connectivity_state connectivity_state_;
208
- RefCountedPtr<ConnectedSubchannelInterface> connected_subchannel_;
209
172
  };
210
173
 
211
174
  // A list of subchannels.
@@ -232,7 +195,6 @@ class SubchannelList : public InternallyRefCounted<SubchannelListType> {
232
195
  // the backoff code out of subchannels and into LB policies.
233
196
  void ResetBackoffLocked();
234
197
 
235
- // Note: Caller must ensure that this is invoked inside of the combiner.
236
198
  void Orphan() override {
237
199
  ShutdownLocked();
238
200
  InternallyRefCounted<SubchannelListType>::Unref(DEBUG_LOCATION, "shutdown");
@@ -242,7 +204,7 @@ class SubchannelList : public InternallyRefCounted<SubchannelListType> {
242
204
 
243
205
  protected:
244
206
  SubchannelList(LoadBalancingPolicy* policy, TraceFlag* tracer,
245
- const ServerAddressList& addresses, grpc_combiner* combiner,
207
+ const ServerAddressList& addresses,
246
208
  LoadBalancingPolicy::ChannelControlHelper* helper,
247
209
  const grpc_channel_args& args);
248
210
 
@@ -263,8 +225,6 @@ class SubchannelList : public InternallyRefCounted<SubchannelListType> {
263
225
 
264
226
  TraceFlag* tracer_;
265
227
 
266
- grpc_combiner* combiner_;
267
-
268
228
  // The list of subchannels.
269
229
  SubchannelVector subchannels_;
270
230
 
@@ -284,59 +244,26 @@ class SubchannelList : public InternallyRefCounted<SubchannelListType> {
284
244
 
285
245
  template <typename SubchannelListType, typename SubchannelDataType>
286
246
  void SubchannelData<SubchannelListType, SubchannelDataType>::Watcher::
287
- OnConnectivityStateChange(
288
- grpc_connectivity_state new_state,
289
- RefCountedPtr<ConnectedSubchannelInterface> connected_subchannel) {
290
- // Will delete itself.
291
- New<Updater>(subchannel_data_,
292
- subchannel_list_->Ref(DEBUG_LOCATION, "Watcher::Updater"),
293
- new_state, std::move(connected_subchannel));
294
- }
295
-
296
- template <typename SubchannelListType, typename SubchannelDataType>
297
- SubchannelData<SubchannelListType, SubchannelDataType>::Watcher::Updater::
298
- Updater(
299
- SubchannelData<SubchannelListType, SubchannelDataType>* subchannel_data,
300
- RefCountedPtr<SubchannelList<SubchannelListType, SubchannelDataType>>
301
- subchannel_list,
302
- grpc_connectivity_state state,
303
- RefCountedPtr<ConnectedSubchannelInterface> connected_subchannel)
304
- : subchannel_data_(subchannel_data),
305
- subchannel_list_(std::move(subchannel_list)),
306
- state_(state),
307
- connected_subchannel_(std::move(connected_subchannel)) {
308
- GRPC_CLOSURE_INIT(&closure_, &OnUpdateLocked, this,
309
- grpc_combiner_scheduler(subchannel_list_->combiner_));
310
- GRPC_CLOSURE_SCHED(&closure_, GRPC_ERROR_NONE);
311
- }
312
-
313
- template <typename SubchannelListType, typename SubchannelDataType>
314
- void SubchannelData<SubchannelListType, SubchannelDataType>::Watcher::Updater::
315
- OnUpdateLocked(void* arg, grpc_error* error) {
316
- Updater* self = static_cast<Updater*>(arg);
317
- SubchannelData* sd = self->subchannel_data_;
318
- if (GRPC_TRACE_FLAG_ENABLED(*sd->subchannel_list_->tracer())) {
247
+ OnConnectivityStateChange(grpc_connectivity_state new_state) {
248
+ if (GRPC_TRACE_FLAG_ENABLED(*subchannel_list_->tracer())) {
319
249
  gpr_log(GPR_INFO,
320
250
  "[%s %p] subchannel list %p index %" PRIuPTR " of %" PRIuPTR
321
251
  " (subchannel %p): connectivity changed: state=%s, "
322
- "connected_subchannel=%p, shutting_down=%d, pending_watcher=%p",
323
- sd->subchannel_list_->tracer()->name(),
324
- sd->subchannel_list_->policy(), sd->subchannel_list_, sd->Index(),
325
- sd->subchannel_list_->num_subchannels(), sd->subchannel_.get(),
326
- grpc_connectivity_state_name(self->state_),
327
- self->connected_subchannel_.get(),
328
- sd->subchannel_list_->shutting_down(), sd->pending_watcher_);
252
+ "shutting_down=%d, pending_watcher=%p",
253
+ subchannel_list_->tracer()->name(), subchannel_list_->policy(),
254
+ subchannel_list_.get(), subchannel_data_->Index(),
255
+ subchannel_list_->num_subchannels(),
256
+ subchannel_data_->subchannel_.get(),
257
+ grpc_connectivity_state_name(new_state),
258
+ subchannel_list_->shutting_down(),
259
+ subchannel_data_->pending_watcher_);
329
260
  }
330
- if (!sd->subchannel_list_->shutting_down() &&
331
- sd->pending_watcher_ != nullptr) {
332
- sd->connectivity_state_ = self->state_;
333
- // Get or release ref to connected subchannel.
334
- sd->connected_subchannel_ = std::move(self->connected_subchannel_);
261
+ if (!subchannel_list_->shutting_down() &&
262
+ subchannel_data_->pending_watcher_ != nullptr) {
263
+ subchannel_data_->connectivity_state_ = new_state;
335
264
  // Call the subclass's ProcessConnectivityChangeLocked() method.
336
- sd->ProcessConnectivityChangeLocked(sd->connectivity_state_);
265
+ subchannel_data_->ProcessConnectivityChangeLocked(new_state);
337
266
  }
338
- // Clean up.
339
- Delete(self);
340
267
  }
341
268
 
342
269
  //
@@ -371,7 +298,6 @@ void SubchannelData<SubchannelListType, SubchannelDataType>::
371
298
  subchannel_.get());
372
299
  }
373
300
  subchannel_.reset();
374
- connected_subchannel_.reset();
375
301
  }
376
302
  }
377
303
 
@@ -400,7 +326,7 @@ void SubchannelData<SubchannelListType,
400
326
  New<Watcher>(this, subchannel_list()->Ref(DEBUG_LOCATION, "Watcher"));
401
327
  subchannel_->WatchConnectivityState(
402
328
  connectivity_state_,
403
- UniquePtr<SubchannelInterface::ConnectivityStateWatcher>(
329
+ UniquePtr<SubchannelInterface::ConnectivityStateWatcherInterface>(
404
330
  pending_watcher_));
405
331
  }
406
332
 
@@ -434,13 +360,12 @@ void SubchannelData<SubchannelListType, SubchannelDataType>::ShutdownLocked() {
434
360
  template <typename SubchannelListType, typename SubchannelDataType>
435
361
  SubchannelList<SubchannelListType, SubchannelDataType>::SubchannelList(
436
362
  LoadBalancingPolicy* policy, TraceFlag* tracer,
437
- const ServerAddressList& addresses, grpc_combiner* combiner,
363
+ const ServerAddressList& addresses,
438
364
  LoadBalancingPolicy::ChannelControlHelper* helper,
439
365
  const grpc_channel_args& args)
440
366
  : InternallyRefCounted<SubchannelListType>(tracer),
441
367
  policy_(policy),
442
- tracer_(tracer),
443
- combiner_(GRPC_COMBINER_REF(combiner, "subchannel_list")) {
368
+ tracer_(tracer) {
444
369
  if (GRPC_TRACE_FLAG_ENABLED(*tracer_)) {
445
370
  gpr_log(GPR_INFO,
446
371
  "[%s %p] Creating subchannel list %p for %" PRIuPTR " subchannels",
@@ -509,7 +434,6 @@ SubchannelList<SubchannelListType, SubchannelDataType>::~SubchannelList() {
509
434
  gpr_log(GPR_INFO, "[%s %p] Destroying subchannel_list %p", tracer_->name(),
510
435
  policy_, this);
511
436
  }
512
- GRPC_COMBINER_UNREF(combiner_, "subchannel_list");
513
437
  }
514
438
 
515
439
  template <typename SubchannelListType, typename SubchannelDataType>