grpc-flamingo 1.11.0 → 1.15.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (452) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +1150 -176
  3. data/etc/roots.pem +40 -196
  4. data/include/grpc/grpc.h +49 -8
  5. data/include/grpc/grpc_security.h +123 -2
  6. data/include/grpc/grpc_security_constants.h +6 -0
  7. data/include/grpc/impl/codegen/fork.h +4 -4
  8. data/include/grpc/impl/codegen/grpc_types.h +26 -5
  9. data/include/grpc/impl/codegen/log.h +112 -0
  10. data/include/grpc/impl/codegen/port_platform.h +55 -4
  11. data/include/grpc/module.modulemap +2 -0
  12. data/include/grpc/support/log.h +2 -80
  13. data/include/grpc/support/string_util.h +2 -0
  14. data/include/grpc/support/sync.h +0 -16
  15. data/src/boringssl/err_data.c +602 -588
  16. data/src/core/ext/{census → filters/census}/grpc_context.cc +0 -0
  17. data/src/core/ext/filters/client_channel/channel_connectivity.cc +1 -1
  18. data/src/core/ext/filters/client_channel/client_channel.cc +1234 -1070
  19. data/src/core/ext/filters/client_channel/client_channel.h +5 -0
  20. data/src/core/ext/filters/client_channel/client_channel_channelz.cc +113 -0
  21. data/src/core/ext/filters/client_channel/client_channel_channelz.h +71 -0
  22. data/src/core/ext/filters/client_channel/client_channel_plugin.cc +9 -0
  23. data/src/core/ext/filters/client_channel/http_connect_handshaker.cc +1 -1
  24. data/src/core/ext/filters/client_channel/http_proxy.cc +22 -5
  25. data/src/core/ext/filters/client_channel/lb_policy.cc +2 -2
  26. data/src/core/ext/filters/client_channel/lb_policy.h +30 -10
  27. data/src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.cc +11 -9
  28. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +120 -127
  29. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.h +36 -0
  30. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.cc +36 -102
  31. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.h +37 -32
  32. data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.cc +25 -22
  33. data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.h +4 -2
  34. data/src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/google/protobuf/duration.pb.c +19 -0
  35. data/src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/google/protobuf/duration.pb.h +54 -0
  36. data/src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/google/protobuf/timestamp.pb.c +19 -0
  37. data/src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/google/protobuf/timestamp.pb.h +54 -0
  38. data/src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.c +4 -17
  39. data/src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.h +37 -63
  40. data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc +306 -239
  41. data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc +444 -392
  42. data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +538 -98
  43. data/src/core/ext/filters/client_channel/lb_policy_factory.cc +8 -0
  44. data/src/core/ext/filters/client_channel/lb_policy_factory.h +4 -0
  45. data/src/core/ext/filters/client_channel/method_params.h +4 -0
  46. data/src/core/ext/filters/client_channel/resolver.h +10 -0
  47. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +36 -19
  48. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.cc +320 -0
  49. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.h +62 -9
  50. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_posix.cc +49 -294
  51. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_windows.cc +537 -0
  52. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc +112 -87
  53. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h +17 -2
  54. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_fallback.cc +6 -5
  55. data/src/core/ext/filters/{load_reporting/server_load_reporting_filter.h → client_channel/resolver/dns/c_ares/grpc_ares_wrapper_posix.cc} +7 -8
  56. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_windows.cc +29 -0
  57. data/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc +32 -15
  58. data/src/core/ext/filters/client_channel/retry_throttle.h +4 -0
  59. data/src/core/ext/filters/client_channel/subchannel.cc +58 -15
  60. data/src/core/ext/filters/client_channel/subchannel.h +11 -0
  61. data/src/core/ext/filters/deadline/deadline_filter.cc +18 -15
  62. data/src/core/ext/filters/deadline/deadline_filter.h +5 -5
  63. data/src/core/ext/filters/http/client/http_client_filter.cc +10 -9
  64. data/src/core/ext/filters/http/client_authority_filter.cc +6 -5
  65. data/src/core/ext/filters/http/message_compress/message_compress_filter.cc +6 -6
  66. data/src/core/ext/filters/http/server/http_server_filter.cc +123 -131
  67. data/src/core/ext/filters/http/server/http_server_filter.h +1 -1
  68. data/src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc +1 -1
  69. data/src/core/ext/transport/chttp2/server/chttp2_server.cc +1 -1
  70. data/src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.cc +3 -2
  71. data/src/core/ext/transport/chttp2/transport/bin_decoder.cc +9 -8
  72. data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +97 -48
  73. data/src/core/ext/transport/chttp2/transport/flow_control.cc +10 -7
  74. data/src/core/ext/transport/chttp2/transport/frame_settings.cc +3 -3
  75. data/src/core/ext/transport/chttp2/transport/hpack_encoder.cc +12 -8
  76. data/src/core/ext/transport/chttp2/transport/hpack_encoder.h +4 -3
  77. data/src/core/ext/transport/chttp2/transport/hpack_parser.cc +2 -2
  78. data/src/core/ext/transport/chttp2/transport/hpack_table.cc +2 -2
  79. data/src/core/ext/transport/chttp2/transport/parsing.cc +14 -12
  80. data/src/core/ext/transport/chttp2/transport/stream_lists.cc +3 -3
  81. data/src/core/ext/transport/chttp2/transport/writing.cc +32 -27
  82. data/src/core/ext/transport/inproc/inproc_transport.cc +87 -49
  83. data/src/core/lib/channel/channel_args.cc +28 -0
  84. data/src/core/lib/channel/channel_args.h +4 -0
  85. data/src/core/lib/channel/channel_stack.cc +22 -29
  86. data/src/core/lib/channel/channel_stack.h +2 -2
  87. data/src/core/lib/channel/channel_stack_builder.cc +0 -3
  88. data/src/core/lib/channel/channel_stack_builder.h +0 -2
  89. data/src/core/lib/channel/channel_trace.cc +28 -63
  90. data/src/core/lib/channel/channel_trace.h +13 -17
  91. data/src/core/lib/channel/channelz.cc +153 -0
  92. data/src/core/lib/channel/channelz.h +133 -0
  93. data/src/core/lib/channel/channelz_registry.cc +145 -0
  94. data/src/core/lib/channel/channelz_registry.h +120 -0
  95. data/src/core/lib/channel/connected_channel.cc +8 -1
  96. data/src/core/lib/channel/handshaker.cc +71 -0
  97. data/src/core/lib/channel/handshaker.h +4 -0
  98. data/src/core/lib/debug/stats.h +7 -0
  99. data/src/core/lib/debug/stats_data.cc +5 -0
  100. data/src/core/lib/debug/stats_data.h +120 -0
  101. data/src/core/lib/debug/trace.cc +2 -1
  102. data/src/core/lib/debug/trace.h +12 -1
  103. data/src/core/lib/gpr/alloc.h +28 -0
  104. data/src/core/lib/gpr/arena.cc +38 -45
  105. data/src/core/lib/gpr/log.cc +8 -2
  106. data/src/core/lib/gpr/log_android.cc +4 -0
  107. data/src/core/lib/gpr/log_linux.cc +4 -0
  108. data/src/core/lib/gpr/log_posix.cc +4 -0
  109. data/src/core/lib/gpr/log_windows.cc +5 -0
  110. data/src/core/lib/gpr/string.cc +28 -0
  111. data/src/core/lib/gpr/string.h +10 -0
  112. data/src/core/lib/gprpp/abstract.h +5 -2
  113. data/src/core/lib/gprpp/fork.cc +268 -0
  114. data/src/core/lib/gprpp/fork.h +88 -0
  115. data/src/core/lib/gprpp/inlined_vector.h +87 -37
  116. data/src/core/lib/gprpp/memory.h +12 -0
  117. data/src/core/lib/gprpp/mutex_lock.h +42 -0
  118. data/src/core/lib/gprpp/orphanable.h +10 -12
  119. data/src/core/lib/gprpp/ref_counted.h +10 -12
  120. data/src/core/lib/gprpp/ref_counted_ptr.h +65 -8
  121. data/src/core/lib/gprpp/thd.h +0 -3
  122. data/src/core/lib/gprpp/thd_posix.cc +5 -54
  123. data/src/core/lib/gprpp/thd_windows.cc +0 -7
  124. data/src/core/lib/http/httpcli_security_connector.cc +1 -3
  125. data/src/core/lib/iomgr/call_combiner.cc +13 -13
  126. data/src/core/lib/iomgr/call_combiner.h +84 -1
  127. data/src/core/lib/iomgr/closure.h +6 -5
  128. data/src/core/lib/iomgr/combiner.cc +30 -13
  129. data/src/core/lib/iomgr/combiner.h +1 -1
  130. data/src/core/lib/iomgr/endpoint_pair_posix.cc +2 -2
  131. data/src/core/lib/iomgr/error.cc +12 -0
  132. data/src/core/lib/iomgr/error.h +5 -0
  133. data/src/core/lib/iomgr/ev_epoll1_linux.cc +138 -51
  134. data/src/core/lib/iomgr/ev_epollex_linux.cc +276 -93
  135. data/src/core/lib/iomgr/ev_epollsig_linux.cc +58 -50
  136. data/src/core/lib/iomgr/ev_poll_posix.cc +163 -42
  137. data/src/core/lib/iomgr/ev_posix.cc +88 -24
  138. data/src/core/lib/iomgr/ev_posix.h +48 -12
  139. data/src/core/lib/iomgr/exec_ctx.cc +15 -9
  140. data/src/core/lib/iomgr/exec_ctx.h +48 -20
  141. data/src/core/lib/iomgr/executor.cc +274 -142
  142. data/src/core/lib/iomgr/executor.h +82 -16
  143. data/src/core/lib/iomgr/fork_posix.cc +42 -19
  144. data/src/core/lib/iomgr/iocp_windows.cc +9 -4
  145. data/src/core/lib/iomgr/iomgr.cc +2 -0
  146. data/src/core/lib/iomgr/iomgr.h +5 -0
  147. data/src/core/lib/iomgr/iomgr_posix.cc +2 -2
  148. data/src/core/lib/iomgr/is_epollexclusive_available.cc +1 -0
  149. data/src/core/lib/iomgr/lockfree_event.cc +5 -1
  150. data/src/core/lib/iomgr/polling_entity.cc +11 -2
  151. data/src/core/lib/iomgr/pollset_custom.cc +2 -2
  152. data/src/core/lib/iomgr/port.h +51 -1
  153. data/src/core/lib/iomgr/resolve_address.h +1 -1
  154. data/src/core/lib/iomgr/resolve_address_posix.cc +4 -3
  155. data/src/core/lib/iomgr/resolve_address_windows.cc +3 -2
  156. data/src/core/lib/iomgr/resource_quota.cc +89 -12
  157. data/src/core/lib/iomgr/resource_quota.h +16 -0
  158. data/src/core/lib/iomgr/sockaddr_posix.h +1 -1
  159. data/src/core/lib/iomgr/socket_factory_posix.cc +1 -1
  160. data/src/core/lib/iomgr/socket_mutator.cc +1 -1
  161. data/src/core/lib/iomgr/socket_mutator.h +1 -1
  162. data/src/core/lib/iomgr/socket_utils.h +9 -0
  163. data/src/core/lib/iomgr/socket_utils_common_posix.cc +29 -1
  164. data/src/core/lib/iomgr/socket_utils_linux.cc +0 -1
  165. data/src/core/lib/iomgr/socket_utils_posix.cc +2 -3
  166. data/src/core/lib/iomgr/socket_utils_posix.h +3 -0
  167. data/src/core/lib/iomgr/socket_utils_uv.cc +4 -0
  168. data/src/core/lib/iomgr/socket_utils_windows.cc +4 -0
  169. data/src/core/lib/iomgr/socket_windows.cc +33 -0
  170. data/src/core/lib/iomgr/socket_windows.h +6 -0
  171. data/src/core/lib/iomgr/tcp_client_custom.cc +5 -5
  172. data/src/core/lib/iomgr/tcp_client_posix.cc +10 -11
  173. data/src/core/lib/iomgr/tcp_custom.cc +11 -11
  174. data/src/core/lib/iomgr/tcp_posix.cc +49 -36
  175. data/src/core/lib/iomgr/tcp_server_custom.cc +5 -5
  176. data/src/core/lib/iomgr/tcp_server_posix.cc +16 -36
  177. data/src/core/lib/iomgr/tcp_server_utils_posix.h +1 -1
  178. data/src/core/lib/iomgr/tcp_server_utils_posix_common.cc +17 -5
  179. data/src/core/lib/iomgr/tcp_server_windows.cc +1 -0
  180. data/src/core/lib/iomgr/tcp_uv.cc +3 -0
  181. data/src/core/lib/iomgr/tcp_windows.cc +18 -2
  182. data/src/core/lib/iomgr/tcp_windows.h +2 -0
  183. data/src/core/lib/iomgr/timer.h +4 -3
  184. data/src/core/lib/iomgr/timer_generic.cc +133 -51
  185. data/src/core/lib/iomgr/timer_manager.cc +12 -14
  186. data/src/core/lib/iomgr/timer_uv.cc +3 -0
  187. data/src/core/lib/iomgr/udp_server.cc +106 -52
  188. data/src/core/lib/iomgr/udp_server.h +8 -4
  189. data/src/core/lib/json/json.cc +12 -1
  190. data/src/core/lib/json/json.h +5 -0
  191. data/src/core/lib/profiling/basic_timers.cc +1 -0
  192. data/src/core/lib/security/context/security_context.cc +8 -8
  193. data/src/core/lib/security/context/security_context.h +6 -2
  194. data/src/core/lib/security/credentials/alts/alts_credentials.h +0 -20
  195. data/src/core/lib/security/credentials/alts/check_gcp_environment_linux.cc +3 -2
  196. data/src/core/lib/security/credentials/alts/grpc_alts_credentials_client_options.cc +7 -7
  197. data/src/core/lib/security/credentials/alts/grpc_alts_credentials_options.h +1 -38
  198. data/src/core/lib/security/credentials/credentials.h +1 -0
  199. data/src/core/lib/security/credentials/google_default/google_default_credentials.cc +89 -115
  200. data/src/core/lib/security/credentials/google_default/google_default_credentials.h +16 -0
  201. data/src/core/lib/security/credentials/jwt/json_token.h +2 -0
  202. data/src/core/lib/security/credentials/jwt/jwt_verifier.cc +2 -0
  203. data/src/core/lib/security/credentials/local/local_credentials.cc +77 -0
  204. data/src/core/lib/security/credentials/local/local_credentials.h +40 -0
  205. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc +11 -7
  206. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.h +1 -1
  207. data/src/core/lib/security/credentials/ssl/ssl_credentials.cc +17 -3
  208. data/src/core/lib/security/security_connector/alts_security_connector.cc +2 -1
  209. data/src/core/lib/security/security_connector/load_system_roots.h +29 -0
  210. data/src/core/lib/{gpr/fork.h → security/security_connector/load_system_roots_fallback.cc} +10 -13
  211. data/src/core/lib/security/security_connector/load_system_roots_linux.cc +165 -0
  212. data/src/core/lib/security/security_connector/load_system_roots_linux.h +44 -0
  213. data/src/core/lib/security/security_connector/local_security_connector.cc +245 -0
  214. data/src/core/lib/security/security_connector/local_security_connector.h +58 -0
  215. data/src/core/lib/security/security_connector/security_connector.cc +79 -32
  216. data/src/core/lib/security/security_connector/security_connector.h +5 -3
  217. data/src/core/lib/security/transport/client_auth_filter.cc +5 -5
  218. data/src/core/lib/security/transport/secure_endpoint.cc +2 -2
  219. data/src/core/lib/security/transport/security_handshaker.cc +7 -2
  220. data/src/core/lib/security/transport/server_auth_filter.cc +4 -7
  221. data/src/core/lib/security/util/json_util.cc +4 -0
  222. data/src/core/lib/slice/slice.cc +6 -2
  223. data/src/core/lib/slice/slice_buffer.cc +27 -7
  224. data/src/core/lib/slice/slice_hash_table.h +4 -0
  225. data/src/core/lib/slice/slice_weak_hash_table.h +4 -0
  226. data/src/core/lib/surface/call.cc +119 -58
  227. data/src/core/lib/surface/call.h +7 -0
  228. data/src/core/lib/surface/channel.cc +50 -18
  229. data/src/core/lib/surface/channel.h +4 -0
  230. data/src/core/lib/surface/completion_queue.cc +153 -18
  231. data/src/core/lib/surface/completion_queue.h +20 -2
  232. data/src/core/lib/surface/completion_queue_factory.cc +13 -4
  233. data/src/core/lib/surface/init.cc +7 -8
  234. data/src/core/lib/surface/init.h +0 -1
  235. data/src/core/lib/surface/server.cc +16 -0
  236. data/src/core/lib/surface/version.cc +1 -1
  237. data/src/core/lib/transport/bdp_estimator.cc +3 -3
  238. data/src/core/lib/transport/bdp_estimator.h +2 -2
  239. data/src/core/lib/transport/byte_stream.cc +1 -1
  240. data/src/core/lib/transport/connectivity_state.cc +6 -7
  241. data/src/core/lib/transport/service_config.cc +2 -2
  242. data/src/core/lib/transport/service_config.h +3 -3
  243. data/src/core/lib/transport/transport.cc +22 -10
  244. data/src/core/lib/transport/transport.h +18 -18
  245. data/src/core/lib/transport/transport_op_string.cc +1 -8
  246. data/src/core/plugin_registry/grpc_plugin_registry.cc +0 -4
  247. data/src/core/tsi/alts/crypt/aes_gcm.cc +2 -0
  248. data/src/core/tsi/alts/handshaker/alts_handshaker_client.cc +19 -7
  249. data/src/core/tsi/alts/handshaker/alts_handshaker_client.h +10 -0
  250. data/src/core/tsi/alts/handshaker/alts_handshaker_service_api_util.h +2 -2
  251. data/src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc +38 -3
  252. data/src/core/tsi/alts/handshaker/alts_tsi_handshaker_private.h +3 -0
  253. data/src/core/tsi/alts/handshaker/altscontext.pb.c +0 -1
  254. data/src/core/tsi/alts/handshaker/altscontext.pb.h +1 -2
  255. data/src/core/tsi/alts/handshaker/handshaker.pb.c +0 -1
  256. data/src/core/tsi/alts/handshaker/handshaker.pb.h +1 -2
  257. data/src/core/tsi/alts/handshaker/transport_security_common.pb.c +0 -1
  258. data/src/core/tsi/alts/handshaker/transport_security_common.pb.h +1 -1
  259. data/src/core/tsi/alts/handshaker/transport_security_common_api.h +2 -2
  260. data/src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_integrity_only_record_protocol.cc +47 -1
  261. data/src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_integrity_only_record_protocol.h +3 -1
  262. data/src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.cc +12 -11
  263. data/src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.h +7 -2
  264. data/src/core/tsi/fake_transport_security.cc +1 -0
  265. data/src/core/tsi/grpc_shadow_boringssl.h +3006 -0
  266. data/src/core/tsi/local_transport_security.cc +209 -0
  267. data/src/core/tsi/local_transport_security.h +51 -0
  268. data/src/core/tsi/ssl/session_cache/ssl_session.h +2 -0
  269. data/src/core/tsi/ssl/session_cache/ssl_session_cache.cc +5 -5
  270. data/src/core/tsi/ssl/session_cache/ssl_session_cache.h +6 -0
  271. data/src/core/tsi/ssl_transport_security.cc +245 -116
  272. data/src/core/tsi/ssl_types.h +2 -0
  273. data/src/core/tsi/transport_security.cc +14 -0
  274. data/src/core/tsi/transport_security.h +2 -0
  275. data/src/core/tsi/transport_security_interface.h +11 -1
  276. data/src/ruby/bin/math_client.rb +17 -9
  277. data/src/ruby/ext/grpc/extconf.rb +1 -26
  278. data/src/ruby/ext/grpc/rb_channel_credentials.c +3 -3
  279. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +42 -16
  280. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +65 -26
  281. data/src/ruby/lib/grpc/generic/active_call.rb +19 -23
  282. data/src/ruby/lib/grpc/generic/rpc_server.rb +2 -1
  283. data/src/ruby/lib/grpc/version.rb +1 -1
  284. data/src/ruby/pb/generate_proto_ruby.sh +7 -1
  285. data/src/ruby/pb/grpc/health/v1/health_services_pb.rb +4 -1
  286. data/src/ruby/spec/call_credentials_spec.rb +1 -1
  287. data/src/ruby/spec/call_spec.rb +1 -1
  288. data/src/ruby/spec/channel_credentials_spec.rb +1 -1
  289. data/src/ruby/spec/channel_spec.rb +1 -1
  290. data/src/ruby/spec/client_auth_spec.rb +1 -12
  291. data/src/ruby/spec/client_server_spec.rb +1 -1
  292. data/src/ruby/spec/compression_options_spec.rb +1 -1
  293. data/src/ruby/spec/error_sanity_spec.rb +1 -1
  294. data/src/ruby/spec/generic/client_stub_spec.rb +16 -4
  295. data/src/ruby/spec/generic/rpc_desc_spec.rb +1 -1
  296. data/src/ruby/spec/generic/rpc_server_pool_spec.rb +1 -1
  297. data/src/ruby/spec/generic/service_spec.rb +1 -1
  298. data/src/ruby/spec/google_rpc_status_utils_spec.rb +1 -12
  299. data/src/ruby/spec/pb/duplicate/codegen_spec.rb +1 -0
  300. data/src/ruby/spec/pb/health/checker_spec.rb +1 -1
  301. data/src/ruby/spec/server_credentials_spec.rb +1 -1
  302. data/src/ruby/spec/server_spec.rb +1 -1
  303. data/src/ruby/spec/spec_helper.rb +1 -0
  304. data/src/ruby/spec/support/services.rb +1 -1
  305. data/src/ruby/spec/time_consts_spec.rb +1 -1
  306. data/third_party/address_sorting/address_sorting.c +17 -11
  307. data/third_party/address_sorting/address_sorting_windows.c +43 -3
  308. data/third_party/address_sorting/include/address_sorting/address_sorting.h +3 -0
  309. data/third_party/boringssl/crypto/asn1/a_int.c +33 -28
  310. data/third_party/boringssl/crypto/asn1/a_mbstr.c +24 -22
  311. data/third_party/boringssl/crypto/asn1/a_utf8.c +13 -11
  312. data/third_party/boringssl/crypto/asn1/asn1_locl.h +3 -0
  313. data/third_party/boringssl/crypto/asn1/tasn_dec.c +40 -19
  314. data/third_party/boringssl/crypto/bio/fd.c +1 -0
  315. data/third_party/boringssl/crypto/bio/file.c +2 -0
  316. data/third_party/boringssl/crypto/bn_extra/convert.c +6 -5
  317. data/third_party/boringssl/crypto/bytestring/ber.c +1 -4
  318. data/third_party/boringssl/crypto/bytestring/cbb.c +116 -16
  319. data/third_party/boringssl/crypto/bytestring/cbs.c +151 -20
  320. data/third_party/boringssl/crypto/cipher_extra/e_aesccm.c +203 -0
  321. data/third_party/boringssl/crypto/cipher_extra/e_rc2.c +2 -0
  322. data/third_party/boringssl/crypto/cipher_extra/e_tls.c +1 -2
  323. data/third_party/boringssl/crypto/cpu-aarch64-fuchsia.c +55 -0
  324. data/third_party/boringssl/crypto/cpu-aarch64-linux.c +2 -1
  325. data/third_party/boringssl/crypto/dsa/dsa.c +16 -54
  326. data/third_party/boringssl/crypto/ec_extra/ec_asn1.c +9 -10
  327. data/third_party/boringssl/crypto/ecdh/ecdh.c +4 -3
  328. data/third_party/boringssl/crypto/fipsmodule/bcm.c +11 -542
  329. data/third_party/boringssl/crypto/fipsmodule/bn/add.c +57 -112
  330. data/third_party/boringssl/crypto/fipsmodule/bn/asm/x86_64-gcc.c +4 -3
  331. data/third_party/boringssl/crypto/fipsmodule/bn/bn.c +128 -70
  332. data/third_party/boringssl/crypto/fipsmodule/bn/bytes.c +32 -71
  333. data/third_party/boringssl/crypto/fipsmodule/bn/cmp.c +64 -118
  334. data/third_party/boringssl/crypto/fipsmodule/bn/div.c +284 -122
  335. data/third_party/boringssl/crypto/fipsmodule/bn/exponentiation.c +31 -65
  336. data/third_party/boringssl/crypto/fipsmodule/bn/gcd.c +274 -218
  337. data/third_party/boringssl/crypto/fipsmodule/bn/generic.c +2 -1
  338. data/third_party/boringssl/crypto/fipsmodule/bn/internal.h +187 -27
  339. data/third_party/boringssl/crypto/fipsmodule/bn/jacobi.c +1 -1
  340. data/third_party/boringssl/crypto/fipsmodule/bn/montgomery.c +124 -81
  341. data/third_party/boringssl/crypto/fipsmodule/bn/montgomery_inv.c +8 -30
  342. data/third_party/boringssl/crypto/fipsmodule/bn/mul.c +321 -347
  343. data/third_party/boringssl/crypto/fipsmodule/bn/prime.c +326 -66
  344. data/third_party/boringssl/crypto/fipsmodule/bn/random.c +77 -25
  345. data/third_party/boringssl/crypto/fipsmodule/bn/rsaz_exp.c +199 -222
  346. data/third_party/boringssl/crypto/fipsmodule/bn/rsaz_exp.h +27 -47
  347. data/third_party/boringssl/crypto/fipsmodule/bn/shift.c +155 -96
  348. data/third_party/boringssl/crypto/fipsmodule/bn/sqrt.c +1 -1
  349. data/third_party/boringssl/crypto/fipsmodule/cipher/e_aes.c +10 -10
  350. data/third_party/boringssl/crypto/fipsmodule/des/internal.h +2 -0
  351. data/third_party/boringssl/crypto/fipsmodule/ec/ec.c +78 -47
  352. data/third_party/boringssl/crypto/fipsmodule/ec/ec_key.c +99 -163
  353. data/third_party/boringssl/crypto/fipsmodule/ec/ec_montgomery.c +3 -10
  354. data/third_party/boringssl/crypto/fipsmodule/ec/internal.h +44 -23
  355. data/third_party/boringssl/crypto/fipsmodule/ec/oct.c +59 -90
  356. data/third_party/boringssl/crypto/fipsmodule/ec/p224-64.c +38 -65
  357. data/third_party/boringssl/crypto/fipsmodule/ec/p256-x86_64-table.h +5378 -5418
  358. data/third_party/boringssl/crypto/fipsmodule/ec/p256-x86_64.c +17 -26
  359. data/third_party/boringssl/crypto/fipsmodule/ec/p256-x86_64.h +15 -11
  360. data/third_party/boringssl/crypto/fipsmodule/ec/simple.c +45 -51
  361. data/third_party/boringssl/crypto/fipsmodule/ec/{util-64.c → util.c} +0 -5
  362. data/third_party/boringssl/crypto/fipsmodule/ec/wnaf.c +144 -264
  363. data/third_party/boringssl/crypto/fipsmodule/ecdsa/ecdsa.c +78 -62
  364. data/third_party/boringssl/crypto/fipsmodule/modes/ccm.c +256 -0
  365. data/third_party/boringssl/crypto/fipsmodule/modes/internal.h +36 -32
  366. data/third_party/boringssl/crypto/fipsmodule/rand/ctrdrbg.c +9 -7
  367. data/third_party/boringssl/crypto/fipsmodule/rsa/blinding.c +16 -40
  368. data/third_party/boringssl/crypto/fipsmodule/rsa/internal.h +1 -6
  369. data/third_party/boringssl/crypto/fipsmodule/rsa/rsa.c +57 -39
  370. data/third_party/boringssl/crypto/fipsmodule/rsa/rsa_impl.c +309 -142
  371. data/third_party/boringssl/crypto/fipsmodule/self_check/self_check.c +581 -0
  372. data/third_party/boringssl/crypto/fipsmodule/tls/internal.h +39 -0
  373. data/third_party/boringssl/crypto/fipsmodule/tls/kdf.c +165 -0
  374. data/third_party/boringssl/crypto/internal.h +65 -2
  375. data/third_party/boringssl/crypto/mem.c +0 -2
  376. data/third_party/boringssl/crypto/obj/obj.c +6 -73
  377. data/third_party/boringssl/crypto/thread_pthread.c +35 -5
  378. data/third_party/boringssl/crypto/x509/a_strex.c +11 -11
  379. data/third_party/boringssl/crypto/x509/vpm_int.h +1 -0
  380. data/third_party/boringssl/crypto/x509/x509_vfy.c +4 -0
  381. data/third_party/boringssl/crypto/x509/x509_vpm.c +44 -22
  382. data/third_party/boringssl/crypto/x509/x_name.c +13 -0
  383. data/third_party/boringssl/include/openssl/aead.h +10 -0
  384. data/third_party/boringssl/include/openssl/asn1.h +2 -3
  385. data/third_party/boringssl/include/openssl/base.h +5 -14
  386. data/third_party/boringssl/include/openssl/bio.h +1 -1
  387. data/third_party/boringssl/include/openssl/bn.h +62 -18
  388. data/third_party/boringssl/include/openssl/bytestring.h +53 -28
  389. data/third_party/boringssl/include/openssl/crypto.h +4 -0
  390. data/third_party/boringssl/include/openssl/ec.h +10 -4
  391. data/third_party/boringssl/include/openssl/ec_key.h +7 -6
  392. data/third_party/boringssl/include/openssl/err.h +9 -9
  393. data/third_party/boringssl/include/openssl/evp.h +1 -1
  394. data/third_party/boringssl/include/openssl/rsa.h +35 -10
  395. data/third_party/boringssl/include/openssl/ssl.h +167 -19
  396. data/third_party/boringssl/include/openssl/ssl3.h +0 -1
  397. data/third_party/boringssl/include/openssl/stack.h +1 -1
  398. data/third_party/boringssl/include/openssl/tls1.h +10 -2
  399. data/third_party/boringssl/include/openssl/x509.h +4 -0
  400. data/third_party/boringssl/include/openssl/x509v3.h +1 -0
  401. data/third_party/boringssl/ssl/d1_both.cc +16 -2
  402. data/third_party/boringssl/ssl/dtls_method.cc +1 -1
  403. data/third_party/boringssl/ssl/handoff.cc +285 -0
  404. data/third_party/boringssl/ssl/handshake.cc +26 -12
  405. data/third_party/boringssl/ssl/handshake_client.cc +101 -95
  406. data/third_party/boringssl/ssl/handshake_server.cc +14 -2
  407. data/third_party/boringssl/ssl/internal.h +132 -79
  408. data/third_party/boringssl/ssl/s3_both.cc +2 -2
  409. data/third_party/boringssl/ssl/s3_lib.cc +3 -1
  410. data/third_party/boringssl/ssl/s3_pkt.cc +0 -18
  411. data/third_party/boringssl/ssl/ssl_aead_ctx.cc +1 -4
  412. data/third_party/boringssl/ssl/ssl_asn1.cc +47 -43
  413. data/third_party/boringssl/ssl/ssl_cipher.cc +12 -8
  414. data/third_party/boringssl/ssl/ssl_key_share.cc +3 -1
  415. data/third_party/boringssl/ssl/ssl_lib.cc +83 -14
  416. data/third_party/boringssl/ssl/ssl_privkey.cc +6 -0
  417. data/third_party/boringssl/ssl/ssl_stat.cc +6 -6
  418. data/third_party/boringssl/ssl/ssl_versions.cc +12 -85
  419. data/third_party/boringssl/ssl/ssl_x509.cc +59 -61
  420. data/third_party/boringssl/ssl/t1_enc.cc +73 -124
  421. data/third_party/boringssl/ssl/t1_lib.cc +367 -41
  422. data/third_party/boringssl/ssl/tls13_both.cc +8 -0
  423. data/third_party/boringssl/ssl/tls13_client.cc +98 -184
  424. data/third_party/boringssl/ssl/tls13_enc.cc +88 -158
  425. data/third_party/boringssl/ssl/tls13_server.cc +91 -137
  426. data/third_party/boringssl/ssl/tls_method.cc +0 -17
  427. data/third_party/boringssl/ssl/tls_record.cc +1 -10
  428. data/third_party/boringssl/third_party/fiat/curve25519.c +921 -2753
  429. data/third_party/boringssl/third_party/fiat/curve25519_tables.h +7880 -0
  430. data/third_party/boringssl/third_party/fiat/internal.h +32 -20
  431. data/third_party/boringssl/third_party/fiat/p256.c +1824 -0
  432. metadata +86 -71
  433. data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.cc +0 -253
  434. data/src/core/ext/filters/load_reporting/server_load_reporting_filter.cc +0 -222
  435. data/src/core/ext/filters/load_reporting/server_load_reporting_plugin.cc +0 -71
  436. data/src/core/ext/filters/load_reporting/server_load_reporting_plugin.h +0 -61
  437. data/src/core/lib/channel/channel_trace_registry.cc +0 -80
  438. data/src/core/lib/channel/channel_trace_registry.h +0 -43
  439. data/src/core/lib/gpr/fork.cc +0 -78
  440. data/src/core/tsi/transport_security_adapter.cc +0 -235
  441. data/src/core/tsi/transport_security_adapter.h +0 -41
  442. data/src/ruby/bin/apis/google/protobuf/empty.rb +0 -29
  443. data/src/ruby/bin/apis/pubsub_demo.rb +0 -241
  444. data/src/ruby/bin/apis/tech/pubsub/proto/pubsub.rb +0 -159
  445. data/src/ruby/bin/apis/tech/pubsub/proto/pubsub_services.rb +0 -88
  446. data/src/ruby/pb/test/client.rb +0 -764
  447. data/src/ruby/pb/test/server.rb +0 -252
  448. data/src/ruby/spec/pb/package_with_underscore/checker_spec.rb +0 -54
  449. data/src/ruby/spec/pb/package_with_underscore/data.proto +0 -23
  450. data/src/ruby/spec/pb/package_with_underscore/service.proto +0 -23
  451. data/third_party/boringssl/crypto/curve25519/x25519-x86_64.c +0 -247
  452. data/third_party/boringssl/crypto/fipsmodule/ec/p256-64.c +0 -1674
@@ -0,0 +1,54 @@
1
+ /* Automatically generated nanopb header */
2
+ /* Generated by nanopb-0.3.7-dev */
3
+
4
+ #ifndef PB_GOOGLE_PROTOBUF_DURATION_PB_H_INCLUDED
5
+ #define PB_GOOGLE_PROTOBUF_DURATION_PB_H_INCLUDED
6
+ #include "pb.h"
7
+ /* @@protoc_insertion_point(includes) */
8
+ #if PB_PROTO_HEADER_VERSION != 30
9
+ #error Regenerate this file with the current version of nanopb generator.
10
+ #endif
11
+
12
+ #ifdef __cplusplus
13
+ extern "C" {
14
+ #endif
15
+
16
+ /* Struct definitions */
17
+ typedef struct _google_protobuf_Duration {
18
+ bool has_seconds;
19
+ int64_t seconds;
20
+ bool has_nanos;
21
+ int32_t nanos;
22
+ /* @@protoc_insertion_point(struct:google_protobuf_Duration) */
23
+ } google_protobuf_Duration;
24
+
25
+ /* Default values for struct fields */
26
+
27
+ /* Initializer values for message structs */
28
+ #define google_protobuf_Duration_init_default {false, 0, false, 0}
29
+ #define google_protobuf_Duration_init_zero {false, 0, false, 0}
30
+
31
+ /* Field tags (for use in manual encoding/decoding) */
32
+ #define google_protobuf_Duration_seconds_tag 1
33
+ #define google_protobuf_Duration_nanos_tag 2
34
+
35
+ /* Struct field encoding specification for nanopb */
36
+ extern const pb_field_t google_protobuf_Duration_fields[3];
37
+
38
+ /* Maximum encoded size of messages (where known) */
39
+ #define google_protobuf_Duration_size 22
40
+
41
+ /* Message IDs (where set with "msgid" option) */
42
+ #ifdef PB_MSGID
43
+
44
+ #define DURATION_MESSAGES \
45
+
46
+
47
+ #endif
48
+
49
+ #ifdef __cplusplus
50
+ } /* extern "C" */
51
+ #endif
52
+ /* @@protoc_insertion_point(eof) */
53
+
54
+ #endif
@@ -0,0 +1,19 @@
1
+ /* Automatically generated nanopb constant definitions */
2
+ /* Generated by nanopb-0.3.7-dev */
3
+
4
+ #include "src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/google/protobuf/timestamp.pb.h"
5
+ /* @@protoc_insertion_point(includes) */
6
+ #if PB_PROTO_HEADER_VERSION != 30
7
+ #error Regenerate this file with the current version of nanopb generator.
8
+ #endif
9
+
10
+
11
+
12
+ const pb_field_t google_protobuf_Timestamp_fields[3] = {
13
+ PB_FIELD( 1, INT64 , OPTIONAL, STATIC , FIRST, google_protobuf_Timestamp, seconds, seconds, 0),
14
+ PB_FIELD( 2, INT32 , OPTIONAL, STATIC , OTHER, google_protobuf_Timestamp, nanos, seconds, 0),
15
+ PB_LAST_FIELD
16
+ };
17
+
18
+
19
+ /* @@protoc_insertion_point(eof) */
@@ -0,0 +1,54 @@
1
+ /* Automatically generated nanopb header */
2
+ /* Generated by nanopb-0.3.7-dev */
3
+
4
+ #ifndef PB_GOOGLE_PROTOBUF_TIMESTAMP_PB_H_INCLUDED
5
+ #define PB_GOOGLE_PROTOBUF_TIMESTAMP_PB_H_INCLUDED
6
+ #include "pb.h"
7
+ /* @@protoc_insertion_point(includes) */
8
+ #if PB_PROTO_HEADER_VERSION != 30
9
+ #error Regenerate this file with the current version of nanopb generator.
10
+ #endif
11
+
12
+ #ifdef __cplusplus
13
+ extern "C" {
14
+ #endif
15
+
16
+ /* Struct definitions */
17
+ typedef struct _google_protobuf_Timestamp {
18
+ bool has_seconds;
19
+ int64_t seconds;
20
+ bool has_nanos;
21
+ int32_t nanos;
22
+ /* @@protoc_insertion_point(struct:google_protobuf_Timestamp) */
23
+ } google_protobuf_Timestamp;
24
+
25
+ /* Default values for struct fields */
26
+
27
+ /* Initializer values for message structs */
28
+ #define google_protobuf_Timestamp_init_default {false, 0, false, 0}
29
+ #define google_protobuf_Timestamp_init_zero {false, 0, false, 0}
30
+
31
+ /* Field tags (for use in manual encoding/decoding) */
32
+ #define google_protobuf_Timestamp_seconds_tag 1
33
+ #define google_protobuf_Timestamp_nanos_tag 2
34
+
35
+ /* Struct field encoding specification for nanopb */
36
+ extern const pb_field_t google_protobuf_Timestamp_fields[3];
37
+
38
+ /* Maximum encoded size of messages (where known) */
39
+ #define google_protobuf_Timestamp_size 22
40
+
41
+ /* Message IDs (where set with "msgid" option) */
42
+ #ifdef PB_MSGID
43
+
44
+ #define TIMESTAMP_MESSAGES \
45
+
46
+
47
+ #endif
48
+
49
+ #ifdef __cplusplus
50
+ } /* extern "C" */
51
+ #endif
52
+ /* @@protoc_insertion_point(eof) */
53
+
54
+ #endif
@@ -2,7 +2,6 @@
2
2
  /* Generated by nanopb-0.3.7-dev */
3
3
 
4
4
  #include "src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.h"
5
-
6
5
  /* @@protoc_insertion_point(includes) */
7
6
  #if PB_PROTO_HEADER_VERSION != 30
8
7
  #error Regenerate this file with the current version of nanopb generator.
@@ -10,18 +9,6 @@
10
9
 
11
10
 
12
11
 
13
- const pb_field_t grpc_lb_v1_Duration_fields[3] = {
14
- PB_FIELD( 1, INT64 , OPTIONAL, STATIC , FIRST, grpc_lb_v1_Duration, seconds, seconds, 0),
15
- PB_FIELD( 2, INT32 , OPTIONAL, STATIC , OTHER, grpc_lb_v1_Duration, nanos, seconds, 0),
16
- PB_LAST_FIELD
17
- };
18
-
19
- const pb_field_t grpc_lb_v1_Timestamp_fields[3] = {
20
- PB_FIELD( 1, INT64 , OPTIONAL, STATIC , FIRST, grpc_lb_v1_Timestamp, seconds, seconds, 0),
21
- PB_FIELD( 2, INT32 , OPTIONAL, STATIC , OTHER, grpc_lb_v1_Timestamp, nanos, seconds, 0),
22
- PB_LAST_FIELD
23
- };
24
-
25
12
  const pb_field_t grpc_lb_v1_LoadBalanceRequest_fields[3] = {
26
13
  PB_FIELD( 1, MESSAGE , OPTIONAL, STATIC , FIRST, grpc_lb_v1_LoadBalanceRequest, initial_request, initial_request, &grpc_lb_v1_InitialLoadBalanceRequest_fields),
27
14
  PB_FIELD( 2, MESSAGE , OPTIONAL, STATIC , OTHER, grpc_lb_v1_LoadBalanceRequest, client_stats, initial_request, &grpc_lb_v1_ClientStats_fields),
@@ -40,7 +27,7 @@ const pb_field_t grpc_lb_v1_ClientStatsPerToken_fields[3] = {
40
27
  };
41
28
 
42
29
  const pb_field_t grpc_lb_v1_ClientStats_fields[7] = {
43
- PB_FIELD( 1, MESSAGE , OPTIONAL, STATIC , FIRST, grpc_lb_v1_ClientStats, timestamp, timestamp, &grpc_lb_v1_Timestamp_fields),
30
+ PB_FIELD( 1, MESSAGE , OPTIONAL, STATIC , FIRST, grpc_lb_v1_ClientStats, timestamp, timestamp, &google_protobuf_Timestamp_fields),
44
31
  PB_FIELD( 2, INT64 , OPTIONAL, STATIC , OTHER, grpc_lb_v1_ClientStats, num_calls_started, timestamp, 0),
45
32
  PB_FIELD( 3, INT64 , OPTIONAL, STATIC , OTHER, grpc_lb_v1_ClientStats, num_calls_finished, num_calls_started, 0),
46
33
  PB_FIELD( 6, INT64 , OPTIONAL, STATIC , OTHER, grpc_lb_v1_ClientStats, num_calls_finished_with_client_failed_to_send, num_calls_finished, 0),
@@ -57,7 +44,7 @@ const pb_field_t grpc_lb_v1_LoadBalanceResponse_fields[3] = {
57
44
 
58
45
  const pb_field_t grpc_lb_v1_InitialLoadBalanceResponse_fields[3] = {
59
46
  PB_FIELD( 1, STRING , OPTIONAL, STATIC , FIRST, grpc_lb_v1_InitialLoadBalanceResponse, load_balancer_delegate, load_balancer_delegate, 0),
60
- PB_FIELD( 2, MESSAGE , OPTIONAL, STATIC , OTHER, grpc_lb_v1_InitialLoadBalanceResponse, client_stats_report_interval, load_balancer_delegate, &grpc_lb_v1_Duration_fields),
47
+ PB_FIELD( 2, MESSAGE , OPTIONAL, STATIC , OTHER, grpc_lb_v1_InitialLoadBalanceResponse, client_stats_report_interval, load_balancer_delegate, &google_protobuf_Duration_fields),
61
48
  PB_LAST_FIELD
62
49
  };
63
50
 
@@ -84,7 +71,7 @@ const pb_field_t grpc_lb_v1_Server_fields[5] = {
84
71
  * numbers or field sizes that are larger than what can fit in 8 or 16 bit
85
72
  * field descriptors.
86
73
  */
87
- PB_STATIC_ASSERT((pb_membersize(grpc_lb_v1_LoadBalanceRequest, initial_request) < 65536 && pb_membersize(grpc_lb_v1_LoadBalanceRequest, client_stats) < 65536 && pb_membersize(grpc_lb_v1_ClientStats, timestamp) < 65536 && pb_membersize(grpc_lb_v1_ClientStats, calls_finished_with_drop) < 65536 && pb_membersize(grpc_lb_v1_LoadBalanceResponse, initial_response) < 65536 && pb_membersize(grpc_lb_v1_LoadBalanceResponse, server_list) < 65536 && pb_membersize(grpc_lb_v1_InitialLoadBalanceResponse, client_stats_report_interval) < 65536 && pb_membersize(grpc_lb_v1_ServerList, servers) < 65536), YOU_MUST_DEFINE_PB_FIELD_32BIT_FOR_MESSAGES_grpc_lb_v1_Duration_grpc_lb_v1_Timestamp_grpc_lb_v1_LoadBalanceRequest_grpc_lb_v1_InitialLoadBalanceRequest_grpc_lb_v1_ClientStatsPerToken_grpc_lb_v1_ClientStats_grpc_lb_v1_LoadBalanceResponse_grpc_lb_v1_InitialLoadBalanceResponse_grpc_lb_v1_ServerList_grpc_lb_v1_Server)
74
+ PB_STATIC_ASSERT((pb_membersize(grpc_lb_v1_LoadBalanceRequest, initial_request) < 65536 && pb_membersize(grpc_lb_v1_LoadBalanceRequest, client_stats) < 65536 && pb_membersize(grpc_lb_v1_ClientStats, timestamp) < 65536 && pb_membersize(grpc_lb_v1_ClientStats, calls_finished_with_drop) < 65536 && pb_membersize(grpc_lb_v1_LoadBalanceResponse, initial_response) < 65536 && pb_membersize(grpc_lb_v1_LoadBalanceResponse, server_list) < 65536 && pb_membersize(grpc_lb_v1_InitialLoadBalanceResponse, client_stats_report_interval) < 65536 && pb_membersize(grpc_lb_v1_ServerList, servers) < 65536), YOU_MUST_DEFINE_PB_FIELD_32BIT_FOR_MESSAGES_grpc_lb_v1_LoadBalanceRequest_grpc_lb_v1_InitialLoadBalanceRequest_grpc_lb_v1_ClientStatsPerToken_grpc_lb_v1_ClientStats_grpc_lb_v1_LoadBalanceResponse_grpc_lb_v1_InitialLoadBalanceResponse_grpc_lb_v1_ServerList_grpc_lb_v1_Server)
88
75
  #endif
89
76
 
90
77
  #if !defined(PB_FIELD_16BIT) && !defined(PB_FIELD_32BIT)
@@ -95,7 +82,7 @@ PB_STATIC_ASSERT((pb_membersize(grpc_lb_v1_LoadBalanceRequest, initial_request)
95
82
  * numbers or field sizes that are larger than what can fit in the default
96
83
  * 8 bit descriptors.
97
84
  */
98
- PB_STATIC_ASSERT((pb_membersize(grpc_lb_v1_LoadBalanceRequest, initial_request) < 256 && pb_membersize(grpc_lb_v1_LoadBalanceRequest, client_stats) < 256 && pb_membersize(grpc_lb_v1_ClientStats, timestamp) < 256 && pb_membersize(grpc_lb_v1_ClientStats, calls_finished_with_drop) < 256 && pb_membersize(grpc_lb_v1_LoadBalanceResponse, initial_response) < 256 && pb_membersize(grpc_lb_v1_LoadBalanceResponse, server_list) < 256 && pb_membersize(grpc_lb_v1_InitialLoadBalanceResponse, client_stats_report_interval) < 256 && pb_membersize(grpc_lb_v1_ServerList, servers) < 256), YOU_MUST_DEFINE_PB_FIELD_16BIT_FOR_MESSAGES_grpc_lb_v1_Duration_grpc_lb_v1_Timestamp_grpc_lb_v1_LoadBalanceRequest_grpc_lb_v1_InitialLoadBalanceRequest_grpc_lb_v1_ClientStatsPerToken_grpc_lb_v1_ClientStats_grpc_lb_v1_LoadBalanceResponse_grpc_lb_v1_InitialLoadBalanceResponse_grpc_lb_v1_ServerList_grpc_lb_v1_Server)
85
+ PB_STATIC_ASSERT((pb_membersize(grpc_lb_v1_LoadBalanceRequest, initial_request) < 256 && pb_membersize(grpc_lb_v1_LoadBalanceRequest, client_stats) < 256 && pb_membersize(grpc_lb_v1_ClientStats, timestamp) < 256 && pb_membersize(grpc_lb_v1_ClientStats, calls_finished_with_drop) < 256 && pb_membersize(grpc_lb_v1_LoadBalanceResponse, initial_response) < 256 && pb_membersize(grpc_lb_v1_LoadBalanceResponse, server_list) < 256 && pb_membersize(grpc_lb_v1_InitialLoadBalanceResponse, client_stats_report_interval) < 256 && pb_membersize(grpc_lb_v1_ServerList, servers) < 256), YOU_MUST_DEFINE_PB_FIELD_16BIT_FOR_MESSAGES_grpc_lb_v1_LoadBalanceRequest_grpc_lb_v1_InitialLoadBalanceRequest_grpc_lb_v1_ClientStatsPerToken_grpc_lb_v1_ClientStats_grpc_lb_v1_LoadBalanceResponse_grpc_lb_v1_InitialLoadBalanceResponse_grpc_lb_v1_ServerList_grpc_lb_v1_Server)
99
86
  #endif
100
87
 
101
88
 
@@ -3,7 +3,9 @@
3
3
 
4
4
  #ifndef PB_GRPC_LB_V1_LOAD_BALANCER_PB_H_INCLUDED
5
5
  #define PB_GRPC_LB_V1_LOAD_BALANCER_PB_H_INCLUDED
6
- #include "third_party/nanopb/pb.h"
6
+ #include "pb.h"
7
+ #include "src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/google/protobuf/duration.pb.h"
8
+ #include "src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/google/protobuf/timestamp.pb.h"
7
9
  /* @@protoc_insertion_point(includes) */
8
10
  #if PB_PROTO_HEADER_VERSION != 30
9
11
  #error Regenerate this file with the current version of nanopb generator.
@@ -19,6 +21,21 @@ typedef struct _grpc_lb_v1_ServerList {
19
21
  /* @@protoc_insertion_point(struct:grpc_lb_v1_ServerList) */
20
22
  } grpc_lb_v1_ServerList;
21
23
 
24
+ typedef struct _grpc_lb_v1_ClientStats {
25
+ bool has_timestamp;
26
+ google_protobuf_Timestamp timestamp;
27
+ bool has_num_calls_started;
28
+ int64_t num_calls_started;
29
+ bool has_num_calls_finished;
30
+ int64_t num_calls_finished;
31
+ bool has_num_calls_finished_with_client_failed_to_send;
32
+ int64_t num_calls_finished_with_client_failed_to_send;
33
+ bool has_num_calls_finished_known_received;
34
+ int64_t num_calls_finished_known_received;
35
+ pb_callback_t calls_finished_with_drop;
36
+ /* @@protoc_insertion_point(struct:grpc_lb_v1_ClientStats) */
37
+ } grpc_lb_v1_ClientStats;
38
+
22
39
  typedef struct _grpc_lb_v1_ClientStatsPerToken {
23
40
  pb_callback_t load_balance_token;
24
41
  bool has_num_calls;
@@ -26,20 +43,20 @@ typedef struct _grpc_lb_v1_ClientStatsPerToken {
26
43
  /* @@protoc_insertion_point(struct:grpc_lb_v1_ClientStatsPerToken) */
27
44
  } grpc_lb_v1_ClientStatsPerToken;
28
45
 
29
- typedef struct _grpc_lb_v1_Duration {
30
- bool has_seconds;
31
- int64_t seconds;
32
- bool has_nanos;
33
- int32_t nanos;
34
- /* @@protoc_insertion_point(struct:grpc_lb_v1_Duration) */
35
- } grpc_lb_v1_Duration;
36
-
37
46
  typedef struct _grpc_lb_v1_InitialLoadBalanceRequest {
38
47
  bool has_name;
39
48
  char name[128];
40
49
  /* @@protoc_insertion_point(struct:grpc_lb_v1_InitialLoadBalanceRequest) */
41
50
  } grpc_lb_v1_InitialLoadBalanceRequest;
42
51
 
52
+ typedef struct _grpc_lb_v1_InitialLoadBalanceResponse {
53
+ bool has_load_balancer_delegate;
54
+ char load_balancer_delegate[64];
55
+ bool has_client_stats_report_interval;
56
+ google_protobuf_Duration client_stats_report_interval;
57
+ /* @@protoc_insertion_point(struct:grpc_lb_v1_InitialLoadBalanceResponse) */
58
+ } grpc_lb_v1_InitialLoadBalanceResponse;
59
+
43
60
  typedef PB_BYTES_ARRAY_T(16) grpc_lb_v1_Server_ip_address_t;
44
61
  typedef struct _grpc_lb_v1_Server {
45
62
  bool has_ip_address;
@@ -53,37 +70,6 @@ typedef struct _grpc_lb_v1_Server {
53
70
  /* @@protoc_insertion_point(struct:grpc_lb_v1_Server) */
54
71
  } grpc_lb_v1_Server;
55
72
 
56
- typedef struct _grpc_lb_v1_Timestamp {
57
- bool has_seconds;
58
- int64_t seconds;
59
- bool has_nanos;
60
- int32_t nanos;
61
- /* @@protoc_insertion_point(struct:grpc_lb_v1_Timestamp) */
62
- } grpc_lb_v1_Timestamp;
63
-
64
- typedef struct _grpc_lb_v1_ClientStats {
65
- bool has_timestamp;
66
- grpc_lb_v1_Timestamp timestamp;
67
- bool has_num_calls_started;
68
- int64_t num_calls_started;
69
- bool has_num_calls_finished;
70
- int64_t num_calls_finished;
71
- bool has_num_calls_finished_with_client_failed_to_send;
72
- int64_t num_calls_finished_with_client_failed_to_send;
73
- bool has_num_calls_finished_known_received;
74
- int64_t num_calls_finished_known_received;
75
- pb_callback_t calls_finished_with_drop;
76
- /* @@protoc_insertion_point(struct:grpc_lb_v1_ClientStats) */
77
- } grpc_lb_v1_ClientStats;
78
-
79
- typedef struct _grpc_lb_v1_InitialLoadBalanceResponse {
80
- bool has_load_balancer_delegate;
81
- char load_balancer_delegate[64];
82
- bool has_client_stats_report_interval;
83
- grpc_lb_v1_Duration client_stats_report_interval;
84
- /* @@protoc_insertion_point(struct:grpc_lb_v1_InitialLoadBalanceResponse) */
85
- } grpc_lb_v1_InitialLoadBalanceResponse;
86
-
87
73
  typedef struct _grpc_lb_v1_LoadBalanceRequest {
88
74
  bool has_initial_request;
89
75
  grpc_lb_v1_InitialLoadBalanceRequest initial_request;
@@ -103,56 +89,46 @@ typedef struct _grpc_lb_v1_LoadBalanceResponse {
103
89
  /* Default values for struct fields */
104
90
 
105
91
  /* Initializer values for message structs */
106
- #define grpc_lb_v1_Duration_init_default {false, 0, false, 0}
107
- #define grpc_lb_v1_Timestamp_init_default {false, 0, false, 0}
108
92
  #define grpc_lb_v1_LoadBalanceRequest_init_default {false, grpc_lb_v1_InitialLoadBalanceRequest_init_default, false, grpc_lb_v1_ClientStats_init_default}
109
93
  #define grpc_lb_v1_InitialLoadBalanceRequest_init_default {false, ""}
110
94
  #define grpc_lb_v1_ClientStatsPerToken_init_default {{{NULL}, NULL}, false, 0}
111
- #define grpc_lb_v1_ClientStats_init_default {false, grpc_lb_v1_Timestamp_init_default, false, 0, false, 0, false, 0, false, 0, {{NULL}, NULL}}
95
+ #define grpc_lb_v1_ClientStats_init_default {false, google_protobuf_Timestamp_init_default, false, 0, false, 0, false, 0, false, 0, {{NULL}, NULL}}
112
96
  #define grpc_lb_v1_LoadBalanceResponse_init_default {false, grpc_lb_v1_InitialLoadBalanceResponse_init_default, false, grpc_lb_v1_ServerList_init_default}
113
- #define grpc_lb_v1_InitialLoadBalanceResponse_init_default {false, "", false, grpc_lb_v1_Duration_init_default}
97
+ #define grpc_lb_v1_InitialLoadBalanceResponse_init_default {false, "", false, google_protobuf_Duration_init_default}
114
98
  #define grpc_lb_v1_ServerList_init_default {{{NULL}, NULL}}
115
99
  #define grpc_lb_v1_Server_init_default {false, {0, {0}}, false, 0, false, "", false, 0}
116
- #define grpc_lb_v1_Duration_init_zero {false, 0, false, 0}
117
- #define grpc_lb_v1_Timestamp_init_zero {false, 0, false, 0}
118
100
  #define grpc_lb_v1_LoadBalanceRequest_init_zero {false, grpc_lb_v1_InitialLoadBalanceRequest_init_zero, false, grpc_lb_v1_ClientStats_init_zero}
119
101
  #define grpc_lb_v1_InitialLoadBalanceRequest_init_zero {false, ""}
120
102
  #define grpc_lb_v1_ClientStatsPerToken_init_zero {{{NULL}, NULL}, false, 0}
121
- #define grpc_lb_v1_ClientStats_init_zero {false, grpc_lb_v1_Timestamp_init_zero, false, 0, false, 0, false, 0, false, 0, {{NULL}, NULL}}
103
+ #define grpc_lb_v1_ClientStats_init_zero {false, google_protobuf_Timestamp_init_zero, false, 0, false, 0, false, 0, false, 0, {{NULL}, NULL}}
122
104
  #define grpc_lb_v1_LoadBalanceResponse_init_zero {false, grpc_lb_v1_InitialLoadBalanceResponse_init_zero, false, grpc_lb_v1_ServerList_init_zero}
123
- #define grpc_lb_v1_InitialLoadBalanceResponse_init_zero {false, "", false, grpc_lb_v1_Duration_init_zero}
105
+ #define grpc_lb_v1_InitialLoadBalanceResponse_init_zero {false, "", false, google_protobuf_Duration_init_zero}
124
106
  #define grpc_lb_v1_ServerList_init_zero {{{NULL}, NULL}}
125
107
  #define grpc_lb_v1_Server_init_zero {false, {0, {0}}, false, 0, false, "", false, 0}
126
108
 
127
109
  /* Field tags (for use in manual encoding/decoding) */
128
110
  #define grpc_lb_v1_ServerList_servers_tag 1
129
- #define grpc_lb_v1_ClientStatsPerToken_load_balance_token_tag 1
130
- #define grpc_lb_v1_ClientStatsPerToken_num_calls_tag 2
131
- #define grpc_lb_v1_Duration_seconds_tag 1
132
- #define grpc_lb_v1_Duration_nanos_tag 2
133
- #define grpc_lb_v1_InitialLoadBalanceRequest_name_tag 1
134
- #define grpc_lb_v1_Server_ip_address_tag 1
135
- #define grpc_lb_v1_Server_port_tag 2
136
- #define grpc_lb_v1_Server_load_balance_token_tag 3
137
- #define grpc_lb_v1_Server_drop_tag 4
138
- #define grpc_lb_v1_Timestamp_seconds_tag 1
139
- #define grpc_lb_v1_Timestamp_nanos_tag 2
140
111
  #define grpc_lb_v1_ClientStats_timestamp_tag 1
141
112
  #define grpc_lb_v1_ClientStats_num_calls_started_tag 2
142
113
  #define grpc_lb_v1_ClientStats_num_calls_finished_tag 3
143
114
  #define grpc_lb_v1_ClientStats_num_calls_finished_with_client_failed_to_send_tag 6
144
115
  #define grpc_lb_v1_ClientStats_num_calls_finished_known_received_tag 7
145
116
  #define grpc_lb_v1_ClientStats_calls_finished_with_drop_tag 8
117
+ #define grpc_lb_v1_ClientStatsPerToken_load_balance_token_tag 1
118
+ #define grpc_lb_v1_ClientStatsPerToken_num_calls_tag 2
119
+ #define grpc_lb_v1_InitialLoadBalanceRequest_name_tag 1
146
120
  #define grpc_lb_v1_InitialLoadBalanceResponse_load_balancer_delegate_tag 1
147
121
  #define grpc_lb_v1_InitialLoadBalanceResponse_client_stats_report_interval_tag 2
122
+ #define grpc_lb_v1_Server_ip_address_tag 1
123
+ #define grpc_lb_v1_Server_port_tag 2
124
+ #define grpc_lb_v1_Server_load_balance_token_tag 3
125
+ #define grpc_lb_v1_Server_drop_tag 4
148
126
  #define grpc_lb_v1_LoadBalanceRequest_initial_request_tag 1
149
127
  #define grpc_lb_v1_LoadBalanceRequest_client_stats_tag 2
150
128
  #define grpc_lb_v1_LoadBalanceResponse_initial_response_tag 1
151
129
  #define grpc_lb_v1_LoadBalanceResponse_server_list_tag 2
152
130
 
153
131
  /* Struct field encoding specification for nanopb */
154
- extern const pb_field_t grpc_lb_v1_Duration_fields[3];
155
- extern const pb_field_t grpc_lb_v1_Timestamp_fields[3];
156
132
  extern const pb_field_t grpc_lb_v1_LoadBalanceRequest_fields[3];
157
133
  extern const pb_field_t grpc_lb_v1_InitialLoadBalanceRequest_fields[2];
158
134
  extern const pb_field_t grpc_lb_v1_ClientStatsPerToken_fields[3];
@@ -163,8 +139,6 @@ extern const pb_field_t grpc_lb_v1_ServerList_fields[2];
163
139
  extern const pb_field_t grpc_lb_v1_Server_fields[5];
164
140
 
165
141
  /* Maximum encoded size of messages (where known) */
166
- #define grpc_lb_v1_Duration_size 22
167
- #define grpc_lb_v1_Timestamp_size 22
168
142
  #define grpc_lb_v1_LoadBalanceRequest_size (140 + grpc_lb_v1_ClientStats_size)
169
143
  #define grpc_lb_v1_InitialLoadBalanceRequest_size 131
170
144
  /* grpc_lb_v1_ClientStatsPerToken_size depends on runtime parameters */
@@ -27,6 +27,7 @@
27
27
  #include "src/core/ext/filters/client_channel/subchannel.h"
28
28
  #include "src/core/ext/filters/client_channel/subchannel_index.h"
29
29
  #include "src/core/lib/channel/channel_args.h"
30
+ #include "src/core/lib/gprpp/mutex_lock.h"
30
31
  #include "src/core/lib/iomgr/combiner.h"
31
32
  #include "src/core/lib/iomgr/sockaddr_utils.h"
32
33
  #include "src/core/lib/transport/connectivity_state.h"
@@ -46,7 +47,7 @@ class PickFirst : public LoadBalancingPolicy {
46
47
  explicit PickFirst(const Args& args);
47
48
 
48
49
  void UpdateLocked(const grpc_channel_args& args) override;
49
- bool PickLocked(PickState* pick) override;
50
+ bool PickLocked(PickState* pick, grpc_error** error) override;
50
51
  void CancelPickLocked(PickState* pick, grpc_error* error) override;
51
52
  void CancelMatchingPicksLocked(uint32_t initial_metadata_flags_mask,
52
53
  uint32_t initial_metadata_flags_eq,
@@ -56,46 +57,107 @@ class PickFirst : public LoadBalancingPolicy {
56
57
  grpc_connectivity_state CheckConnectivityLocked(
57
58
  grpc_error** connectivity_error) override;
58
59
  void HandOffPendingPicksLocked(LoadBalancingPolicy* new_policy) override;
59
- void PingOneLocked(grpc_closure* on_initiate, grpc_closure* on_ack) override;
60
60
  void ExitIdleLocked() override;
61
+ void ResetBackoffLocked() override;
62
+ void FillChildRefsForChannelz(ChildRefsList* child_subchannels,
63
+ ChildRefsList* ignored) override;
61
64
 
62
65
  private:
63
66
  ~PickFirst();
64
67
 
65
- void ShutdownLocked() override;
68
+ class PickFirstSubchannelList;
69
+
70
+ class PickFirstSubchannelData
71
+ : public SubchannelData<PickFirstSubchannelList,
72
+ PickFirstSubchannelData> {
73
+ public:
74
+ PickFirstSubchannelData(PickFirstSubchannelList* subchannel_list,
75
+ const grpc_lb_user_data_vtable* user_data_vtable,
76
+ const grpc_lb_address& address,
77
+ grpc_subchannel* subchannel,
78
+ grpc_combiner* combiner)
79
+ : SubchannelData(subchannel_list, user_data_vtable, address, subchannel,
80
+ combiner) {}
81
+
82
+ void ProcessConnectivityChangeLocked(
83
+ grpc_connectivity_state connectivity_state, grpc_error* error) override;
84
+
85
+ // Processes the connectivity change to READY for an unselected subchannel.
86
+ void ProcessUnselectedReadyLocked();
87
+
88
+ void CheckConnectivityStateAndStartWatchingLocked();
89
+ };
90
+
91
+ class PickFirstSubchannelList
92
+ : public SubchannelList<PickFirstSubchannelList,
93
+ PickFirstSubchannelData> {
94
+ public:
95
+ PickFirstSubchannelList(PickFirst* policy, TraceFlag* tracer,
96
+ const grpc_lb_addresses* addresses,
97
+ grpc_combiner* combiner,
98
+ grpc_client_channel_factory* client_channel_factory,
99
+ const grpc_channel_args& args)
100
+ : SubchannelList(policy, tracer, addresses, combiner,
101
+ client_channel_factory, args) {
102
+ // Need to maintain a ref to the LB policy as long as we maintain
103
+ // any references to subchannels, since the subchannels'
104
+ // pollset_sets will include the LB policy's pollset_set.
105
+ policy->Ref(DEBUG_LOCATION, "subchannel_list").release();
106
+ }
66
107
 
67
- void StartPickingLocked();
68
- void DestroyUnselectedSubchannelsLocked();
108
+ ~PickFirstSubchannelList() {
109
+ PickFirst* p = static_cast<PickFirst*>(policy());
110
+ p->Unref(DEBUG_LOCATION, "subchannel_list");
111
+ }
112
+ };
69
113
 
70
- static void OnConnectivityChangedLocked(void* arg, grpc_error* error);
114
+ // Helper class to ensure that any function that modifies the child refs
115
+ // data structures will update the channelz snapshot data structures before
116
+ // returning.
117
+ class AutoChildRefsUpdater {
118
+ public:
119
+ explicit AutoChildRefsUpdater(PickFirst* pf) : pf_(pf) {}
120
+ ~AutoChildRefsUpdater() { pf_->UpdateChildRefsLocked(); }
71
121
 
72
- void SubchannelListRefForConnectivityWatch(
73
- grpc_lb_subchannel_list* subchannel_list, const char* reason);
74
- void SubchannelListUnrefForConnectivityWatch(
75
- grpc_lb_subchannel_list* subchannel_list, const char* reason);
122
+ private:
123
+ PickFirst* pf_;
124
+ };
76
125
 
77
- /** all our subchannels */
78
- grpc_lb_subchannel_list* subchannel_list_ = nullptr;
79
- /** latest pending subchannel list */
80
- grpc_lb_subchannel_list* latest_pending_subchannel_list_ = nullptr;
81
- /** selected subchannel in \a subchannel_list */
82
- grpc_lb_subchannel_data* selected_ = nullptr;
83
- /** have we started picking? */
126
+ void ShutdownLocked() override;
127
+
128
+ void StartPickingLocked();
129
+ void DestroyUnselectedSubchannelsLocked();
130
+ void UpdateChildRefsLocked();
131
+
132
+ // All our subchannels.
133
+ OrphanablePtr<PickFirstSubchannelList> subchannel_list_;
134
+ // Latest pending subchannel list.
135
+ OrphanablePtr<PickFirstSubchannelList> latest_pending_subchannel_list_;
136
+ // Selected subchannel in \a subchannel_list_.
137
+ PickFirstSubchannelData* selected_ = nullptr;
138
+ // Have we started picking?
84
139
  bool started_picking_ = false;
85
- /** are we shut down? */
140
+ // Are we shut down?
86
141
  bool shutdown_ = false;
87
- /** list of picks that are waiting on connectivity */
142
+ // List of picks that are waiting on connectivity.
88
143
  PickState* pending_picks_ = nullptr;
89
- /** our connectivity state tracker */
144
+ // Our connectivity state tracker.
90
145
  grpc_connectivity_state_tracker state_tracker_;
146
+
147
+ /// Lock and data used to capture snapshots of this channels child
148
+ /// channels and subchannels. This data is consumed by channelz.
149
+ gpr_mu child_refs_mu_;
150
+ ChildRefsList child_subchannels_;
151
+ ChildRefsList child_channels_;
91
152
  };
92
153
 
93
154
  PickFirst::PickFirst(const Args& args) : LoadBalancingPolicy(args) {
94
155
  GPR_ASSERT(args.client_channel_factory != nullptr);
156
+ gpr_mu_init(&child_refs_mu_);
95
157
  grpc_connectivity_state_init(&state_tracker_, GRPC_CHANNEL_IDLE,
96
158
  "pick_first");
97
159
  if (grpc_lb_pick_first_trace.enabled()) {
98
- gpr_log(GPR_DEBUG, "Pick First %p created.", this);
160
+ gpr_log(GPR_INFO, "Pick First %p created.", this);
99
161
  }
100
162
  UpdateLocked(*args.args);
101
163
  grpc_subchannel_index_ref();
@@ -103,8 +165,9 @@ PickFirst::PickFirst(const Args& args) : LoadBalancingPolicy(args) {
103
165
 
104
166
  PickFirst::~PickFirst() {
105
167
  if (grpc_lb_pick_first_trace.enabled()) {
106
- gpr_log(GPR_DEBUG, "Destroying Pick First %p", this);
168
+ gpr_log(GPR_INFO, "Destroying Pick First %p", this);
107
169
  }
170
+ gpr_mu_destroy(&child_refs_mu_);
108
171
  GPR_ASSERT(subchannel_list_ == nullptr);
109
172
  GPR_ASSERT(latest_pending_subchannel_list_ == nullptr);
110
173
  GPR_ASSERT(pending_picks_ == nullptr);
@@ -116,17 +179,19 @@ void PickFirst::HandOffPendingPicksLocked(LoadBalancingPolicy* new_policy) {
116
179
  PickState* pick;
117
180
  while ((pick = pending_picks_) != nullptr) {
118
181
  pending_picks_ = pick->next;
119
- if (new_policy->PickLocked(pick)) {
182
+ grpc_error* error = GRPC_ERROR_NONE;
183
+ if (new_policy->PickLocked(pick, &error)) {
120
184
  // Synchronous return, schedule closure.
121
- GRPC_CLOSURE_SCHED(pick->on_complete, GRPC_ERROR_NONE);
185
+ GRPC_CLOSURE_SCHED(pick->on_complete, error);
122
186
  }
123
187
  }
124
188
  }
125
189
 
126
190
  void PickFirst::ShutdownLocked() {
191
+ AutoChildRefsUpdater guard(this);
127
192
  grpc_error* error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("Channel shutdown");
128
193
  if (grpc_lb_pick_first_trace.enabled()) {
129
- gpr_log(GPR_DEBUG, "Pick First %p Shutting down", this);
194
+ gpr_log(GPR_INFO, "Pick First %p Shutting down", this);
130
195
  }
131
196
  shutdown_ = true;
132
197
  PickState* pick;
@@ -137,15 +202,8 @@ void PickFirst::ShutdownLocked() {
137
202
  }
138
203
  grpc_connectivity_state_set(&state_tracker_, GRPC_CHANNEL_SHUTDOWN,
139
204
  GRPC_ERROR_REF(error), "shutdown");
140
- if (subchannel_list_ != nullptr) {
141
- grpc_lb_subchannel_list_shutdown_and_unref(subchannel_list_, "pf_shutdown");
142
- subchannel_list_ = nullptr;
143
- }
144
- if (latest_pending_subchannel_list_ != nullptr) {
145
- grpc_lb_subchannel_list_shutdown_and_unref(latest_pending_subchannel_list_,
146
- "pf_shutdown");
147
- latest_pending_subchannel_list_ = nullptr;
148
- }
205
+ subchannel_list_.reset();
206
+ latest_pending_subchannel_list_.reset();
149
207
  TryReresolutionLocked(&grpc_lb_pick_first_trace, GRPC_ERROR_CANCELLED);
150
208
  GRPC_ERROR_UNREF(error);
151
209
  }
@@ -192,14 +250,11 @@ void PickFirst::CancelMatchingPicksLocked(uint32_t initial_metadata_flags_mask,
192
250
 
193
251
  void PickFirst::StartPickingLocked() {
194
252
  started_picking_ = true;
195
- if (subchannel_list_ != nullptr && subchannel_list_->num_subchannels > 0) {
196
- subchannel_list_->checking_subchannel = 0;
197
- for (size_t i = 0; i < subchannel_list_->num_subchannels; ++i) {
198
- if (subchannel_list_->subchannels[i].subchannel != nullptr) {
199
- SubchannelListRefForConnectivityWatch(
200
- subchannel_list_, "connectivity_watch+start_picking");
201
- grpc_lb_subchannel_data_start_connectivity_watch(
202
- &subchannel_list_->subchannels[i]);
253
+ if (subchannel_list_ != nullptr) {
254
+ for (size_t i = 0; i < subchannel_list_->num_subchannels(); ++i) {
255
+ if (subchannel_list_->subchannel(i)->subchannel() != nullptr) {
256
+ subchannel_list_->subchannel(i)
257
+ ->CheckConnectivityStateAndStartWatchingLocked();
203
258
  break;
204
259
  }
205
260
  }
@@ -212,27 +267,38 @@ void PickFirst::ExitIdleLocked() {
212
267
  }
213
268
  }
214
269
 
215
- bool PickFirst::PickLocked(PickState* pick) {
270
+ void PickFirst::ResetBackoffLocked() {
271
+ subchannel_list_->ResetBackoffLocked();
272
+ if (latest_pending_subchannel_list_ != nullptr) {
273
+ latest_pending_subchannel_list_->ResetBackoffLocked();
274
+ }
275
+ }
276
+
277
+ bool PickFirst::PickLocked(PickState* pick, grpc_error** error) {
216
278
  // If we have a selected subchannel already, return synchronously.
217
279
  if (selected_ != nullptr) {
218
- pick->connected_subchannel = selected_->connected_subchannel;
280
+ pick->connected_subchannel = selected_->connected_subchannel()->Ref();
219
281
  return true;
220
282
  }
221
283
  // No subchannel selected yet, so handle asynchronously.
222
- if (!started_picking_) {
223
- StartPickingLocked();
284
+ if (pick->on_complete == nullptr) {
285
+ *error = GRPC_ERROR_CREATE_FROM_STATIC_STRING(
286
+ "No pick result available but synchronous result required.");
287
+ return true;
224
288
  }
225
289
  pick->next = pending_picks_;
226
290
  pending_picks_ = pick;
291
+ if (!started_picking_) {
292
+ StartPickingLocked();
293
+ }
227
294
  return false;
228
295
  }
229
296
 
230
297
  void PickFirst::DestroyUnselectedSubchannelsLocked() {
231
- for (size_t i = 0; i < subchannel_list_->num_subchannels; ++i) {
232
- grpc_lb_subchannel_data* sd = &subchannel_list_->subchannels[i];
298
+ for (size_t i = 0; i < subchannel_list_->num_subchannels(); ++i) {
299
+ PickFirstSubchannelData* sd = subchannel_list_->subchannel(i);
233
300
  if (selected_ != sd) {
234
- grpc_lb_subchannel_data_unref_subchannel(sd,
235
- "selected_different_subchannel");
301
+ sd->UnrefSubchannelLocked("selected_different_subchannel");
236
302
  }
237
303
  }
238
304
  }
@@ -247,36 +313,41 @@ void PickFirst::NotifyOnStateChangeLocked(grpc_connectivity_state* current,
247
313
  notify);
248
314
  }
249
315
 
250
- void PickFirst::PingOneLocked(grpc_closure* on_initiate, grpc_closure* on_ack) {
251
- if (selected_ != nullptr) {
252
- selected_->connected_subchannel->Ping(on_initiate, on_ack);
253
- } else {
254
- GRPC_CLOSURE_SCHED(on_initiate,
255
- GRPC_ERROR_CREATE_FROM_STATIC_STRING("Not connected"));
256
- GRPC_CLOSURE_SCHED(on_ack,
257
- GRPC_ERROR_CREATE_FROM_STATIC_STRING("Not connected"));
316
+ void PickFirst::FillChildRefsForChannelz(
317
+ ChildRefsList* child_subchannels_to_fill, ChildRefsList* ignored) {
318
+ MutexLock lock(&child_refs_mu_);
319
+ for (size_t i = 0; i < child_subchannels_.size(); ++i) {
320
+ // TODO(ncteisen): implement a de dup loop that is not O(n^2). Might
321
+ // have to implement lightweight set. For now, we don't care about
322
+ // performance when channelz requests are made.
323
+ bool found = false;
324
+ for (size_t j = 0; j < child_subchannels_to_fill->size(); ++j) {
325
+ if ((*child_subchannels_to_fill)[j] == child_subchannels_[i]) {
326
+ found = true;
327
+ break;
328
+ }
329
+ }
330
+ if (!found) {
331
+ child_subchannels_to_fill->push_back(child_subchannels_[i]);
332
+ }
258
333
  }
259
334
  }
260
335
 
261
- void PickFirst::SubchannelListRefForConnectivityWatch(
262
- grpc_lb_subchannel_list* subchannel_list, const char* reason) {
263
- // TODO(roth): We currently track this ref manually. Once the new
264
- // ClosureRef API is ready and the subchannel_list code has been
265
- // converted to a C++ API, find a way to hold the RefCountedPtr<>
266
- // somewhere (maybe in the subchannel_data object) instead of doing
267
- // this manually.
268
- auto self = Ref(DEBUG_LOCATION, reason);
269
- self.release();
270
- grpc_lb_subchannel_list_ref(subchannel_list, reason);
271
- }
272
-
273
- void PickFirst::SubchannelListUnrefForConnectivityWatch(
274
- grpc_lb_subchannel_list* subchannel_list, const char* reason) {
275
- Unref(DEBUG_LOCATION, reason);
276
- grpc_lb_subchannel_list_unref(subchannel_list, reason);
336
+ void PickFirst::UpdateChildRefsLocked() {
337
+ ChildRefsList cs;
338
+ if (subchannel_list_ != nullptr) {
339
+ subchannel_list_->PopulateChildRefsList(&cs);
340
+ }
341
+ if (latest_pending_subchannel_list_ != nullptr) {
342
+ latest_pending_subchannel_list_->PopulateChildRefsList(&cs);
343
+ }
344
+ // atomically update the data that channelz will actually be looking at.
345
+ MutexLock lock(&child_refs_mu_);
346
+ child_subchannels_ = std::move(cs);
277
347
  }
278
348
 
279
349
  void PickFirst::UpdateLocked(const grpc_channel_args& args) {
350
+ AutoChildRefsUpdater guard(this);
280
351
  const grpc_arg* arg = grpc_channel_args_find(&args, GRPC_ARG_LB_ADDRESSES);
281
352
  if (arg == nullptr || arg->type != GRPC_ARG_POINTER) {
282
353
  if (subchannel_list_ == nullptr) {
@@ -295,75 +366,68 @@ void PickFirst::UpdateLocked(const grpc_channel_args& args) {
295
366
  return;
296
367
  }
297
368
  const grpc_lb_addresses* addresses =
298
- (const grpc_lb_addresses*)arg->value.pointer.p;
369
+ static_cast<const grpc_lb_addresses*>(arg->value.pointer.p);
299
370
  if (grpc_lb_pick_first_trace.enabled()) {
300
371
  gpr_log(GPR_INFO,
301
372
  "Pick First %p received update with %" PRIuPTR " addresses", this,
302
373
  addresses->num_addresses);
303
374
  }
304
- grpc_lb_subchannel_list* subchannel_list = grpc_lb_subchannel_list_create(
375
+ auto subchannel_list = MakeOrphanable<PickFirstSubchannelList>(
305
376
  this, &grpc_lb_pick_first_trace, addresses, combiner(),
306
- client_channel_factory(), args, &PickFirst::OnConnectivityChangedLocked);
307
- if (subchannel_list->num_subchannels == 0) {
377
+ client_channel_factory(), args);
378
+ if (subchannel_list->num_subchannels() == 0) {
308
379
  // Empty update or no valid subchannels. Unsubscribe from all current
309
380
  // subchannels and put the channel in TRANSIENT_FAILURE.
310
381
  grpc_connectivity_state_set(
311
382
  &state_tracker_, GRPC_CHANNEL_TRANSIENT_FAILURE,
312
383
  GRPC_ERROR_CREATE_FROM_STATIC_STRING("Empty update"),
313
384
  "pf_update_empty");
314
- if (subchannel_list_ != nullptr) {
315
- grpc_lb_subchannel_list_shutdown_and_unref(subchannel_list_,
316
- "sl_shutdown_empty_update");
317
- }
318
- subchannel_list_ = subchannel_list; // Empty list.
385
+ subchannel_list_ = std::move(subchannel_list); // Empty list.
319
386
  selected_ = nullptr;
320
387
  return;
321
388
  }
322
389
  if (selected_ == nullptr) {
323
390
  // We don't yet have a selected subchannel, so replace the current
324
391
  // subchannel list immediately.
325
- if (subchannel_list_ != nullptr) {
326
- grpc_lb_subchannel_list_shutdown_and_unref(subchannel_list_,
327
- "pf_update_before_selected");
392
+ subchannel_list_ = std::move(subchannel_list);
393
+ // If we've started picking, start trying to connect to the first
394
+ // subchannel in the new list.
395
+ if (started_picking_) {
396
+ subchannel_list_->subchannel(0)
397
+ ->CheckConnectivityStateAndStartWatchingLocked();
328
398
  }
329
- subchannel_list_ = subchannel_list;
330
399
  } else {
331
400
  // We do have a selected subchannel.
332
401
  // Check if it's present in the new list. If so, we're done.
333
- for (size_t i = 0; i < subchannel_list->num_subchannels; ++i) {
334
- grpc_lb_subchannel_data* sd = &subchannel_list->subchannels[i];
335
- if (sd->subchannel == selected_->subchannel) {
402
+ for (size_t i = 0; i < subchannel_list->num_subchannels(); ++i) {
403
+ PickFirstSubchannelData* sd = subchannel_list->subchannel(i);
404
+ if (sd->subchannel() == selected_->subchannel()) {
336
405
  // The currently selected subchannel is in the update: we are done.
337
406
  if (grpc_lb_pick_first_trace.enabled()) {
338
407
  gpr_log(GPR_INFO,
339
408
  "Pick First %p found already selected subchannel %p "
340
409
  "at update index %" PRIuPTR " of %" PRIuPTR "; update done",
341
- this, selected_->subchannel, i,
342
- subchannel_list->num_subchannels);
343
- }
344
- if (selected_->connected_subchannel != nullptr) {
345
- sd->connected_subchannel = selected_->connected_subchannel;
410
+ this, selected_->subchannel(), i,
411
+ subchannel_list->num_subchannels());
346
412
  }
347
- selected_ = sd;
348
- if (subchannel_list_ != nullptr) {
349
- grpc_lb_subchannel_list_shutdown_and_unref(
350
- subchannel_list_, "pf_update_includes_selected");
413
+ // Make sure it's in state READY. It might not be if we grabbed
414
+ // the combiner while a connectivity state notification
415
+ // informing us otherwise is pending.
416
+ // Note that CheckConnectivityStateLocked() also takes a ref to
417
+ // the connected subchannel.
418
+ grpc_error* error = GRPC_ERROR_NONE;
419
+ if (sd->CheckConnectivityStateLocked(&error) == GRPC_CHANNEL_READY) {
420
+ selected_ = sd;
421
+ subchannel_list_ = std::move(subchannel_list);
422
+ DestroyUnselectedSubchannelsLocked();
423
+ sd->StartConnectivityWatchLocked();
424
+ // If there was a previously pending update (which may or may
425
+ // not have contained the currently selected subchannel), drop
426
+ // it, so that it doesn't override what we've done here.
427
+ latest_pending_subchannel_list_.reset();
428
+ return;
351
429
  }
352
- subchannel_list_ = subchannel_list;
353
- DestroyUnselectedSubchannelsLocked();
354
- SubchannelListRefForConnectivityWatch(
355
- subchannel_list, "connectivity_watch+replace_selected");
356
- grpc_lb_subchannel_data_start_connectivity_watch(sd);
357
- // If there was a previously pending update (which may or may
358
- // not have contained the currently selected subchannel), drop
359
- // it, so that it doesn't override what we've done here.
360
- if (latest_pending_subchannel_list_ != nullptr) {
361
- grpc_lb_subchannel_list_shutdown_and_unref(
362
- latest_pending_subchannel_list_,
363
- "pf_update_includes_selected+outdated");
364
- latest_pending_subchannel_list_ = nullptr;
365
- }
366
- return;
430
+ GRPC_ERROR_UNREF(error);
367
431
  }
368
432
  }
369
433
  // Not keeping the previous selected subchannel, so set the latest
@@ -372,89 +436,67 @@ void PickFirst::UpdateLocked(const grpc_channel_args& args) {
372
436
  // subchannel list.
373
437
  if (latest_pending_subchannel_list_ != nullptr) {
374
438
  if (grpc_lb_pick_first_trace.enabled()) {
375
- gpr_log(GPR_DEBUG,
439
+ gpr_log(GPR_INFO,
376
440
  "Pick First %p Shutting down latest pending subchannel list "
377
441
  "%p, about to be replaced by newer latest %p",
378
- this, latest_pending_subchannel_list_, subchannel_list);
442
+ this, latest_pending_subchannel_list_.get(),
443
+ subchannel_list.get());
379
444
  }
380
- grpc_lb_subchannel_list_shutdown_and_unref(
381
- latest_pending_subchannel_list_, "sl_outdated_dont_smash");
382
445
  }
383
- latest_pending_subchannel_list_ = subchannel_list;
384
- }
385
- // If we've started picking, start trying to connect to the first
386
- // subchannel in the new list.
387
- if (started_picking_) {
388
- SubchannelListRefForConnectivityWatch(subchannel_list,
389
- "connectivity_watch+update");
390
- grpc_lb_subchannel_data_start_connectivity_watch(
391
- &subchannel_list->subchannels[0]);
446
+ latest_pending_subchannel_list_ = std::move(subchannel_list);
447
+ // If we've started picking, start trying to connect to the first
448
+ // subchannel in the new list.
449
+ if (started_picking_) {
450
+ latest_pending_subchannel_list_->subchannel(0)
451
+ ->CheckConnectivityStateAndStartWatchingLocked();
452
+ }
392
453
  }
393
454
  }
394
455
 
395
- void PickFirst::OnConnectivityChangedLocked(void* arg, grpc_error* error) {
396
- grpc_lb_subchannel_data* sd = static_cast<grpc_lb_subchannel_data*>(arg);
397
- PickFirst* p = static_cast<PickFirst*>(sd->subchannel_list->policy);
398
- if (grpc_lb_pick_first_trace.enabled()) {
399
- gpr_log(GPR_DEBUG,
400
- "Pick First %p connectivity changed for subchannel %p (%" PRIuPTR
401
- " of %" PRIuPTR
402
- "), subchannel_list %p: state=%s p->shutdown_=%d "
403
- "sd->subchannel_list->shutting_down=%d error=%s",
404
- p, sd->subchannel, sd->subchannel_list->checking_subchannel,
405
- sd->subchannel_list->num_subchannels, sd->subchannel_list,
406
- grpc_connectivity_state_name(sd->pending_connectivity_state_unsafe),
407
- p->shutdown_, sd->subchannel_list->shutting_down,
408
- grpc_error_string(error));
409
- }
410
- // If the policy is shutting down, unref and return.
411
- if (p->shutdown_) {
412
- grpc_lb_subchannel_data_stop_connectivity_watch(sd);
413
- grpc_lb_subchannel_data_unref_subchannel(sd, "pf_shutdown");
414
- p->SubchannelListUnrefForConnectivityWatch(sd->subchannel_list,
415
- "pf_shutdown");
416
- return;
417
- }
418
- // If the subchannel list is shutting down, stop watching.
419
- if (sd->subchannel_list->shutting_down || error == GRPC_ERROR_CANCELLED) {
420
- grpc_lb_subchannel_data_stop_connectivity_watch(sd);
421
- grpc_lb_subchannel_data_unref_subchannel(sd, "pf_sl_shutdown");
422
- p->SubchannelListUnrefForConnectivityWatch(sd->subchannel_list,
423
- "pf_sl_shutdown");
424
- return;
425
- }
426
- // If we're still here, the notification must be for a subchannel in
427
- // either the current or latest pending subchannel lists.
428
- GPR_ASSERT(sd->subchannel_list == p->subchannel_list_ ||
429
- sd->subchannel_list == p->latest_pending_subchannel_list_);
430
- // Update state.
431
- sd->curr_connectivity_state = sd->pending_connectivity_state_unsafe;
456
+ void PickFirst::PickFirstSubchannelData::ProcessConnectivityChangeLocked(
457
+ grpc_connectivity_state connectivity_state, grpc_error* error) {
458
+ PickFirst* p = static_cast<PickFirst*>(subchannel_list()->policy());
459
+ AutoChildRefsUpdater guard(p);
460
+ // The notification must be for a subchannel in either the current or
461
+ // latest pending subchannel lists.
462
+ GPR_ASSERT(subchannel_list() == p->subchannel_list_.get() ||
463
+ subchannel_list() == p->latest_pending_subchannel_list_.get());
464
+ GPR_ASSERT(connectivity_state != GRPC_CHANNEL_SHUTDOWN);
432
465
  // Handle updates for the currently selected subchannel.
433
- if (p->selected_ == sd) {
466
+ if (p->selected_ == this) {
467
+ if (grpc_lb_pick_first_trace.enabled()) {
468
+ gpr_log(GPR_INFO,
469
+ "Pick First %p connectivity changed for selected subchannel", p);
470
+ }
434
471
  // If the new state is anything other than READY and there is a
435
472
  // pending update, switch to the pending update.
436
- if (sd->curr_connectivity_state != GRPC_CHANNEL_READY &&
473
+ if (connectivity_state != GRPC_CHANNEL_READY &&
437
474
  p->latest_pending_subchannel_list_ != nullptr) {
475
+ if (grpc_lb_pick_first_trace.enabled()) {
476
+ gpr_log(GPR_INFO,
477
+ "Pick First %p promoting pending subchannel list %p to "
478
+ "replace %p",
479
+ p, p->latest_pending_subchannel_list_.get(),
480
+ p->subchannel_list_.get());
481
+ }
438
482
  p->selected_ = nullptr;
439
- grpc_lb_subchannel_data_stop_connectivity_watch(sd);
440
- p->SubchannelListUnrefForConnectivityWatch(
441
- sd->subchannel_list, "selected_not_ready+switch_to_update");
442
- grpc_lb_subchannel_list_shutdown_and_unref(
443
- p->subchannel_list_, "selected_not_ready+switch_to_update");
444
- p->subchannel_list_ = p->latest_pending_subchannel_list_;
445
- p->latest_pending_subchannel_list_ = nullptr;
483
+ StopConnectivityWatchLocked();
484
+ p->subchannel_list_ = std::move(p->latest_pending_subchannel_list_);
446
485
  grpc_connectivity_state_set(
447
486
  &p->state_tracker_, GRPC_CHANNEL_TRANSIENT_FAILURE,
448
- GRPC_ERROR_REF(error), "selected_not_ready+switch_to_update");
487
+ error != GRPC_ERROR_NONE
488
+ ? GRPC_ERROR_REF(error)
489
+ : GRPC_ERROR_CREATE_FROM_STATIC_STRING(
490
+ "selected subchannel not ready; switching to pending "
491
+ "update"),
492
+ "selected_not_ready+switch_to_update");
449
493
  } else {
450
- // TODO(juanlishen): we re-resolve when the selected subchannel goes to
451
- // TRANSIENT_FAILURE because we used to shut down in this case before
452
- // re-resolution is introduced. But we need to investigate whether we
453
- // really want to take any action instead of waiting for the selected
454
- // subchannel reconnecting.
455
- GPR_ASSERT(sd->curr_connectivity_state != GRPC_CHANNEL_SHUTDOWN);
456
- if (sd->curr_connectivity_state == GRPC_CHANNEL_TRANSIENT_FAILURE) {
457
- // If the selected channel goes bad, request a re-resolution.
494
+ if (connectivity_state == GRPC_CHANNEL_TRANSIENT_FAILURE) {
495
+ // If the selected subchannel goes bad, request a re-resolution. We also
496
+ // set the channel state to IDLE and reset started_picking_. The reason
497
+ // is that if the new state is TRANSIENT_FAILURE due to a GOAWAY
498
+ // reception we don't want to connect to the re-resolved backends until
499
+ // we leave the IDLE state.
458
500
  grpc_connectivity_state_set(&p->state_tracker_, GRPC_CHANNEL_IDLE,
459
501
  GRPC_ERROR_NONE,
460
502
  "selected_changed+reresolve");
@@ -462,19 +504,16 @@ void PickFirst::OnConnectivityChangedLocked(void* arg, grpc_error* error) {
462
504
  p->TryReresolutionLocked(&grpc_lb_pick_first_trace, GRPC_ERROR_NONE);
463
505
  // In transient failure. Rely on re-resolution to recover.
464
506
  p->selected_ = nullptr;
465
- grpc_lb_subchannel_data_stop_connectivity_watch(sd);
466
- p->SubchannelListUnrefForConnectivityWatch(sd->subchannel_list,
467
- "pf_selected_shutdown");
468
- grpc_lb_subchannel_data_unref_subchannel(
469
- sd, "pf_selected_shutdown"); // Unrefs connected subchannel
507
+ UnrefSubchannelLocked("pf_selected_shutdown");
508
+ StopConnectivityWatchLocked();
470
509
  } else {
471
- grpc_connectivity_state_set(&p->state_tracker_,
472
- sd->curr_connectivity_state,
510
+ grpc_connectivity_state_set(&p->state_tracker_, connectivity_state,
473
511
  GRPC_ERROR_REF(error), "selected_changed");
474
512
  // Renew notification.
475
- grpc_lb_subchannel_data_start_connectivity_watch(sd);
513
+ RenewConnectivityWatchLocked();
476
514
  }
477
515
  }
516
+ GRPC_ERROR_UNREF(error);
478
517
  return;
479
518
  }
480
519
  // If we get here, there are two possible cases:
@@ -486,81 +525,109 @@ void PickFirst::OnConnectivityChangedLocked(void* arg, grpc_error* error) {
486
525
  // for a subchannel in p->latest_pending_subchannel_list_. The
487
526
  // goal here is to find a subchannel from the update that we can
488
527
  // select in place of the current one.
489
- switch (sd->curr_connectivity_state) {
528
+ switch (connectivity_state) {
490
529
  case GRPC_CHANNEL_READY: {
491
- // Case 2. Promote p->latest_pending_subchannel_list_ to
492
- // p->subchannel_list_.
493
- sd->connected_subchannel =
494
- grpc_subchannel_get_connected_subchannel(sd->subchannel);
495
- if (sd->subchannel_list == p->latest_pending_subchannel_list_) {
496
- GPR_ASSERT(p->subchannel_list_ != nullptr);
497
- grpc_lb_subchannel_list_shutdown_and_unref(p->subchannel_list_,
498
- "finish_update");
499
- p->subchannel_list_ = p->latest_pending_subchannel_list_;
500
- p->latest_pending_subchannel_list_ = nullptr;
501
- }
502
- // Cases 1 and 2.
503
- grpc_connectivity_state_set(&p->state_tracker_, GRPC_CHANNEL_READY,
504
- GRPC_ERROR_NONE, "connecting_ready");
505
- p->selected_ = sd;
506
- if (grpc_lb_pick_first_trace.enabled()) {
507
- gpr_log(GPR_INFO, "Pick First %p selected subchannel %p", p,
508
- sd->subchannel);
509
- }
510
- // Drop all other subchannels, since we are now connected.
511
- p->DestroyUnselectedSubchannelsLocked();
512
- // Update any calls that were waiting for a pick.
513
- PickState* pick;
514
- while ((pick = p->pending_picks_)) {
515
- p->pending_picks_ = pick->next;
516
- pick->connected_subchannel = p->selected_->connected_subchannel;
517
- if (grpc_lb_pick_first_trace.enabled()) {
518
- gpr_log(GPR_INFO,
519
- "Servicing pending pick with selected subchannel %p",
520
- p->selected_);
521
- }
522
- GRPC_CLOSURE_SCHED(pick->on_complete, GRPC_ERROR_NONE);
523
- }
530
+ ProcessUnselectedReadyLocked();
524
531
  // Renew notification.
525
- grpc_lb_subchannel_data_start_connectivity_watch(sd);
532
+ RenewConnectivityWatchLocked();
526
533
  break;
527
534
  }
528
535
  case GRPC_CHANNEL_TRANSIENT_FAILURE: {
529
- grpc_lb_subchannel_data_stop_connectivity_watch(sd);
536
+ StopConnectivityWatchLocked();
537
+ PickFirstSubchannelData* sd = this;
530
538
  do {
531
- sd->subchannel_list->checking_subchannel =
532
- (sd->subchannel_list->checking_subchannel + 1) %
533
- sd->subchannel_list->num_subchannels;
534
- sd = &sd->subchannel_list
535
- ->subchannels[sd->subchannel_list->checking_subchannel];
536
- } while (sd->subchannel == nullptr);
539
+ size_t next_index =
540
+ (sd->Index() + 1) % subchannel_list()->num_subchannels();
541
+ sd = subchannel_list()->subchannel(next_index);
542
+ } while (sd->subchannel() == nullptr);
537
543
  // Case 1: Only set state to TRANSIENT_FAILURE if we've tried
538
544
  // all subchannels.
539
- if (sd->subchannel_list->checking_subchannel == 0 &&
540
- sd->subchannel_list == p->subchannel_list_) {
545
+ if (sd->Index() == 0 && subchannel_list() == p->subchannel_list_.get()) {
546
+ p->TryReresolutionLocked(&grpc_lb_pick_first_trace, GRPC_ERROR_NONE);
541
547
  grpc_connectivity_state_set(
542
548
  &p->state_tracker_, GRPC_CHANNEL_TRANSIENT_FAILURE,
543
- GRPC_ERROR_REF(error), "connecting_transient_failure");
549
+ GRPC_ERROR_REF(error), "exhausted_subchannels");
544
550
  }
545
- // Reuses the connectivity refs from the previous watch.
546
- grpc_lb_subchannel_data_start_connectivity_watch(sd);
551
+ sd->CheckConnectivityStateAndStartWatchingLocked();
547
552
  break;
548
553
  }
549
554
  case GRPC_CHANNEL_CONNECTING:
550
555
  case GRPC_CHANNEL_IDLE: {
551
556
  // Only update connectivity state in case 1.
552
- if (sd->subchannel_list == p->subchannel_list_) {
557
+ if (subchannel_list() == p->subchannel_list_.get()) {
553
558
  grpc_connectivity_state_set(&p->state_tracker_, GRPC_CHANNEL_CONNECTING,
554
559
  GRPC_ERROR_REF(error),
555
560
  "connecting_changed");
556
561
  }
557
562
  // Renew notification.
558
- grpc_lb_subchannel_data_start_connectivity_watch(sd);
563
+ RenewConnectivityWatchLocked();
559
564
  break;
560
565
  }
561
566
  case GRPC_CHANNEL_SHUTDOWN:
562
567
  GPR_UNREACHABLE_CODE(break);
563
568
  }
569
+ GRPC_ERROR_UNREF(error);
570
+ }
571
+
572
+ void PickFirst::PickFirstSubchannelData::ProcessUnselectedReadyLocked() {
573
+ PickFirst* p = static_cast<PickFirst*>(subchannel_list()->policy());
574
+ // If we get here, there are two possible cases:
575
+ // 1. We do not currently have a selected subchannel, and the update is
576
+ // for a subchannel in p->subchannel_list_ that we're trying to
577
+ // connect to. The goal here is to find a subchannel that we can
578
+ // select.
579
+ // 2. We do currently have a selected subchannel, and the update is
580
+ // for a subchannel in p->latest_pending_subchannel_list_. The
581
+ // goal here is to find a subchannel from the update that we can
582
+ // select in place of the current one.
583
+ GPR_ASSERT(subchannel_list() == p->subchannel_list_.get() ||
584
+ subchannel_list() == p->latest_pending_subchannel_list_.get());
585
+ // Case 2. Promote p->latest_pending_subchannel_list_ to p->subchannel_list_.
586
+ if (subchannel_list() == p->latest_pending_subchannel_list_.get()) {
587
+ if (grpc_lb_pick_first_trace.enabled()) {
588
+ gpr_log(GPR_INFO,
589
+ "Pick First %p promoting pending subchannel list %p to "
590
+ "replace %p",
591
+ p, p->latest_pending_subchannel_list_.get(),
592
+ p->subchannel_list_.get());
593
+ }
594
+ p->subchannel_list_ = std::move(p->latest_pending_subchannel_list_);
595
+ }
596
+ // Cases 1 and 2.
597
+ grpc_connectivity_state_set(&p->state_tracker_, GRPC_CHANNEL_READY,
598
+ GRPC_ERROR_NONE, "subchannel_ready");
599
+ p->selected_ = this;
600
+ if (grpc_lb_pick_first_trace.enabled()) {
601
+ gpr_log(GPR_INFO, "Pick First %p selected subchannel %p", p, subchannel());
602
+ }
603
+ // Drop all other subchannels, since we are now connected.
604
+ p->DestroyUnselectedSubchannelsLocked();
605
+ // Update any calls that were waiting for a pick.
606
+ PickState* pick;
607
+ while ((pick = p->pending_picks_)) {
608
+ p->pending_picks_ = pick->next;
609
+ pick->connected_subchannel = p->selected_->connected_subchannel()->Ref();
610
+ if (grpc_lb_pick_first_trace.enabled()) {
611
+ gpr_log(GPR_INFO, "Servicing pending pick with selected subchannel %p",
612
+ p->selected_->subchannel());
613
+ }
614
+ GRPC_CLOSURE_SCHED(pick->on_complete, GRPC_ERROR_NONE);
615
+ }
616
+ }
617
+
618
+ void PickFirst::PickFirstSubchannelData::
619
+ CheckConnectivityStateAndStartWatchingLocked() {
620
+ PickFirst* p = static_cast<PickFirst*>(subchannel_list()->policy());
621
+ grpc_error* error = GRPC_ERROR_NONE;
622
+ if (p->selected_ != this &&
623
+ CheckConnectivityStateLocked(&error) == GRPC_CHANNEL_READY) {
624
+ // We must process the READY subchannel before we start watching it.
625
+ // Otherwise, we won't know it's READY because we will be waiting for its
626
+ // connectivity state to change from READY.
627
+ ProcessUnselectedReadyLocked();
628
+ }
629
+ GRPC_ERROR_UNREF(error);
630
+ StartConnectivityWatchLocked();
564
631
  }
565
632
 
566
633
  //