grpc 1.18.0 → 1.22.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 (428) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +4731 -7404
  3. data/etc/roots.pem +146 -0
  4. data/include/grpc/grpc.h +11 -6
  5. data/include/grpc/grpc_security.h +297 -4
  6. data/include/grpc/grpc_security_constants.h +1 -1
  7. data/include/grpc/impl/codegen/byte_buffer.h +13 -0
  8. data/include/grpc/impl/codegen/gpr_types.h +1 -1
  9. data/include/grpc/impl/codegen/grpc_types.h +30 -7
  10. data/include/grpc/impl/codegen/port_platform.h +88 -7
  11. data/include/grpc/impl/codegen/slice.h +2 -22
  12. data/include/grpc/impl/codegen/status.h +2 -1
  13. data/include/grpc/impl/codegen/sync_posix.h +18 -0
  14. data/include/grpc/slice.h +3 -3
  15. data/src/core/ext/filters/client_channel/backup_poller.cc +21 -16
  16. data/src/core/ext/filters/client_channel/backup_poller.h +8 -2
  17. data/src/core/ext/filters/client_channel/channel_connectivity.cc +3 -1
  18. data/src/core/ext/filters/client_channel/client_channel.cc +2435 -1557
  19. data/src/core/ext/filters/client_channel/client_channel.h +2 -10
  20. data/src/core/ext/filters/client_channel/client_channel_channelz.cc +6 -89
  21. data/src/core/ext/filters/client_channel/client_channel_channelz.h +8 -33
  22. data/src/core/ext/filters/client_channel/client_channel_factory.cc +22 -34
  23. data/src/core/ext/filters/client_channel/client_channel_factory.h +19 -38
  24. data/src/core/ext/filters/client_channel/client_channel_plugin.cc +9 -11
  25. data/src/core/ext/filters/client_channel/global_subchannel_pool.cc +179 -0
  26. data/src/core/ext/filters/client_channel/global_subchannel_pool.h +68 -0
  27. data/src/core/ext/filters/client_channel/health/health_check_client.cc +59 -55
  28. data/src/core/ext/filters/client_channel/health/health_check_client.h +20 -9
  29. data/src/core/ext/filters/client_channel/http_connect_handshaker.cc +146 -157
  30. data/src/core/ext/filters/client_channel/http_connect_handshaker.h +1 -1
  31. data/src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.cc +29 -32
  32. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +844 -859
  33. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel.h +3 -1
  34. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel_secure.cc +2 -6
  35. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.cc +6 -2
  36. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.h +14 -12
  37. data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.cc +16 -12
  38. data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.h +3 -3
  39. data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc +185 -312
  40. data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc +143 -375
  41. data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +192 -245
  42. data/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc +1554 -955
  43. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_channel_secure.cc +0 -43
  44. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_load_balancer_api.cc +14 -10
  45. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_load_balancer_api.h +2 -2
  46. data/src/core/ext/filters/client_channel/lb_policy.cc +115 -22
  47. data/src/core/ext/filters/client_channel/lb_policy.h +260 -129
  48. data/src/core/ext/filters/client_channel/lb_policy_factory.h +5 -2
  49. data/src/core/ext/filters/client_channel/lb_policy_registry.cc +107 -4
  50. data/src/core/ext/filters/client_channel/lb_policy_registry.h +10 -3
  51. data/src/core/ext/filters/client_channel/local_subchannel_pool.cc +96 -0
  52. data/src/core/ext/filters/client_channel/local_subchannel_pool.h +56 -0
  53. data/src/core/ext/filters/client_channel/parse_address.cc +24 -5
  54. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +121 -122
  55. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.cc +84 -2
  56. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.h +3 -0
  57. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_libuv.cc +179 -0
  58. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_windows.cc +24 -10
  59. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc +111 -47
  60. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h +7 -13
  61. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_fallback.cc +2 -2
  62. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_libuv.cc +39 -0
  63. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_posix.cc +0 -6
  64. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_windows.cc +2 -64
  65. data/src/core/ext/filters/client_channel/resolver/dns/dns_resolver_selection.cc +28 -0
  66. data/src/core/{lib/iomgr/network_status_tracker.cc → ext/filters/client_channel/resolver/dns/dns_resolver_selection.h} +8 -15
  67. data/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc +36 -82
  68. data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc +111 -72
  69. data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.h +13 -8
  70. data/src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.cc +28 -63
  71. data/src/core/ext/filters/client_channel/resolver.cc +54 -1
  72. data/src/core/ext/filters/client_channel/resolver.h +52 -23
  73. data/src/core/ext/filters/client_channel/resolver_factory.h +3 -1
  74. data/src/core/ext/filters/client_channel/resolver_registry.cc +5 -2
  75. data/src/core/ext/filters/client_channel/resolver_registry.h +5 -4
  76. data/src/core/ext/filters/client_channel/resolver_result_parsing.cc +368 -241
  77. data/src/core/ext/filters/client_channel/resolver_result_parsing.h +58 -76
  78. data/src/core/ext/filters/client_channel/resolving_lb_policy.cc +543 -0
  79. data/src/core/ext/filters/client_channel/resolving_lb_policy.h +139 -0
  80. data/src/core/ext/filters/client_channel/server_address.cc +4 -54
  81. data/src/core/ext/filters/client_channel/server_address.h +1 -13
  82. data/src/core/ext/filters/client_channel/service_config.cc +329 -0
  83. data/src/core/ext/filters/client_channel/service_config.h +205 -0
  84. data/src/core/ext/filters/client_channel/subchannel.cc +803 -838
  85. data/src/core/ext/filters/client_channel/subchannel.h +295 -128
  86. data/src/core/ext/filters/client_channel/subchannel_interface.h +113 -0
  87. data/src/core/ext/filters/client_channel/subchannel_pool_interface.cc +97 -0
  88. data/src/core/ext/filters/client_channel/subchannel_pool_interface.h +94 -0
  89. data/src/core/ext/filters/deadline/deadline_filter.cc +3 -4
  90. data/src/core/ext/filters/deadline/deadline_filter.h +3 -2
  91. data/src/core/ext/filters/http/client/http_client_filter.cc +7 -5
  92. data/src/core/ext/filters/http/client/http_client_filter.h +1 -1
  93. data/src/core/ext/filters/http/client_authority_filter.cc +6 -3
  94. data/src/core/ext/filters/http/message_compress/message_compress_filter.cc +4 -3
  95. data/src/core/ext/filters/http/server/http_server_filter.cc +18 -12
  96. data/src/core/ext/filters/max_age/max_age_filter.cc +5 -2
  97. data/src/core/ext/filters/message_size/message_size_filter.cc +119 -77
  98. data/src/core/ext/filters/message_size/message_size_filter.h +33 -0
  99. data/src/core/ext/transport/chttp2/alpn/alpn.h +1 -1
  100. data/src/core/ext/transport/chttp2/client/chttp2_connector.cc +13 -12
  101. data/src/core/ext/transport/chttp2/client/insecure/channel_create.cc +45 -47
  102. data/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc +134 -143
  103. data/src/core/ext/transport/chttp2/server/chttp2_server.cc +68 -21
  104. data/src/core/ext/transport/chttp2/transport/bin_decoder.cc +4 -4
  105. data/src/core/ext/transport/chttp2/transport/bin_decoder.h +4 -4
  106. data/src/core/ext/transport/chttp2/transport/bin_encoder.cc +7 -6
  107. data/src/core/ext/transport/chttp2/transport/bin_encoder.h +4 -3
  108. data/src/core/ext/transport/chttp2/transport/chttp2_plugin.cc +9 -7
  109. data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +156 -94
  110. data/src/core/ext/transport/chttp2/transport/flow_control.cc +2 -2
  111. data/src/core/ext/transport/chttp2/transport/flow_control.h +1 -1
  112. data/src/core/ext/transport/chttp2/transport/frame_data.cc +33 -37
  113. data/src/core/ext/transport/chttp2/transport/frame_data.h +1 -1
  114. data/src/core/ext/transport/chttp2/transport/frame_goaway.cc +6 -5
  115. data/src/core/ext/transport/chttp2/transport/frame_goaway.h +3 -2
  116. data/src/core/ext/transport/chttp2/transport/frame_ping.cc +5 -4
  117. data/src/core/ext/transport/chttp2/transport/frame_ping.h +1 -1
  118. data/src/core/ext/transport/chttp2/transport/frame_rst_stream.cc +8 -6
  119. data/src/core/ext/transport/chttp2/transport/frame_rst_stream.h +2 -1
  120. data/src/core/ext/transport/chttp2/transport/frame_settings.cc +6 -4
  121. data/src/core/ext/transport/chttp2/transport/frame_settings.h +2 -1
  122. data/src/core/ext/transport/chttp2/transport/frame_window_update.cc +7 -6
  123. data/src/core/ext/transport/chttp2/transport/frame_window_update.h +1 -1
  124. data/src/core/ext/transport/chttp2/transport/hpack_encoder.cc +74 -55
  125. data/src/core/ext/transport/chttp2/transport/hpack_parser.cc +33 -11
  126. data/src/core/ext/transport/chttp2/transport/hpack_parser.h +3 -2
  127. data/src/core/ext/transport/chttp2/transport/hpack_table.cc +7 -14
  128. data/src/core/ext/transport/chttp2/transport/hpack_table.h +10 -1
  129. data/src/core/ext/transport/chttp2/transport/incoming_metadata.cc +9 -5
  130. data/src/core/ext/transport/chttp2/transport/incoming_metadata.h +9 -3
  131. data/src/core/ext/transport/chttp2/transport/internal.h +43 -30
  132. data/src/core/ext/transport/chttp2/transport/parsing.cc +52 -70
  133. data/src/core/ext/transport/chttp2/transport/stream_lists.cc +3 -3
  134. data/src/core/ext/transport/chttp2/transport/writing.cc +70 -33
  135. data/src/core/ext/transport/inproc/inproc_transport.cc +26 -18
  136. data/src/core/lib/channel/channel_args.cc +2 -101
  137. data/src/core/lib/channel/channel_args.h +3 -37
  138. data/src/core/lib/channel/channel_stack.h +10 -6
  139. data/src/core/lib/channel/channel_trace.cc +4 -4
  140. data/src/core/lib/channel/channel_trace.h +4 -4
  141. data/src/core/lib/channel/channelz.cc +168 -38
  142. data/src/core/lib/channel/channelz.h +40 -44
  143. data/src/core/lib/channel/channelz_registry.cc +75 -107
  144. data/src/core/lib/channel/channelz_registry.h +10 -28
  145. data/src/core/lib/channel/connected_channel.cc +2 -2
  146. data/src/core/lib/channel/context.h +2 -2
  147. data/src/core/lib/channel/handshaker.cc +151 -218
  148. data/src/core/lib/channel/handshaker.h +110 -101
  149. data/src/core/lib/channel/handshaker_factory.h +11 -19
  150. data/src/core/lib/channel/handshaker_registry.cc +67 -51
  151. data/src/core/lib/channel/handshaker_registry.h +21 -16
  152. data/src/core/lib/compression/algorithm_metadata.h +3 -3
  153. data/src/core/lib/compression/compression.cc +14 -9
  154. data/src/core/lib/compression/compression_args.cc +127 -0
  155. data/src/core/lib/compression/compression_args.h +55 -0
  156. data/src/core/lib/compression/compression_internal.cc +16 -12
  157. data/src/core/lib/compression/compression_internal.h +1 -1
  158. data/src/core/lib/compression/stream_compression.cc +3 -2
  159. data/src/core/lib/compression/stream_compression.h +2 -2
  160. data/src/core/lib/compression/stream_compression_gzip.cc +9 -9
  161. data/src/core/lib/debug/trace.cc +13 -7
  162. data/src/core/lib/debug/trace.h +14 -1
  163. data/src/core/lib/gpr/arena.h +13 -9
  164. data/src/core/lib/gpr/cpu_posix.cc +5 -3
  165. data/src/core/lib/gpr/env.h +3 -6
  166. data/src/core/lib/gpr/env_linux.cc +6 -1
  167. data/src/core/lib/gpr/env_posix.cc +5 -0
  168. data/src/core/lib/gpr/env_windows.cc +7 -5
  169. data/src/core/lib/gpr/log.cc +9 -13
  170. data/src/core/lib/gpr/log_posix.cc +2 -1
  171. data/src/core/lib/gpr/string.cc +20 -7
  172. data/src/core/lib/gpr/string.h +10 -3
  173. data/src/core/lib/gpr/sync_posix.cc +65 -4
  174. data/src/core/lib/gpr/time.cc +8 -0
  175. data/src/core/lib/gpr/time_posix.cc +21 -2
  176. data/src/core/lib/gprpp/arena.cc +103 -0
  177. data/src/core/lib/gprpp/arena.h +121 -0
  178. data/src/core/lib/gprpp/atomic.h +75 -5
  179. data/src/core/lib/gprpp/fork.cc +13 -32
  180. data/src/core/lib/gprpp/fork.h +5 -1
  181. data/src/core/lib/gprpp/global_config.h +96 -0
  182. data/src/core/lib/gprpp/global_config_custom.h +29 -0
  183. data/src/core/lib/gprpp/global_config_env.cc +135 -0
  184. data/src/core/lib/gprpp/global_config_env.h +131 -0
  185. data/src/core/lib/gprpp/global_config_generic.h +44 -0
  186. data/src/core/lib/gprpp/inlined_vector.h +8 -0
  187. data/src/core/lib/gprpp/map.h +436 -0
  188. data/src/core/lib/gprpp/memory.h +2 -2
  189. data/src/core/lib/gprpp/optional.h +48 -0
  190. data/src/core/lib/gprpp/orphanable.h +6 -5
  191. data/src/core/lib/gprpp/{mutex_lock.h → pair.h} +15 -19
  192. data/src/core/lib/gprpp/ref_counted.h +36 -17
  193. data/src/core/lib/gprpp/sync.h +126 -0
  194. data/src/core/lib/gprpp/thd.h +42 -7
  195. data/src/core/lib/gprpp/thd_posix.cc +31 -13
  196. data/src/core/lib/gprpp/thd_windows.cc +47 -34
  197. data/src/core/lib/http/httpcli.cc +6 -5
  198. data/src/core/lib/http/httpcli_security_connector.cc +13 -15
  199. data/src/core/lib/http/parser.cc +3 -2
  200. data/src/core/lib/http/parser.h +2 -1
  201. data/src/core/lib/iomgr/buffer_list.cc +182 -24
  202. data/src/core/lib/iomgr/buffer_list.h +72 -10
  203. data/src/core/lib/iomgr/call_combiner.cc +84 -90
  204. data/src/core/lib/iomgr/call_combiner.h +75 -82
  205. data/src/core/lib/iomgr/cfstream_handle.cc +203 -0
  206. data/src/core/lib/iomgr/cfstream_handle.h +86 -0
  207. data/src/core/lib/iomgr/combiner.cc +11 -3
  208. data/src/core/lib/iomgr/combiner.h +1 -1
  209. data/src/core/lib/iomgr/endpoint.cc +2 -2
  210. data/src/core/lib/iomgr/endpoint.h +3 -2
  211. data/src/core/lib/iomgr/endpoint_cfstream.cc +375 -0
  212. data/src/core/lib/iomgr/endpoint_cfstream.h +49 -0
  213. data/src/core/lib/iomgr/endpoint_pair_windows.cc +2 -2
  214. data/src/core/lib/iomgr/error.cc +21 -17
  215. data/src/core/lib/iomgr/error.h +36 -6
  216. data/src/core/lib/iomgr/error_cfstream.cc +52 -0
  217. data/src/core/lib/iomgr/error_cfstream.h +31 -0
  218. data/src/core/lib/iomgr/error_internal.h +1 -1
  219. data/src/core/lib/iomgr/ev_epoll1_linux.cc +44 -28
  220. data/src/core/lib/iomgr/ev_epollex_linux.cc +173 -194
  221. data/src/core/lib/iomgr/ev_poll_posix.cc +16 -487
  222. data/src/core/lib/iomgr/ev_posix.cc +29 -19
  223. data/src/core/lib/iomgr/ev_posix.h +19 -3
  224. data/src/core/lib/iomgr/ev_windows.cc +2 -2
  225. data/src/core/lib/iomgr/exec_ctx.cc +1 -0
  226. data/src/core/lib/iomgr/exec_ctx.h +137 -8
  227. data/src/core/lib/iomgr/executor.cc +147 -95
  228. data/src/core/lib/iomgr/executor.h +55 -49
  229. data/src/core/lib/iomgr/fork_posix.cc +6 -5
  230. data/src/core/lib/{gprpp/atomic_with_std.h → iomgr/grpc_if_nametoindex.h} +8 -13
  231. data/src/core/lib/iomgr/grpc_if_nametoindex_posix.cc +42 -0
  232. data/src/core/lib/iomgr/{network_status_tracker.h → grpc_if_nametoindex_unsupported.cc} +15 -9
  233. data/src/core/lib/iomgr/internal_errqueue.cc +3 -5
  234. data/src/core/lib/iomgr/internal_errqueue.h +105 -3
  235. data/src/core/lib/iomgr/iomgr.cc +20 -13
  236. data/src/core/lib/iomgr/iomgr.h +15 -0
  237. data/src/core/lib/iomgr/iomgr_custom.cc +17 -3
  238. data/src/core/lib/iomgr/iomgr_custom.h +2 -0
  239. data/src/core/lib/iomgr/iomgr_internal.cc +10 -0
  240. data/src/core/lib/iomgr/iomgr_internal.h +12 -0
  241. data/src/core/lib/iomgr/iomgr_posix.cc +19 -2
  242. data/src/core/lib/iomgr/iomgr_posix_cfstream.cc +93 -0
  243. data/src/core/lib/iomgr/iomgr_windows.cc +18 -2
  244. data/src/core/lib/iomgr/lockfree_event.cc +4 -4
  245. data/src/core/lib/iomgr/port.h +35 -0
  246. data/src/core/lib/iomgr/resolve_address_posix.cc +4 -3
  247. data/src/core/lib/iomgr/resolve_address_windows.cc +2 -1
  248. data/src/core/lib/iomgr/resource_quota.cc +40 -37
  249. data/src/core/lib/iomgr/socket_utils_common_posix.cc +6 -2
  250. data/src/core/lib/iomgr/socket_windows.cc +19 -0
  251. data/src/core/lib/iomgr/socket_windows.h +8 -0
  252. data/src/core/lib/iomgr/tcp_client_cfstream.cc +216 -0
  253. data/src/core/lib/iomgr/tcp_client_custom.cc +2 -2
  254. data/src/core/lib/iomgr/tcp_client_posix.cc +3 -3
  255. data/src/core/lib/iomgr/tcp_client_windows.cc +7 -5
  256. data/src/core/lib/iomgr/tcp_custom.cc +10 -14
  257. data/src/core/lib/iomgr/tcp_posix.cc +256 -140
  258. data/src/core/lib/iomgr/tcp_server.cc +5 -0
  259. data/src/core/lib/iomgr/tcp_server.h +24 -0
  260. data/src/core/lib/iomgr/tcp_server_custom.cc +14 -12
  261. data/src/core/lib/iomgr/tcp_server_posix.cc +86 -12
  262. data/src/core/lib/iomgr/tcp_server_utils_posix.h +3 -0
  263. data/src/core/lib/iomgr/tcp_server_windows.cc +13 -11
  264. data/src/core/lib/iomgr/tcp_uv.cc +5 -7
  265. data/src/core/lib/iomgr/tcp_windows.cc +8 -14
  266. data/src/core/lib/iomgr/timer.h +2 -1
  267. data/src/core/lib/iomgr/timer_generic.cc +16 -16
  268. data/src/core/lib/iomgr/timer_manager.cc +20 -11
  269. data/src/core/lib/iomgr/udp_server.cc +8 -6
  270. data/src/core/lib/iomgr/wakeup_fd_posix.cc +1 -19
  271. data/src/core/lib/json/json.cc +1 -4
  272. data/src/core/lib/profiling/basic_timers.cc +10 -4
  273. data/src/core/lib/security/context/security_context.cc +6 -7
  274. data/src/core/lib/security/context/security_context.h +3 -4
  275. data/src/core/lib/security/credentials/alts/alts_credentials.cc +1 -1
  276. data/src/core/lib/security/credentials/alts/check_gcp_environment_no_op.cc +2 -2
  277. data/src/core/lib/security/credentials/composite/composite_credentials.h +4 -0
  278. data/src/core/lib/security/credentials/credentials.h +9 -1
  279. data/src/core/lib/security/credentials/google_default/google_default_credentials.cc +15 -3
  280. data/src/core/lib/security/credentials/google_default/google_default_credentials.h +2 -0
  281. data/src/core/lib/security/credentials/jwt/json_token.cc +1 -1
  282. data/src/core/lib/security/credentials/jwt/jwt_credentials.cc +2 -1
  283. data/src/core/lib/security/credentials/jwt/jwt_verifier.cc +10 -6
  284. data/src/core/lib/security/credentials/jwt/jwt_verifier.h +2 -1
  285. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc +3 -3
  286. data/src/core/lib/security/credentials/plugin/plugin_credentials.cc +9 -8
  287. data/src/core/lib/security/credentials/ssl/ssl_credentials.cc +20 -2
  288. data/src/core/lib/security/credentials/ssl/ssl_credentials.h +2 -2
  289. data/src/core/lib/security/credentials/tls/grpc_tls_credentials_options.cc +192 -0
  290. data/src/core/lib/security/credentials/tls/grpc_tls_credentials_options.h +210 -0
  291. data/src/core/lib/security/credentials/tls/spiffe_credentials.cc +129 -0
  292. data/src/core/lib/security/credentials/tls/spiffe_credentials.h +62 -0
  293. data/src/core/lib/security/security_connector/alts/alts_security_connector.cc +10 -8
  294. data/src/core/lib/security/security_connector/fake/fake_security_connector.cc +13 -12
  295. data/src/core/lib/security/security_connector/load_system_roots_linux.cc +7 -5
  296. data/src/core/lib/security/security_connector/local/local_security_connector.cc +10 -8
  297. data/src/core/lib/security/security_connector/security_connector.cc +0 -1
  298. data/src/core/lib/security/security_connector/security_connector.h +3 -3
  299. data/src/core/lib/security/security_connector/ssl/ssl_security_connector.cc +39 -38
  300. data/src/core/lib/security/security_connector/ssl_utils.cc +164 -26
  301. data/src/core/lib/security/security_connector/ssl_utils.h +70 -1
  302. data/src/core/lib/security/security_connector/tls/spiffe_security_connector.cc +426 -0
  303. data/src/core/lib/security/security_connector/tls/spiffe_security_connector.h +122 -0
  304. data/src/core/lib/security/transport/auth_filters.h +5 -2
  305. data/src/core/lib/security/transport/client_auth_filter.cc +55 -50
  306. data/src/core/lib/security/transport/secure_endpoint.cc +6 -6
  307. data/src/core/lib/security/transport/security_handshaker.cc +271 -303
  308. data/src/core/lib/security/transport/security_handshaker.h +11 -2
  309. data/src/core/lib/security/transport/server_auth_filter.cc +3 -3
  310. data/src/core/lib/slice/b64.h +2 -2
  311. data/src/core/lib/slice/percent_encoding.cc +3 -3
  312. data/src/core/lib/slice/percent_encoding.h +3 -3
  313. data/src/core/lib/slice/slice.cc +174 -122
  314. data/src/core/lib/slice/slice_buffer.cc +54 -21
  315. data/src/core/lib/slice/slice_hash_table.h +4 -4
  316. data/src/core/lib/slice/slice_intern.cc +49 -107
  317. data/src/core/lib/slice/slice_internal.h +264 -3
  318. data/src/core/lib/slice/slice_string_helpers.cc +10 -1
  319. data/src/core/lib/slice/slice_string_helpers.h +3 -1
  320. data/src/core/lib/slice/slice_utils.h +50 -0
  321. data/src/core/lib/slice/slice_weak_hash_table.h +6 -6
  322. data/src/core/lib/surface/api_trace.h +1 -1
  323. data/src/core/lib/surface/byte_buffer_reader.cc +17 -0
  324. data/src/core/lib/surface/call.cc +67 -46
  325. data/src/core/lib/surface/call.h +7 -2
  326. data/src/core/lib/surface/call_details.cc +0 -1
  327. data/src/core/lib/surface/channel.cc +89 -97
  328. data/src/core/lib/surface/channel.h +60 -6
  329. data/src/core/lib/surface/channel_init.h +5 -0
  330. data/src/core/lib/surface/completion_queue.cc +221 -216
  331. data/src/core/lib/surface/completion_queue.h +2 -1
  332. data/src/core/lib/surface/init.cc +82 -33
  333. data/src/core/lib/surface/init.h +1 -0
  334. data/src/core/lib/surface/init_secure.cc +1 -1
  335. data/src/core/lib/surface/lame_client.cc +5 -7
  336. data/src/core/lib/surface/server.cc +42 -47
  337. data/src/core/lib/surface/validate_metadata.cc +14 -8
  338. data/src/core/lib/surface/validate_metadata.h +13 -2
  339. data/src/core/lib/surface/version.cc +1 -1
  340. data/src/core/lib/transport/bdp_estimator.cc +3 -3
  341. data/src/core/lib/transport/bdp_estimator.h +2 -2
  342. data/src/core/lib/transport/connectivity_state.cc +10 -40
  343. data/src/core/lib/transport/connectivity_state.h +0 -8
  344. data/src/core/lib/transport/error_utils.cc +12 -0
  345. data/src/core/lib/transport/metadata.cc +258 -267
  346. data/src/core/lib/transport/metadata.h +227 -16
  347. data/src/core/lib/transport/metadata_batch.cc +1 -1
  348. data/src/core/lib/transport/metadata_batch.h +1 -1
  349. data/src/core/lib/transport/static_metadata.cc +477 -399
  350. data/src/core/lib/transport/static_metadata.h +273 -182
  351. data/src/core/lib/transport/status_metadata.cc +3 -3
  352. data/src/core/lib/transport/timeout_encoding.cc +1 -1
  353. data/src/core/lib/transport/timeout_encoding.h +1 -1
  354. data/src/core/lib/transport/transport.cc +39 -72
  355. data/src/core/lib/transport/transport.h +59 -24
  356. data/src/core/lib/transport/transport_impl.h +1 -1
  357. data/src/core/tsi/alts/handshaker/alts_handshaker_client.cc +3 -3
  358. data/src/core/tsi/alts/handshaker/alts_handshaker_client.h +1 -1
  359. data/src/core/tsi/alts/handshaker/alts_shared_resource.h +1 -1
  360. data/src/core/tsi/alts/handshaker/transport_security_common_api.cc +4 -3
  361. data/src/core/tsi/alts/handshaker/transport_security_common_api.h +1 -1
  362. data/src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.cc +1 -1
  363. data/src/core/tsi/fake_transport_security.cc +4 -4
  364. data/src/core/tsi/ssl/session_cache/ssl_session_cache.cc +1 -1
  365. data/src/core/tsi/ssl_transport_security.cc +12 -10
  366. data/src/core/tsi/ssl_transport_security.h +24 -4
  367. data/src/ruby/bin/math_pb.rb +18 -16
  368. data/src/ruby/ext/grpc/extconf.rb +12 -4
  369. data/src/ruby/ext/grpc/rb_call_credentials.c +8 -5
  370. data/src/ruby/ext/grpc/rb_channel.c +14 -10
  371. data/src/ruby/ext/grpc/rb_channel_credentials.c +8 -4
  372. data/src/ruby/ext/grpc/rb_compression_options.c +9 -7
  373. data/src/ruby/ext/grpc/rb_event_thread.c +2 -0
  374. data/src/ruby/ext/grpc/rb_grpc.c +23 -24
  375. data/src/ruby/ext/grpc/rb_grpc.h +4 -2
  376. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +24 -0
  377. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +36 -0
  378. data/src/ruby/ext/grpc/rb_server.c +8 -4
  379. data/src/ruby/lib/grpc/errors.rb +22 -3
  380. data/src/ruby/lib/grpc/generic/bidi_call.rb +1 -1
  381. data/src/ruby/lib/grpc/generic/rpc_server.rb +2 -2
  382. data/src/ruby/lib/grpc/version.rb +1 -1
  383. data/src/ruby/pb/README.md +1 -1
  384. data/src/ruby/pb/grpc/health/v1/health_pb.rb +13 -10
  385. data/src/ruby/pb/grpc/health/v1/health_services_pb.rb +18 -0
  386. data/src/ruby/pb/src/proto/grpc/testing/empty_pb.rb +3 -1
  387. data/src/ruby/pb/src/proto/grpc/testing/messages_pb.rb +58 -56
  388. data/src/ruby/pb/src/proto/grpc/testing/test_pb.rb +2 -0
  389. data/src/ruby/spec/errors_spec.rb +141 -0
  390. data/third_party/cares/cares/ares.h +12 -0
  391. data/third_party/cares/cares/ares_create_query.c +5 -1
  392. data/third_party/cares/cares/ares_data.c +74 -73
  393. data/third_party/cares/cares/ares_destroy.c +6 -1
  394. data/third_party/cares/cares/ares_gethostbyaddr.c +5 -5
  395. data/third_party/cares/cares/ares_gethostbyname.c +15 -4
  396. data/third_party/cares/cares/ares_getnameinfo.c +11 -0
  397. data/third_party/cares/cares/ares_init.c +274 -173
  398. data/third_party/cares/cares/ares_library_init.c +21 -3
  399. data/third_party/cares/cares/ares_options.c +6 -2
  400. data/third_party/cares/cares/ares_parse_naptr_reply.c +7 -6
  401. data/third_party/cares/cares/ares_parse_ptr_reply.c +4 -2
  402. data/third_party/cares/cares/ares_platform.c +7 -0
  403. data/third_party/cares/cares/ares_private.h +19 -11
  404. data/third_party/cares/cares/ares_process.c +27 -2
  405. data/third_party/cares/cares/ares_rules.h +1 -1
  406. data/third_party/cares/cares/ares_search.c +7 -0
  407. data/third_party/cares/cares/ares_send.c +6 -0
  408. data/third_party/cares/cares/ares_strsplit.c +174 -0
  409. data/third_party/cares/cares/ares_strsplit.h +43 -0
  410. data/third_party/cares/cares/ares_version.h +4 -4
  411. data/third_party/cares/cares/config-win32.h +1 -1
  412. data/third_party/cares/cares/inet_ntop.c +2 -3
  413. data/third_party/cares/config_darwin/ares_config.h +3 -0
  414. data/third_party/cares/config_freebsd/ares_config.h +3 -0
  415. data/third_party/cares/config_linux/ares_config.h +3 -0
  416. data/third_party/cares/config_openbsd/ares_config.h +3 -0
  417. metadata +83 -48
  418. data/src/core/ext/filters/client_channel/request_routing.cc +0 -936
  419. data/src/core/ext/filters/client_channel/request_routing.h +0 -177
  420. data/src/core/ext/filters/client_channel/subchannel_index.cc +0 -248
  421. data/src/core/ext/filters/client_channel/subchannel_index.h +0 -76
  422. data/src/core/lib/channel/handshaker_factory.cc +0 -42
  423. data/src/core/lib/gpr/arena.cc +0 -192
  424. data/src/core/lib/gprpp/atomic_with_atm.h +0 -57
  425. data/src/core/lib/iomgr/wakeup_fd_cv.cc +0 -107
  426. data/src/core/lib/iomgr/wakeup_fd_cv.h +0 -69
  427. data/src/core/lib/transport/service_config.cc +0 -106
  428. data/src/core/lib/transport/service_config.h +0 -249
@@ -26,9 +26,8 @@
26
26
  #include "src/core/ext/filters/client_channel/lb_policy_registry.h"
27
27
  #include "src/core/ext/filters/client_channel/server_address.h"
28
28
  #include "src/core/ext/filters/client_channel/subchannel.h"
29
- #include "src/core/ext/filters/client_channel/subchannel_index.h"
30
29
  #include "src/core/lib/channel/channel_args.h"
31
- #include "src/core/lib/gprpp/mutex_lock.h"
30
+ #include "src/core/lib/gprpp/sync.h"
32
31
  #include "src/core/lib/iomgr/combiner.h"
33
32
  #include "src/core/lib/iomgr/sockaddr_utils.h"
34
33
  #include "src/core/lib/transport/connectivity_state.h"
@@ -47,26 +46,13 @@ constexpr char kPickFirst[] = "pick_first";
47
46
 
48
47
  class PickFirst : public LoadBalancingPolicy {
49
48
  public:
50
- explicit PickFirst(const Args& args);
49
+ explicit PickFirst(Args args);
51
50
 
52
51
  const char* name() const override { return kPickFirst; }
53
52
 
54
- void UpdateLocked(const grpc_channel_args& args,
55
- grpc_json* lb_config) override;
56
- bool PickLocked(PickState* pick, grpc_error** error) override;
57
- void CancelPickLocked(PickState* pick, grpc_error* error) override;
58
- void CancelMatchingPicksLocked(uint32_t initial_metadata_flags_mask,
59
- uint32_t initial_metadata_flags_eq,
60
- grpc_error* error) override;
61
- void NotifyOnStateChangeLocked(grpc_connectivity_state* state,
62
- grpc_closure* closure) override;
63
- grpc_connectivity_state CheckConnectivityLocked(
64
- grpc_error** connectivity_error) override;
65
- void HandOffPendingPicksLocked(LoadBalancingPolicy* new_policy) override;
53
+ void UpdateLocked(UpdateArgs args) override;
66
54
  void ExitIdleLocked() override;
67
55
  void ResetBackoffLocked() override;
68
- void FillChildRefsForChannelz(channelz::ChildRefsList* child_subchannels,
69
- channelz::ChildRefsList* ignored) override;
70
56
 
71
57
  private:
72
58
  ~PickFirst();
@@ -80,12 +66,12 @@ class PickFirst : public LoadBalancingPolicy {
80
66
  PickFirstSubchannelData(
81
67
  SubchannelList<PickFirstSubchannelList, PickFirstSubchannelData>*
82
68
  subchannel_list,
83
- const ServerAddress& address, grpc_subchannel* subchannel,
84
- grpc_combiner* combiner)
85
- : SubchannelData(subchannel_list, address, subchannel, combiner) {}
69
+ const ServerAddress& address,
70
+ RefCountedPtr<SubchannelInterface> subchannel)
71
+ : SubchannelData(subchannel_list, address, std::move(subchannel)) {}
86
72
 
87
73
  void ProcessConnectivityChangeLocked(
88
- grpc_connectivity_state connectivity_state, grpc_error* error) override;
74
+ grpc_connectivity_state connectivity_state) override;
89
75
 
90
76
  // Processes the connectivity change to READY for an unselected subchannel.
91
77
  void ProcessUnselectedReadyLocked();
@@ -100,10 +86,9 @@ class PickFirst : public LoadBalancingPolicy {
100
86
  PickFirstSubchannelList(PickFirst* policy, TraceFlag* tracer,
101
87
  const ServerAddressList& addresses,
102
88
  grpc_combiner* combiner,
103
- grpc_client_channel_factory* client_channel_factory,
104
89
  const grpc_channel_args& args)
105
90
  : SubchannelList(policy, tracer, addresses, combiner,
106
- client_channel_factory, args) {
91
+ policy->channel_control_helper(), args) {
107
92
  // Need to maintain a ref to the LB policy as long as we maintain
108
93
  // any references to subchannels, since the subchannels'
109
94
  // pollset_sets will include the LB policy's pollset_set.
@@ -114,155 +99,86 @@ class PickFirst : public LoadBalancingPolicy {
114
99
  PickFirst* p = static_cast<PickFirst*>(policy());
115
100
  p->Unref(DEBUG_LOCATION, "subchannel_list");
116
101
  }
102
+
103
+ bool in_transient_failure() const { return in_transient_failure_; }
104
+ void set_in_transient_failure(bool in_transient_failure) {
105
+ in_transient_failure_ = in_transient_failure;
106
+ }
107
+
108
+ private:
109
+ bool in_transient_failure_ = false;
117
110
  };
118
111
 
119
- // Helper class to ensure that any function that modifies the child refs
120
- // data structures will update the channelz snapshot data structures before
121
- // returning.
122
- class AutoChildRefsUpdater {
112
+ class Picker : public SubchannelPicker {
123
113
  public:
124
- explicit AutoChildRefsUpdater(PickFirst* pf) : pf_(pf) {}
125
- ~AutoChildRefsUpdater() { pf_->UpdateChildRefsLocked(); }
114
+ explicit Picker(
115
+ RefCountedPtr<ConnectedSubchannelInterface> connected_subchannel)
116
+ : connected_subchannel_(std::move(connected_subchannel)) {}
117
+
118
+ PickResult Pick(PickArgs args) override {
119
+ PickResult result;
120
+ result.type = PickResult::PICK_COMPLETE;
121
+ result.connected_subchannel = connected_subchannel_;
122
+ return result;
123
+ }
126
124
 
127
125
  private:
128
- PickFirst* pf_;
126
+ RefCountedPtr<ConnectedSubchannelInterface> connected_subchannel_;
129
127
  };
130
128
 
131
129
  void ShutdownLocked() override;
132
130
 
133
- void StartPickingLocked();
134
- void UpdateChildRefsLocked();
135
-
136
131
  // All our subchannels.
137
132
  OrphanablePtr<PickFirstSubchannelList> subchannel_list_;
138
133
  // Latest pending subchannel list.
139
134
  OrphanablePtr<PickFirstSubchannelList> latest_pending_subchannel_list_;
140
135
  // Selected subchannel in \a subchannel_list_.
141
136
  PickFirstSubchannelData* selected_ = nullptr;
142
- // Have we started picking?
143
- bool started_picking_ = false;
137
+ // Are we in IDLE state?
138
+ bool idle_ = false;
144
139
  // Are we shut down?
145
140
  bool shutdown_ = false;
146
- // List of picks that are waiting on connectivity.
147
- PickState* pending_picks_ = nullptr;
148
- // Our connectivity state tracker.
149
- grpc_connectivity_state_tracker state_tracker_;
150
-
151
- /// Lock and data used to capture snapshots of this channels child
152
- /// channels and subchannels. This data is consumed by channelz.
153
- gpr_mu child_refs_mu_;
154
- channelz::ChildRefsList child_subchannels_;
155
- channelz::ChildRefsList child_channels_;
156
141
  };
157
142
 
158
- PickFirst::PickFirst(const Args& args) : LoadBalancingPolicy(args) {
159
- GPR_ASSERT(args.client_channel_factory != nullptr);
160
- gpr_mu_init(&child_refs_mu_);
161
- grpc_connectivity_state_init(&state_tracker_, GRPC_CHANNEL_IDLE,
162
- "pick_first");
163
- if (grpc_lb_pick_first_trace.enabled()) {
143
+ PickFirst::PickFirst(Args args) : LoadBalancingPolicy(std::move(args)) {
144
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_pick_first_trace)) {
164
145
  gpr_log(GPR_INFO, "Pick First %p created.", this);
165
146
  }
166
- UpdateLocked(*args.args, args.lb_config);
167
- grpc_subchannel_index_ref();
168
147
  }
169
148
 
170
149
  PickFirst::~PickFirst() {
171
- if (grpc_lb_pick_first_trace.enabled()) {
150
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_pick_first_trace)) {
172
151
  gpr_log(GPR_INFO, "Destroying Pick First %p", this);
173
152
  }
174
- gpr_mu_destroy(&child_refs_mu_);
175
153
  GPR_ASSERT(subchannel_list_ == nullptr);
176
154
  GPR_ASSERT(latest_pending_subchannel_list_ == nullptr);
177
- GPR_ASSERT(pending_picks_ == nullptr);
178
- grpc_connectivity_state_destroy(&state_tracker_);
179
- grpc_subchannel_index_unref();
180
- }
181
-
182
- void PickFirst::HandOffPendingPicksLocked(LoadBalancingPolicy* new_policy) {
183
- PickState* pick;
184
- while ((pick = pending_picks_) != nullptr) {
185
- pending_picks_ = pick->next;
186
- grpc_error* error = GRPC_ERROR_NONE;
187
- if (new_policy->PickLocked(pick, &error)) {
188
- // Synchronous return, schedule closure.
189
- GRPC_CLOSURE_SCHED(pick->on_complete, error);
190
- }
191
- }
192
155
  }
193
156
 
194
157
  void PickFirst::ShutdownLocked() {
195
- AutoChildRefsUpdater guard(this);
196
- grpc_error* error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("Channel shutdown");
197
- if (grpc_lb_pick_first_trace.enabled()) {
158
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_pick_first_trace)) {
198
159
  gpr_log(GPR_INFO, "Pick First %p Shutting down", this);
199
160
  }
200
161
  shutdown_ = true;
201
- PickState* pick;
202
- while ((pick = pending_picks_) != nullptr) {
203
- pending_picks_ = pick->next;
204
- pick->connected_subchannel.reset();
205
- GRPC_CLOSURE_SCHED(pick->on_complete, GRPC_ERROR_REF(error));
206
- }
207
- grpc_connectivity_state_set(&state_tracker_, GRPC_CHANNEL_SHUTDOWN,
208
- GRPC_ERROR_REF(error), "shutdown");
209
162
  subchannel_list_.reset();
210
163
  latest_pending_subchannel_list_.reset();
211
- TryReresolutionLocked(&grpc_lb_pick_first_trace, GRPC_ERROR_CANCELLED);
212
- GRPC_ERROR_UNREF(error);
213
- }
214
-
215
- void PickFirst::CancelPickLocked(PickState* pick, grpc_error* error) {
216
- PickState* pp = pending_picks_;
217
- pending_picks_ = nullptr;
218
- while (pp != nullptr) {
219
- PickState* next = pp->next;
220
- if (pp == pick) {
221
- pick->connected_subchannel.reset();
222
- GRPC_CLOSURE_SCHED(pick->on_complete,
223
- GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING(
224
- "Pick Cancelled", &error, 1));
225
- } else {
226
- pp->next = pending_picks_;
227
- pending_picks_ = pp;
228
- }
229
- pp = next;
230
- }
231
- GRPC_ERROR_UNREF(error);
232
164
  }
233
165
 
234
- void PickFirst::CancelMatchingPicksLocked(uint32_t initial_metadata_flags_mask,
235
- uint32_t initial_metadata_flags_eq,
236
- grpc_error* error) {
237
- PickState* pick = pending_picks_;
238
- pending_picks_ = nullptr;
239
- while (pick != nullptr) {
240
- PickState* next = pick->next;
241
- if ((*pick->initial_metadata_flags & initial_metadata_flags_mask) ==
242
- initial_metadata_flags_eq) {
243
- GRPC_CLOSURE_SCHED(pick->on_complete,
244
- GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING(
245
- "Pick Cancelled", &error, 1));
166
+ void PickFirst::ExitIdleLocked() {
167
+ if (shutdown_) return;
168
+ 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)));
246
178
  } else {
247
- pick->next = pending_picks_;
248
- pending_picks_ = pick;
179
+ subchannel_list_->subchannel(0)
180
+ ->CheckConnectivityStateAndStartWatchingLocked();
249
181
  }
250
- pick = next;
251
- }
252
- GRPC_ERROR_UNREF(error);
253
- }
254
-
255
- void PickFirst::StartPickingLocked() {
256
- started_picking_ = true;
257
- if (subchannel_list_ != nullptr && subchannel_list_->num_subchannels() > 0) {
258
- subchannel_list_->subchannel(0)
259
- ->CheckConnectivityStateAndStartWatchingLocked();
260
- }
261
- }
262
-
263
- void PickFirst::ExitIdleLocked() {
264
- if (!started_picking_) {
265
- StartPickingLocked();
266
182
  }
267
183
  }
268
184
 
@@ -273,128 +189,52 @@ void PickFirst::ResetBackoffLocked() {
273
189
  }
274
190
  }
275
191
 
276
- bool PickFirst::PickLocked(PickState* pick, grpc_error** error) {
277
- // If we have a selected subchannel already, return synchronously.
278
- if (selected_ != nullptr) {
279
- pick->connected_subchannel = selected_->connected_subchannel()->Ref();
280
- return true;
281
- }
282
- // No subchannel selected yet, so handle asynchronously.
283
- if (pick->on_complete == nullptr) {
284
- *error = GRPC_ERROR_CREATE_FROM_STATIC_STRING(
285
- "No pick result available but synchronous result required.");
286
- return true;
287
- }
288
- pick->next = pending_picks_;
289
- pending_picks_ = pick;
290
- if (!started_picking_) {
291
- StartPickingLocked();
292
- }
293
- return false;
294
- }
295
-
296
- grpc_connectivity_state PickFirst::CheckConnectivityLocked(grpc_error** error) {
297
- return grpc_connectivity_state_get(&state_tracker_, error);
298
- }
299
-
300
- void PickFirst::NotifyOnStateChangeLocked(grpc_connectivity_state* current,
301
- grpc_closure* notify) {
302
- grpc_connectivity_state_notify_on_state_change(&state_tracker_, current,
303
- notify);
304
- }
305
-
306
- void PickFirst::FillChildRefsForChannelz(
307
- channelz::ChildRefsList* child_subchannels_to_fill,
308
- channelz::ChildRefsList* ignored) {
309
- MutexLock lock(&child_refs_mu_);
310
- for (size_t i = 0; i < child_subchannels_.size(); ++i) {
311
- // TODO(ncteisen): implement a de dup loop that is not O(n^2). Might
312
- // have to implement lightweight set. For now, we don't care about
313
- // performance when channelz requests are made.
314
- bool found = false;
315
- for (size_t j = 0; j < child_subchannels_to_fill->size(); ++j) {
316
- if ((*child_subchannels_to_fill)[j] == child_subchannels_[i]) {
317
- found = true;
318
- break;
319
- }
320
- }
321
- if (!found) {
322
- child_subchannels_to_fill->push_back(child_subchannels_[i]);
323
- }
324
- }
325
- }
326
-
327
- void PickFirst::UpdateChildRefsLocked() {
328
- channelz::ChildRefsList cs;
329
- if (subchannel_list_ != nullptr) {
330
- subchannel_list_->PopulateChildRefsList(&cs);
331
- }
332
- if (latest_pending_subchannel_list_ != nullptr) {
333
- latest_pending_subchannel_list_->PopulateChildRefsList(&cs);
334
- }
335
- // atomically update the data that channelz will actually be looking at.
336
- MutexLock lock(&child_refs_mu_);
337
- child_subchannels_ = std::move(cs);
338
- }
339
-
340
- void PickFirst::UpdateLocked(const grpc_channel_args& args,
341
- grpc_json* lb_config) {
342
- AutoChildRefsUpdater guard(this);
343
- const ServerAddressList* addresses = FindServerAddressListChannelArg(&args);
344
- if (addresses == nullptr) {
345
- if (subchannel_list_ == nullptr) {
346
- // If we don't have a current subchannel list, go into TRANSIENT FAILURE.
347
- grpc_connectivity_state_set(
348
- &state_tracker_, GRPC_CHANNEL_TRANSIENT_FAILURE,
349
- GRPC_ERROR_CREATE_FROM_STATIC_STRING("Missing update in args"),
350
- "pf_update_missing");
351
- } else {
352
- // otherwise, keep using the current subchannel list (ignore this update).
353
- gpr_log(GPR_ERROR,
354
- "No valid LB addresses channel arg for Pick First %p update, "
355
- "ignoring.",
356
- this);
357
- }
358
- return;
359
- }
360
- if (grpc_lb_pick_first_trace.enabled()) {
192
+ void PickFirst::UpdateLocked(UpdateArgs args) {
193
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_pick_first_trace)) {
361
194
  gpr_log(GPR_INFO,
362
195
  "Pick First %p received update with %" PRIuPTR " addresses", this,
363
- addresses->size());
196
+ args.addresses.size());
364
197
  }
365
198
  grpc_arg new_arg = grpc_channel_arg_integer_create(
366
199
  const_cast<char*>(GRPC_ARG_INHIBIT_HEALTH_CHECKING), 1);
367
200
  grpc_channel_args* new_args =
368
- grpc_channel_args_copy_and_add(&args, &new_arg, 1);
201
+ grpc_channel_args_copy_and_add(args.args, &new_arg, 1);
369
202
  auto subchannel_list = MakeOrphanable<PickFirstSubchannelList>(
370
- this, &grpc_lb_pick_first_trace, *addresses, combiner(),
371
- client_channel_factory(), *new_args);
203
+ this, &grpc_lb_pick_first_trace, args.addresses, combiner(), *new_args);
372
204
  grpc_channel_args_destroy(new_args);
373
205
  if (subchannel_list->num_subchannels() == 0) {
374
206
  // Empty update or no valid subchannels. Unsubscribe from all current
375
- // subchannels and put the channel in TRANSIENT_FAILURE.
376
- grpc_connectivity_state_set(
377
- &state_tracker_, GRPC_CHANNEL_TRANSIENT_FAILURE,
378
- GRPC_ERROR_CREATE_FROM_STATIC_STRING("Empty update"),
379
- "pf_update_empty");
207
+ // subchannels.
380
208
  subchannel_list_ = std::move(subchannel_list); // Empty list.
381
209
  selected_ = nullptr;
210
+ // If not idle, put the channel in TRANSIENT_FAILURE.
211
+ // (If we are idle, then this will happen in ExitIdleLocked() if we
212
+ // haven't gotten a non-empty update by the time the application tries
213
+ // 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
+ }
382
222
  return;
383
223
  }
384
224
  // If one of the subchannels in the new list is already in state
385
225
  // READY, then select it immediately. This can happen when the
386
226
  // currently selected subchannel is also present in the update. It
387
227
  // can also happen if one of the subchannels in the update is already
388
- // in the subchannel index because it's in use by another channel.
228
+ // 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().
389
231
  for (size_t i = 0; i < subchannel_list->num_subchannels(); ++i) {
390
232
  PickFirstSubchannelData* sd = subchannel_list->subchannel(i);
391
- grpc_error* error = GRPC_ERROR_NONE;
392
- grpc_connectivity_state state = sd->CheckConnectivityStateLocked(&error);
393
- GRPC_ERROR_UNREF(error);
233
+ grpc_connectivity_state state = sd->CheckConnectivityStateLocked();
394
234
  if (state == GRPC_CHANNEL_READY) {
395
235
  subchannel_list_ = std::move(subchannel_list);
396
- sd->ProcessUnselectedReadyLocked();
397
236
  sd->StartConnectivityWatchLocked();
237
+ sd->ProcessUnselectedReadyLocked();
398
238
  // If there was a previously pending update (which may or may
399
239
  // not have contained the currently selected subchannel), drop
400
240
  // it, so that it doesn't override what we've done here.
@@ -402,7 +242,7 @@ void PickFirst::UpdateLocked(const grpc_channel_args& args,
402
242
  // Make sure that subsequent calls to ExitIdleLocked() don't cause
403
243
  // us to start watching a subchannel other than the one we've
404
244
  // selected.
405
- started_picking_ = true;
245
+ idle_ = false;
406
246
  return;
407
247
  }
408
248
  }
@@ -410,19 +250,20 @@ void PickFirst::UpdateLocked(const grpc_channel_args& args,
410
250
  // We don't yet have a selected subchannel, so replace the current
411
251
  // subchannel list immediately.
412
252
  subchannel_list_ = std::move(subchannel_list);
413
- // If we've started picking, start trying to connect to the first
253
+ // If we're not in IDLE state, start trying to connect to the first
414
254
  // subchannel in the new list.
415
- if (started_picking_) {
255
+ if (!idle_) {
416
256
  // Note: No need to use CheckConnectivityStateAndStartWatchingLocked()
417
257
  // here, since we've already checked the initial connectivity
418
258
  // state of all subchannels above.
419
259
  subchannel_list_->subchannel(0)->StartConnectivityWatchLocked();
260
+ subchannel_list_->subchannel(0)->subchannel()->AttemptToConnect();
420
261
  }
421
262
  } else {
422
- // We do have a selected subchannel, so keep using it until one of
423
- // the subchannels in the new list reports READY.
263
+ // We do have a selected subchannel (which means it's READY), so keep
264
+ // using it until one of the subchannels in the new list reports READY.
424
265
  if (latest_pending_subchannel_list_ != nullptr) {
425
- if (grpc_lb_pick_first_trace.enabled()) {
266
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_pick_first_trace)) {
426
267
  gpr_log(GPR_INFO,
427
268
  "Pick First %p Shutting down latest pending subchannel list "
428
269
  "%p, about to be replaced by newer latest %p",
@@ -431,22 +272,24 @@ void PickFirst::UpdateLocked(const grpc_channel_args& args,
431
272
  }
432
273
  }
433
274
  latest_pending_subchannel_list_ = std::move(subchannel_list);
434
- // If we've started picking, start trying to connect to the first
275
+ // If we're not in IDLE state, start trying to connect to the first
435
276
  // subchannel in the new list.
436
- if (started_picking_) {
277
+ if (!idle_) {
437
278
  // Note: No need to use CheckConnectivityStateAndStartWatchingLocked()
438
279
  // here, since we've already checked the initial connectivity
439
280
  // state of all subchannels above.
440
281
  latest_pending_subchannel_list_->subchannel(0)
441
282
  ->StartConnectivityWatchLocked();
283
+ latest_pending_subchannel_list_->subchannel(0)
284
+ ->subchannel()
285
+ ->AttemptToConnect();
442
286
  }
443
287
  }
444
288
  }
445
289
 
446
290
  void PickFirst::PickFirstSubchannelData::ProcessConnectivityChangeLocked(
447
- grpc_connectivity_state connectivity_state, grpc_error* error) {
291
+ grpc_connectivity_state connectivity_state) {
448
292
  PickFirst* p = static_cast<PickFirst*>(subchannel_list()->policy());
449
- AutoChildRefsUpdater guard(p);
450
293
  // The notification must be for a subchannel in either the current or
451
294
  // latest pending subchannel lists.
452
295
  GPR_ASSERT(subchannel_list() == p->subchannel_list_.get() ||
@@ -454,15 +297,16 @@ void PickFirst::PickFirstSubchannelData::ProcessConnectivityChangeLocked(
454
297
  GPR_ASSERT(connectivity_state != GRPC_CHANNEL_SHUTDOWN);
455
298
  // Handle updates for the currently selected subchannel.
456
299
  if (p->selected_ == this) {
457
- if (grpc_lb_pick_first_trace.enabled()) {
300
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_pick_first_trace)) {
458
301
  gpr_log(GPR_INFO,
459
- "Pick First %p connectivity changed for selected subchannel", p);
302
+ "Pick First %p selected subchannel connectivity changed to %s", p,
303
+ grpc_connectivity_state_name(connectivity_state));
460
304
  }
461
305
  // If the new state is anything other than READY and there is a
462
306
  // pending update, switch to the pending update.
463
307
  if (connectivity_state != GRPC_CHANNEL_READY &&
464
308
  p->latest_pending_subchannel_list_ != nullptr) {
465
- if (grpc_lb_pick_first_trace.enabled()) {
309
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_pick_first_trace)) {
466
310
  gpr_log(GPR_INFO,
467
311
  "Pick First %p promoting pending subchannel list %p to "
468
312
  "replace %p",
@@ -470,39 +314,52 @@ void PickFirst::PickFirstSubchannelData::ProcessConnectivityChangeLocked(
470
314
  p->subchannel_list_.get());
471
315
  }
472
316
  p->selected_ = nullptr;
473
- StopConnectivityWatchLocked();
317
+ CancelConnectivityWatchLocked(
318
+ "selected subchannel failed; switching to pending update");
474
319
  p->subchannel_list_ = std::move(p->latest_pending_subchannel_list_);
475
- grpc_connectivity_state_set(
476
- &p->state_tracker_, GRPC_CHANNEL_TRANSIENT_FAILURE,
477
- error != GRPC_ERROR_NONE
478
- ? GRPC_ERROR_REF(error)
479
- : GRPC_ERROR_CREATE_FROM_STATIC_STRING(
480
- "selected subchannel not ready; switching to pending "
481
- "update"),
482
- "selected_not_ready+switch_to_update");
320
+ // Set our state to that of the pending subchannel list.
321
+ if (p->subchannel_list_->in_transient_failure()) {
322
+ grpc_error* error = grpc_error_set_int(
323
+ GRPC_ERROR_CREATE_FROM_STATIC_STRING(
324
+ "selected subchannel failed; switching to pending update"),
325
+ GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_UNAVAILABLE);
326
+ p->channel_control_helper()->UpdateState(
327
+ GRPC_CHANNEL_TRANSIENT_FAILURE,
328
+ UniquePtr<SubchannelPicker>(New<TransientFailurePicker>(error)));
329
+ } else {
330
+ p->channel_control_helper()->UpdateState(
331
+ GRPC_CHANNEL_CONNECTING,
332
+ UniquePtr<SubchannelPicker>(
333
+ New<QueuePicker>(p->Ref(DEBUG_LOCATION, "QueuePicker"))));
334
+ }
483
335
  } else {
484
336
  if (connectivity_state == GRPC_CHANNEL_TRANSIENT_FAILURE) {
485
- // If the selected subchannel goes bad, request a re-resolution. We also
486
- // set the channel state to IDLE and reset started_picking_. The reason
487
- // is that if the new state is TRANSIENT_FAILURE due to a GOAWAY
488
- // reception we don't want to connect to the re-resolved backends until
489
- // we leave the IDLE state.
490
- grpc_connectivity_state_set(&p->state_tracker_, GRPC_CHANNEL_IDLE,
491
- GRPC_ERROR_NONE,
492
- "selected_changed+reresolve");
493
- p->started_picking_ = false;
494
- p->TryReresolutionLocked(&grpc_lb_pick_first_trace, GRPC_ERROR_NONE);
495
- // In transient failure. Rely on re-resolution to recover.
337
+ // If the selected subchannel goes bad, request a re-resolution. We
338
+ // also set the channel state to IDLE. The reason is that if the new
339
+ // state is TRANSIENT_FAILURE due to a GOAWAY reception we don't want
340
+ // to connect to the re-resolved backends until we leave IDLE state.
341
+ p->idle_ = true;
342
+ p->channel_control_helper()->RequestReresolution();
496
343
  p->selected_ = nullptr;
497
- StopConnectivityWatchLocked();
344
+ CancelConnectivityWatchLocked("selected subchannel failed; going IDLE");
345
+ p->channel_control_helper()->UpdateState(
346
+ GRPC_CHANNEL_IDLE, UniquePtr<SubchannelPicker>(New<QueuePicker>(
347
+ p->Ref(DEBUG_LOCATION, "QueuePicker"))));
498
348
  } else {
499
- grpc_connectivity_state_set(&p->state_tracker_, connectivity_state,
500
- GRPC_ERROR_REF(error), "selected_changed");
501
- // Renew notification.
502
- RenewConnectivityWatchLocked();
349
+ // This is unlikely but can happen when a subchannel has been asked
350
+ // to reconnect by a different channel and this channel has dropped
351
+ // some connectivity state notifications.
352
+ if (connectivity_state == GRPC_CHANNEL_READY) {
353
+ p->channel_control_helper()->UpdateState(
354
+ GRPC_CHANNEL_READY, UniquePtr<SubchannelPicker>(New<Picker>(
355
+ connected_subchannel()->Ref())));
356
+ } else { // CONNECTING
357
+ p->channel_control_helper()->UpdateState(
358
+ connectivity_state, UniquePtr<SubchannelPicker>(New<QueuePicker>(
359
+ p->Ref(DEBUG_LOCATION, "QueuePicker"))));
360
+ }
503
361
  }
504
362
  }
505
- GRPC_ERROR_UNREF(error);
506
363
  return;
507
364
  }
508
365
  // If we get here, there are two possible cases:
@@ -514,26 +371,37 @@ void PickFirst::PickFirstSubchannelData::ProcessConnectivityChangeLocked(
514
371
  // for a subchannel in p->latest_pending_subchannel_list_. The
515
372
  // goal here is to find a subchannel from the update that we can
516
373
  // select in place of the current one.
374
+ subchannel_list()->set_in_transient_failure(false);
517
375
  switch (connectivity_state) {
518
376
  case GRPC_CHANNEL_READY: {
519
377
  ProcessUnselectedReadyLocked();
520
- // Renew notification.
521
- RenewConnectivityWatchLocked();
522
378
  break;
523
379
  }
524
380
  case GRPC_CHANNEL_TRANSIENT_FAILURE: {
525
- StopConnectivityWatchLocked();
381
+ CancelConnectivityWatchLocked("connection attempt failed");
526
382
  PickFirstSubchannelData* sd = this;
527
383
  size_t next_index =
528
384
  (sd->Index() + 1) % subchannel_list()->num_subchannels();
529
385
  sd = subchannel_list()->subchannel(next_index);
530
- // Case 1: Only set state to TRANSIENT_FAILURE if we've tried
531
- // all subchannels.
532
- if (sd->Index() == 0 && subchannel_list() == p->subchannel_list_.get()) {
533
- p->TryReresolutionLocked(&grpc_lb_pick_first_trace, GRPC_ERROR_NONE);
534
- grpc_connectivity_state_set(
535
- &p->state_tracker_, GRPC_CHANNEL_TRANSIENT_FAILURE,
536
- GRPC_ERROR_REF(error), "exhausted_subchannels");
386
+ // If we're tried all subchannels, set state to TRANSIENT_FAILURE.
387
+ if (sd->Index() == 0) {
388
+ // Re-resolve if this is the most recent subchannel list.
389
+ if (subchannel_list() == (p->latest_pending_subchannel_list_ != nullptr
390
+ ? p->latest_pending_subchannel_list_.get()
391
+ : p->subchannel_list_.get())) {
392
+ p->channel_control_helper()->RequestReresolution();
393
+ }
394
+ subchannel_list()->set_in_transient_failure(true);
395
+ // Only report new state in case 1.
396
+ if (subchannel_list() == p->subchannel_list_.get()) {
397
+ grpc_error* error = grpc_error_set_int(
398
+ GRPC_ERROR_CREATE_FROM_STATIC_STRING(
399
+ "failed to connect to all addresses"),
400
+ GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_UNAVAILABLE);
401
+ p->channel_control_helper()->UpdateState(
402
+ GRPC_CHANNEL_TRANSIENT_FAILURE,
403
+ UniquePtr<SubchannelPicker>(New<TransientFailurePicker>(error)));
404
+ }
537
405
  }
538
406
  sd->CheckConnectivityStateAndStartWatchingLocked();
539
407
  break;
@@ -542,18 +410,16 @@ void PickFirst::PickFirstSubchannelData::ProcessConnectivityChangeLocked(
542
410
  case GRPC_CHANNEL_IDLE: {
543
411
  // Only update connectivity state in case 1.
544
412
  if (subchannel_list() == p->subchannel_list_.get()) {
545
- grpc_connectivity_state_set(&p->state_tracker_, GRPC_CHANNEL_CONNECTING,
546
- GRPC_ERROR_REF(error),
547
- "connecting_changed");
413
+ p->channel_control_helper()->UpdateState(
414
+ GRPC_CHANNEL_CONNECTING,
415
+ UniquePtr<SubchannelPicker>(
416
+ New<QueuePicker>(p->Ref(DEBUG_LOCATION, "QueuePicker"))));
548
417
  }
549
- // Renew notification.
550
- RenewConnectivityWatchLocked();
551
418
  break;
552
419
  }
553
420
  case GRPC_CHANNEL_SHUTDOWN:
554
421
  GPR_UNREACHABLE_CODE(break);
555
422
  }
556
- GRPC_ERROR_UNREF(error);
557
423
  }
558
424
 
559
425
  void PickFirst::PickFirstSubchannelData::ProcessUnselectedReadyLocked() {
@@ -571,7 +437,7 @@ void PickFirst::PickFirstSubchannelData::ProcessUnselectedReadyLocked() {
571
437
  subchannel_list() == p->latest_pending_subchannel_list_.get());
572
438
  // Case 2. Promote p->latest_pending_subchannel_list_ to p->subchannel_list_.
573
439
  if (subchannel_list() == p->latest_pending_subchannel_list_.get()) {
574
- if (grpc_lb_pick_first_trace.enabled()) {
440
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_pick_first_trace)) {
575
441
  gpr_log(GPR_INFO,
576
442
  "Pick First %p promoting pending subchannel list %p to "
577
443
  "replace %p",
@@ -581,40 +447,38 @@ void PickFirst::PickFirstSubchannelData::ProcessUnselectedReadyLocked() {
581
447
  p->subchannel_list_ = std::move(p->latest_pending_subchannel_list_);
582
448
  }
583
449
  // Cases 1 and 2.
584
- grpc_connectivity_state_set(&p->state_tracker_, GRPC_CHANNEL_READY,
585
- GRPC_ERROR_NONE, "subchannel_ready");
586
450
  p->selected_ = this;
587
- if (grpc_lb_pick_first_trace.enabled()) {
451
+ p->channel_control_helper()->UpdateState(
452
+ GRPC_CHANNEL_READY,
453
+ UniquePtr<SubchannelPicker>(New<Picker>(connected_subchannel()->Ref())));
454
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_pick_first_trace)) {
588
455
  gpr_log(GPR_INFO, "Pick First %p selected subchannel %p", p, subchannel());
589
456
  }
590
- // Update any calls that were waiting for a pick.
591
- PickState* pick;
592
- while ((pick = p->pending_picks_)) {
593
- p->pending_picks_ = pick->next;
594
- pick->connected_subchannel = p->selected_->connected_subchannel()->Ref();
595
- if (grpc_lb_pick_first_trace.enabled()) {
596
- gpr_log(GPR_INFO, "Servicing pending pick with selected subchannel %p",
597
- p->selected_->subchannel());
598
- }
599
- GRPC_CLOSURE_SCHED(pick->on_complete, GRPC_ERROR_NONE);
600
- }
601
457
  }
602
458
 
603
459
  void PickFirst::PickFirstSubchannelData::
604
460
  CheckConnectivityStateAndStartWatchingLocked() {
605
461
  PickFirst* p = static_cast<PickFirst*>(subchannel_list()->policy());
606
- grpc_error* error = GRPC_ERROR_NONE;
607
- if (p->selected_ != this &&
608
- CheckConnectivityStateLocked(&error) == GRPC_CHANNEL_READY) {
609
- // We must process the READY subchannel before we start watching it.
610
- // Otherwise, we won't know it's READY because we will be waiting for its
611
- // connectivity state to change from READY.
612
- ProcessUnselectedReadyLocked();
613
- }
614
- GRPC_ERROR_UNREF(error);
462
+ // Check current state.
463
+ grpc_connectivity_state current_state = CheckConnectivityStateLocked();
464
+ // Start watch.
615
465
  StartConnectivityWatchLocked();
466
+ // If current state is READY, select the subchannel now, since we started
467
+ // watching from this state and will not get a notification of it
468
+ // transitioning into this state.
469
+ // If the current state is not READY, attempt to connect.
470
+ if (current_state == GRPC_CHANNEL_READY) {
471
+ if (p->selected_ != this) ProcessUnselectedReadyLocked();
472
+ } else {
473
+ subchannel()->AttemptToConnect();
474
+ }
616
475
  }
617
476
 
477
+ class ParsedPickFirstConfig : public LoadBalancingPolicy::Config {
478
+ public:
479
+ const char* name() const override { return kPickFirst; }
480
+ };
481
+
618
482
  //
619
483
  // factory
620
484
  //
@@ -622,11 +486,20 @@ void PickFirst::PickFirstSubchannelData::
622
486
  class PickFirstFactory : public LoadBalancingPolicyFactory {
623
487
  public:
624
488
  OrphanablePtr<LoadBalancingPolicy> CreateLoadBalancingPolicy(
625
- const LoadBalancingPolicy::Args& args) const override {
626
- return OrphanablePtr<LoadBalancingPolicy>(New<PickFirst>(args));
489
+ LoadBalancingPolicy::Args args) const override {
490
+ return OrphanablePtr<LoadBalancingPolicy>(New<PickFirst>(std::move(args)));
627
491
  }
628
492
 
629
493
  const char* name() const override { return kPickFirst; }
494
+
495
+ RefCountedPtr<LoadBalancingPolicy::Config> ParseLoadBalancingConfig(
496
+ const grpc_json* json, grpc_error** error) const override {
497
+ if (json != nullptr) {
498
+ GPR_DEBUG_ASSERT(strcmp(json->key, name()) == 0);
499
+ }
500
+ return RefCountedPtr<LoadBalancingPolicy::Config>(
501
+ New<ParsedPickFirstConfig>());
502
+ }
630
503
  };
631
504
 
632
505
  } // namespace