grpc 1.30.2 → 1.31.0.pre1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of grpc might be problematic. Click here for more details.

Files changed (317) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +560 -619
  3. data/include/grpc/grpc_security_constants.h +3 -0
  4. data/include/grpc/impl/codegen/grpc_types.h +7 -5
  5. data/include/grpc/impl/codegen/port_platform.h +0 -32
  6. data/src/core/ext/filters/client_channel/backend_metric.cc +12 -9
  7. data/src/core/ext/filters/client_channel/client_channel.cc +406 -265
  8. data/src/core/ext/filters/client_channel/config_selector.cc +62 -0
  9. data/src/core/ext/filters/client_channel/config_selector.h +93 -0
  10. data/src/core/ext/filters/client_channel/global_subchannel_pool.cc +24 -2
  11. data/src/core/ext/filters/client_channel/health/health_check_client.cc +2 -0
  12. data/src/core/ext/filters/client_channel/http_connect_handshaker.cc +6 -5
  13. data/src/core/ext/filters/client_channel/http_proxy.cc +6 -4
  14. data/src/core/ext/filters/client_channel/lb_policy.h +2 -0
  15. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +39 -23
  16. data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +4 -6
  17. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_routing.cc +376 -68
  18. data/src/core/ext/filters/client_channel/lb_policy_registry.cc +4 -5
  19. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +5 -2
  20. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.cc +6 -5
  21. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_libuv.cc +8 -6
  22. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_posix.cc +9 -7
  23. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_windows.cc +7 -5
  24. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc +33 -48
  25. data/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc +6 -2
  26. data/src/core/ext/filters/client_channel/resolver/xds/xds_resolver.cc +21 -18
  27. data/src/core/ext/filters/client_channel/resolver_registry.cc +13 -14
  28. data/src/core/ext/filters/client_channel/resolver_result_parsing.cc +6 -7
  29. data/src/core/ext/filters/client_channel/resolving_lb_policy.cc +33 -28
  30. data/src/core/ext/filters/client_channel/resolving_lb_policy.h +39 -20
  31. data/src/core/ext/filters/client_channel/service_config_channel_arg_filter.cc +142 -0
  32. data/src/core/ext/filters/client_channel/subchannel.cc +1 -1
  33. data/src/core/ext/filters/client_channel/xds/xds_api.cc +327 -123
  34. data/src/core/ext/filters/client_channel/xds/xds_api.h +72 -7
  35. data/src/core/ext/filters/client_channel/xds/xds_bootstrap.cc +12 -23
  36. data/src/core/ext/filters/client_channel/xds/xds_client.cc +112 -33
  37. data/src/core/ext/filters/client_channel/xds/xds_client_stats.h +10 -10
  38. data/src/core/ext/filters/http/client/http_client_filter.cc +5 -5
  39. data/src/core/ext/filters/http/http_filters_plugin.cc +2 -1
  40. data/src/core/ext/filters/http/message_compress/message_decompress_filter.cc +74 -33
  41. data/src/core/ext/filters/http/message_compress/message_decompress_filter.h +3 -1
  42. data/src/core/ext/filters/message_size/message_size_filter.cc +56 -80
  43. data/src/core/ext/filters/message_size/message_size_filter.h +6 -0
  44. data/src/core/ext/transport/chttp2/server/chttp2_server.cc +383 -347
  45. data/src/core/ext/transport/chttp2/server/chttp2_server.h +6 -2
  46. data/src/core/ext/transport/chttp2/server/insecure/server_chttp2.cc +1 -1
  47. data/src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.cc +7 -13
  48. data/src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.cc +7 -8
  49. data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +19 -4
  50. data/src/core/ext/transport/chttp2/transport/flow_control.cc +22 -27
  51. data/src/core/ext/transport/chttp2/transport/flow_control.h +14 -16
  52. data/src/core/ext/transport/chttp2/transport/frame_data.cc +9 -12
  53. data/src/core/ext/transport/chttp2/transport/frame_goaway.cc +4 -6
  54. data/src/core/ext/transport/chttp2/transport/frame_ping.cc +5 -6
  55. data/src/core/ext/transport/chttp2/transport/frame_rst_stream.cc +12 -13
  56. data/src/core/ext/transport/chttp2/transport/frame_settings.cc +6 -7
  57. data/src/core/ext/transport/chttp2/transport/frame_window_update.cc +9 -12
  58. data/src/core/ext/transport/chttp2/transport/hpack_parser.cc +25 -29
  59. data/src/core/ext/transport/chttp2/transport/hpack_table.cc +13 -17
  60. data/src/core/ext/transport/chttp2/transport/internal.h +13 -0
  61. data/src/core/ext/transport/chttp2/transport/parsing.cc +33 -43
  62. data/src/core/ext/transport/chttp2/transport/writing.cc +9 -14
  63. data/src/core/ext/transport/inproc/inproc_transport.cc +35 -15
  64. data/src/core/ext/upb-generated/envoy/annotations/deprecation.upb.h +0 -1
  65. data/src/core/ext/upb-generated/envoy/annotations/resource.upb.h +3 -4
  66. data/src/core/ext/upb-generated/envoy/api/v2/auth/cert.upb.h +0 -1
  67. data/src/core/ext/upb-generated/envoy/api/v2/auth/common.upb.h +80 -69
  68. data/src/core/ext/upb-generated/envoy/api/v2/auth/secret.upb.h +24 -23
  69. data/src/core/ext/upb-generated/envoy/api/v2/auth/tls.upb.h +66 -56
  70. data/src/core/ext/upb-generated/envoy/api/v2/cds.upb.h +1 -2
  71. data/src/core/ext/upb-generated/envoy/api/v2/cluster.upb.c +2 -2
  72. data/src/core/ext/upb-generated/envoy/api/v2/cluster.upb.h +317 -311
  73. data/src/core/ext/upb-generated/envoy/api/v2/cluster/circuit_breaker.upb.h +42 -34
  74. data/src/core/ext/upb-generated/envoy/api/v2/cluster/filter.upb.h +7 -7
  75. data/src/core/ext/upb-generated/envoy/api/v2/cluster/outlier_detection.upb.h +79 -61
  76. data/src/core/ext/upb-generated/envoy/api/v2/core/address.upb.h +55 -49
  77. data/src/core/ext/upb-generated/envoy/api/v2/core/backoff.upb.h +9 -8
  78. data/src/core/ext/upb-generated/envoy/api/v2/core/base.upb.c +1 -1
  79. data/src/core/ext/upb-generated/envoy/api/v2/core/base.upb.h +163 -169
  80. data/src/core/ext/upb-generated/envoy/api/v2/core/config_source.upb.h +51 -45
  81. data/src/core/ext/upb-generated/envoy/api/v2/core/event_service_config.upb.h +4 -5
  82. data/src/core/ext/upb-generated/envoy/api/v2/core/grpc_service.upb.h +107 -100
  83. data/src/core/ext/upb-generated/envoy/api/v2/core/health_check.upb.h +137 -117
  84. data/src/core/ext/upb-generated/envoy/api/v2/core/http_uri.upb.h +9 -9
  85. data/src/core/ext/upb-generated/envoy/api/v2/core/protocol.upb.h +105 -87
  86. data/src/core/ext/upb-generated/envoy/api/v2/core/socket_option.upb.h +12 -13
  87. data/src/core/ext/upb-generated/envoy/api/v2/discovery.upb.c +1 -1
  88. data/src/core/ext/upb-generated/envoy/api/v2/discovery.upb.h +95 -101
  89. data/src/core/ext/upb-generated/envoy/api/v2/eds.upb.h +1 -2
  90. data/src/core/ext/upb-generated/envoy/api/v2/endpoint.upb.c +1 -1
  91. data/src/core/ext/upb-generated/envoy/api/v2/endpoint.upb.h +49 -65
  92. data/src/core/ext/upb-generated/envoy/api/v2/endpoint/endpoint.upb.h +0 -1
  93. data/src/core/ext/upb-generated/envoy/api/v2/endpoint/endpoint_components.upb.h +49 -42
  94. data/src/core/ext/upb-generated/envoy/api/v2/endpoint/load_report.upb.h +70 -62
  95. data/src/core/ext/upb-generated/envoy/api/v2/lds.upb.h +1 -2
  96. data/src/core/ext/upb-generated/envoy/api/v2/listener.upb.h +81 -65
  97. data/src/core/ext/upb-generated/envoy/api/v2/listener/listener.upb.h +0 -1
  98. data/src/core/ext/upb-generated/envoy/api/v2/listener/listener_components.upb.c +1 -1
  99. data/src/core/ext/upb-generated/envoy/api/v2/listener/listener_components.upb.h +91 -80
  100. data/src/core/ext/upb-generated/envoy/api/v2/listener/udp_listener_config.upb.h +9 -10
  101. data/src/core/ext/upb-generated/envoy/api/v2/rds.upb.h +1 -2
  102. data/src/core/ext/upb-generated/envoy/api/v2/route.upb.h +36 -31
  103. data/src/core/ext/upb-generated/envoy/api/v2/route/route.upb.h +0 -1
  104. data/src/core/ext/upb-generated/envoy/api/v2/route/route_components.upb.c +7 -7
  105. data/src/core/ext/upb-generated/envoy/api/v2/route/route_components.upb.h +648 -696
  106. data/src/core/ext/upb-generated/envoy/api/v2/scoped_route.upb.h +16 -15
  107. data/src/core/ext/upb-generated/envoy/api/v2/srds.upb.h +1 -2
  108. data/src/core/ext/upb-generated/envoy/config/filter/accesslog/v2/accesslog.upb.c +1 -1
  109. data/src/core/ext/upb-generated/envoy/config/filter/accesslog/v2/accesslog.upb.h +95 -88
  110. data/src/core/ext/upb-generated/envoy/config/filter/network/http_connection_manager/v2/http_connection_manager.upb.h +234 -199
  111. data/src/core/ext/upb-generated/envoy/config/listener/v2/api_listener.upb.h +5 -5
  112. data/src/core/ext/upb-generated/envoy/config/trace/v2/http_tracer.upb.h +13 -13
  113. data/src/core/ext/upb-generated/envoy/service/discovery/v2/ads.upb.h +1 -2
  114. data/src/core/ext/upb-generated/envoy/service/load_stats/v2/lrs.upb.h +20 -18
  115. data/src/core/ext/upb-generated/envoy/type/http.upb.h +0 -1
  116. data/src/core/ext/upb-generated/envoy/type/matcher/regex.upb.h +18 -17
  117. data/src/core/ext/upb-generated/envoy/type/matcher/string.upb.h +14 -14
  118. data/src/core/ext/upb-generated/envoy/type/metadata/v2/metadata.upb.h +23 -23
  119. data/src/core/ext/upb-generated/envoy/type/percent.upb.h +8 -9
  120. data/src/core/ext/upb-generated/envoy/type/range.upb.h +15 -16
  121. data/src/core/ext/upb-generated/envoy/type/semantic_version.upb.h +7 -8
  122. data/src/core/ext/upb-generated/envoy/type/tracing/v2/custom_tag.upb.h +36 -35
  123. data/src/core/ext/upb-generated/gogoproto/gogo.upb.h +0 -1
  124. data/src/core/ext/upb-generated/google/api/annotations.upb.h +0 -1
  125. data/src/core/ext/upb-generated/google/api/http.upb.h +29 -28
  126. data/src/core/ext/upb-generated/google/protobuf/any.upb.h +5 -6
  127. data/src/core/ext/upb-generated/google/protobuf/descriptor.upb.c +3 -3
  128. data/src/core/ext/upb-generated/google/protobuf/descriptor.upb.h +412 -386
  129. data/src/core/ext/upb-generated/google/protobuf/duration.upb.h +5 -6
  130. data/src/core/ext/upb-generated/google/protobuf/empty.upb.h +1 -2
  131. data/src/core/ext/upb-generated/google/protobuf/struct.upb.c +1 -1
  132. data/src/core/ext/upb-generated/google/protobuf/struct.upb.h +33 -54
  133. data/src/core/ext/upb-generated/google/protobuf/timestamp.upb.h +5 -6
  134. data/src/core/ext/upb-generated/google/protobuf/wrappers.upb.h +27 -28
  135. data/src/core/ext/upb-generated/google/rpc/status.upb.h +8 -8
  136. data/src/core/ext/upb-generated/src/proto/grpc/gcp/altscontext.upb.c +1 -1
  137. data/src/core/ext/upb-generated/src/proto/grpc/gcp/altscontext.upb.h +32 -45
  138. data/src/core/ext/upb-generated/src/proto/grpc/gcp/handshaker.upb.c +4 -4
  139. data/src/core/ext/upb-generated/src/proto/grpc/gcp/handshaker.upb.h +157 -178
  140. data/src/core/ext/upb-generated/src/proto/grpc/gcp/transport_security_common.upb.h +14 -13
  141. data/src/core/ext/upb-generated/src/proto/grpc/health/v1/health.upb.h +6 -7
  142. data/src/core/ext/upb-generated/src/proto/grpc/lb/v1/load_balancer.upb.h +59 -56
  143. data/src/core/ext/upb-generated/udpa/annotations/migrate.upb.h +11 -12
  144. data/src/core/ext/upb-generated/udpa/annotations/sensitive.upb.h +0 -1
  145. data/src/core/ext/upb-generated/udpa/annotations/status.upb.h +5 -6
  146. data/src/core/ext/upb-generated/udpa/data/orca/v1/orca_load_report.upb.c +6 -6
  147. data/src/core/ext/upb-generated/udpa/data/orca/v1/orca_load_report.upb.h +41 -68
  148. data/src/core/ext/upb-generated/validate/validate.upb.h +536 -535
  149. data/src/core/lib/channel/channel_trace.cc +2 -6
  150. data/src/core/lib/channel/channelz.cc +5 -15
  151. data/src/core/lib/gpr/log_linux.cc +6 -8
  152. data/src/core/lib/gpr/log_posix.cc +6 -8
  153. data/src/core/lib/gpr/string.cc +10 -9
  154. data/src/core/lib/gpr/string.h +4 -2
  155. data/src/core/lib/gprpp/global_config_env.cc +8 -6
  156. data/src/core/lib/http/httpcli.cc +13 -10
  157. data/src/core/lib/http/httpcli_security_connector.cc +5 -5
  158. data/src/core/lib/iomgr/cfstream_handle.cc +1 -0
  159. data/src/core/lib/iomgr/endpoint_pair_posix.cc +10 -10
  160. data/src/core/lib/iomgr/error_cfstream.cc +9 -8
  161. data/src/core/lib/iomgr/ev_epoll1_linux.cc +5 -6
  162. data/src/core/lib/iomgr/ev_epollex_linux.cc +15 -21
  163. data/src/core/lib/iomgr/ev_poll_posix.cc +6 -5
  164. data/src/core/lib/iomgr/ev_posix.cc +2 -0
  165. data/src/core/lib/iomgr/iomgr.cc +10 -0
  166. data/src/core/lib/iomgr/iomgr.h +10 -0
  167. data/src/core/lib/iomgr/is_epollexclusive_available.cc +14 -0
  168. data/src/core/lib/iomgr/port.h +1 -21
  169. data/src/core/lib/iomgr/resolve_address_custom.cc +13 -18
  170. data/src/core/lib/iomgr/resolve_address_windows.cc +8 -8
  171. data/src/core/lib/iomgr/resource_quota.cc +34 -31
  172. data/src/core/lib/iomgr/sockaddr_utils.cc +7 -5
  173. data/src/core/lib/iomgr/sockaddr_utils.h +1 -1
  174. data/src/core/lib/iomgr/socket_utils_common_posix.cc +95 -55
  175. data/src/core/lib/iomgr/socket_windows.cc +4 -5
  176. data/src/core/lib/iomgr/tcp_client_cfstream.cc +9 -11
  177. data/src/core/lib/iomgr/tcp_client_custom.cc +6 -9
  178. data/src/core/lib/iomgr/tcp_client_posix.cc +27 -36
  179. data/src/core/lib/iomgr/tcp_client_windows.cc +9 -9
  180. data/src/core/lib/iomgr/tcp_custom.cc +1 -1
  181. data/src/core/lib/iomgr/tcp_custom.h +1 -1
  182. data/src/core/lib/iomgr/tcp_server.cc +3 -4
  183. data/src/core/lib/iomgr/tcp_server.h +7 -5
  184. data/src/core/lib/iomgr/tcp_server_custom.cc +6 -14
  185. data/src/core/lib/iomgr/tcp_server_posix.cc +34 -41
  186. data/src/core/lib/iomgr/tcp_server_utils_posix.h +3 -4
  187. data/src/core/lib/iomgr/tcp_server_utils_posix_common.cc +5 -7
  188. data/src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc +4 -9
  189. data/src/core/lib/iomgr/tcp_server_windows.cc +16 -16
  190. data/src/core/lib/iomgr/timer_generic.cc +13 -12
  191. data/src/core/lib/iomgr/udp_server.cc +24 -23
  192. data/src/core/lib/iomgr/udp_server.h +5 -2
  193. data/src/core/lib/iomgr/unix_sockets_posix.cc +9 -14
  194. data/src/core/lib/iomgr/unix_sockets_posix.h +3 -1
  195. data/src/core/lib/iomgr/unix_sockets_posix_noop.cc +5 -2
  196. data/src/core/lib/json/json_reader.cc +20 -21
  197. data/src/core/lib/security/credentials/credentials.h +5 -3
  198. data/src/core/lib/security/credentials/google_default/credentials_generic.cc +8 -6
  199. data/src/core/lib/security/credentials/google_default/google_default_credentials.cc +12 -9
  200. data/src/core/lib/security/credentials/jwt/jwt_credentials.cc +7 -4
  201. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc +19 -28
  202. data/src/core/lib/security/credentials/plugin/plugin_credentials.cc +6 -6
  203. data/src/core/lib/security/credentials/ssl/ssl_credentials.cc +20 -0
  204. data/src/core/lib/security/credentials/ssl/ssl_credentials.h +10 -0
  205. data/src/core/lib/security/credentials/tls/grpc_tls_credentials_options.h +10 -0
  206. data/src/core/lib/security/security_connector/fake/fake_security_connector.cc +10 -10
  207. data/src/core/lib/security/security_connector/security_connector.cc +2 -0
  208. data/src/core/lib/security/security_connector/security_connector.h +1 -1
  209. data/src/core/lib/security/security_connector/ssl/ssl_security_connector.cc +18 -11
  210. data/src/core/lib/security/security_connector/ssl/ssl_security_connector.h +5 -0
  211. data/src/core/lib/security/security_connector/ssl_utils.cc +44 -23
  212. data/src/core/lib/security/security_connector/ssl_utils.h +6 -2
  213. data/src/core/lib/security/security_connector/tls/tls_security_connector.cc +27 -24
  214. data/src/core/lib/security/transport/client_auth_filter.cc +10 -9
  215. data/src/core/lib/security/util/json_util.cc +12 -13
  216. data/src/core/lib/slice/slice.cc +38 -1
  217. data/src/core/lib/slice/slice_internal.h +1 -0
  218. data/src/core/lib/surface/call.cc +40 -41
  219. data/src/core/lib/surface/completion_queue.cc +271 -14
  220. data/src/core/lib/surface/completion_queue.h +8 -0
  221. data/src/core/lib/surface/init.cc +2 -0
  222. data/src/core/lib/surface/server.cc +565 -632
  223. data/src/core/lib/surface/server.h +34 -12
  224. data/src/core/lib/surface/version.cc +2 -2
  225. data/src/core/lib/transport/transport.h +6 -0
  226. data/src/core/lib/uri/uri_parser.cc +8 -15
  227. data/src/core/plugin_registry/grpc_plugin_registry.cc +4 -0
  228. data/src/core/tsi/alts/handshaker/alts_handshaker_client.cc +23 -13
  229. data/src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc +2 -0
  230. data/src/core/tsi/alts/handshaker/transport_security_common_api.cc +2 -0
  231. data/src/core/tsi/ssl_transport_security.cc +102 -11
  232. data/src/core/tsi/ssl_transport_security.h +14 -2
  233. data/src/core/tsi/transport_security_interface.h +5 -0
  234. data/src/ruby/ext/grpc/extconf.rb +5 -2
  235. data/src/ruby/ext/grpc/rb_call.c +3 -2
  236. data/src/ruby/ext/grpc/rb_call.h +4 -0
  237. data/src/ruby/ext/grpc/rb_call_credentials.c +54 -10
  238. data/src/ruby/lib/grpc/generic/interceptors.rb +1 -1
  239. data/src/ruby/lib/grpc/version.rb +1 -1
  240. data/third_party/boringssl-with-bazel/err_data.c +89 -83
  241. data/third_party/boringssl-with-bazel/src/crypto/asn1/a_bitstr.c +3 -3
  242. data/third_party/boringssl-with-bazel/src/crypto/asn1/a_enum.c +3 -3
  243. data/third_party/boringssl-with-bazel/src/crypto/asn1/a_int.c +1 -1
  244. data/third_party/boringssl-with-bazel/src/crypto/asn1/a_object.c +3 -3
  245. data/third_party/boringssl-with-bazel/src/crypto/asn1/a_time.c +2 -2
  246. data/third_party/boringssl-with-bazel/src/crypto/asn1/a_type.c +1 -1
  247. data/third_party/boringssl-with-bazel/src/crypto/asn1/asn1_lib.c +1 -1
  248. data/third_party/boringssl-with-bazel/src/crypto/asn1/asn_pack.c +1 -1
  249. data/third_party/boringssl-with-bazel/src/crypto/asn1/f_enum.c +1 -1
  250. data/third_party/boringssl-with-bazel/src/crypto/asn1/f_int.c +1 -1
  251. data/third_party/boringssl-with-bazel/src/crypto/asn1/f_string.c +1 -1
  252. data/third_party/boringssl-with-bazel/src/crypto/cipher_extra/tls_cbc.c +1 -0
  253. data/third_party/boringssl-with-bazel/src/crypto/ec_extra/hash_to_curve.c +12 -52
  254. data/third_party/boringssl-with-bazel/src/crypto/ec_extra/internal.h +0 -22
  255. data/third_party/boringssl-with-bazel/src/crypto/evp/evp_asn1.c +143 -0
  256. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/aes/mode_wrappers.c +17 -1
  257. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/bn/internal.h +11 -1
  258. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/internal.h +2 -1
  259. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/p224-64.c +13 -11
  260. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/p256-x86_64.c +24 -23
  261. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/p256.c +20 -16
  262. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/simple_mul.c +2 -2
  263. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/util.c +3 -3
  264. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/self_check/self_check.c +62 -0
  265. data/third_party/boringssl-with-bazel/src/crypto/mem.c +29 -15
  266. data/third_party/boringssl-with-bazel/src/crypto/pkcs8/internal.h +7 -0
  267. data/third_party/boringssl-with-bazel/src/crypto/pkcs8/pkcs8_x509.c +36 -5
  268. data/third_party/boringssl-with-bazel/src/crypto/trust_token/internal.h +0 -29
  269. data/third_party/boringssl-with-bazel/src/crypto/trust_token/pmbtoken.c +116 -363
  270. data/third_party/boringssl-with-bazel/src/crypto/trust_token/trust_token.c +7 -45
  271. data/third_party/boringssl-with-bazel/src/crypto/x509/a_strex.c +4 -4
  272. data/third_party/boringssl-with-bazel/src/crypto/x509/algorithm.c +8 -0
  273. data/third_party/boringssl-with-bazel/src/crypto/x509/asn1_gen.c +4 -4
  274. data/third_party/boringssl-with-bazel/src/crypto/x509/x509.c +0 -67
  275. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_cmp.c +13 -6
  276. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_req.c +10 -0
  277. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_set.c +41 -0
  278. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_trs.c +4 -1
  279. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_vfy.c +28 -9
  280. data/third_party/boringssl-with-bazel/src/crypto/x509/x509cset.c +25 -0
  281. data/third_party/boringssl-with-bazel/src/crypto/x509/x_crl.c +35 -13
  282. data/third_party/boringssl-with-bazel/src/crypto/x509/x_pubkey.c +0 -154
  283. data/third_party/boringssl-with-bazel/src/crypto/x509/x_x509.c +28 -6
  284. data/third_party/boringssl-with-bazel/src/crypto/x509v3/internal.h +5 -0
  285. data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_purp.c +74 -35
  286. data/third_party/boringssl-with-bazel/src/include/openssl/aes.h +16 -4
  287. data/third_party/boringssl-with-bazel/src/include/openssl/asn1.h +22 -22
  288. data/third_party/boringssl-with-bazel/src/include/openssl/base.h +1 -1
  289. data/third_party/boringssl-with-bazel/src/include/openssl/evp.h +69 -0
  290. data/third_party/boringssl-with-bazel/src/include/openssl/ssl.h +33 -16
  291. data/third_party/boringssl-with-bazel/src/include/openssl/trust_token.h +1 -10
  292. data/third_party/boringssl-with-bazel/src/include/openssl/x509.h +789 -715
  293. data/third_party/boringssl-with-bazel/src/ssl/handoff.cc +3 -3
  294. data/third_party/boringssl-with-bazel/src/ssl/handshake.cc +9 -2
  295. data/third_party/boringssl-with-bazel/src/ssl/handshake_client.cc +2 -2
  296. data/third_party/boringssl-with-bazel/src/ssl/handshake_server.cc +9 -0
  297. data/third_party/boringssl-with-bazel/src/ssl/internal.h +17 -14
  298. data/third_party/boringssl-with-bazel/src/ssl/ssl_asn1.cc +7 -7
  299. data/third_party/boringssl-with-bazel/src/ssl/ssl_lib.cc +28 -0
  300. data/third_party/boringssl-with-bazel/src/ssl/ssl_session.cc +4 -24
  301. data/third_party/boringssl-with-bazel/src/ssl/ssl_versions.cc +5 -5
  302. data/third_party/boringssl-with-bazel/src/ssl/t1_enc.cc +45 -24
  303. data/third_party/boringssl-with-bazel/src/ssl/tls13_client.cc +31 -21
  304. data/third_party/boringssl-with-bazel/src/ssl/tls13_server.cc +12 -9
  305. data/third_party/upb/upb/decode.c +467 -504
  306. data/third_party/upb/upb/encode.c +163 -121
  307. data/third_party/upb/upb/msg.c +130 -64
  308. data/third_party/upb/upb/msg.h +418 -14
  309. data/third_party/upb/upb/port_def.inc +35 -6
  310. data/third_party/upb/upb/port_undef.inc +8 -1
  311. data/third_party/upb/upb/table.c +53 -75
  312. data/third_party/upb/upb/table.int.h +11 -43
  313. data/third_party/upb/upb/upb.c +148 -124
  314. data/third_party/upb/upb/upb.h +65 -147
  315. data/third_party/upb/upb/upb.hpp +86 -0
  316. metadata +40 -37
  317. data/third_party/upb/upb/generated_util.h +0 -105
@@ -139,6 +139,9 @@ typedef enum {
139
139
  */
140
140
  typedef enum { UDS = 0, LOCAL_TCP } grpc_local_connect_type;
141
141
 
142
+ /** The TLS versions that are supported by the SSL stack. **/
143
+ typedef enum { TLS1_2, TLS1_3 } grpc_tls_version;
144
+
142
145
  #ifdef __cplusplus
143
146
  }
144
147
  #endif
@@ -203,18 +203,18 @@ typedef struct {
203
203
  /** Should BDP probing be performed? */
204
204
  #define GRPC_ARG_HTTP2_BDP_PROBE "grpc.http2.bdp_probe"
205
205
  /** Minimum time between sending successive ping frames without receiving any
206
- data/header/window_update frame, Int valued, milliseconds. */
206
+ data/header frame, Int valued, milliseconds. */
207
207
  #define GRPC_ARG_HTTP2_MIN_SENT_PING_INTERVAL_WITHOUT_DATA_MS \
208
208
  "grpc.http2.min_time_between_pings_ms"
209
209
  /** Minimum allowed time between a server receiving successive ping frames
210
- without sending any data/header/window_update frame. Int valued, milliseconds
210
+ without sending any data/header frame. Int valued, milliseconds
211
211
  */
212
212
  #define GRPC_ARG_HTTP2_MIN_RECV_PING_INTERVAL_WITHOUT_DATA_MS \
213
213
  "grpc.http2.min_ping_interval_without_data_ms"
214
214
  /** Channel arg to override the http2 :scheme header */
215
215
  #define GRPC_ARG_HTTP2_SCHEME "grpc.http2_scheme"
216
216
  /** How many pings can we send before needing to send a
217
- data/header/window_update frame? (0 indicates that an infinite number of
217
+ data/header frame? (0 indicates that an infinite number of
218
218
  pings can be sent without sending a data frame or header frame) */
219
219
  #define GRPC_ARG_HTTP2_MAX_PINGS_WITHOUT_DATA \
220
220
  "grpc.http2.max_pings_without_data"
@@ -674,8 +674,10 @@ typedef struct grpc_op {
674
674
  const char** error_string;
675
675
  } recv_status_on_client;
676
676
  struct grpc_op_recv_close_on_server {
677
- /** out argument, set to 1 if the call failed in any way (seen as a
678
- cancellation on the server), or 0 if the call succeeded */
677
+ /** out argument, set to 1 if the call failed at the server for
678
+ a reason other than a non-OK status (cancel, deadline
679
+ exceeded, network failure, etc.), 0 otherwise (RPC processing ran to
680
+ completion and was able to provide any status from the server) */
679
681
  int* cancelled;
680
682
  } recv_close_on_server;
681
683
  } data;
@@ -27,13 +27,6 @@
27
27
  * - some syscalls to be made directly
28
28
  */
29
29
 
30
- /*
31
- * Defines GRPC_USE_ABSL to use Abseil Common Libraries (C++)
32
- */
33
- #ifndef GRPC_USE_ABSL
34
- #define GRPC_USE_ABSL 1
35
- #endif
36
-
37
30
  /*
38
31
  * Defines GPR_ABSEIL_SYNC to use synchronization features from Abseil
39
32
  */
@@ -112,31 +105,6 @@
112
105
  #define GPR_WINDOWS_ATOMIC 1
113
106
  #define GPR_MSVC_TLS 1
114
107
  #endif
115
- #elif defined(GPR_MANYLINUX1)
116
- // TODO(atash): manylinux1 is just another __linux__ but with ancient
117
- // libraries; it should be integrated with the `__linux__` definitions below.
118
- #define GPR_PLATFORM_STRING "manylinux"
119
- #define GPR_POSIX_CRASH_HANDLER 1
120
- #define GPR_CPU_POSIX 1
121
- #define GPR_GCC_ATOMIC 1
122
- #define GPR_GCC_TLS 1
123
- #define GPR_LINUX 1
124
- #define GPR_LINUX_LOG 1
125
- #define GPR_SUPPORT_CHANNELS_FROM_FD 1
126
- #define GPR_LINUX_ENV 1
127
- #define GPR_POSIX_TMPFILE 1
128
- #define GPR_POSIX_STRING 1
129
- #define GPR_POSIX_SUBPROCESS 1
130
- #define GPR_POSIX_SYNC 1
131
- #define GPR_POSIX_TIME 1
132
- #define GPR_HAS_PTHREAD_H 1
133
- #define GPR_GETPID_IN_UNISTD_H 1
134
- #ifdef _LP64
135
- #define GPR_ARCH_64 1
136
- #else /* _LP64 */
137
- #define GPR_ARCH_32 1
138
- #endif /* _LP64 */
139
- #include <linux/version.h>
140
108
  #elif defined(ANDROID) || defined(__ANDROID__)
141
109
  #define GPR_PLATFORM_STRING "android"
142
110
  #define GPR_ANDROID 1
@@ -21,6 +21,7 @@
21
21
  #include "absl/strings/string_view.h"
22
22
 
23
23
  #include "udpa/data/orca/v1/orca_load_report.upb.h"
24
+ #include "upb/upb.hpp"
24
25
 
25
26
  #include "src/core/lib/gprpp/map.h"
26
27
 
@@ -31,17 +32,19 @@ namespace {
31
32
  template <typename EntryType>
32
33
  std::map<absl::string_view, double, StringLess> ParseMap(
33
34
  udpa_data_orca_v1_OrcaLoadReport* msg,
34
- EntryType** (*entry_func)(udpa_data_orca_v1_OrcaLoadReport*, size_t*),
35
+ const EntryType* (*entry_func)(const udpa_data_orca_v1_OrcaLoadReport*,
36
+ size_t*),
35
37
  upb_strview (*key_func)(const EntryType*),
36
38
  double (*value_func)(const EntryType*), Arena* arena) {
37
39
  std::map<absl::string_view, double, StringLess> result;
38
- size_t size;
39
- const auto* const* entries = entry_func(msg, &size);
40
- for (size_t i = 0; i < size; ++i) {
41
- upb_strview key_view = key_func(entries[i]);
42
- char* key = static_cast<char*>(arena->Alloc(key_view.size + 1));
40
+ size_t i = UPB_MAP_BEGIN;
41
+ while (true) {
42
+ const auto* entry = entry_func(msg, &i);
43
+ if (entry == nullptr) break;
44
+ upb_strview key_view = key_func(entry);
45
+ char* key = static_cast<char*>(arena->Alloc(key_view.size));
43
46
  memcpy(key, key_view.data, key_view.size);
44
- result[absl::string_view(key, key_view.size)] = value_func(entries[i]);
47
+ result[absl::string_view(key, key_view.size)] = value_func(entry);
45
48
  }
46
49
  return result;
47
50
  }
@@ -67,12 +70,12 @@ const LoadBalancingPolicy::BackendMetricData* ParseBackendMetricData(
67
70
  udpa_data_orca_v1_OrcaLoadReport_rps(msg);
68
71
  backend_metric_data->request_cost =
69
72
  ParseMap<udpa_data_orca_v1_OrcaLoadReport_RequestCostEntry>(
70
- msg, udpa_data_orca_v1_OrcaLoadReport_mutable_request_cost,
73
+ msg, udpa_data_orca_v1_OrcaLoadReport_request_cost_next,
71
74
  udpa_data_orca_v1_OrcaLoadReport_RequestCostEntry_key,
72
75
  udpa_data_orca_v1_OrcaLoadReport_RequestCostEntry_value, arena);
73
76
  backend_metric_data->utilization =
74
77
  ParseMap<udpa_data_orca_v1_OrcaLoadReport_UtilizationEntry>(
75
- msg, udpa_data_orca_v1_OrcaLoadReport_mutable_utilization,
78
+ msg, udpa_data_orca_v1_OrcaLoadReport_utilization_next,
76
79
  udpa_data_orca_v1_OrcaLoadReport_UtilizationEntry_key,
77
80
  udpa_data_orca_v1_OrcaLoadReport_UtilizationEntry_value, arena);
78
81
  return backend_metric_data;
@@ -40,6 +40,7 @@
40
40
 
41
41
  #include "src/core/ext/filters/client_channel/backend_metric.h"
42
42
  #include "src/core/ext/filters/client_channel/backup_poller.h"
43
+ #include "src/core/ext/filters/client_channel/config_selector.h"
43
44
  #include "src/core/ext/filters/client_channel/global_subchannel_pool.h"
44
45
  #include "src/core/ext/filters/client_channel/http_connect_handshaker.h"
45
46
  #include "src/core/ext/filters/client_channel/lb_policy_registry.h"
@@ -149,12 +150,16 @@ class ChannelData {
149
150
  bool received_service_config_data() const {
150
151
  return received_service_config_data_;
151
152
  }
153
+ grpc_error* resolver_transient_failure_error() const {
154
+ return resolver_transient_failure_error_;
155
+ }
152
156
  RefCountedPtr<ServerRetryThrottleData> retry_throttle_data() const {
153
157
  return retry_throttle_data_;
154
158
  }
155
159
  RefCountedPtr<ServiceConfig> service_config() const {
156
160
  return service_config_;
157
161
  }
162
+ ConfigSelector* config_selector() const { return config_selector_.get(); }
158
163
  WorkSerializer* work_serializer() const { return work_serializer_.get(); }
159
164
 
160
165
  RefCountedPtr<ConnectedSubchannel> GetConnectedSubchannelInDataPlane(
@@ -166,29 +171,14 @@ class ChannelData {
166
171
  grpc_connectivity_state* state,
167
172
  grpc_closure* on_complete,
168
173
  grpc_closure* watcher_timer_init) {
169
- auto* watcher = new ExternalConnectivityWatcher(
170
- this, pollent, state, on_complete, watcher_timer_init);
171
- {
172
- MutexLock lock(&external_watchers_mu_);
173
- // Will be deleted when the watch is complete.
174
- GPR_ASSERT(external_watchers_[on_complete] == nullptr);
175
- external_watchers_[on_complete] = watcher;
176
- }
177
- watcher->Start();
174
+ new ExternalConnectivityWatcher(this, pollent, state, on_complete,
175
+ watcher_timer_init);
178
176
  }
179
177
 
180
178
  void RemoveExternalConnectivityWatcher(grpc_closure* on_complete,
181
179
  bool cancel) {
182
- ExternalConnectivityWatcher* watcher = nullptr;
183
- {
184
- MutexLock lock(&external_watchers_mu_);
185
- auto it = external_watchers_.find(on_complete);
186
- if (it != external_watchers_.end()) {
187
- watcher = it->second;
188
- external_watchers_.erase(it);
189
- }
190
- }
191
- if (watcher != nullptr && cancel) watcher->Cancel();
180
+ ExternalConnectivityWatcher::RemoveWatcherFromExternalWatchersMap(
181
+ this, on_complete, cancel);
192
182
  }
193
183
 
194
184
  int NumExternalConnectivityWatchers() const {
@@ -219,13 +209,18 @@ class ChannelData {
219
209
 
220
210
  ~ExternalConnectivityWatcher();
221
211
 
222
- void Start();
212
+ // Removes the watcher from the external_watchers_ map.
213
+ static void RemoveWatcherFromExternalWatchersMap(ChannelData* chand,
214
+ grpc_closure* on_complete,
215
+ bool cancel);
223
216
 
224
217
  void Notify(grpc_connectivity_state state) override;
225
218
 
226
219
  void Cancel();
227
220
 
228
221
  private:
222
+ // Adds the watcher to state_tracker_. Consumes the ref that is passed to it
223
+ // from Start().
229
224
  void AddWatcherLocked();
230
225
  void RemoveWatcherLocked();
231
226
 
@@ -238,6 +233,29 @@ class ChannelData {
238
233
  Atomic<bool> done_{false};
239
234
  };
240
235
 
236
+ class ChannelConfigHelper
237
+ : public ResolvingLoadBalancingPolicy::ChannelConfigHelper {
238
+ public:
239
+ explicit ChannelConfigHelper(ChannelData* chand) : chand_(chand) {}
240
+
241
+ ApplyServiceConfigResult ApplyServiceConfig(
242
+ const Resolver::Result& result) override;
243
+
244
+ void ApplyConfigSelector(
245
+ bool service_config_changed,
246
+ RefCountedPtr<ConfigSelector> config_selector) override;
247
+
248
+ void ResolverTransientFailure(grpc_error* error) override;
249
+
250
+ private:
251
+ static void ProcessLbPolicy(
252
+ const Resolver::Result& resolver_result,
253
+ const internal::ClientChannelGlobalParsedConfig* parsed_service_config,
254
+ RefCountedPtr<LoadBalancingPolicy::Config>* lb_policy_config);
255
+
256
+ ChannelData* chand_;
257
+ };
258
+
241
259
  ChannelData(grpc_channel_element_args* args, grpc_error** error);
242
260
  ~ChannelData();
243
261
 
@@ -245,30 +263,20 @@ class ChannelData {
245
263
  grpc_connectivity_state state, const char* reason,
246
264
  std::unique_ptr<LoadBalancingPolicy::SubchannelPicker> picker);
247
265
 
248
- void UpdateServiceConfigLocked(
249
- RefCountedPtr<ServerRetryThrottleData> retry_throttle_data,
250
- RefCountedPtr<ServiceConfig> service_config);
266
+ void UpdateServiceConfigInDataPlaneLocked(
267
+ bool service_config_changed,
268
+ RefCountedPtr<ConfigSelector> config_selector);
251
269
 
252
270
  void CreateResolvingLoadBalancingPolicyLocked();
253
271
 
254
272
  void DestroyResolvingLoadBalancingPolicyLocked();
255
273
 
256
- static bool ProcessResolverResultLocked(
257
- void* arg, const Resolver::Result& result,
258
- RefCountedPtr<LoadBalancingPolicy::Config>* lb_policy_config,
259
- grpc_error** service_config_error, bool* no_valid_service_config);
260
-
261
274
  grpc_error* DoPingLocked(grpc_transport_op* op);
262
275
 
263
276
  void StartTransportOpLocked(grpc_transport_op* op);
264
277
 
265
278
  void TryToConnectLocked();
266
279
 
267
- void ProcessLbPolicy(
268
- const Resolver::Result& resolver_result,
269
- const internal::ClientChannelGlobalParsedConfig* parsed_service_config,
270
- RefCountedPtr<LoadBalancingPolicy::Config>* lb_policy_config);
271
-
272
280
  //
273
281
  // Fields set at construction and never modified.
274
282
  //
@@ -282,6 +290,7 @@ class ChannelData {
282
290
  grpc_core::UniquePtr<char> server_name_;
283
291
  grpc_core::UniquePtr<char> target_uri_;
284
292
  channelz::ChannelNode* channelz_node_;
293
+ ChannelConfigHelper channel_config_helper_;
285
294
 
286
295
  //
287
296
  // Fields used in the data plane. Guarded by data_plane_mu.
@@ -290,9 +299,11 @@ class ChannelData {
290
299
  std::unique_ptr<LoadBalancingPolicy::SubchannelPicker> picker_;
291
300
  QueuedPick* queued_picks_ = nullptr; // Linked list of queued picks.
292
301
  // Data from service config.
302
+ grpc_error* resolver_transient_failure_error_ = GRPC_ERROR_NONE;
293
303
  bool received_service_config_data_ = false;
294
304
  RefCountedPtr<ServerRetryThrottleData> retry_throttle_data_;
295
305
  RefCountedPtr<ServiceConfig> service_config_;
306
+ RefCountedPtr<ConfigSelector> config_selector_;
296
307
 
297
308
  //
298
309
  // Fields used in the control plane. Guarded by work_serializer.
@@ -304,6 +315,7 @@ class ChannelData {
304
315
  ConnectivityStateTracker state_tracker_;
305
316
  grpc_core::UniquePtr<char> health_check_service_name_;
306
317
  RefCountedPtr<ServiceConfig> saved_service_config_;
318
+ RefCountedPtr<ConfigSelector> saved_config_selector_;
307
319
  bool received_first_resolver_result_ = false;
308
320
  // The number of SubchannelWrapper instances referencing a given Subchannel.
309
321
  std::map<Subchannel*, int> subchannel_refcount_map_;
@@ -336,7 +348,8 @@ class ChannelData {
336
348
  // synchronously via grpc_channel_num_external_connectivity_watchers().
337
349
  //
338
350
  mutable Mutex external_watchers_mu_;
339
- std::map<grpc_closure*, ExternalConnectivityWatcher*> external_watchers_;
351
+ std::map<grpc_closure*, RefCountedPtr<ExternalConnectivityWatcher>>
352
+ external_watchers_;
340
353
  };
341
354
 
342
355
  //
@@ -356,9 +369,6 @@ class CallData {
356
369
 
357
370
  RefCountedPtr<SubchannelCall> subchannel_call() { return subchannel_call_; }
358
371
 
359
- // Invoked by channel for queued picks once resolver results are available.
360
- void MaybeApplyServiceConfigToCallLocked(grpc_call_element* elem);
361
-
362
372
  // Invoked by channel for queued picks when the picker is updated.
363
373
  static void PickSubchannel(void* arg, grpc_error* error);
364
374
 
@@ -392,7 +402,8 @@ class CallData {
392
402
  iterator begin() const override {
393
403
  static_assert(sizeof(grpc_linked_mdelem*) <= sizeof(intptr_t),
394
404
  "iterator size too large");
395
- return iterator(this, reinterpret_cast<intptr_t>(batch_->list.head));
405
+ return iterator(
406
+ this, reinterpret_cast<intptr_t>(MaybeSkipEntry(batch_->list.head)));
396
407
  }
397
408
  iterator end() const override {
398
409
  static_assert(sizeof(grpc_linked_mdelem*) <= sizeof(intptr_t),
@@ -409,11 +420,19 @@ class CallData {
409
420
  }
410
421
 
411
422
  private:
423
+ grpc_linked_mdelem* MaybeSkipEntry(grpc_linked_mdelem* entry) const {
424
+ if (entry != nullptr && batch_->idx.named.path == entry) {
425
+ return entry->next;
426
+ }
427
+ return entry;
428
+ }
429
+
412
430
  intptr_t IteratorHandleNext(intptr_t handle) const override {
413
431
  grpc_linked_mdelem* linked_mdelem =
414
432
  reinterpret_cast<grpc_linked_mdelem*>(handle);
415
- return reinterpret_cast<intptr_t>(linked_mdelem->next);
433
+ return reinterpret_cast<intptr_t>(MaybeSkipEntry(linked_mdelem->next));
416
434
  }
435
+
417
436
  std::pair<absl::string_view, absl::string_view> IteratorHandleGet(
418
437
  intptr_t handle) const override {
419
438
  grpc_linked_mdelem* linked_mdelem =
@@ -746,13 +765,17 @@ class CallData {
746
765
  void CreateSubchannelCall(grpc_call_element* elem);
747
766
  // Invoked when a pick is completed, on both success or failure.
748
767
  static void PickDone(void* arg, grpc_error* error);
749
- // Removes the call from the channel's list of queued picks.
750
- void RemoveCallFromQueuedPicksLocked(grpc_call_element* elem);
751
- // Adds the call to the channel's list of queued picks.
752
- void AddCallToQueuedPicksLocked(grpc_call_element* elem);
768
+ // Removes the call from the channel's list of queued picks if present.
769
+ void MaybeRemoveCallFromQueuedPicksLocked(grpc_call_element* elem);
770
+ // Adds the call to the channel's list of queued picks if not already present.
771
+ void MaybeAddCallToQueuedPicksLocked(grpc_call_element* elem);
753
772
  // Applies service config to the call. Must be invoked once we know
754
773
  // that the resolver has returned results to the channel.
755
- void ApplyServiceConfigToCallLocked(grpc_call_element* elem);
774
+ // If an error is returned, the error indicates the status with which
775
+ // the call should be failed.
776
+ grpc_error* ApplyServiceConfigToCallLocked(
777
+ grpc_call_element* elem, grpc_metadata_batch* initial_metadata);
778
+ void MaybeInvokeConfigSelectorCommitCallback();
756
779
 
757
780
  // State for handling deadlines.
758
781
  // The code in deadline_filter.c requires this to be the first field.
@@ -773,6 +796,7 @@ class CallData {
773
796
  RefCountedPtr<ServerRetryThrottleData> retry_throttle_data_;
774
797
  const ClientChannelMethodParsedConfig* method_params_ = nullptr;
775
798
  std::map<const char*, absl::string_view> call_attributes_;
799
+ std::function<void()> on_call_committed_;
776
800
 
777
801
  RefCountedPtr<SubchannelCall> subchannel_call_;
778
802
 
@@ -1145,6 +1169,21 @@ ChannelData::ExternalConnectivityWatcher::ExternalConnectivityWatcher(
1145
1169
  grpc_polling_entity_add_to_pollset_set(&pollent_,
1146
1170
  chand_->interested_parties_);
1147
1171
  GRPC_CHANNEL_STACK_REF(chand_->owning_stack_, "ExternalConnectivityWatcher");
1172
+ {
1173
+ MutexLock lock(&chand_->external_watchers_mu_);
1174
+ // Will be deleted when the watch is complete.
1175
+ GPR_ASSERT(chand->external_watchers_[on_complete] == nullptr);
1176
+ // Store a ref to the watcher in the external_watchers_ map.
1177
+ chand->external_watchers_[on_complete] =
1178
+ Ref(DEBUG_LOCATION, "AddWatcherToExternalWatchersMapLocked");
1179
+ }
1180
+ // Pass the ref from creating the object to Start().
1181
+ chand_->work_serializer_->Run(
1182
+ [this]() {
1183
+ // The ref is passed to AddWatcherLocked().
1184
+ AddWatcherLocked();
1185
+ },
1186
+ DEBUG_LOCATION);
1148
1187
  }
1149
1188
 
1150
1189
  ChannelData::ExternalConnectivityWatcher::~ExternalConnectivityWatcher() {
@@ -1154,9 +1193,22 @@ ChannelData::ExternalConnectivityWatcher::~ExternalConnectivityWatcher() {
1154
1193
  "ExternalConnectivityWatcher");
1155
1194
  }
1156
1195
 
1157
- void ChannelData::ExternalConnectivityWatcher::Start() {
1158
- chand_->work_serializer_->Run([this]() { AddWatcherLocked(); },
1159
- DEBUG_LOCATION);
1196
+ void ChannelData::ExternalConnectivityWatcher::
1197
+ RemoveWatcherFromExternalWatchersMap(ChannelData* chand,
1198
+ grpc_closure* on_complete,
1199
+ bool cancel) {
1200
+ RefCountedPtr<ExternalConnectivityWatcher> watcher;
1201
+ {
1202
+ MutexLock lock(&chand->external_watchers_mu_);
1203
+ auto it = chand->external_watchers_.find(on_complete);
1204
+ if (it != chand->external_watchers_.end()) {
1205
+ watcher = std::move(it->second);
1206
+ chand->external_watchers_.erase(it);
1207
+ }
1208
+ }
1209
+ // watcher->Cancel() will hop into the WorkSerializer, so we have to unlock
1210
+ // the mutex before calling it.
1211
+ if (watcher != nullptr && cancel) watcher->Cancel();
1160
1212
  }
1161
1213
 
1162
1214
  void ChannelData::ExternalConnectivityWatcher::Notify(
@@ -1194,7 +1246,7 @@ void ChannelData::ExternalConnectivityWatcher::Cancel() {
1194
1246
 
1195
1247
  void ChannelData::ExternalConnectivityWatcher::AddWatcherLocked() {
1196
1248
  Closure::Run(DEBUG_LOCATION, watcher_timer_init_, GRPC_ERROR_NONE);
1197
- // Add new watcher.
1249
+ // Add new watcher. Pass the ref of the object from creation to OrphanablePtr.
1198
1250
  chand_->state_tracker_.AddWatcher(
1199
1251
  initial_state_, OrphanablePtr<ConnectivityStateWatcherInterface>(this));
1200
1252
  }
@@ -1339,6 +1391,180 @@ class ChannelData::ClientChannelControlHelper
1339
1391
  ChannelData* chand_;
1340
1392
  };
1341
1393
 
1394
+ //
1395
+ // ChannelData::ChannelConfigHelper
1396
+ //
1397
+
1398
+ // Synchronous callback from ResolvingLoadBalancingPolicy to process a
1399
+ // resolver result update.
1400
+ ChannelData::ChannelConfigHelper::ApplyServiceConfigResult
1401
+ ChannelData::ChannelConfigHelper::ApplyServiceConfig(
1402
+ const Resolver::Result& result) {
1403
+ ApplyServiceConfigResult service_config_result;
1404
+ RefCountedPtr<ServiceConfig> service_config;
1405
+ // If resolver did not return a service config or returned an invalid service
1406
+ // config, we need a fallback service config.
1407
+ if (result.service_config_error != GRPC_ERROR_NONE) {
1408
+ // If the service config was invalid, then fallback to the saved service
1409
+ // config. If there is no saved config either, use the default service
1410
+ // config.
1411
+ if (chand_->saved_service_config_ != nullptr) {
1412
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_client_channel_routing_trace)) {
1413
+ gpr_log(GPR_INFO,
1414
+ "chand=%p: resolver returned invalid service config. "
1415
+ "Continuing to use previous service config.",
1416
+ chand_);
1417
+ }
1418
+ service_config = chand_->saved_service_config_;
1419
+ } else if (chand_->default_service_config_ != nullptr) {
1420
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_client_channel_routing_trace)) {
1421
+ gpr_log(GPR_INFO,
1422
+ "chand=%p: resolver returned invalid service config. Using "
1423
+ "default service config provided by client API.",
1424
+ chand_);
1425
+ }
1426
+ service_config = chand_->default_service_config_;
1427
+ }
1428
+ } else if (result.service_config == nullptr) {
1429
+ if (chand_->default_service_config_ != nullptr) {
1430
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_client_channel_routing_trace)) {
1431
+ gpr_log(GPR_INFO,
1432
+ "chand=%p: resolver returned no service config. Using default "
1433
+ "service config provided by client API.",
1434
+ chand_);
1435
+ }
1436
+ service_config = chand_->default_service_config_;
1437
+ }
1438
+ } else {
1439
+ service_config = result.service_config;
1440
+ }
1441
+ service_config_result.service_config_error =
1442
+ GRPC_ERROR_REF(result.service_config_error);
1443
+ if (service_config == nullptr &&
1444
+ result.service_config_error != GRPC_ERROR_NONE) {
1445
+ service_config_result.no_valid_service_config = true;
1446
+ return service_config_result;
1447
+ }
1448
+ // Process service config.
1449
+ grpc_core::UniquePtr<char> service_config_json;
1450
+ const internal::ClientChannelGlobalParsedConfig* parsed_service_config =
1451
+ nullptr;
1452
+ if (service_config != nullptr) {
1453
+ parsed_service_config =
1454
+ static_cast<const internal::ClientChannelGlobalParsedConfig*>(
1455
+ service_config->GetGlobalParsedConfig(
1456
+ internal::ClientChannelServiceConfigParser::ParserIndex()));
1457
+ }
1458
+ // Check if the config has changed.
1459
+ service_config_result.service_config_changed =
1460
+ ((service_config == nullptr) !=
1461
+ (chand_->saved_service_config_ == nullptr)) ||
1462
+ (service_config != nullptr &&
1463
+ service_config->json_string() !=
1464
+ chand_->saved_service_config_->json_string());
1465
+ if (service_config_result.service_config_changed) {
1466
+ service_config_json.reset(gpr_strdup(
1467
+ service_config != nullptr ? service_config->json_string().c_str()
1468
+ : ""));
1469
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_client_channel_routing_trace)) {
1470
+ gpr_log(GPR_INFO,
1471
+ "chand=%p: resolver returned updated service config: \"%s\"",
1472
+ chand_, service_config_json.get());
1473
+ }
1474
+ // Save health check service name.
1475
+ if (service_config != nullptr) {
1476
+ chand_->health_check_service_name_.reset(
1477
+ gpr_strdup(parsed_service_config->health_check_service_name()));
1478
+ } else {
1479
+ chand_->health_check_service_name_.reset();
1480
+ }
1481
+ // Update health check service name used by existing subchannel wrappers.
1482
+ for (auto* subchannel_wrapper : chand_->subchannel_wrappers_) {
1483
+ subchannel_wrapper->UpdateHealthCheckServiceName(
1484
+ grpc_core::UniquePtr<char>(
1485
+ gpr_strdup(chand_->health_check_service_name_.get())));
1486
+ }
1487
+ // Save service config.
1488
+ chand_->saved_service_config_ = std::move(service_config);
1489
+ }
1490
+ // Find LB policy config.
1491
+ ProcessLbPolicy(result, parsed_service_config,
1492
+ &service_config_result.lb_policy_config);
1493
+ grpc_core::UniquePtr<char> lb_policy_name(
1494
+ gpr_strdup((service_config_result.lb_policy_config)->name()));
1495
+ // Swap out the data used by GetChannelInfo().
1496
+ {
1497
+ MutexLock lock(&chand_->info_mu_);
1498
+ chand_->info_lb_policy_name_ = std::move(lb_policy_name);
1499
+ if (service_config_json != nullptr) {
1500
+ chand_->info_service_config_json_ = std::move(service_config_json);
1501
+ }
1502
+ }
1503
+ // Return results.
1504
+ return service_config_result;
1505
+ }
1506
+
1507
+ void ChannelData::ChannelConfigHelper::ApplyConfigSelector(
1508
+ bool service_config_changed,
1509
+ RefCountedPtr<ConfigSelector> config_selector) {
1510
+ chand_->UpdateServiceConfigInDataPlaneLocked(service_config_changed,
1511
+ std::move(config_selector));
1512
+ }
1513
+
1514
+ void ChannelData::ChannelConfigHelper::ResolverTransientFailure(
1515
+ grpc_error* error) {
1516
+ MutexLock lock(&chand_->data_plane_mu_);
1517
+ GRPC_ERROR_UNREF(chand_->resolver_transient_failure_error_);
1518
+ chand_->resolver_transient_failure_error_ = error;
1519
+ }
1520
+
1521
+ void ChannelData::ChannelConfigHelper::ProcessLbPolicy(
1522
+ const Resolver::Result& resolver_result,
1523
+ const internal::ClientChannelGlobalParsedConfig* parsed_service_config,
1524
+ RefCountedPtr<LoadBalancingPolicy::Config>* lb_policy_config) {
1525
+ // Prefer the LB policy config found in the service config.
1526
+ if (parsed_service_config != nullptr &&
1527
+ parsed_service_config->parsed_lb_config() != nullptr) {
1528
+ *lb_policy_config = parsed_service_config->parsed_lb_config();
1529
+ return;
1530
+ }
1531
+ // Try the deprecated LB policy name from the service config.
1532
+ // If not, try the setting from channel args.
1533
+ const char* policy_name = nullptr;
1534
+ if (parsed_service_config != nullptr &&
1535
+ !parsed_service_config->parsed_deprecated_lb_policy().empty()) {
1536
+ policy_name = parsed_service_config->parsed_deprecated_lb_policy().c_str();
1537
+ } else {
1538
+ const grpc_arg* channel_arg =
1539
+ grpc_channel_args_find(resolver_result.args, GRPC_ARG_LB_POLICY_NAME);
1540
+ policy_name = grpc_channel_arg_get_string(channel_arg);
1541
+ }
1542
+ // Use pick_first if nothing was specified and we didn't select grpclb
1543
+ // above.
1544
+ if (policy_name == nullptr) policy_name = "pick_first";
1545
+ // Now that we have the policy name, construct an empty config for it.
1546
+ Json config_json = Json::Array{Json::Object{
1547
+ {policy_name, Json::Object{}},
1548
+ }};
1549
+ grpc_error* parse_error = GRPC_ERROR_NONE;
1550
+ *lb_policy_config = LoadBalancingPolicyRegistry::ParseLoadBalancingConfig(
1551
+ config_json, &parse_error);
1552
+ // The policy name came from one of three places:
1553
+ // - The deprecated loadBalancingPolicy field in the service config,
1554
+ // in which case the code in ClientChannelServiceConfigParser
1555
+ // already verified that the policy does not require a config.
1556
+ // - One of the hard-coded values here, all of which are known to not
1557
+ // require a config.
1558
+ // - A channel arg, in which case the application did something that
1559
+ // is a misuse of our API.
1560
+ // In the first two cases, these assertions will always be true. In
1561
+ // the last case, this is probably fine for now.
1562
+ // TODO(roth): If the last case becomes a problem, add better error
1563
+ // handling here.
1564
+ GPR_ASSERT(*lb_policy_config != nullptr);
1565
+ GPR_ASSERT(parse_error == GRPC_ERROR_NONE);
1566
+ }
1567
+
1342
1568
  //
1343
1569
  // ChannelData implementation
1344
1570
  //
@@ -1397,6 +1623,7 @@ ChannelData::ChannelData(grpc_channel_element_args* args, grpc_error** error)
1397
1623
  client_channel_factory_(
1398
1624
  ClientChannelFactory::GetFromChannelArgs(args->channel_args)),
1399
1625
  channelz_node_(GetChannelzNode(args->channel_args)),
1626
+ channel_config_helper_(this),
1400
1627
  work_serializer_(std::make_shared<WorkSerializer>()),
1401
1628
  interested_parties_(grpc_pollset_set_create()),
1402
1629
  subchannel_pool_(GetSubchannelPool(args->channel_args)),
@@ -1465,6 +1692,7 @@ ChannelData::~ChannelData() {
1465
1692
  }
1466
1693
  DestroyResolvingLoadBalancingPolicyLocked();
1467
1694
  grpc_channel_args_destroy(channel_args_);
1695
+ GRPC_ERROR_UNREF(resolver_transient_failure_error_);
1468
1696
  // Stop backup polling.
1469
1697
  grpc_client_channel_stop_backup_polling(interested_parties_);
1470
1698
  grpc_pollset_set_destroy(interested_parties_);
@@ -1479,6 +1707,7 @@ void ChannelData::UpdateStateAndPickerLocked(
1479
1707
  if (picker_ == nullptr) {
1480
1708
  health_check_service_name_.reset();
1481
1709
  saved_service_config_.reset();
1710
+ saved_config_selector_.reset();
1482
1711
  received_first_resolver_result_ = false;
1483
1712
  }
1484
1713
  // Update connectivity state.
@@ -1501,9 +1730,11 @@ void ChannelData::UpdateStateAndPickerLocked(
1501
1730
  // - refs to subchannel wrappers in the keys of pending_subchannel_updates_
1502
1731
  // - ref stored in retry_throttle_data_
1503
1732
  // - ref stored in service_config_
1733
+ // - ref stored in config_selector_
1504
1734
  // - ownership of the existing picker in picker_
1505
1735
  RefCountedPtr<ServerRetryThrottleData> retry_throttle_data_to_unref;
1506
1736
  RefCountedPtr<ServiceConfig> service_config_to_unref;
1737
+ RefCountedPtr<ConfigSelector> config_selector_to_unref;
1507
1738
  {
1508
1739
  MutexLock lock(&data_plane_mu_);
1509
1740
  // Handle subchannel updates.
@@ -1528,6 +1759,7 @@ void ChannelData::UpdateStateAndPickerLocked(
1528
1759
  // Note: We save the objects to unref until after the lock is released.
1529
1760
  retry_throttle_data_to_unref = std::move(retry_throttle_data_);
1530
1761
  service_config_to_unref = std::move(service_config_);
1762
+ config_selector_to_unref = std::move(config_selector_);
1531
1763
  }
1532
1764
  // Re-process queued picks.
1533
1765
  for (QueuedPick* pick = queued_picks_; pick != nullptr; pick = pick->next) {
@@ -1544,24 +1776,72 @@ void ChannelData::UpdateStateAndPickerLocked(
1544
1776
  pending_subchannel_updates_.clear();
1545
1777
  }
1546
1778
 
1547
- void ChannelData::UpdateServiceConfigLocked(
1548
- RefCountedPtr<ServerRetryThrottleData> retry_throttle_data,
1549
- RefCountedPtr<ServiceConfig> service_config) {
1779
+ void ChannelData::UpdateServiceConfigInDataPlaneLocked(
1780
+ bool service_config_changed,
1781
+ RefCountedPtr<ConfigSelector> config_selector) {
1782
+ // Check if ConfigSelector has changed.
1783
+ const bool config_selector_changed =
1784
+ saved_config_selector_ != config_selector;
1785
+ saved_config_selector_ = config_selector;
1786
+ // We want to set the service config at least once, even if the
1787
+ // resolver does not return a config, because that ensures that we
1788
+ // disable retries if they are not enabled in the service config.
1789
+ // TODO(roth): Consider removing the received_first_resolver_result_ check
1790
+ // when we implement transparent retries.
1791
+ if (!service_config_changed && !config_selector_changed &&
1792
+ received_first_resolver_result_) {
1793
+ return;
1794
+ }
1795
+ received_first_resolver_result_ = true;
1796
+ // Get retry throttle data from service config.
1797
+ RefCountedPtr<ServerRetryThrottleData> retry_throttle_data;
1798
+ if (saved_service_config_ != nullptr) {
1799
+ const internal::ClientChannelGlobalParsedConfig* parsed_service_config =
1800
+ static_cast<const internal::ClientChannelGlobalParsedConfig*>(
1801
+ saved_service_config_->GetGlobalParsedConfig(
1802
+ internal::ClientChannelServiceConfigParser::ParserIndex()));
1803
+ if (parsed_service_config != nullptr) {
1804
+ absl::optional<internal::ClientChannelGlobalParsedConfig::RetryThrottling>
1805
+ retry_throttle_config = parsed_service_config->retry_throttling();
1806
+ if (retry_throttle_config.has_value()) {
1807
+ retry_throttle_data =
1808
+ internal::ServerRetryThrottleMap::GetDataForServer(
1809
+ server_name_.get(),
1810
+ retry_throttle_config.value().max_milli_tokens,
1811
+ retry_throttle_config.value().milli_token_ratio);
1812
+ }
1813
+ }
1814
+ }
1815
+ // Create default config selector if not provided by resolver.
1816
+ if (config_selector == nullptr) {
1817
+ config_selector =
1818
+ MakeRefCounted<DefaultConfigSelector>(saved_service_config_);
1819
+ }
1550
1820
  // Grab data plane lock to update service config.
1551
1821
  //
1552
1822
  // We defer unreffing the old values (and deallocating memory) until
1553
1823
  // after releasing the lock to keep the critical section small.
1824
+ RefCountedPtr<ServiceConfig> service_config_to_unref = saved_service_config_;
1825
+ RefCountedPtr<ConfigSelector> config_selector_to_unref =
1826
+ std::move(config_selector);
1554
1827
  {
1555
1828
  MutexLock lock(&data_plane_mu_);
1829
+ GRPC_ERROR_UNREF(resolver_transient_failure_error_);
1830
+ resolver_transient_failure_error_ = GRPC_ERROR_NONE;
1556
1831
  // Update service config.
1557
1832
  received_service_config_data_ = true;
1558
1833
  // Old values will be unreffed after lock is released.
1559
1834
  retry_throttle_data_.swap(retry_throttle_data);
1560
- service_config_.swap(service_config);
1561
- // Apply service config to queued picks.
1835
+ service_config_.swap(service_config_to_unref);
1836
+ config_selector_.swap(config_selector_to_unref);
1837
+ // Re-process queued picks.
1562
1838
  for (QueuedPick* pick = queued_picks_; pick != nullptr; pick = pick->next) {
1563
- CallData* calld = static_cast<CallData*>(pick->elem->call_data);
1564
- calld->MaybeApplyServiceConfigToCallLocked(pick->elem);
1839
+ grpc_call_element* elem = pick->elem;
1840
+ CallData* calld = static_cast<CallData*>(elem->call_data);
1841
+ grpc_error* error = GRPC_ERROR_NONE;
1842
+ if (calld->PickSubchannelLocked(elem, &error)) {
1843
+ calld->AsyncPickDone(elem, error);
1844
+ }
1565
1845
  }
1566
1846
  }
1567
1847
  // Old values will be unreffed after lock is released when they go out
@@ -1578,7 +1858,7 @@ void ChannelData::CreateResolvingLoadBalancingPolicyLocked() {
1578
1858
  grpc_core::UniquePtr<char> target_uri(gpr_strdup(target_uri_.get()));
1579
1859
  resolving_lb_policy_.reset(new ResolvingLoadBalancingPolicy(
1580
1860
  std::move(lb_args), &grpc_client_channel_routing_trace,
1581
- std::move(target_uri), ProcessResolverResultLocked, this));
1861
+ std::move(target_uri), &channel_config_helper_));
1582
1862
  grpc_pollset_set_add_pollset_set(resolving_lb_policy_->interested_parties(),
1583
1863
  interested_parties_);
1584
1864
  if (GRPC_TRACE_FLAG_ENABLED(grpc_client_channel_routing_trace)) {
@@ -1595,180 +1875,6 @@ void ChannelData::DestroyResolvingLoadBalancingPolicyLocked() {
1595
1875
  }
1596
1876
  }
1597
1877
 
1598
- void ChannelData::ProcessLbPolicy(
1599
- const Resolver::Result& resolver_result,
1600
- const internal::ClientChannelGlobalParsedConfig* parsed_service_config,
1601
- RefCountedPtr<LoadBalancingPolicy::Config>* lb_policy_config) {
1602
- // Prefer the LB policy config found in the service config.
1603
- if (parsed_service_config != nullptr &&
1604
- parsed_service_config->parsed_lb_config() != nullptr) {
1605
- *lb_policy_config = parsed_service_config->parsed_lb_config();
1606
- return;
1607
- }
1608
- // Try the deprecated LB policy name from the service config.
1609
- // If not, try the setting from channel args.
1610
- const char* policy_name = nullptr;
1611
- if (parsed_service_config != nullptr &&
1612
- !parsed_service_config->parsed_deprecated_lb_policy().empty()) {
1613
- policy_name = parsed_service_config->parsed_deprecated_lb_policy().c_str();
1614
- } else {
1615
- const grpc_arg* channel_arg =
1616
- grpc_channel_args_find(resolver_result.args, GRPC_ARG_LB_POLICY_NAME);
1617
- policy_name = grpc_channel_arg_get_string(channel_arg);
1618
- }
1619
- // Use pick_first if nothing was specified and we didn't select grpclb
1620
- // above.
1621
- if (policy_name == nullptr) policy_name = "pick_first";
1622
- // Now that we have the policy name, construct an empty config for it.
1623
- Json config_json = Json::Array{Json::Object{
1624
- {policy_name, Json::Object{}},
1625
- }};
1626
- grpc_error* parse_error = GRPC_ERROR_NONE;
1627
- *lb_policy_config = LoadBalancingPolicyRegistry::ParseLoadBalancingConfig(
1628
- config_json, &parse_error);
1629
- // The policy name came from one of three places:
1630
- // - The deprecated loadBalancingPolicy field in the service config,
1631
- // in which case the code in ClientChannelServiceConfigParser
1632
- // already verified that the policy does not require a config.
1633
- // - One of the hard-coded values here, all of which are known to not
1634
- // require a config.
1635
- // - A channel arg, in which case the application did something that
1636
- // is a misuse of our API.
1637
- // In the first two cases, these assertions will always be true. In
1638
- // the last case, this is probably fine for now.
1639
- // TODO(roth): If the last case becomes a problem, add better error
1640
- // handling here.
1641
- GPR_ASSERT(*lb_policy_config != nullptr);
1642
- GPR_ASSERT(parse_error == GRPC_ERROR_NONE);
1643
- }
1644
-
1645
- // Synchronous callback from ResolvingLoadBalancingPolicy to process a
1646
- // resolver result update.
1647
- bool ChannelData::ProcessResolverResultLocked(
1648
- void* arg, const Resolver::Result& result,
1649
- RefCountedPtr<LoadBalancingPolicy::Config>* lb_policy_config,
1650
- grpc_error** service_config_error, bool* no_valid_service_config) {
1651
- ChannelData* chand = static_cast<ChannelData*>(arg);
1652
- RefCountedPtr<ServiceConfig> service_config;
1653
- // If resolver did not return a service config or returned an invalid service
1654
- // config, we need a fallback service config.
1655
- if (result.service_config_error != GRPC_ERROR_NONE) {
1656
- // If the service config was invalid, then fallback to the saved service
1657
- // config. If there is no saved config either, use the default service
1658
- // config.
1659
- if (chand->saved_service_config_ != nullptr) {
1660
- if (GRPC_TRACE_FLAG_ENABLED(grpc_client_channel_routing_trace)) {
1661
- gpr_log(GPR_INFO,
1662
- "chand=%p: resolver returned invalid service config. "
1663
- "Continuing to use previous service config.",
1664
- chand);
1665
- }
1666
- service_config = chand->saved_service_config_;
1667
- } else if (chand->default_service_config_ != nullptr) {
1668
- if (GRPC_TRACE_FLAG_ENABLED(grpc_client_channel_routing_trace)) {
1669
- gpr_log(GPR_INFO,
1670
- "chand=%p: resolver returned invalid service config. Using "
1671
- "default service config provided by client API.",
1672
- chand);
1673
- }
1674
- service_config = chand->default_service_config_;
1675
- }
1676
- } else if (result.service_config == nullptr) {
1677
- if (chand->default_service_config_ != nullptr) {
1678
- if (GRPC_TRACE_FLAG_ENABLED(grpc_client_channel_routing_trace)) {
1679
- gpr_log(GPR_INFO,
1680
- "chand=%p: resolver returned no service config. Using default "
1681
- "service config provided by client API.",
1682
- chand);
1683
- }
1684
- service_config = chand->default_service_config_;
1685
- }
1686
- } else {
1687
- service_config = result.service_config;
1688
- }
1689
- *service_config_error = GRPC_ERROR_REF(result.service_config_error);
1690
- if (service_config == nullptr &&
1691
- result.service_config_error != GRPC_ERROR_NONE) {
1692
- *no_valid_service_config = true;
1693
- return false;
1694
- }
1695
- // Process service config.
1696
- grpc_core::UniquePtr<char> service_config_json;
1697
- const internal::ClientChannelGlobalParsedConfig* parsed_service_config =
1698
- nullptr;
1699
- if (service_config != nullptr) {
1700
- parsed_service_config =
1701
- static_cast<const internal::ClientChannelGlobalParsedConfig*>(
1702
- service_config->GetGlobalParsedConfig(
1703
- internal::ClientChannelServiceConfigParser::ParserIndex()));
1704
- }
1705
- // Check if the config has changed.
1706
- const bool service_config_changed =
1707
- ((service_config == nullptr) !=
1708
- (chand->saved_service_config_ == nullptr)) ||
1709
- (service_config != nullptr &&
1710
- service_config->json_string() !=
1711
- chand->saved_service_config_->json_string());
1712
- if (service_config_changed) {
1713
- service_config_json.reset(gpr_strdup(
1714
- service_config != nullptr ? service_config->json_string().c_str()
1715
- : ""));
1716
- if (GRPC_TRACE_FLAG_ENABLED(grpc_client_channel_routing_trace)) {
1717
- gpr_log(GPR_INFO,
1718
- "chand=%p: resolver returned updated service config: \"%s\"",
1719
- chand, service_config_json.get());
1720
- }
1721
- // Save health check service name.
1722
- if (service_config != nullptr) {
1723
- chand->health_check_service_name_.reset(
1724
- gpr_strdup(parsed_service_config->health_check_service_name()));
1725
- } else {
1726
- chand->health_check_service_name_.reset();
1727
- }
1728
- // Update health check service name used by existing subchannel wrappers.
1729
- for (auto* subchannel_wrapper : chand->subchannel_wrappers_) {
1730
- subchannel_wrapper->UpdateHealthCheckServiceName(
1731
- grpc_core::UniquePtr<char>(
1732
- gpr_strdup(chand->health_check_service_name_.get())));
1733
- }
1734
- // Save service config.
1735
- chand->saved_service_config_ = std::move(service_config);
1736
- }
1737
- // We want to set the service config at least once. This should not really be
1738
- // needed, but we are doing it as a defensive approach. This can be removed,
1739
- // if we feel it is unnecessary.
1740
- if (service_config_changed || !chand->received_first_resolver_result_) {
1741
- chand->received_first_resolver_result_ = true;
1742
- RefCountedPtr<ServerRetryThrottleData> retry_throttle_data;
1743
- if (parsed_service_config != nullptr) {
1744
- absl::optional<internal::ClientChannelGlobalParsedConfig::RetryThrottling>
1745
- retry_throttle_config = parsed_service_config->retry_throttling();
1746
- if (retry_throttle_config.has_value()) {
1747
- retry_throttle_data =
1748
- internal::ServerRetryThrottleMap::GetDataForServer(
1749
- chand->server_name_.get(),
1750
- retry_throttle_config.value().max_milli_tokens,
1751
- retry_throttle_config.value().milli_token_ratio);
1752
- }
1753
- }
1754
- chand->UpdateServiceConfigLocked(std::move(retry_throttle_data),
1755
- chand->saved_service_config_);
1756
- }
1757
- chand->ProcessLbPolicy(result, parsed_service_config, lb_policy_config);
1758
- grpc_core::UniquePtr<char> lb_policy_name(
1759
- gpr_strdup((*lb_policy_config)->name()));
1760
- // Swap out the data used by GetChannelInfo().
1761
- {
1762
- MutexLock lock(&chand->info_mu_);
1763
- chand->info_lb_policy_name_ = std::move(lb_policy_name);
1764
- if (service_config_json != nullptr) {
1765
- chand->info_service_config_json_ = std::move(service_config_json);
1766
- }
1767
- }
1768
- // Return results.
1769
- return service_config_changed;
1770
- }
1771
-
1772
1878
  grpc_error* ChannelData::DoPingLocked(grpc_transport_op* op) {
1773
1879
  if (state_tracker_.state() != GRPC_CHANNEL_READY) {
1774
1880
  return GRPC_ERROR_CREATE_FROM_STATIC_STRING("channel not connected");
@@ -2811,6 +2917,7 @@ void CallData::RecvInitialMetadataReady(void* arg, grpc_error* error) {
2811
2917
  }
2812
2918
  // Received valid initial metadata, so commit the call.
2813
2919
  calld->RetryCommit(elem, retry_state);
2920
+ calld->MaybeInvokeConfigSelectorCommitCallback();
2814
2921
  // Invoke the callback to return the result to the surface.
2815
2922
  // Manually invoking a callback function; it does not take ownership of error.
2816
2923
  calld->InvokeRecvInitialMetadataCallback(batch_data, error);
@@ -2897,6 +3004,7 @@ void CallData::RecvMessageReady(void* arg, grpc_error* error) {
2897
3004
  }
2898
3005
  // Received a valid message, so commit the call.
2899
3006
  calld->RetryCommit(elem, retry_state);
3007
+ calld->MaybeInvokeConfigSelectorCommitCallback();
2900
3008
  // Invoke the callback to return the result to the surface.
2901
3009
  // Manually invoking a callback function; it does not take ownership of error.
2902
3010
  calld->InvokeRecvMessageCallback(batch_data, error);
@@ -3098,6 +3206,7 @@ void CallData::RecvTrailingMetadataReady(void* arg, grpc_error* error) {
3098
3206
  }
3099
3207
  // Not retrying, so commit the call.
3100
3208
  calld->RetryCommit(elem, retry_state);
3209
+ calld->MaybeInvokeConfigSelectorCommitCallback();
3101
3210
  // Run any necessary closures.
3102
3211
  calld->RunClosuresForCompletedCall(batch_data, GRPC_ERROR_REF(error));
3103
3212
  }
@@ -3720,7 +3829,7 @@ class CallData::QueuedPickCanceller {
3720
3829
  }
3721
3830
  if (calld->pick_canceller_ == self && error != GRPC_ERROR_NONE) {
3722
3831
  // Remove pick from list of queued picks.
3723
- calld->RemoveCallFromQueuedPicksLocked(self->elem_);
3832
+ calld->MaybeRemoveCallFromQueuedPicksLocked(self->elem_);
3724
3833
  // Fail pending batches on the call.
3725
3834
  calld->PendingBatchesFail(self->elem_, GRPC_ERROR_REF(error),
3726
3835
  YieldCallCombinerIfPendingBatchesFound);
@@ -3733,7 +3842,8 @@ class CallData::QueuedPickCanceller {
3733
3842
  grpc_closure closure_;
3734
3843
  };
3735
3844
 
3736
- void CallData::RemoveCallFromQueuedPicksLocked(grpc_call_element* elem) {
3845
+ void CallData::MaybeRemoveCallFromQueuedPicksLocked(grpc_call_element* elem) {
3846
+ if (!pick_queued_) return;
3737
3847
  auto* chand = static_cast<ChannelData*>(elem->channel_data);
3738
3848
  if (GRPC_TRACE_FLAG_ENABLED(grpc_client_channel_routing_trace)) {
3739
3849
  gpr_log(GPR_INFO, "chand=%p calld=%p: removing from queued picks list",
@@ -3745,7 +3855,8 @@ void CallData::RemoveCallFromQueuedPicksLocked(grpc_call_element* elem) {
3745
3855
  pick_canceller_ = nullptr;
3746
3856
  }
3747
3857
 
3748
- void CallData::AddCallToQueuedPicksLocked(grpc_call_element* elem) {
3858
+ void CallData::MaybeAddCallToQueuedPicksLocked(grpc_call_element* elem) {
3859
+ if (pick_queued_) return;
3749
3860
  auto* chand = static_cast<ChannelData*>(elem->channel_data);
3750
3861
  if (GRPC_TRACE_FLAG_ENABLED(grpc_client_channel_routing_trace)) {
3751
3862
  gpr_log(GPR_INFO, "chand=%p calld=%p: adding to queued picks list", chand,
@@ -3758,23 +3869,29 @@ void CallData::AddCallToQueuedPicksLocked(grpc_call_element* elem) {
3758
3869
  pick_canceller_ = new QueuedPickCanceller(elem);
3759
3870
  }
3760
3871
 
3761
- void CallData::ApplyServiceConfigToCallLocked(grpc_call_element* elem) {
3872
+ grpc_error* CallData::ApplyServiceConfigToCallLocked(
3873
+ grpc_call_element* elem, grpc_metadata_batch* initial_metadata) {
3762
3874
  ChannelData* chand = static_cast<ChannelData*>(elem->channel_data);
3763
3875
  if (GRPC_TRACE_FLAG_ENABLED(grpc_client_channel_routing_trace)) {
3764
3876
  gpr_log(GPR_INFO, "chand=%p calld=%p: applying service config to call",
3765
3877
  chand, this);
3766
3878
  }
3879
+ ConfigSelector* config_selector = chand->config_selector();
3767
3880
  auto service_config = chand->service_config();
3768
3881
  if (service_config != nullptr) {
3882
+ // Use the ConfigSelector to determine the config for the call.
3883
+ ConfigSelector::CallConfig call_config =
3884
+ config_selector->GetCallConfig({&path_, initial_metadata, arena_});
3885
+ if (call_config.error != GRPC_ERROR_NONE) return call_config.error;
3886
+ call_attributes_ = std::move(call_config.call_attributes);
3887
+ on_call_committed_ = std::move(call_config.on_call_committed);
3769
3888
  // Create a ServiceConfigCallData for the call. This stores a ref to the
3770
3889
  // ServiceConfig and caches the right set of parsed configs to use for
3771
3890
  // the call. The MethodConfig will store itself in the call context,
3772
3891
  // so that it can be accessed by filters in the subchannel, and it
3773
3892
  // will be cleaned up when the call ends.
3774
- const auto* method_params_vector =
3775
- service_config->GetMethodParsedConfigVector(path_);
3776
3893
  auto* service_config_call_data = arena_->New<ServiceConfigCallData>(
3777
- std::move(service_config), method_params_vector, call_context_);
3894
+ std::move(service_config), call_config.method_configs, call_context_);
3778
3895
  // Apply our own method params to the call.
3779
3896
  method_params_ = static_cast<ClientChannelMethodParsedConfig*>(
3780
3897
  service_config_call_data->GetMethodParsedConfig(
@@ -3816,16 +3933,13 @@ void CallData::ApplyServiceConfigToCallLocked(grpc_call_element* elem) {
3816
3933
  if (method_params_ == nullptr || method_params_->retry_policy() == nullptr) {
3817
3934
  enable_retries_ = false;
3818
3935
  }
3936
+ return GRPC_ERROR_NONE;
3819
3937
  }
3820
3938
 
3821
- void CallData::MaybeApplyServiceConfigToCallLocked(grpc_call_element* elem) {
3822
- ChannelData* chand = static_cast<ChannelData*>(elem->channel_data);
3823
- // Apply service config data to the call only once, and only if the
3824
- // channel has the data available.
3825
- if (GPR_LIKELY(chand->received_service_config_data() &&
3826
- !service_config_applied_)) {
3827
- service_config_applied_ = true;
3828
- ApplyServiceConfigToCallLocked(elem);
3939
+ void CallData::MaybeInvokeConfigSelectorCommitCallback() {
3940
+ if (on_call_committed_ != nullptr) {
3941
+ on_call_committed_();
3942
+ on_call_committed_ = nullptr;
3829
3943
  }
3830
3944
  }
3831
3945
 
@@ -3886,11 +4000,45 @@ bool CallData::PickSubchannelLocked(grpc_call_element* elem,
3886
4000
  GRPC_ERROR_NONE);
3887
4001
  // Queue the pick, so that it will be attempted once the channel
3888
4002
  // becomes connected.
3889
- AddCallToQueuedPicksLocked(elem);
4003
+ MaybeAddCallToQueuedPicksLocked(elem);
4004
+ return false;
4005
+ }
4006
+ grpc_metadata_batch* initial_metadata_batch =
4007
+ seen_send_initial_metadata_
4008
+ ? &send_initial_metadata_
4009
+ : pending_batches_[0]
4010
+ .batch->payload->send_initial_metadata.send_initial_metadata;
4011
+ // Grab initial metadata flags so that we can check later if the call has
4012
+ // wait_for_ready enabled.
4013
+ const uint32_t send_initial_metadata_flags =
4014
+ seen_send_initial_metadata_ ? send_initial_metadata_flags_
4015
+ : pending_batches_[0]
4016
+ .batch->payload->send_initial_metadata
4017
+ .send_initial_metadata_flags;
4018
+ // Avoid picking if we haven't yet received service config data.
4019
+ if (GPR_UNLIKELY(!chand->received_service_config_data())) {
4020
+ // If the resolver returned transient failure before returning the
4021
+ // first service config, fail any non-wait_for_ready calls.
4022
+ grpc_error* resolver_error = chand->resolver_transient_failure_error();
4023
+ if (resolver_error != GRPC_ERROR_NONE &&
4024
+ (send_initial_metadata_flags & GRPC_INITIAL_METADATA_WAIT_FOR_READY) ==
4025
+ 0) {
4026
+ MaybeRemoveCallFromQueuedPicksLocked(elem);
4027
+ *error = GRPC_ERROR_REF(resolver_error);
4028
+ return true;
4029
+ }
4030
+ // Either the resolver has not yet returned a result, or it has
4031
+ // returned transient failure but the call is wait_for_ready. In
4032
+ // either case, queue the call.
4033
+ MaybeAddCallToQueuedPicksLocked(elem);
3890
4034
  return false;
3891
4035
  }
3892
- // Apply service config to call if needed.
3893
- MaybeApplyServiceConfigToCallLocked(elem);
4036
+ // Apply service config to call if not yet applied.
4037
+ if (GPR_LIKELY(!service_config_applied_)) {
4038
+ service_config_applied_ = true;
4039
+ *error = ApplyServiceConfigToCallLocked(elem, initial_metadata_batch);
4040
+ if (*error != GRPC_ERROR_NONE) return true;
4041
+ }
3894
4042
  // If this is a retry, use the send_initial_metadata payload that
3895
4043
  // we've cached; otherwise, use the pending batch. The
3896
4044
  // send_initial_metadata batch will be the first pending batch in the
@@ -3902,21 +4050,10 @@ bool CallData::PickSubchannelLocked(grpc_call_element* elem,
3902
4050
  // subchannel's copy of the metadata batch (which is copied for each
3903
4051
  // attempt) to the LB policy instead the one from the parent channel.
3904
4052
  LoadBalancingPolicy::PickArgs pick_args;
4053
+ pick_args.path = StringViewFromSlice(path_);
3905
4054
  pick_args.call_state = &lb_call_state_;
3906
- Metadata initial_metadata(
3907
- this,
3908
- seen_send_initial_metadata_
3909
- ? &send_initial_metadata_
3910
- : pending_batches_[0]
3911
- .batch->payload->send_initial_metadata.send_initial_metadata);
4055
+ Metadata initial_metadata(this, initial_metadata_batch);
3912
4056
  pick_args.initial_metadata = &initial_metadata;
3913
- // Grab initial metadata flags so that we can check later if the call has
3914
- // wait_for_ready enabled.
3915
- const uint32_t send_initial_metadata_flags =
3916
- seen_send_initial_metadata_ ? send_initial_metadata_flags_
3917
- : pending_batches_[0]
3918
- .batch->payload->send_initial_metadata
3919
- .send_initial_metadata_flags;
3920
4057
  // Attempt pick.
3921
4058
  auto result = chand->picker()->Pick(pick_args);
3922
4059
  if (GRPC_TRACE_FLAG_ENABLED(grpc_client_channel_routing_trace)) {
@@ -3931,7 +4068,8 @@ bool CallData::PickSubchannelLocked(grpc_call_element* elem,
3931
4068
  grpc_error* disconnect_error = chand->disconnect_error();
3932
4069
  if (disconnect_error != GRPC_ERROR_NONE) {
3933
4070
  GRPC_ERROR_UNREF(result.error);
3934
- if (pick_queued_) RemoveCallFromQueuedPicksLocked(elem);
4071
+ MaybeRemoveCallFromQueuedPicksLocked(elem);
4072
+ MaybeInvokeConfigSelectorCommitCallback();
3935
4073
  *error = GRPC_ERROR_REF(disconnect_error);
3936
4074
  return true;
3937
4075
  }
@@ -3952,8 +4090,9 @@ bool CallData::PickSubchannelLocked(grpc_call_element* elem,
3952
4090
  "Failed to pick subchannel", &result.error, 1);
3953
4091
  GRPC_ERROR_UNREF(result.error);
3954
4092
  *error = new_error;
4093
+ MaybeInvokeConfigSelectorCommitCallback();
3955
4094
  }
3956
- if (pick_queued_) RemoveCallFromQueuedPicksLocked(elem);
4095
+ MaybeRemoveCallFromQueuedPicksLocked(elem);
3957
4096
  return !retried;
3958
4097
  }
3959
4098
  // If wait_for_ready is true, then queue to retry when we get a new
@@ -3962,22 +4101,24 @@ bool CallData::PickSubchannelLocked(grpc_call_element* elem,
3962
4101
  }
3963
4102
  // Fallthrough
3964
4103
  case LoadBalancingPolicy::PickResult::PICK_QUEUE:
3965
- if (!pick_queued_) AddCallToQueuedPicksLocked(elem);
4104
+ MaybeAddCallToQueuedPicksLocked(elem);
3966
4105
  return false;
3967
4106
  default: // PICK_COMPLETE
3968
- if (pick_queued_) RemoveCallFromQueuedPicksLocked(elem);
4107
+ MaybeRemoveCallFromQueuedPicksLocked(elem);
3969
4108
  // Handle drops.
3970
4109
  if (GPR_UNLIKELY(result.subchannel == nullptr)) {
3971
4110
  result.error = grpc_error_set_int(
3972
4111
  GRPC_ERROR_CREATE_FROM_STATIC_STRING(
3973
4112
  "Call dropped by load balancing policy"),
3974
4113
  GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_UNAVAILABLE);
4114
+ MaybeInvokeConfigSelectorCommitCallback();
3975
4115
  } else {
3976
4116
  // Grab a ref to the connected subchannel while we're still
3977
4117
  // holding the data plane mutex.
3978
4118
  connected_subchannel_ =
3979
4119
  chand->GetConnectedSubchannelInDataPlane(result.subchannel.get());
3980
4120
  GPR_ASSERT(connected_subchannel_ != nullptr);
4121
+ if (retry_committed_) MaybeInvokeConfigSelectorCommitCallback();
3981
4122
  }
3982
4123
  lb_recv_trailing_metadata_ready_ = result.recv_trailing_metadata_ready;
3983
4124
  *error = result.error;