grpc 1.43.1 → 1.44.0.pre2

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 (382) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +84 -64
  3. data/include/grpc/grpc_security.h +10 -0
  4. data/include/grpc/impl/codegen/compression_types.h +0 -2
  5. data/include/grpc/impl/codegen/grpc_types.h +6 -0
  6. data/src/core/ext/filters/client_channel/backend_metric.h +1 -1
  7. data/src/core/ext/filters/client_channel/client_channel.cc +62 -68
  8. data/src/core/ext/filters/client_channel/client_channel.h +8 -8
  9. data/src/core/ext/filters/client_channel/client_channel_plugin.cc +1 -1
  10. data/src/core/ext/filters/client_channel/config_selector.h +4 -4
  11. data/src/core/ext/filters/client_channel/dynamic_filters.h +1 -1
  12. data/src/core/ext/filters/client_channel/health/health_check_client.cc +16 -14
  13. data/src/core/ext/filters/client_channel/health/health_check_client.h +3 -3
  14. data/src/core/ext/filters/client_channel/http_connect_handshaker.cc +1 -1
  15. data/src/core/ext/filters/client_channel/lb_policy/address_filtering.cc +4 -3
  16. data/src/core/ext/filters/client_channel/lb_policy/address_filtering.h +6 -5
  17. data/src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.cc +3 -7
  18. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +31 -32
  19. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.h +0 -7
  20. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_balancer_addresses.h +1 -1
  21. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel.h +1 -1
  22. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel_secure.cc +1 -1
  23. data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc +43 -29
  24. data/src/core/ext/filters/client_channel/lb_policy/priority/priority.cc +6 -2
  25. data/src/core/ext/filters/client_channel/lb_policy/ring_hash/ring_hash.cc +120 -68
  26. data/src/core/ext/filters/client_channel/lb_policy/rls/rls.cc +60 -48
  27. data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc +62 -61
  28. data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +16 -11
  29. data/src/core/ext/filters/client_channel/lb_policy/weighted_target/weighted_target.cc +11 -5
  30. data/src/core/ext/filters/client_channel/lb_policy/xds/cds.cc +19 -15
  31. data/src/core/ext/filters/client_channel/lb_policy/xds/xds.h +1 -1
  32. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_impl.cc +14 -12
  33. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_manager.cc +3 -2
  34. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_resolver.cc +50 -105
  35. data/src/core/ext/filters/client_channel/lb_policy.cc +15 -14
  36. data/src/core/ext/filters/client_channel/lb_policy.h +19 -3
  37. data/src/core/ext/filters/client_channel/resolver/binder/binder_resolver.cc +3 -3
  38. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +207 -81
  39. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.h +22 -12
  40. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_posix.cc +19 -15
  41. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_windows.cc +23 -38
  42. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc +118 -207
  43. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h +25 -32
  44. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_windows.cc +1 -1
  45. data/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc +82 -73
  46. data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc +10 -10
  47. data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.h +2 -1
  48. data/src/core/ext/filters/client_channel/resolver/google_c2p/google_c2p_resolver.cc +2 -5
  49. data/src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.cc +5 -5
  50. data/src/core/ext/filters/client_channel/resolver/xds/xds_resolver.cc +157 -67
  51. data/src/core/ext/filters/client_channel/resolver_result_parsing.cc +1 -1
  52. data/src/core/ext/filters/client_channel/resolver_result_parsing.h +2 -2
  53. data/src/core/ext/filters/client_channel/retry_filter.cc +37 -64
  54. data/src/core/ext/filters/client_channel/retry_service_config.cc +1 -1
  55. data/src/core/ext/filters/client_channel/retry_service_config.h +1 -1
  56. data/src/core/ext/filters/client_channel/service_config_channel_arg_filter.cc +1 -1
  57. data/src/core/ext/filters/client_channel/subchannel.cc +12 -16
  58. data/src/core/ext/filters/client_channel/subchannel.h +2 -3
  59. data/src/core/ext/filters/fault_injection/fault_injection_filter.cc +37 -48
  60. data/src/core/ext/filters/fault_injection/service_config_parser.cc +6 -8
  61. data/src/core/ext/filters/fault_injection/service_config_parser.h +1 -1
  62. data/src/core/ext/filters/http/client/http_client_filter.cc +51 -122
  63. data/src/core/ext/filters/http/client_authority_filter.cc +8 -24
  64. data/src/core/ext/filters/http/message_compress/message_compress_filter.cc +42 -140
  65. data/src/core/ext/filters/http/message_compress/message_decompress_filter.cc +5 -25
  66. data/src/core/ext/filters/http/server/http_server_filter.cc +50 -135
  67. data/src/core/ext/filters/message_size/message_size_filter.cc +1 -1
  68. data/src/core/ext/filters/message_size/message_size_filter.h +1 -1
  69. data/src/core/ext/filters/rbac/rbac_filter.cc +157 -0
  70. data/src/core/ext/filters/rbac/rbac_filter.h +74 -0
  71. data/src/core/ext/filters/rbac/rbac_service_config_parser.cc +605 -0
  72. data/src/core/ext/filters/rbac/rbac_service_config_parser.h +70 -0
  73. data/src/core/ext/filters/server_config_selector/server_config_selector.h +3 -2
  74. data/src/core/ext/filters/server_config_selector/server_config_selector_filter.cc +11 -6
  75. data/src/core/ext/transport/chttp2/client/insecure/channel_create.cc +1 -1
  76. data/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc +1 -1
  77. data/src/core/ext/transport/chttp2/server/chttp2_server.cc +89 -29
  78. data/src/core/ext/transport/chttp2/transport/chttp2_plugin.cc +0 -1
  79. data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +45 -186
  80. data/src/core/ext/transport/chttp2/transport/frame_data.cc +0 -1
  81. data/src/core/ext/transport/chttp2/transport/hpack_encoder.cc +341 -279
  82. data/src/core/ext/transport/chttp2/transport/hpack_encoder.h +69 -159
  83. data/src/core/ext/transport/chttp2/transport/hpack_encoder_table.cc +1 -1
  84. data/src/core/ext/transport/chttp2/transport/hpack_encoder_table.h +2 -0
  85. data/src/core/ext/transport/chttp2/transport/hpack_parser.cc +19 -32
  86. data/src/core/ext/transport/chttp2/transport/hpack_parser.h +0 -1
  87. data/src/core/ext/transport/chttp2/transport/hpack_parser_table.cc +94 -1
  88. data/src/core/ext/transport/chttp2/transport/hpack_parser_table.h +2 -24
  89. data/src/core/ext/transport/chttp2/transport/internal.h +0 -33
  90. data/src/core/ext/transport/chttp2/transport/parsing.cc +0 -6
  91. data/src/core/ext/transport/chttp2/transport/writing.cc +47 -116
  92. data/src/core/ext/transport/inproc/inproc_plugin.cc +0 -4
  93. data/src/core/ext/transport/inproc/inproc_transport.cc +11 -63
  94. data/src/core/ext/transport/inproc/inproc_transport.h +0 -3
  95. data/src/core/ext/upb-generated/envoy/extensions/filters/http/rbac/v3/rbac.upb.c +61 -0
  96. data/src/core/ext/upb-generated/envoy/extensions/filters/http/rbac/v3/rbac.upb.h +146 -0
  97. data/src/core/ext/upbdefs-generated/envoy/config/rbac/v3/rbac.upbdefs.c +188 -0
  98. data/src/core/ext/upbdefs-generated/envoy/config/rbac/v3/rbac.upbdefs.h +70 -0
  99. data/src/core/ext/upbdefs-generated/envoy/extensions/filters/http/rbac/v3/rbac.upbdefs.c +56 -0
  100. data/src/core/ext/upbdefs-generated/envoy/extensions/filters/http/rbac/v3/rbac.upbdefs.h +40 -0
  101. data/src/core/ext/upbdefs-generated/google/api/expr/v1alpha1/checked.upbdefs.c +154 -0
  102. data/src/core/ext/upbdefs-generated/google/api/expr/v1alpha1/checked.upbdefs.h +95 -0
  103. data/src/core/ext/upbdefs-generated/google/api/expr/v1alpha1/eval.upbdefs.c +58 -0
  104. data/src/core/ext/upbdefs-generated/google/api/expr/v1alpha1/eval.upbdefs.h +55 -0
  105. data/src/core/ext/upbdefs-generated/google/api/expr/v1alpha1/explain.upbdefs.c +44 -0
  106. data/src/core/ext/upbdefs-generated/google/api/expr/v1alpha1/explain.upbdefs.h +40 -0
  107. data/src/core/ext/upbdefs-generated/google/api/expr/v1alpha1/syntax.upbdefs.c +153 -0
  108. data/src/core/ext/upbdefs-generated/google/api/expr/v1alpha1/syntax.upbdefs.h +100 -0
  109. data/src/core/ext/upbdefs-generated/google/api/expr/v1alpha1/value.upbdefs.c +75 -0
  110. data/src/core/ext/upbdefs-generated/google/api/expr/v1alpha1/value.upbdefs.h +55 -0
  111. data/src/core/ext/xds/upb_utils.h +65 -0
  112. data/src/core/ext/xds/xds_api.cc +81 -3458
  113. data/src/core/ext/xds/xds_api.h +56 -611
  114. data/src/core/ext/xds/xds_bootstrap.cc +189 -125
  115. data/src/core/ext/xds/xds_bootstrap.h +20 -15
  116. data/src/core/ext/xds/xds_certificate_provider.h +1 -0
  117. data/src/core/ext/xds/xds_channel_creds.cc +108 -0
  118. data/src/core/ext/xds/xds_channel_creds.h +50 -0
  119. data/src/core/ext/xds/xds_client.cc +584 -994
  120. data/src/core/ext/xds/xds_client.h +78 -135
  121. data/src/core/ext/xds/xds_cluster.cc +451 -0
  122. data/src/core/ext/xds/xds_cluster.h +111 -0
  123. data/src/core/ext/xds/xds_common_types.cc +388 -0
  124. data/src/core/ext/xds/xds_common_types.h +110 -0
  125. data/src/core/ext/xds/xds_endpoint.cc +364 -0
  126. data/src/core/ext/xds/xds_endpoint.h +135 -0
  127. data/src/core/ext/xds/xds_http_filters.cc +5 -0
  128. data/src/core/ext/xds/xds_http_rbac_filter.cc +563 -0
  129. data/src/core/ext/xds/xds_http_rbac_filter.h +54 -0
  130. data/src/core/ext/xds/xds_listener.cc +1036 -0
  131. data/src/core/ext/xds/xds_listener.h +220 -0
  132. data/src/core/ext/{transport/chttp2/transport/hpack_utils.h → xds/xds_resource_type.cc} +12 -9
  133. data/src/core/ext/xds/xds_resource_type.h +98 -0
  134. data/src/core/ext/xds/xds_resource_type_impl.h +87 -0
  135. data/src/core/ext/xds/xds_route_config.cc +993 -0
  136. data/src/core/ext/xds/xds_route_config.h +215 -0
  137. data/src/core/ext/xds/xds_routing.cc +11 -8
  138. data/src/core/ext/xds/xds_routing.h +8 -5
  139. data/src/core/ext/xds/xds_server_config_fetcher.cc +159 -99
  140. data/src/core/lib/address_utils/parse_address.cc +20 -0
  141. data/src/core/lib/address_utils/parse_address.h +5 -0
  142. data/src/core/lib/address_utils/sockaddr_utils.cc +33 -36
  143. data/src/core/lib/address_utils/sockaddr_utils.h +1 -16
  144. data/src/core/lib/backoff/backoff.cc +4 -30
  145. data/src/core/lib/backoff/backoff.h +3 -3
  146. data/src/core/lib/channel/channel_args.cc +0 -1
  147. data/src/core/lib/channel/channel_stack.cc +8 -0
  148. data/src/core/lib/channel/channel_stack.h +1 -1
  149. data/src/core/lib/channel/channel_stack_builder.cc +5 -9
  150. data/src/core/lib/channel/channel_stack_builder.h +4 -7
  151. data/src/core/lib/channel/channelz.cc +1 -0
  152. data/src/core/lib/compression/compression.cc +19 -111
  153. data/src/core/lib/compression/compression_internal.cc +142 -202
  154. data/src/core/lib/compression/compression_internal.h +64 -69
  155. data/src/core/lib/compression/message_compress.cc +11 -11
  156. data/src/core/lib/compression/message_compress.h +2 -2
  157. data/src/core/lib/gpr/useful.h +4 -0
  158. data/src/core/lib/gprpp/bitset.h +7 -0
  159. data/src/core/lib/gprpp/chunked_vector.h +45 -3
  160. data/src/core/lib/gprpp/status_helper.cc +20 -28
  161. data/src/core/lib/gprpp/status_helper.h +6 -19
  162. data/src/core/lib/gprpp/table.h +11 -0
  163. data/src/core/lib/http/httpcli.cc +37 -46
  164. data/src/core/lib/http/httpcli.h +3 -15
  165. data/src/core/lib/iomgr/call_combiner.cc +15 -4
  166. data/src/core/lib/iomgr/closure.h +29 -9
  167. data/src/core/lib/iomgr/combiner.cc +25 -3
  168. data/src/core/lib/iomgr/error.cc +2 -0
  169. data/src/core/lib/iomgr/error.h +3 -0
  170. data/src/core/lib/iomgr/event_engine/iomgr.cc +3 -2
  171. data/src/core/lib/iomgr/event_engine/resolved_address_internal.cc +6 -0
  172. data/src/core/lib/iomgr/event_engine/resolved_address_internal.h +2 -0
  173. data/src/core/lib/iomgr/event_engine/resolver.cc +66 -48
  174. data/src/core/lib/iomgr/event_engine/resolver.h +56 -0
  175. data/src/core/lib/iomgr/exec_ctx.cc +22 -9
  176. data/src/core/lib/iomgr/executor.cc +10 -1
  177. data/src/core/lib/iomgr/fork_posix.cc +3 -2
  178. data/src/core/lib/iomgr/iomgr_custom.cc +4 -1
  179. data/src/core/lib/iomgr/iomgr_posix.cc +2 -2
  180. data/src/core/lib/iomgr/iomgr_posix_cfstream.cc +2 -2
  181. data/src/core/lib/iomgr/iomgr_windows.cc +2 -2
  182. data/src/core/lib/iomgr/port.h +2 -2
  183. data/src/core/lib/iomgr/resolve_address.cc +5 -24
  184. data/src/core/lib/iomgr/resolve_address.h +47 -44
  185. data/src/core/lib/iomgr/resolve_address_custom.cc +131 -109
  186. data/src/core/lib/iomgr/resolve_address_custom.h +101 -19
  187. data/src/core/lib/iomgr/resolve_address_impl.h +59 -0
  188. data/src/core/lib/iomgr/resolve_address_posix.cc +82 -66
  189. data/src/core/lib/iomgr/resolve_address_posix.h +47 -0
  190. data/src/core/lib/iomgr/resolve_address_windows.cc +93 -74
  191. data/src/core/lib/iomgr/resolve_address_windows.h +47 -0
  192. data/src/core/lib/iomgr/resolved_address.h +39 -0
  193. data/src/core/lib/iomgr/tcp_server_utils_posix_common.cc +1 -0
  194. data/src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc +1 -0
  195. data/src/core/lib/iomgr/unix_sockets_posix.cc +22 -34
  196. data/src/core/lib/iomgr/unix_sockets_posix.h +4 -7
  197. data/src/core/lib/iomgr/unix_sockets_posix_noop.cc +6 -15
  198. data/src/core/lib/matchers/matchers.cc +1 -1
  199. data/src/core/lib/promise/activity.h +49 -20
  200. data/src/core/lib/promise/detail/status.h +5 -0
  201. data/src/core/{ext/filters/client_channel → lib/resolver}/resolver.cc +17 -25
  202. data/src/core/{ext/filters/client_channel → lib/resolver}/resolver.h +43 -44
  203. data/src/core/{ext/filters/client_channel → lib/resolver}/resolver_factory.h +10 -5
  204. data/src/core/{ext/filters/client_channel → lib/resolver}/resolver_registry.cc +3 -2
  205. data/src/core/{ext/filters/client_channel → lib/resolver}/resolver_registry.h +4 -5
  206. data/src/core/{ext/filters/client_channel → lib/resolver}/server_address.cc +1 -1
  207. data/src/core/{ext/filters/client_channel → lib/resolver}/server_address.h +4 -4
  208. data/src/core/lib/resource_quota/api.h +0 -1
  209. data/src/core/lib/{gprpp → resource_quota}/arena.cc +16 -13
  210. data/src/core/lib/{gprpp → resource_quota}/arena.h +24 -13
  211. data/src/core/lib/security/authorization/evaluate_args.cc +30 -15
  212. data/src/core/lib/security/authorization/evaluate_args.h +1 -0
  213. data/src/core/lib/security/authorization/grpc_authorization_engine.cc +60 -0
  214. data/src/core/lib/security/authorization/grpc_authorization_engine.h +62 -0
  215. data/src/core/lib/security/authorization/matchers.cc +227 -0
  216. data/src/core/lib/security/authorization/matchers.h +211 -0
  217. data/src/core/lib/security/authorization/rbac_policy.cc +442 -0
  218. data/src/core/lib/security/authorization/rbac_policy.h +170 -0
  219. data/src/core/lib/security/context/security_context.cc +4 -2
  220. data/src/core/lib/security/context/security_context.h +1 -1
  221. data/src/core/lib/security/credentials/composite/composite_credentials.cc +5 -5
  222. data/src/core/lib/security/credentials/composite/composite_credentials.h +4 -3
  223. data/src/core/lib/security/credentials/credentials.h +10 -20
  224. data/src/core/lib/security/credentials/external/aws_external_account_credentials.cc +6 -9
  225. data/src/core/lib/security/credentials/external/external_account_credentials.cc +7 -9
  226. data/src/core/lib/security/credentials/external/external_account_credentials.h +2 -7
  227. data/src/core/lib/security/credentials/external/url_external_account_credentials.cc +2 -3
  228. data/src/core/lib/security/credentials/fake/fake_credentials.cc +5 -4
  229. data/src/core/lib/security/credentials/fake/fake_credentials.h +8 -7
  230. data/src/core/lib/security/credentials/google_default/google_default_credentials.cc +2 -5
  231. data/src/core/lib/security/credentials/iam/iam_credentials.cc +16 -19
  232. data/src/core/lib/security/credentials/iam/iam_credentials.h +6 -5
  233. data/src/core/lib/security/credentials/jwt/json_token.cc +4 -6
  234. data/src/core/lib/security/credentials/jwt/jwt_credentials.cc +16 -28
  235. data/src/core/lib/security/credentials/jwt/jwt_credentials.h +8 -8
  236. data/src/core/lib/security/credentials/jwt/jwt_verifier.cc +6 -13
  237. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc +44 -57
  238. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.h +13 -15
  239. data/src/core/lib/security/credentials/plugin/plugin_credentials.cc +6 -7
  240. data/src/core/lib/security/credentials/plugin/plugin_credentials.h +5 -4
  241. data/src/core/lib/security/credentials/ssl/ssl_credentials.cc +1 -10
  242. data/src/core/lib/security/credentials/tls/grpc_tls_credentials_options.cc +6 -0
  243. data/src/core/lib/security/credentials/tls/grpc_tls_credentials_options.h +7 -0
  244. data/src/core/lib/security/credentials/xds/xds_credentials.h +1 -1
  245. data/src/core/lib/security/security_connector/security_connector.cc +0 -4
  246. data/src/core/lib/security/security_connector/security_connector.h +5 -1
  247. data/src/core/lib/security/security_connector/ssl_utils.cc +14 -24
  248. data/src/core/lib/security/security_connector/ssl_utils.h +5 -14
  249. data/src/core/lib/security/security_connector/tls/tls_security_connector.cc +2 -3
  250. data/src/core/lib/security/transport/auth_filters.h +7 -0
  251. data/src/core/lib/security/transport/client_auth_filter.cc +53 -33
  252. data/src/core/lib/security/transport/server_auth_filter.cc +40 -35
  253. data/src/core/{ext → lib}/service_config/service_config.cc +2 -2
  254. data/src/core/{ext → lib}/service_config/service_config.h +4 -4
  255. data/src/core/{ext → lib}/service_config/service_config_call_data.h +5 -5
  256. data/src/core/{ext → lib}/service_config/service_config_parser.cc +1 -1
  257. data/src/core/{ext → lib}/service_config/service_config_parser.h +3 -3
  258. data/src/core/lib/slice/slice.cc +3 -1
  259. data/src/core/lib/slice/slice.h +43 -13
  260. data/src/core/lib/slice/slice_intern.cc +3 -101
  261. data/src/core/lib/slice/slice_internal.h +1 -2
  262. data/src/core/lib/slice/slice_refcount.h +4 -13
  263. data/src/core/lib/slice/slice_refcount_base.h +0 -16
  264. data/src/core/lib/surface/call.cc +140 -382
  265. data/src/core/lib/surface/call.h +4 -4
  266. data/src/core/lib/surface/channel.cc +42 -44
  267. data/src/core/lib/surface/channel.h +4 -4
  268. data/src/core/lib/surface/init.cc +0 -2
  269. data/src/core/lib/surface/lame_client.cc +0 -1
  270. data/src/core/lib/surface/server.cc +12 -29
  271. data/src/core/lib/surface/server.h +2 -2
  272. data/src/core/lib/surface/version.cc +2 -2
  273. data/src/core/lib/transport/error_utils.h +14 -0
  274. data/src/core/lib/transport/metadata_batch.h +799 -717
  275. data/src/core/lib/transport/parsed_metadata.cc +2 -0
  276. data/src/core/lib/transport/parsed_metadata.h +95 -92
  277. data/src/core/lib/transport/timeout_encoding.cc +200 -66
  278. data/src/core/lib/transport/timeout_encoding.h +40 -10
  279. data/src/core/lib/transport/transport.h +1 -1
  280. data/src/core/lib/transport/transport_op_string.cc +6 -39
  281. data/src/core/lib/uri/uri_parser.cc +223 -53
  282. data/src/core/lib/uri/uri_parser.h +36 -23
  283. data/src/core/plugin_registry/grpc_plugin_registry.cc +4 -3
  284. data/src/core/tsi/alts/handshaker/alts_handshaker_client.cc +1 -1
  285. data/src/core/tsi/ssl/session_cache/ssl_session.h +2 -4
  286. data/src/core/tsi/ssl/session_cache/ssl_session_cache.h +3 -5
  287. data/src/core/tsi/ssl_transport_security.cc +53 -13
  288. data/src/core/tsi/ssl_transport_security.h +18 -6
  289. data/src/ruby/ext/grpc/extconf.rb +10 -3
  290. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +2 -0
  291. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +3 -0
  292. data/src/ruby/lib/grpc/version.rb +1 -1
  293. data/src/ruby/pb/src/proto/grpc/testing/test_pb.rb +2 -1
  294. data/third_party/abseil-cpp/absl/base/internal/fast_type_id.h +48 -0
  295. data/third_party/abseil-cpp/absl/random/bernoulli_distribution.h +200 -0
  296. data/third_party/abseil-cpp/absl/random/beta_distribution.h +427 -0
  297. data/third_party/abseil-cpp/absl/random/discrete_distribution.cc +98 -0
  298. data/third_party/abseil-cpp/absl/random/discrete_distribution.h +247 -0
  299. data/third_party/abseil-cpp/absl/random/distributions.h +452 -0
  300. data/third_party/abseil-cpp/absl/random/exponential_distribution.h +165 -0
  301. data/third_party/abseil-cpp/absl/random/gaussian_distribution.cc +104 -0
  302. data/third_party/abseil-cpp/absl/random/gaussian_distribution.h +275 -0
  303. data/third_party/abseil-cpp/absl/random/internal/distribution_caller.h +92 -0
  304. data/third_party/abseil-cpp/absl/random/internal/fast_uniform_bits.h +268 -0
  305. data/third_party/abseil-cpp/absl/random/internal/fastmath.h +57 -0
  306. data/third_party/abseil-cpp/absl/random/internal/generate_real.h +144 -0
  307. data/third_party/abseil-cpp/absl/random/internal/iostream_state_saver.h +245 -0
  308. data/third_party/abseil-cpp/absl/random/internal/nonsecure_base.h +150 -0
  309. data/third_party/abseil-cpp/absl/random/internal/pcg_engine.h +308 -0
  310. data/third_party/abseil-cpp/absl/random/internal/platform.h +171 -0
  311. data/third_party/abseil-cpp/absl/random/internal/pool_urbg.cc +253 -0
  312. data/third_party/abseil-cpp/absl/random/internal/pool_urbg.h +131 -0
  313. data/third_party/abseil-cpp/absl/random/internal/randen.cc +91 -0
  314. data/third_party/abseil-cpp/absl/random/internal/randen.h +102 -0
  315. data/third_party/abseil-cpp/absl/random/internal/randen_detect.cc +221 -0
  316. data/third_party/abseil-cpp/absl/random/internal/randen_detect.h +33 -0
  317. data/third_party/abseil-cpp/absl/random/internal/randen_engine.h +239 -0
  318. data/third_party/abseil-cpp/absl/random/internal/randen_hwaes.cc +526 -0
  319. data/third_party/abseil-cpp/absl/random/internal/randen_hwaes.h +50 -0
  320. data/third_party/abseil-cpp/absl/random/internal/randen_round_keys.cc +462 -0
  321. data/third_party/abseil-cpp/absl/random/internal/randen_slow.cc +471 -0
  322. data/third_party/abseil-cpp/absl/random/internal/randen_slow.h +40 -0
  323. data/third_party/abseil-cpp/absl/random/internal/randen_traits.h +88 -0
  324. data/third_party/abseil-cpp/absl/random/internal/salted_seed_seq.h +167 -0
  325. data/third_party/abseil-cpp/absl/random/internal/seed_material.cc +267 -0
  326. data/third_party/abseil-cpp/absl/random/internal/seed_material.h +104 -0
  327. data/third_party/abseil-cpp/absl/random/internal/traits.h +101 -0
  328. data/third_party/abseil-cpp/absl/random/internal/uniform_helper.h +244 -0
  329. data/third_party/abseil-cpp/absl/random/internal/wide_multiply.h +111 -0
  330. data/third_party/abseil-cpp/absl/random/log_uniform_int_distribution.h +257 -0
  331. data/third_party/abseil-cpp/absl/random/poisson_distribution.h +258 -0
  332. data/third_party/abseil-cpp/absl/random/random.h +189 -0
  333. data/third_party/abseil-cpp/absl/random/seed_gen_exception.cc +46 -0
  334. data/third_party/abseil-cpp/absl/random/seed_gen_exception.h +55 -0
  335. data/third_party/abseil-cpp/absl/random/seed_sequences.cc +29 -0
  336. data/third_party/abseil-cpp/absl/random/seed_sequences.h +110 -0
  337. data/third_party/abseil-cpp/absl/random/uniform_int_distribution.h +275 -0
  338. data/third_party/abseil-cpp/absl/random/uniform_real_distribution.h +202 -0
  339. data/third_party/abseil-cpp/absl/random/zipf_distribution.h +271 -0
  340. data/third_party/boringssl-with-bazel/src/crypto/asn1/tasn_enc.c +1 -0
  341. data/third_party/boringssl-with-bazel/src/crypto/base64/base64.c +13 -0
  342. data/third_party/boringssl-with-bazel/src/crypto/dsa/dsa.c +21 -0
  343. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/cipher/cipher.c +12 -0
  344. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ecdsa/ecdsa.c +1 -2
  345. data/third_party/boringssl-with-bazel/src/crypto/hpke/hpke.c +2 -2
  346. data/third_party/boringssl-with-bazel/src/crypto/mem.c +1 -1
  347. data/third_party/boringssl-with-bazel/src/crypto/pkcs7/pkcs7.c +29 -0
  348. data/third_party/boringssl-with-bazel/src/crypto/pkcs8/internal.h +0 -1
  349. data/third_party/boringssl-with-bazel/src/crypto/pkcs8/pkcs8.c +1 -1
  350. data/third_party/boringssl-with-bazel/src/crypto/pkcs8/pkcs8_x509.c +1 -1
  351. data/third_party/boringssl-with-bazel/src/include/openssl/base64.h +8 -0
  352. data/third_party/boringssl-with-bazel/src/include/openssl/cipher.h +13 -1
  353. data/third_party/boringssl-with-bazel/src/include/openssl/dsa.h +10 -0
  354. data/third_party/boringssl-with-bazel/src/include/openssl/hpke.h +1 -1
  355. data/third_party/boringssl-with-bazel/src/include/openssl/pkcs7.h +9 -4
  356. data/third_party/boringssl-with-bazel/src/include/openssl/pkcs8.h +6 -1
  357. data/third_party/boringssl-with-bazel/src/include/openssl/ssl.h +23 -2
  358. data/third_party/boringssl-with-bazel/src/ssl/ssl_lib.cc +4 -0
  359. data/third_party/xxhash/xxhash.h +607 -352
  360. metadata +149 -77
  361. data/src/core/ext/transport/chttp2/transport/hpack_encoder_index.h +0 -107
  362. data/src/core/ext/transport/chttp2/transport/hpack_utils.cc +0 -46
  363. data/src/core/ext/transport/chttp2/transport/popularity_count.h +0 -60
  364. data/src/core/lib/compression/algorithm_metadata.h +0 -62
  365. data/src/core/lib/compression/compression_args.cc +0 -140
  366. data/src/core/lib/compression/compression_args.h +0 -58
  367. data/src/core/lib/compression/stream_compression.cc +0 -81
  368. data/src/core/lib/compression/stream_compression.h +0 -117
  369. data/src/core/lib/compression/stream_compression_gzip.cc +0 -231
  370. data/src/core/lib/compression/stream_compression_gzip.h +0 -28
  371. data/src/core/lib/compression/stream_compression_identity.cc +0 -91
  372. data/src/core/lib/compression/stream_compression_identity.h +0 -29
  373. data/src/core/lib/security/credentials/credentials_metadata.cc +0 -61
  374. data/src/core/lib/slice/static_slice.cc +0 -377
  375. data/src/core/lib/slice/static_slice.h +0 -300
  376. data/src/core/lib/transport/metadata.cc +0 -714
  377. data/src/core/lib/transport/metadata.h +0 -449
  378. data/src/core/lib/transport/metadata_batch.cc +0 -99
  379. data/src/core/lib/transport/static_metadata.cc +0 -1032
  380. data/src/core/lib/transport/static_metadata.h +0 -322
  381. data/src/core/lib/transport/status_metadata.cc +0 -63
  382. data/src/core/lib/transport/status_metadata.h +0 -48
@@ -37,7 +37,6 @@
37
37
  #include "src/core/lib/gprpp/sync.h"
38
38
  #include "src/core/lib/transport/connectivity_state.h"
39
39
  #include "src/core/lib/transport/error_utils.h"
40
- #include "src/core/lib/transport/static_metadata.h"
41
40
 
42
41
  namespace grpc_core {
43
42
 
@@ -106,6 +105,7 @@ class RingHashLbConfig : public LoadBalancingPolicy::Config {
106
105
  //
107
106
  // ring_hash LB policy
108
107
  //
108
+
109
109
  class RingHash : public LoadBalancingPolicy {
110
110
  public:
111
111
  explicit RingHash(Args args);
@@ -118,8 +118,9 @@ class RingHash : public LoadBalancingPolicy {
118
118
  private:
119
119
  ~RingHash() override;
120
120
 
121
- // Forward declaration.
121
+ // Forward declarations.
122
122
  class RingHashSubchannelList;
123
+ class Ring;
123
124
 
124
125
  // Data for a particular subchannel in a subchannel list.
125
126
  // This subclass adds the following functionality:
@@ -136,9 +137,10 @@ class RingHash : public LoadBalancingPolicy {
136
137
  : SubchannelData(subchannel_list, address, std::move(subchannel)),
137
138
  address_(address) {}
138
139
 
139
- grpc_connectivity_state connectivity_state() const {
140
- return last_connectivity_state_;
140
+ grpc_connectivity_state GetConnectivityState() const {
141
+ return connectivity_state_for_picker_.load(std::memory_order_relaxed);
141
142
  }
143
+
142
144
  const ServerAddress& address() const { return address_; }
143
145
 
144
146
  bool seen_failure_since_ready() const { return seen_failure_since_ready_; }
@@ -156,6 +158,8 @@ class RingHash : public LoadBalancingPolicy {
156
158
 
157
159
  ServerAddress address_;
158
160
  grpc_connectivity_state last_connectivity_state_ = GRPC_CHANNEL_SHUTDOWN;
161
+ std::atomic<grpc_connectivity_state> connectivity_state_for_picker_{
162
+ GRPC_CHANNEL_IDLE};
159
163
  bool seen_failure_since_ready_ = false;
160
164
  };
161
165
 
@@ -193,6 +197,9 @@ class RingHash : public LoadBalancingPolicy {
193
197
  // Transient Failure.
194
198
  bool UpdateRingHashConnectivityStateLocked();
195
199
 
200
+ // Create a new ring from this subchannel list.
201
+ RefCountedPtr<Ring> MakeRing();
202
+
196
203
  private:
197
204
  size_t num_idle_ = 0;
198
205
  size_t num_ready_ = 0;
@@ -200,20 +207,31 @@ class RingHash : public LoadBalancingPolicy {
200
207
  size_t num_transient_failure_ = 0;
201
208
  };
202
209
 
210
+ class Ring : public RefCounted<Ring> {
211
+ public:
212
+ struct Entry {
213
+ uint64_t hash;
214
+ RingHashSubchannelData* subchannel;
215
+ };
216
+
217
+ Ring(RingHash* parent,
218
+ RefCountedPtr<RingHashSubchannelList> subchannel_list);
219
+
220
+ const std::vector<Entry>& ring() const { return ring_; }
221
+
222
+ private:
223
+ RefCountedPtr<RingHashSubchannelList> subchannel_list_;
224
+ std::vector<Entry> ring_;
225
+ };
226
+
203
227
  class Picker : public SubchannelPicker {
204
228
  public:
205
- Picker(RefCountedPtr<RingHash> parent,
206
- RingHashSubchannelList* subchannel_list);
229
+ Picker(RefCountedPtr<RingHash> parent, RefCountedPtr<Ring> ring)
230
+ : parent_(std::move(parent)), ring_(std::move(ring)) {}
207
231
 
208
232
  PickResult Pick(PickArgs args) override;
209
233
 
210
234
  private:
211
- struct RingEntry {
212
- uint64_t hash;
213
- RefCountedPtr<SubchannelInterface> subchannel;
214
- grpc_connectivity_state connectivity_state;
215
- };
216
-
217
235
  // A fire-and-forget class that schedules subchannel connection attempts
218
236
  // on the control plane WorkSerializer.
219
237
  class SubchannelConnectionAttempter : public Orphanable {
@@ -255,9 +273,7 @@ class RingHash : public LoadBalancingPolicy {
255
273
  };
256
274
 
257
275
  RefCountedPtr<RingHash> parent_;
258
-
259
- // A ring of subchannels.
260
- std::vector<RingEntry> ring_;
276
+ RefCountedPtr<Ring> ring_;
261
277
  };
262
278
 
263
279
  void ShutdownLocked() override;
@@ -269,16 +285,19 @@ class RingHash : public LoadBalancingPolicy {
269
285
  OrphanablePtr<RingHashSubchannelList> subchannel_list_;
270
286
  // indicating if we are shutting down.
271
287
  bool shutdown_ = false;
288
+
289
+ // Current ring.
290
+ RefCountedPtr<Ring> ring_;
272
291
  };
273
292
 
274
293
  //
275
- // RingHash::Picker
294
+ // RingHash::Ring
276
295
  //
277
296
 
278
- RingHash::Picker::Picker(RefCountedPtr<RingHash> parent,
279
- RingHashSubchannelList* subchannel_list)
280
- : parent_(std::move(parent)) {
281
- size_t num_subchannels = subchannel_list->num_subchannels();
297
+ RingHash::Ring::Ring(RingHash* parent,
298
+ RefCountedPtr<RingHashSubchannelList> subchannel_list)
299
+ : subchannel_list_(std::move(subchannel_list)) {
300
+ size_t num_subchannels = subchannel_list_->num_subchannels();
282
301
  // Store the weights while finding the sum.
283
302
  struct AddressWeight {
284
303
  std::string address;
@@ -291,7 +310,7 @@ RingHash::Picker::Picker(RefCountedPtr<RingHash> parent,
291
310
  size_t sum = 0;
292
311
  address_weights.reserve(num_subchannels);
293
312
  for (size_t i = 0; i < num_subchannels; ++i) {
294
- RingHashSubchannelData* sd = subchannel_list->subchannel(i);
313
+ RingHashSubchannelData* sd = subchannel_list_->subchannel(i);
295
314
  const ServerAddressWeightAttribute* weight_attribute = static_cast<
296
315
  const ServerAddressWeightAttribute*>(sd->address().GetAttribute(
297
316
  ServerAddressWeightAttribute::kServerAddressWeightAttributeKey));
@@ -322,8 +341,8 @@ RingHash::Picker::Picker(RefCountedPtr<RingHash> parent,
322
341
  // weights aren't provided, all hosts should get an equal number of hashes. In
323
342
  // the case where this number exceeds the max_ring_size, it's scaled back down
324
343
  // to fit.
325
- const size_t min_ring_size = parent_->config_->min_ring_size();
326
- const size_t max_ring_size = parent_->config_->max_ring_size();
344
+ const size_t min_ring_size = parent->config_->min_ring_size();
345
+ const size_t max_ring_size = parent->config_->max_ring_size();
327
346
  const double scale = std::min(
328
347
  std::ceil(min_normalized_weight * min_ring_size) / min_normalized_weight,
329
348
  static_cast<double>(max_ring_size));
@@ -347,17 +366,13 @@ RingHash::Picker::Picker(RefCountedPtr<RingHash> parent,
347
366
  auto offset_start = hash_key_buffer.end();
348
367
  target_hashes += scale * address_weights[i].normalized_weight;
349
368
  size_t count = 0;
350
- auto current_state =
351
- subchannel_list->subchannel(i)->subchannel()->CheckConnectivityState();
352
369
  while (current_hashes < target_hashes) {
353
370
  const std::string count_str = absl::StrCat(count);
354
371
  hash_key_buffer.insert(offset_start, count_str.begin(), count_str.end());
355
372
  absl::string_view hash_key(hash_key_buffer.data(),
356
373
  hash_key_buffer.size());
357
374
  const uint64_t hash = XXH64(hash_key.data(), hash_key.size(), 0);
358
- ring_.push_back({hash,
359
- subchannel_list->subchannel(i)->subchannel()->Ref(),
360
- current_state});
375
+ ring_.push_back({hash, subchannel_list_->subchannel(i)});
361
376
  ++count;
362
377
  ++current_hashes;
363
378
  hash_key_buffer.erase(offset_start, hash_key_buffer.end());
@@ -368,17 +383,21 @@ RingHash::Picker::Picker(RefCountedPtr<RingHash> parent,
368
383
  std::max(static_cast<uint64_t>(i), max_hashes_per_host);
369
384
  }
370
385
  std::sort(ring_.begin(), ring_.end(),
371
- [](const RingEntry& lhs, const RingEntry& rhs) -> bool {
386
+ [](const Entry& lhs, const Entry& rhs) -> bool {
372
387
  return lhs.hash < rhs.hash;
373
388
  });
374
389
  if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_ring_hash_trace)) {
375
390
  gpr_log(GPR_INFO,
376
- "[RH %p picker %p] created picker from subchannel_list=%p "
391
+ "[RH %p picker %p] created ring from subchannel_list=%p "
377
392
  "with %" PRIuPTR " ring entries",
378
- parent_.get(), this, subchannel_list, ring_.size());
393
+ parent, this, subchannel_list_.get(), ring_.size());
379
394
  }
380
395
  }
381
396
 
397
+ //
398
+ // RingHash::Picker
399
+ //
400
+
382
401
  RingHash::PickResult RingHash::Picker::Pick(PickArgs args) {
383
402
  auto hash =
384
403
  args.call_state->ExperimentalGetCallAttribute(kRequestRingHashAttribute);
@@ -387,20 +406,21 @@ RingHash::PickResult RingHash::Picker::Pick(PickArgs args) {
387
406
  return PickResult::Fail(
388
407
  absl::InternalError("xds ring hash value is not a number"));
389
408
  }
409
+ const std::vector<Ring::Entry>& ring = ring_->ring();
390
410
  // Ported from https://github.com/RJ/ketama/blob/master/libketama/ketama.c
391
411
  // (ketama_get_server) NOTE: The algorithm depends on using signed integers
392
412
  // for lowp, highp, and first_index. Do not change them!
393
413
  int64_t lowp = 0;
394
- int64_t highp = ring_.size();
414
+ int64_t highp = ring.size();
395
415
  int64_t first_index = 0;
396
416
  while (true) {
397
417
  first_index = (lowp + highp) / 2;
398
- if (first_index == static_cast<int64_t>(ring_.size())) {
418
+ if (first_index == static_cast<int64_t>(ring.size())) {
399
419
  first_index = 0;
400
420
  break;
401
421
  }
402
- uint64_t midval = ring_[first_index].hash;
403
- uint64_t midval1 = first_index == 0 ? 0 : ring_[first_index - 1].hash;
422
+ uint64_t midval = ring[first_index].hash;
423
+ uint64_t midval1 = first_index == 0 ? 0 : ring[first_index - 1].hash;
404
424
  if (h <= midval && h > midval1) {
405
425
  break;
406
426
  }
@@ -423,35 +443,41 @@ RingHash::PickResult RingHash::Picker::Pick(PickArgs args) {
423
443
  }
424
444
  subchannel_connection_attempter->AddSubchannel(std::move(subchannel));
425
445
  };
426
- switch (ring_[first_index].connectivity_state) {
446
+ switch (ring[first_index].subchannel->GetConnectivityState()) {
427
447
  case GRPC_CHANNEL_READY:
428
- return PickResult::Complete(ring_[first_index].subchannel);
448
+ return PickResult::Complete(
449
+ ring[first_index].subchannel->subchannel()->Ref());
429
450
  case GRPC_CHANNEL_IDLE:
430
- ScheduleSubchannelConnectionAttempt(ring_[first_index].subchannel);
451
+ ScheduleSubchannelConnectionAttempt(
452
+ ring[first_index].subchannel->subchannel()->Ref());
431
453
  ABSL_FALLTHROUGH_INTENDED;
432
454
  case GRPC_CHANNEL_CONNECTING:
433
455
  return PickResult::Queue();
434
456
  default: // GRPC_CHANNEL_TRANSIENT_FAILURE
435
457
  break;
436
458
  }
437
- ScheduleSubchannelConnectionAttempt(ring_[first_index].subchannel);
459
+ ScheduleSubchannelConnectionAttempt(
460
+ ring[first_index].subchannel->subchannel()->Ref());
438
461
  // Loop through remaining subchannels to find one in READY.
439
462
  // On the way, we make sure the right set of connection attempts
440
463
  // will happen.
441
464
  bool found_second_subchannel = false;
442
465
  bool found_first_non_failed = false;
443
- for (size_t i = 1; i < ring_.size(); ++i) {
444
- const RingEntry& entry = ring_[(first_index + i) % ring_.size()];
445
- if (entry.subchannel == ring_[first_index].subchannel) {
466
+ for (size_t i = 1; i < ring.size(); ++i) {
467
+ const Ring::Entry& entry = ring[(first_index + i) % ring.size()];
468
+ if (entry.subchannel == ring[first_index].subchannel) {
446
469
  continue;
447
470
  }
448
- if (entry.connectivity_state == GRPC_CHANNEL_READY) {
449
- return PickResult::Complete(entry.subchannel);
471
+ grpc_connectivity_state connectivity_state =
472
+ entry.subchannel->GetConnectivityState();
473
+ if (connectivity_state == GRPC_CHANNEL_READY) {
474
+ return PickResult::Complete(entry.subchannel->subchannel()->Ref());
450
475
  }
451
476
  if (!found_second_subchannel) {
452
- switch (entry.connectivity_state) {
477
+ switch (connectivity_state) {
453
478
  case GRPC_CHANNEL_IDLE:
454
- ScheduleSubchannelConnectionAttempt(entry.subchannel);
479
+ ScheduleSubchannelConnectionAttempt(
480
+ entry.subchannel->subchannel()->Ref());
455
481
  ABSL_FALLTHROUGH_INTENDED;
456
482
  case GRPC_CHANNEL_CONNECTING:
457
483
  return PickResult::Queue();
@@ -461,11 +487,13 @@ RingHash::PickResult RingHash::Picker::Pick(PickArgs args) {
461
487
  found_second_subchannel = true;
462
488
  }
463
489
  if (!found_first_non_failed) {
464
- if (entry.connectivity_state == GRPC_CHANNEL_TRANSIENT_FAILURE) {
465
- ScheduleSubchannelConnectionAttempt(entry.subchannel);
490
+ if (connectivity_state == GRPC_CHANNEL_TRANSIENT_FAILURE) {
491
+ ScheduleSubchannelConnectionAttempt(
492
+ entry.subchannel->subchannel()->Ref());
466
493
  } else {
467
- if (entry.connectivity_state == GRPC_CHANNEL_IDLE) {
468
- ScheduleSubchannelConnectionAttempt(entry.subchannel);
494
+ if (connectivity_state == GRPC_CHANNEL_IDLE) {
495
+ ScheduleSubchannelConnectionAttempt(
496
+ entry.subchannel->subchannel()->Ref());
469
497
  }
470
498
  found_first_non_failed = true;
471
499
  }
@@ -498,7 +526,7 @@ void RingHash::RingHashSubchannelList::StartWatchingLocked() {
498
526
  p->channel_control_helper()->UpdateState(
499
527
  GRPC_CHANNEL_READY, absl::Status(),
500
528
  absl::make_unique<Picker>(p->Ref(DEBUG_LOCATION, "RingHashPicker"),
501
- this));
529
+ p->ring_));
502
530
  }
503
531
 
504
532
  void RingHash::RingHashSubchannelList::UpdateStateCountersLocked(
@@ -547,7 +575,7 @@ bool RingHash::RingHashSubchannelList::UpdateRingHashConnectivityStateLocked() {
547
575
  p->channel_control_helper()->UpdateState(
548
576
  GRPC_CHANNEL_READY, absl::Status(),
549
577
  absl::make_unique<Picker>(p->Ref(DEBUG_LOCATION, "RingHashPicker"),
550
- this));
578
+ p->ring_));
551
579
  return false;
552
580
  }
553
581
  if (num_connecting_ > 0 && num_transient_failure_ < 2) {
@@ -560,7 +588,7 @@ bool RingHash::RingHashSubchannelList::UpdateRingHashConnectivityStateLocked() {
560
588
  p->channel_control_helper()->UpdateState(
561
589
  GRPC_CHANNEL_IDLE, absl::Status(),
562
590
  absl::make_unique<Picker>(p->Ref(DEBUG_LOCATION, "RingHashPicker"),
563
- this));
591
+ p->ring_));
564
592
  return false;
565
593
  }
566
594
  absl::Status status =
@@ -571,6 +599,11 @@ bool RingHash::RingHashSubchannelList::UpdateRingHashConnectivityStateLocked() {
571
599
  return true;
572
600
  }
573
601
 
602
+ RefCountedPtr<RingHash::Ring> RingHash::RingHashSubchannelList::MakeRing() {
603
+ RingHash* p = static_cast<RingHash*>(policy());
604
+ return MakeRefCounted<Ring>(p, Ref(DEBUG_LOCATION, "Ring"));
605
+ }
606
+
574
607
  //
575
608
  // RingHash::RingHashSubchannelData
576
609
  //
@@ -581,7 +614,7 @@ void RingHash::RingHashSubchannelData::UpdateConnectivityStateLocked(
581
614
  if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_ring_hash_trace)) {
582
615
  gpr_log(
583
616
  GPR_INFO,
584
- "[RR %p] connectivity changed for subchannel %p, subchannel_list %p "
617
+ "[RH %p] connectivity changed for subchannel %p, subchannel_list %p "
585
618
  "(index %" PRIuPTR " of %" PRIuPTR "): prev_state=%s new_state=%s",
586
619
  p, subchannel(), subchannel_list(), Index(),
587
620
  subchannel_list()->num_subchannels(),
@@ -614,6 +647,9 @@ void RingHash::RingHashSubchannelData::ProcessConnectivityChangeLocked(
614
647
  grpc_connectivity_state connectivity_state) {
615
648
  RingHash* p = static_cast<RingHash*>(subchannel_list()->policy());
616
649
  GPR_ASSERT(subchannel() != nullptr);
650
+ // Update connectivity state used by picker.
651
+ connectivity_state_for_picker_.store(connectivity_state,
652
+ std::memory_order_relaxed);
617
653
  // If the new state is TRANSIENT_FAILURE, re-resolve.
618
654
  // Only do this if we've started watching, not at startup time.
619
655
  // Otherwise, if the subchannel was already in state TRANSIENT_FAILURE
@@ -623,7 +659,7 @@ void RingHash::RingHashSubchannelData::ProcessConnectivityChangeLocked(
623
659
  if (connectivity_state == GRPC_CHANNEL_TRANSIENT_FAILURE) {
624
660
  if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_ring_hash_trace)) {
625
661
  gpr_log(GPR_INFO,
626
- "[RR %p] Subchannel %p has gone into TRANSIENT_FAILURE. "
662
+ "[RH %p] Subchannel %p has gone into TRANSIENT_FAILURE. "
627
663
  "Requesting re-resolution",
628
664
  p, subchannel());
629
665
  }
@@ -680,36 +716,52 @@ void RingHash::ShutdownLocked() {
680
716
  }
681
717
  shutdown_ = true;
682
718
  subchannel_list_.reset();
719
+ ring_.reset(DEBUG_LOCATION, "RingHash");
683
720
  }
684
721
 
685
722
  void RingHash::ResetBackoffLocked() { subchannel_list_->ResetBackoffLocked(); }
686
723
 
687
724
  void RingHash::UpdateLocked(UpdateArgs args) {
688
- if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_ring_hash_trace)) {
689
- gpr_log(GPR_INFO, "[RR %p] received update with %" PRIuPTR " addresses",
690
- this, args.addresses.size());
691
- }
692
725
  config_ = std::move(args.config);
693
- // Filter out any address with weight 0.
694
726
  ServerAddressList addresses;
695
- addresses.reserve(args.addresses.size());
696
- for (ServerAddress& address : args.addresses) {
697
- const ServerAddressWeightAttribute* weight_attribute =
698
- static_cast<const ServerAddressWeightAttribute*>(address.GetAttribute(
699
- ServerAddressWeightAttribute::kServerAddressWeightAttributeKey));
700
- if (weight_attribute == nullptr || weight_attribute->weight() > 0) {
701
- addresses.push_back(std::move(address));
727
+ if (args.addresses.ok()) {
728
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_ring_hash_trace)) {
729
+ gpr_log(GPR_INFO, "[RH %p] received update with %" PRIuPTR " addresses",
730
+ this, args.addresses->size());
731
+ }
732
+ // Filter out any address with weight 0.
733
+ addresses.reserve(args.addresses->size());
734
+ for (ServerAddress& address : *args.addresses) {
735
+ const ServerAddressWeightAttribute* weight_attribute =
736
+ static_cast<const ServerAddressWeightAttribute*>(address.GetAttribute(
737
+ ServerAddressWeightAttribute::kServerAddressWeightAttributeKey));
738
+ if (weight_attribute == nullptr || weight_attribute->weight() > 0) {
739
+ addresses.emplace_back(std::move(address));
740
+ }
741
+ }
742
+ } else {
743
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_ring_hash_trace)) {
744
+ gpr_log(GPR_INFO, "[RH %p] received update with addresses error: %s",
745
+ this, args.addresses.status().ToString().c_str());
702
746
  }
747
+ // If we already have a subchannel list, then ignore the resolver
748
+ // failure and keep using the existing list.
749
+ if (subchannel_list_ != nullptr) return;
703
750
  }
704
751
  subchannel_list_ = MakeOrphanable<RingHashSubchannelList>(
705
752
  this, &grpc_lb_ring_hash_trace, std::move(addresses), *args.args);
706
753
  if (subchannel_list_->num_subchannels() == 0) {
707
754
  // If the new list is empty, immediately transition to TRANSIENT_FAILURE.
708
- absl::Status status = absl::UnavailableError("Empty update");
755
+ absl::Status status =
756
+ args.addresses.ok() ? absl::UnavailableError(absl::StrCat(
757
+ "empty address list: ", args.resolution_note))
758
+ : args.addresses.status();
709
759
  channel_control_helper()->UpdateState(
710
760
  GRPC_CHANNEL_TRANSIENT_FAILURE, status,
711
761
  absl::make_unique<TransientFailurePicker>(status));
712
762
  } else {
763
+ // Build the ring.
764
+ ring_ = subchannel_list_->MakeRing();
713
765
  // Start watching the new list.
714
766
  subchannel_list_->StartWatchingLocked();
715
767
  }
@@ -52,7 +52,6 @@
52
52
  #include "src/core/ext/filters/client_channel/lb_policy/child_policy_handler.h"
53
53
  #include "src/core/ext/filters/client_channel/lb_policy_factory.h"
54
54
  #include "src/core/ext/filters/client_channel/lb_policy_registry.h"
55
- #include "src/core/ext/filters/client_channel/resolver_registry.h"
56
55
  #include "src/core/lib/backoff/backoff.h"
57
56
  #include "src/core/lib/gpr/env.h"
58
57
  #include "src/core/lib/gpr/string.h"
@@ -64,13 +63,13 @@
64
63
  #include "src/core/lib/iomgr/timer.h"
65
64
  #include "src/core/lib/json/json.h"
66
65
  #include "src/core/lib/json/json_util.h"
66
+ #include "src/core/lib/resolver/resolver_registry.h"
67
67
  #include "src/core/lib/security/credentials/credentials.h"
68
68
  #include "src/core/lib/security/credentials/fake/fake_credentials.h"
69
69
  #include "src/core/lib/surface/call.h"
70
70
  #include "src/core/lib/surface/channel.h"
71
71
  #include "src/core/lib/transport/connectivity_state.h"
72
72
  #include "src/core/lib/transport/error_utils.h"
73
- #include "src/core/lib/transport/static_metadata.h"
74
73
  #include "src/core/lib/uri/uri_parser.h"
75
74
  #include "src/proto/grpc/lookup/v1/rls.upb.h"
76
75
 
@@ -93,9 +92,9 @@ const grpc_millis kCacheBackoffInitial = 1 * GPR_MS_PER_SEC;
93
92
  const double kCacheBackoffMultiplier = 1.6;
94
93
  const double kCacheBackoffJitter = 0.2;
95
94
  const grpc_millis kCacheBackoffMax = 120 * GPR_MS_PER_SEC;
96
- const grpc_millis kDefaultThrottleWindowSize = 30 * GPR_MS_PER_SEC;
97
- const double kDefaultThrottleRatioForSuccesses = 2.0;
98
- const int kDefaultThrottlePaddings = 8;
95
+ const grpc_millis kDefaultThrottleWindowSizeMs = 30 * GPR_MS_PER_SEC;
96
+ const float kDefaultThrottleRatioForSuccesses = 2.0;
97
+ const int kDefaultThrottlePadding = 8;
99
98
  const grpc_millis kCacheCleanupTimerInterval = 60 * GPR_MS_PER_SEC;
100
99
  const int64_t kMaxCacheSizeBytes = 5 * 1024 * 1024;
101
100
 
@@ -557,8 +556,13 @@ class RlsLb : public LoadBalancingPolicy {
557
556
  // Throttle state for RLS requests.
558
557
  class Throttle {
559
558
  public:
560
- explicit Throttle(int window_size_seconds = 0,
561
- double ratio_for_successes = 0, int paddings = 0);
559
+ explicit Throttle(
560
+ int window_size_ms = kDefaultThrottleWindowSizeMs,
561
+ float ratio_for_successes = kDefaultThrottleRatioForSuccesses,
562
+ int padding = kDefaultThrottlePadding)
563
+ : window_size_ms_(window_size_ms),
564
+ ratio_for_successes_(ratio_for_successes),
565
+ padding_(padding) {}
562
566
 
563
567
  bool ShouldThrottle() ABSL_EXCLUSIVE_LOCKS_REQUIRED(&RlsLb::mu_);
564
568
 
@@ -566,15 +570,15 @@ class RlsLb : public LoadBalancingPolicy {
566
570
  ABSL_EXCLUSIVE_LOCKS_REQUIRED(&RlsLb::mu_);
567
571
 
568
572
  private:
569
- grpc_millis window_size_;
570
- double ratio_for_successes_;
571
- int paddings_;
573
+ grpc_millis window_size_ms_;
574
+ float ratio_for_successes_;
575
+ int padding_;
572
576
 
573
- // Logged timestamp of requests.
577
+ // Logged timestamps of requests.
574
578
  std::deque<grpc_millis> requests_ ABSL_GUARDED_BY(&RlsLb::mu_);
575
579
 
576
- // Logged timestamp of responses that were successful.
577
- std::deque<grpc_millis> successes_ ABSL_GUARDED_BY(&RlsLb::mu_);
580
+ // Logged timestamps of failures.
581
+ std::deque<grpc_millis> failures_ ABSL_GUARDED_BY(&RlsLb::mu_);
578
582
  };
579
583
 
580
584
  RefCountedPtr<RlsLb> lb_policy_;
@@ -669,7 +673,7 @@ class RlsLb : public LoadBalancingPolicy {
669
673
  OrphanablePtr<RlsChannel> rls_channel_ ABSL_GUARDED_BY(mu_);
670
674
 
671
675
  // Accessed only from within WorkSerializer.
672
- ServerAddressList addresses_;
676
+ absl::StatusOr<ServerAddressList> addresses_;
673
677
  const grpc_channel_args* channel_args_ = nullptr;
674
678
  RefCountedPtr<RlsLbConfig> config_;
675
679
  RefCountedPtr<ChildPolicyWrapper> default_child_policy_;
@@ -1459,41 +1463,40 @@ void RlsLb::RlsChannel::StateWatcher::OnConnectivityStateChange(
1459
1463
  // RlsLb::RlsChannel::Throttle
1460
1464
  //
1461
1465
 
1462
- RlsLb::RlsChannel::Throttle::Throttle(int window_size_seconds,
1463
- double ratio_for_successes,
1464
- int paddings) {
1465
- GPR_DEBUG_ASSERT(window_size_seconds >= 0);
1466
- GPR_DEBUG_ASSERT(ratio_for_successes >= 0);
1467
- GPR_DEBUG_ASSERT(paddings >= 0);
1468
- window_size_ = window_size_seconds == 0 ? window_size_seconds * GPR_MS_PER_SEC
1469
- : kDefaultThrottleWindowSize;
1470
- ratio_for_successes_ = ratio_for_successes == 0
1471
- ? kDefaultThrottleRatioForSuccesses
1472
- : ratio_for_successes;
1473
- paddings_ = paddings == 0 ? kDefaultThrottlePaddings : paddings;
1474
- }
1475
-
1476
1466
  bool RlsLb::RlsChannel::Throttle::ShouldThrottle() {
1477
1467
  grpc_millis now = ExecCtx::Get()->Now();
1478
- while (!requests_.empty() && now - requests_.front() > window_size_) {
1468
+ while (!requests_.empty() && now - requests_.front() > window_size_ms_) {
1479
1469
  requests_.pop_front();
1480
1470
  }
1481
- while (!successes_.empty() && now - successes_.front() > window_size_) {
1482
- successes_.pop_front();
1483
- }
1484
- int successes = successes_.size();
1485
- int requests = requests_.size();
1486
- bool result = ((rand() % (requests + paddings_)) <
1487
- static_cast<double>(requests) -
1488
- static_cast<double>(successes) * ratio_for_successes_);
1489
- requests_.push_back(now);
1490
- return result;
1471
+ while (!failures_.empty() && now - failures_.front() > window_size_ms_) {
1472
+ failures_.pop_front();
1473
+ }
1474
+ // Compute probability of throttling.
1475
+ float num_requests = requests_.size();
1476
+ float num_successes = num_requests - failures_.size();
1477
+ // Note: it's possible that this ratio will be negative, in which case
1478
+ // no throttling will be done.
1479
+ float throttle_probability =
1480
+ (num_requests - (num_successes * ratio_for_successes_)) /
1481
+ (num_requests + padding_);
1482
+ // Generate a random number for the request.
1483
+ std::random_device rd;
1484
+ std::mt19937 mt(rd());
1485
+ std::uniform_real_distribution<float> dist(0, 1.0);
1486
+ // Check if we should throttle the request.
1487
+ bool throttle = dist(mt) < throttle_probability;
1488
+ // If we're throttling, record the request and the failure.
1489
+ if (throttle) {
1490
+ requests_.push_back(now);
1491
+ failures_.push_back(now);
1492
+ }
1493
+ return throttle;
1491
1494
  }
1492
1495
 
1493
1496
  void RlsLb::RlsChannel::Throttle::RegisterResponse(bool success) {
1494
- if (success) {
1495
- successes_.push_back(ExecCtx::Get()->Now());
1496
- }
1497
+ grpc_millis now = ExecCtx::Get()->Now();
1498
+ requests_.push_back(now);
1499
+ if (!success) failures_.push_back(now);
1497
1500
  }
1498
1501
 
1499
1502
  //
@@ -1762,7 +1765,7 @@ void RlsLb::RlsRequest::OnRlsCallCompleteLocked(grpc_error_handle error) {
1762
1765
  {
1763
1766
  MutexLock lock(&lb_policy_->mu_);
1764
1767
  if (lb_policy_->is_shutdown_) return;
1765
- rls_channel_->ReportResponseLocked(!response.status.ok());
1768
+ rls_channel_->ReportResponseLocked(response.status.ok());
1766
1769
  Cache::Entry* cache_entry = lb_policy_->cache_.FindOrInsert(key_);
1767
1770
  child_policies_to_finish_update = cache_entry->OnRlsResponseLocked(
1768
1771
  std::move(response), std::move(backoff_state_));
@@ -1863,19 +1866,28 @@ void RlsLb::UpdateLocked(UpdateArgs args) {
1863
1866
  if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_rls_trace)) {
1864
1867
  gpr_log(GPR_INFO, "[rlslb %p] policy updated", this);
1865
1868
  }
1866
- // Swap out config, addresses, and channel args.
1869
+ // Swap out config.
1867
1870
  RefCountedPtr<RlsLbConfig> old_config = std::move(config_);
1868
1871
  config_ = std::move(args.config);
1869
- ServerAddressList old_addresses = std::move(addresses_);
1870
- addresses_ = std::move(args.addresses);
1871
- grpc_channel_args_destroy(channel_args_);
1872
- channel_args_ = grpc_channel_args_copy(args.args);
1873
1872
  if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_rls_trace) &&
1874
1873
  (old_config == nullptr ||
1875
1874
  old_config->child_policy_config() != config_->child_policy_config())) {
1876
1875
  gpr_log(GPR_INFO, "[rlslb %p] updated child policy config: %s", this,
1877
1876
  config_->child_policy_config().Dump().c_str());
1878
1877
  }
1878
+ // Swap out addresses.
1879
+ // If the new address list is an error and we have an existing address list,
1880
+ // stick with the existing addresses.
1881
+ absl::StatusOr<ServerAddressList> old_addresses;
1882
+ if (args.addresses.ok()) {
1883
+ old_addresses = std::move(addresses_);
1884
+ addresses_ = std::move(args.addresses);
1885
+ } else {
1886
+ old_addresses = addresses_;
1887
+ }
1888
+ // Swap out channel args.
1889
+ grpc_channel_args_destroy(channel_args_);
1890
+ channel_args_ = grpc_channel_args_copy(args.args);
1879
1891
  // Determine whether we need to update all child policies.
1880
1892
  bool update_child_policies =
1881
1893
  old_config == nullptr ||