grpc 1.32.0 → 1.35.0

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

Potentially problematic release.


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

Files changed (938) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +1078 -3049
  3. data/etc/roots.pem +257 -573
  4. data/include/grpc/compression.h +1 -1
  5. data/include/grpc/grpc.h +15 -7
  6. data/include/grpc/grpc_security.h +222 -171
  7. data/include/grpc/impl/codegen/atm_windows.h +4 -0
  8. data/include/grpc/impl/codegen/byte_buffer.h +1 -1
  9. data/include/grpc/impl/codegen/grpc_types.h +10 -8
  10. data/include/grpc/impl/codegen/log.h +0 -2
  11. data/include/grpc/impl/codegen/port_platform.h +22 -55
  12. data/include/grpc/impl/codegen/sync_windows.h +4 -0
  13. data/include/grpc/slice_buffer.h +3 -3
  14. data/include/grpc/support/sync.h +3 -3
  15. data/include/grpc/support/time.h +7 -7
  16. data/src/core/ext/filters/client_channel/backend_metric.cc +2 -4
  17. data/src/core/ext/filters/client_channel/client_channel.cc +2776 -1529
  18. data/src/core/ext/filters/client_channel/client_channel.h +0 -4
  19. data/src/core/ext/filters/client_channel/client_channel_plugin.cc +1 -1
  20. data/src/core/ext/filters/client_channel/config_selector.cc +0 -4
  21. data/src/core/ext/filters/client_channel/config_selector.h +40 -8
  22. data/src/core/ext/filters/client_channel/dynamic_filters.cc +186 -0
  23. data/src/core/ext/filters/client_channel/dynamic_filters.h +99 -0
  24. data/src/core/ext/filters/client_channel/health/health_check_client.cc +10 -7
  25. data/src/core/ext/filters/client_channel/health/health_check_client.h +4 -4
  26. data/src/core/ext/filters/client_channel/http_connect_handshaker.cc +5 -6
  27. data/src/core/ext/filters/client_channel/http_proxy.cc +21 -20
  28. data/src/core/ext/filters/client_channel/lb_policy.cc +6 -2
  29. data/src/core/ext/filters/client_channel/lb_policy.h +6 -7
  30. data/src/core/ext/filters/client_channel/lb_policy/address_filtering.cc +48 -35
  31. data/src/core/ext/filters/client_channel/lb_policy/address_filtering.h +7 -5
  32. data/src/core/ext/filters/client_channel/lb_policy/child_policy_handler.cc +4 -3
  33. data/src/core/ext/filters/client_channel/lb_policy/child_policy_handler.h +1 -1
  34. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +201 -190
  35. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.cc +3 -1
  36. data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.cc +3 -3
  37. data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.h +1 -1
  38. data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc +4 -4
  39. data/src/core/ext/filters/client_channel/lb_policy/priority/priority.cc +50 -20
  40. data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc +5 -5
  41. data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +14 -34
  42. data/src/core/ext/filters/client_channel/lb_policy/weighted_target/weighted_target.cc +6 -6
  43. data/src/core/ext/filters/client_channel/lb_policy/xds/cds.cc +341 -127
  44. data/src/core/ext/filters/client_channel/lb_policy/xds/xds.h +52 -24
  45. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_channel_args.h +24 -0
  46. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_impl.cc +812 -0
  47. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_manager.cc +722 -0
  48. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_resolver.cc +1262 -0
  49. data/src/core/ext/filters/client_channel/lb_policy_registry.cc +8 -1
  50. data/src/core/ext/filters/client_channel/resolver.cc +3 -1
  51. data/src/core/ext/filters/client_channel/resolver.h +4 -1
  52. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +9 -16
  53. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.h +1 -32
  54. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_posix.cc +3 -3
  55. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc +454 -16
  56. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h +5 -0
  57. data/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc +7 -10
  58. data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc +3 -3
  59. data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.h +1 -1
  60. data/src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.cc +34 -27
  61. data/src/core/ext/filters/client_channel/resolver/xds/xds_resolver.cc +618 -366
  62. data/src/core/ext/filters/client_channel/resolver/xds/xds_resolver.h +28 -0
  63. data/src/core/ext/filters/client_channel/resolver_factory.h +6 -6
  64. data/src/core/ext/filters/client_channel/resolver_registry.cc +40 -39
  65. data/src/core/ext/filters/client_channel/resolver_registry.h +2 -2
  66. data/src/core/ext/filters/client_channel/resolver_result_parsing.cc +29 -74
  67. data/src/core/ext/filters/client_channel/resolver_result_parsing.h +12 -10
  68. data/src/core/ext/filters/client_channel/retry_throttle.cc +5 -3
  69. data/src/core/ext/filters/client_channel/retry_throttle.h +4 -2
  70. data/src/core/ext/filters/client_channel/server_address.cc +80 -0
  71. data/src/core/ext/filters/client_channel/server_address.h +21 -36
  72. data/src/core/ext/filters/client_channel/service_config.cc +18 -13
  73. data/src/core/ext/filters/client_channel/service_config.h +8 -5
  74. data/src/core/ext/filters/client_channel/service_config_call_data.h +19 -1
  75. data/src/core/ext/filters/client_channel/service_config_channel_arg_filter.cc +2 -2
  76. data/src/core/ext/filters/client_channel/service_config_parser.cc +8 -6
  77. data/src/core/ext/filters/client_channel/service_config_parser.h +8 -5
  78. data/src/core/ext/filters/client_channel/subchannel.cc +51 -64
  79. data/src/core/ext/filters/client_channel/subchannel.h +14 -20
  80. data/src/core/ext/filters/client_channel/subchannel_interface.h +41 -5
  81. data/src/core/ext/filters/client_channel/subchannel_pool_interface.h +6 -2
  82. data/src/core/ext/filters/deadline/deadline_filter.cc +87 -79
  83. data/src/core/ext/filters/deadline/deadline_filter.h +7 -11
  84. data/src/core/ext/filters/http/client/http_client_filter.cc +1 -1
  85. data/src/core/ext/filters/http/client_authority_filter.cc +6 -6
  86. data/src/core/ext/filters/http/http_filters_plugin.cc +6 -3
  87. data/src/core/ext/filters/http/server/http_server_filter.cc +3 -3
  88. data/src/core/ext/filters/max_age/max_age_filter.cc +1 -1
  89. data/src/core/ext/filters/message_size/message_size_filter.cc +3 -2
  90. data/src/core/ext/filters/message_size/message_size_filter.h +2 -1
  91. data/src/core/ext/filters/workarounds/workaround_utils.cc +1 -1
  92. data/src/core/ext/transport/chttp2/client/authority.cc +3 -3
  93. data/src/core/ext/transport/chttp2/client/chttp2_connector.h +1 -1
  94. data/src/core/ext/transport/chttp2/client/insecure/channel_create.cc +20 -8
  95. data/src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc +21 -10
  96. data/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc +26 -14
  97. data/src/core/ext/transport/chttp2/server/chttp2_server.cc +185 -79
  98. data/src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.cc +12 -5
  99. data/src/core/ext/transport/chttp2/transport/bin_decoder.cc +7 -7
  100. data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +28 -42
  101. data/src/core/ext/transport/chttp2/transport/flow_control.cc +10 -2
  102. data/src/core/ext/transport/chttp2/transport/flow_control.h +13 -3
  103. data/src/core/ext/transport/chttp2/transport/frame_goaway.cc +2 -1
  104. data/src/core/ext/transport/chttp2/transport/frame_settings.h +2 -1
  105. data/src/core/ext/transport/chttp2/transport/frame_window_update.cc +6 -6
  106. data/src/core/ext/transport/chttp2/transport/hpack_parser.cc +12 -8
  107. data/src/core/ext/transport/chttp2/transport/internal.h +5 -1
  108. data/src/core/ext/transport/chttp2/transport/parsing.cc +18 -3
  109. data/src/core/ext/transport/chttp2/transport/writing.cc +2 -3
  110. data/src/core/ext/transport/inproc/inproc_transport.cc +42 -8
  111. data/src/core/ext/upb-generated/envoy/annotations/deprecation.upb.h +1 -0
  112. data/src/core/ext/upb-generated/envoy/annotations/resource.upb.c +1 -1
  113. data/src/core/ext/upb-generated/envoy/annotations/resource.upb.h +7 -0
  114. data/src/core/ext/upb-generated/envoy/config/accesslog/v3/accesslog.upb.c +52 -32
  115. data/src/core/ext/upb-generated/envoy/config/accesslog/v3/accesslog.upb.h +199 -34
  116. data/src/core/ext/upb-generated/envoy/config/cluster/v3/circuit_breaker.upb.c +13 -13
  117. data/src/core/ext/upb-generated/envoy/config/cluster/v3/circuit_breaker.upb.h +44 -17
  118. data/src/core/ext/upb-generated/envoy/config/cluster/v3/cluster.upb.c +177 -99
  119. data/src/core/ext/upb-generated/envoy/config/cluster/v3/cluster.upb.h +642 -202
  120. data/src/core/ext/upb-generated/envoy/config/cluster/v3/filter.upb.c +3 -3
  121. data/src/core/ext/upb-generated/envoy/config/cluster/v3/filter.upb.h +13 -5
  122. data/src/core/ext/upb-generated/envoy/config/cluster/v3/outlier_detection.upb.c +22 -22
  123. data/src/core/ext/upb-generated/envoy/config/cluster/v3/outlier_detection.upb.h +47 -21
  124. data/src/core/ext/upb-generated/envoy/config/core/v3/address.upb.c +36 -24
  125. data/src/core/ext/upb-generated/envoy/config/core/v3/address.upb.h +133 -39
  126. data/src/core/ext/upb-generated/envoy/config/core/v3/backoff.upb.c +4 -4
  127. data/src/core/ext/upb-generated/envoy/config/core/v3/backoff.upb.h +15 -6
  128. data/src/core/ext/upb-generated/envoy/config/core/v3/base.upb.c +45 -44
  129. data/src/core/ext/upb-generated/envoy/config/core/v3/base.upb.h +200 -78
  130. data/src/core/ext/upb-generated/envoy/config/core/v3/config_source.upb.c +31 -24
  131. data/src/core/ext/upb-generated/envoy/config/core/v3/config_source.upb.h +107 -47
  132. data/src/core/ext/upb-generated/envoy/config/core/v3/event_service_config.upb.c +1 -1
  133. data/src/core/ext/upb-generated/envoy/config/core/v3/event_service_config.upb.h +7 -0
  134. data/src/core/ext/upb-generated/envoy/config/core/v3/extension.upb.c +53 -0
  135. data/src/core/ext/upb-generated/envoy/config/core/v3/extension.upb.h +149 -0
  136. data/src/core/ext/upb-generated/envoy/config/core/v3/grpc_service.upb.c +74 -28
  137. data/src/core/ext/upb-generated/envoy/config/core/v3/grpc_service.upb.h +248 -43
  138. data/src/core/ext/upb-generated/envoy/config/core/v3/health_check.upb.c +39 -39
  139. data/src/core/ext/upb-generated/envoy/config/core/v3/health_check.upb.h +157 -89
  140. data/src/core/ext/upb-generated/envoy/config/core/v3/http_uri.upb.c +4 -4
  141. data/src/core/ext/upb-generated/envoy/config/core/v3/http_uri.upb.h +17 -9
  142. data/src/core/ext/upb-generated/envoy/config/core/v3/protocol.upb.c +63 -39
  143. data/src/core/ext/upb-generated/envoy/config/core/v3/protocol.upb.h +254 -60
  144. data/src/core/ext/upb-generated/envoy/config/core/v3/proxy_protocol.upb.c +1 -1
  145. data/src/core/ext/upb-generated/envoy/config/core/v3/proxy_protocol.upb.h +7 -0
  146. data/src/core/ext/upb-generated/envoy/config/core/v3/socket_option.upb.c +2 -2
  147. data/src/core/ext/upb-generated/envoy/config/core/v3/socket_option.upb.h +9 -2
  148. data/src/core/ext/upb-generated/envoy/config/core/v3/substitution_format_string.upb.c +36 -0
  149. data/src/core/ext/upb-generated/envoy/config/core/v3/substitution_format_string.upb.h +92 -0
  150. data/src/core/ext/upb-generated/envoy/config/endpoint/v3/endpoint.upb.c +13 -13
  151. data/src/core/ext/upb-generated/envoy/config/endpoint/v3/endpoint.upb.h +59 -36
  152. data/src/core/ext/upb-generated/envoy/config/endpoint/v3/endpoint_components.upb.c +16 -16
  153. data/src/core/ext/upb-generated/envoy/config/endpoint/v3/endpoint_components.upb.h +61 -29
  154. data/src/core/ext/upb-generated/envoy/config/endpoint/v3/load_report.upb.c +26 -26
  155. data/src/core/ext/upb-generated/envoy/config/endpoint/v3/load_report.upb.h +101 -66
  156. data/src/core/ext/upb-generated/envoy/config/listener/v3/api_listener.upb.c +2 -2
  157. data/src/core/ext/upb-generated/envoy/config/listener/v3/api_listener.upb.h +11 -3
  158. data/src/core/ext/upb-generated/envoy/config/listener/v3/listener.upb.c +46 -26
  159. data/src/core/ext/upb-generated/envoy/config/listener/v3/listener.upb.h +179 -68
  160. data/src/core/ext/upb-generated/envoy/config/listener/v3/listener_components.upb.c +39 -22
  161. data/src/core/ext/upb-generated/envoy/config/listener/v3/listener_components.upb.h +149 -48
  162. data/src/core/ext/upb-generated/envoy/config/listener/v3/udp_listener_config.upb.c +2 -2
  163. data/src/core/ext/upb-generated/envoy/config/listener/v3/udp_listener_config.upb.h +13 -0
  164. data/src/core/ext/upb-generated/envoy/config/rbac/v3/rbac.upb.c +21 -17
  165. data/src/core/ext/upb-generated/envoy/config/rbac/v3/rbac.upb.h +96 -33
  166. data/src/core/ext/upb-generated/envoy/config/route/v3/route.upb.c +7 -7
  167. data/src/core/ext/upb-generated/envoy/config/route/v3/route.upb.h +38 -22
  168. data/src/core/ext/upb-generated/envoy/config/route/v3/route_components.upb.c +321 -194
  169. data/src/core/ext/upb-generated/envoy/config/route/v3/route_components.upb.h +1228 -443
  170. data/src/core/ext/upb-generated/envoy/config/route/v3/scoped_route.upb.c +8 -7
  171. data/src/core/ext/upb-generated/envoy/config/route/v3/scoped_route.upb.h +34 -10
  172. data/src/core/ext/upb-generated/envoy/config/trace/v3/http_tracer.upb.c +3 -3
  173. data/src/core/ext/upb-generated/envoy/config/trace/v3/http_tracer.upb.h +17 -3
  174. data/src/core/ext/upb-generated/envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.upb.c +132 -80
  175. data/src/core/ext/upb-generated/envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.upb.h +516 -166
  176. data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/cert.upb.h +1 -0
  177. data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/common.upb.c +24 -25
  178. data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/common.upb.h +96 -71
  179. data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/secret.upb.c +12 -8
  180. data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/secret.upb.h +46 -8
  181. data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/tls.upb.c +71 -29
  182. data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/tls.upb.h +296 -63
  183. data/src/core/ext/upb-generated/envoy/service/cluster/v3/cds.upb.c +1 -1
  184. data/src/core/ext/upb-generated/envoy/service/cluster/v3/cds.upb.h +7 -0
  185. data/src/core/ext/upb-generated/envoy/service/discovery/v3/ads.upb.c +1 -1
  186. data/src/core/ext/upb-generated/envoy/service/discovery/v3/ads.upb.h +7 -0
  187. data/src/core/ext/upb-generated/envoy/service/discovery/v3/discovery.upb.c +41 -31
  188. data/src/core/ext/upb-generated/envoy/service/discovery/v3/discovery.upb.h +165 -64
  189. data/src/core/ext/upb-generated/envoy/service/endpoint/v3/eds.upb.c +1 -1
  190. data/src/core/ext/upb-generated/envoy/service/endpoint/v3/eds.upb.h +7 -0
  191. data/src/core/ext/upb-generated/envoy/service/listener/v3/lds.upb.c +1 -1
  192. data/src/core/ext/upb-generated/envoy/service/listener/v3/lds.upb.h +7 -0
  193. data/src/core/ext/upb-generated/envoy/service/load_stats/v3/lrs.upb.c +7 -7
  194. data/src/core/ext/upb-generated/envoy/service/load_stats/v3/lrs.upb.h +31 -16
  195. data/src/core/ext/upb-generated/envoy/service/route/v3/rds.upb.c +1 -1
  196. data/src/core/ext/upb-generated/envoy/service/route/v3/rds.upb.h +7 -0
  197. data/src/core/ext/upb-generated/envoy/service/route/v3/srds.upb.c +1 -1
  198. data/src/core/ext/upb-generated/envoy/service/route/v3/srds.upb.h +7 -0
  199. data/src/core/ext/upb-generated/envoy/type/matcher/v3/metadata.upb.c +5 -5
  200. data/src/core/ext/upb-generated/envoy/type/matcher/v3/metadata.upb.h +25 -11
  201. data/src/core/ext/upb-generated/envoy/type/matcher/v3/number.upb.c +1 -1
  202. data/src/core/ext/upb-generated/envoy/type/matcher/v3/number.upb.h +7 -0
  203. data/src/core/ext/upb-generated/envoy/type/matcher/v3/path.upb.c +1 -1
  204. data/src/core/ext/upb-generated/envoy/type/matcher/v3/path.upb.h +7 -0
  205. data/src/core/ext/upb-generated/envoy/type/matcher/v3/regex.upb.c +6 -6
  206. data/src/core/ext/upb-generated/envoy/type/matcher/v3/regex.upb.h +29 -8
  207. data/src/core/ext/upb-generated/envoy/type/matcher/v3/string.upb.c +4 -3
  208. data/src/core/ext/upb-generated/envoy/type/matcher/v3/string.upb.h +22 -3
  209. data/src/core/ext/upb-generated/envoy/type/matcher/v3/value.upb.c +3 -3
  210. data/src/core/ext/upb-generated/envoy/type/matcher/v3/value.upb.h +19 -0
  211. data/src/core/ext/upb-generated/envoy/type/metadata/v3/metadata.upb.c +7 -7
  212. data/src/core/ext/upb-generated/envoy/type/metadata/v3/metadata.upb.h +46 -3
  213. data/src/core/ext/upb-generated/envoy/type/tracing/v3/custom_tag.upb.c +8 -8
  214. data/src/core/ext/upb-generated/envoy/type/tracing/v3/custom_tag.upb.h +41 -8
  215. data/src/core/ext/upb-generated/envoy/type/v3/http.upb.h +1 -0
  216. data/src/core/ext/upb-generated/envoy/type/v3/percent.upb.c +3 -3
  217. data/src/core/ext/upb-generated/envoy/type/v3/percent.upb.h +15 -2
  218. data/src/core/ext/upb-generated/envoy/type/v3/range.upb.c +3 -3
  219. data/src/core/ext/upb-generated/envoy/type/v3/range.upb.h +19 -0
  220. data/src/core/ext/upb-generated/envoy/type/v3/semantic_version.upb.c +1 -1
  221. data/src/core/ext/upb-generated/envoy/type/v3/semantic_version.upb.h +7 -0
  222. data/src/core/ext/upb-generated/google/api/annotations.upb.h +1 -0
  223. data/src/core/ext/upb-generated/google/api/expr/v1alpha1/checked.upb.c +242 -0
  224. data/src/core/ext/upb-generated/google/api/expr/v1alpha1/checked.upb.h +830 -0
  225. data/src/core/ext/upb-generated/google/api/expr/v1alpha1/syntax.upb.c +34 -34
  226. data/src/core/ext/upb-generated/google/api/expr/v1alpha1/syntax.upb.h +142 -59
  227. data/src/core/ext/upb-generated/google/api/http.upb.c +3 -3
  228. data/src/core/ext/upb-generated/google/api/http.upb.h +25 -6
  229. data/src/core/ext/upb-generated/google/protobuf/any.upb.c +1 -1
  230. data/src/core/ext/upb-generated/google/protobuf/any.upb.h +7 -0
  231. data/src/core/ext/upb-generated/google/protobuf/descriptor.upb.c +90 -90
  232. data/src/core/ext/upb-generated/google/protobuf/descriptor.upb.h +455 -292
  233. data/src/core/ext/upb-generated/google/protobuf/duration.upb.c +1 -1
  234. data/src/core/ext/upb-generated/google/protobuf/duration.upb.h +7 -0
  235. data/src/core/ext/upb-generated/google/protobuf/empty.upb.c +1 -1
  236. data/src/core/ext/upb-generated/google/protobuf/empty.upb.h +7 -0
  237. data/src/core/ext/upb-generated/google/protobuf/struct.upb.c +4 -4
  238. data/src/core/ext/upb-generated/google/protobuf/struct.upb.h +22 -3
  239. data/src/core/ext/upb-generated/google/protobuf/timestamp.upb.c +1 -1
  240. data/src/core/ext/upb-generated/google/protobuf/timestamp.upb.h +7 -0
  241. data/src/core/ext/upb-generated/google/protobuf/wrappers.upb.c +9 -9
  242. data/src/core/ext/upb-generated/google/protobuf/wrappers.upb.h +55 -0
  243. data/src/core/ext/upb-generated/google/rpc/status.upb.c +1 -1
  244. data/src/core/ext/upb-generated/google/rpc/status.upb.h +10 -3
  245. data/src/core/ext/upb-generated/src/proto/grpc/gcp/altscontext.upb.c +4 -4
  246. data/src/core/ext/upb-generated/src/proto/grpc/gcp/altscontext.upb.h +11 -3
  247. data/src/core/ext/upb-generated/src/proto/grpc/gcp/handshaker.upb.c +41 -41
  248. data/src/core/ext/upb-generated/src/proto/grpc/gcp/handshaker.upb.h +149 -76
  249. data/src/core/ext/upb-generated/src/proto/grpc/gcp/transport_security_common.upb.c +5 -5
  250. data/src/core/ext/upb-generated/src/proto/grpc/gcp/transport_security_common.upb.h +21 -6
  251. data/src/core/ext/upb-generated/src/proto/grpc/health/v1/health.upb.c +2 -2
  252. data/src/core/ext/upb-generated/src/proto/grpc/health/v1/health.upb.h +13 -0
  253. data/src/core/ext/upb-generated/src/proto/grpc/lb/v1/load_balancer.upb.c +17 -17
  254. data/src/core/ext/upb-generated/src/proto/grpc/lb/v1/load_balancer.upb.h +82 -25
  255. data/src/core/ext/upb-generated/udpa/annotations/migrate.upb.c +3 -3
  256. data/src/core/ext/upb-generated/udpa/annotations/migrate.upb.h +19 -0
  257. data/src/core/ext/upb-generated/udpa/annotations/security.upb.c +31 -0
  258. data/src/core/ext/upb-generated/udpa/annotations/security.upb.h +64 -0
  259. data/src/core/ext/upb-generated/udpa/annotations/sensitive.upb.h +1 -0
  260. data/src/core/ext/upb-generated/udpa/annotations/status.upb.c +2 -2
  261. data/src/core/ext/upb-generated/udpa/annotations/status.upb.h +9 -2
  262. data/src/core/ext/upb-generated/udpa/annotations/versioning.upb.c +1 -1
  263. data/src/core/ext/upb-generated/udpa/annotations/versioning.upb.h +7 -0
  264. data/src/core/ext/upb-generated/udpa/core/v1/authority.upb.c +28 -0
  265. data/src/core/ext/upb-generated/udpa/core/v1/authority.upb.h +60 -0
  266. data/src/core/ext/upb-generated/udpa/core/v1/collection_entry.upb.c +52 -0
  267. data/src/core/ext/upb-generated/udpa/core/v1/collection_entry.upb.h +143 -0
  268. data/src/core/ext/upb-generated/udpa/core/v1/context_params.upb.c +42 -0
  269. data/src/core/ext/upb-generated/udpa/core/v1/context_params.upb.h +84 -0
  270. data/src/core/ext/upb-generated/udpa/core/v1/resource.upb.c +36 -0
  271. data/src/core/ext/upb-generated/udpa/core/v1/resource.upb.h +94 -0
  272. data/src/core/ext/upb-generated/udpa/core/v1/resource_locator.upb.c +54 -0
  273. data/src/core/ext/upb-generated/udpa/core/v1/resource_locator.upb.h +173 -0
  274. data/src/core/ext/upb-generated/udpa/core/v1/resource_name.upb.c +36 -0
  275. data/src/core/ext/upb-generated/udpa/core/v1/resource_name.upb.h +92 -0
  276. data/src/core/ext/upb-generated/udpa/data/orca/v1/orca_load_report.upb.c +3 -3
  277. data/src/core/ext/upb-generated/udpa/data/orca/v1/orca_load_report.upb.h +7 -0
  278. data/src/core/ext/upb-generated/validate/validate.upb.c +64 -64
  279. data/src/core/ext/upb-generated/validate/validate.upb.h +296 -157
  280. data/src/core/ext/upbdefs-generated/envoy/annotations/deprecation.upbdefs.c +38 -0
  281. data/src/core/ext/upbdefs-generated/envoy/annotations/deprecation.upbdefs.h +30 -0
  282. data/src/core/ext/upbdefs-generated/envoy/annotations/resource.upbdefs.c +41 -0
  283. data/src/core/ext/upbdefs-generated/envoy/annotations/resource.upbdefs.h +35 -0
  284. data/src/core/ext/upbdefs-generated/envoy/config/accesslog/v3/accesslog.upbdefs.c +254 -0
  285. data/src/core/ext/upbdefs-generated/envoy/config/accesslog/v3/accesslog.upbdefs.h +105 -0
  286. data/src/core/ext/upbdefs-generated/envoy/config/cluster/v3/circuit_breaker.upbdefs.c +100 -0
  287. data/src/core/ext/upbdefs-generated/envoy/config/cluster/v3/circuit_breaker.upbdefs.h +45 -0
  288. data/src/core/ext/upbdefs-generated/envoy/config/cluster/v3/cluster.upbdefs.c +558 -0
  289. data/src/core/ext/upbdefs-generated/envoy/config/cluster/v3/cluster.upbdefs.h +145 -0
  290. data/src/core/ext/upbdefs-generated/envoy/config/cluster/v3/filter.upbdefs.c +53 -0
  291. data/src/core/ext/upbdefs-generated/envoy/config/cluster/v3/filter.upbdefs.h +35 -0
  292. data/src/core/ext/upbdefs-generated/envoy/config/cluster/v3/outlier_detection.upbdefs.c +133 -0
  293. data/src/core/ext/upbdefs-generated/envoy/config/cluster/v3/outlier_detection.upbdefs.h +35 -0
  294. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/address.upbdefs.c +127 -0
  295. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/address.upbdefs.h +65 -0
  296. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/backoff.upbdefs.c +56 -0
  297. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/backoff.upbdefs.h +35 -0
  298. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/base.upbdefs.c +266 -0
  299. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/base.upbdefs.h +125 -0
  300. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/config_source.upbdefs.c +143 -0
  301. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/config_source.upbdefs.h +55 -0
  302. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/event_service_config.upbdefs.c +56 -0
  303. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/event_service_config.upbdefs.h +35 -0
  304. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/extension.upbdefs.c +66 -0
  305. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/extension.upbdefs.h +40 -0
  306. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/grpc_service.upbdefs.c +263 -0
  307. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/grpc_service.upbdefs.h +100 -0
  308. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/health_check.upbdefs.c +233 -0
  309. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/health_check.upbdefs.h +70 -0
  310. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/http_uri.upbdefs.c +56 -0
  311. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/http_uri.upbdefs.h +35 -0
  312. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/protocol.upbdefs.c +228 -0
  313. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/protocol.upbdefs.h +80 -0
  314. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/proxy_protocol.upbdefs.c +46 -0
  315. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/proxy_protocol.upbdefs.h +35 -0
  316. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/socket_option.upbdefs.c +59 -0
  317. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/socket_option.upbdefs.h +35 -0
  318. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/substitution_format_string.upbdefs.c +55 -0
  319. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/substitution_format_string.upbdefs.h +35 -0
  320. data/src/core/ext/upbdefs-generated/envoy/config/endpoint/v3/endpoint.upbdefs.c +110 -0
  321. data/src/core/ext/upbdefs-generated/envoy/config/endpoint/v3/endpoint.upbdefs.h +50 -0
  322. data/src/core/ext/upbdefs-generated/envoy/config/endpoint/v3/endpoint_components.upbdefs.c +113 -0
  323. data/src/core/ext/upbdefs-generated/envoy/config/endpoint/v3/endpoint_components.upbdefs.h +50 -0
  324. data/src/core/ext/upbdefs-generated/envoy/config/endpoint/v3/load_report.upbdefs.c +146 -0
  325. data/src/core/ext/upbdefs-generated/envoy/config/endpoint/v3/load_report.upbdefs.h +55 -0
  326. data/src/core/ext/upbdefs-generated/envoy/config/listener/v3/api_listener.upbdefs.c +50 -0
  327. data/src/core/ext/upbdefs-generated/envoy/config/listener/v3/api_listener.upbdefs.h +35 -0
  328. data/src/core/ext/upbdefs-generated/envoy/config/listener/v3/listener.upbdefs.c +190 -0
  329. data/src/core/ext/upbdefs-generated/envoy/config/listener/v3/listener.upbdefs.h +55 -0
  330. data/src/core/ext/upbdefs-generated/envoy/config/listener/v3/listener_components.upbdefs.c +185 -0
  331. data/src/core/ext/upbdefs-generated/envoy/config/listener/v3/listener_components.upbdefs.h +65 -0
  332. data/src/core/ext/upbdefs-generated/envoy/config/listener/v3/udp_listener_config.upbdefs.c +62 -0
  333. data/src/core/ext/upbdefs-generated/envoy/config/listener/v3/udp_listener_config.upbdefs.h +40 -0
  334. data/src/core/ext/upbdefs-generated/envoy/config/route/v3/route.upbdefs.c +97 -0
  335. data/src/core/ext/upbdefs-generated/envoy/config/route/v3/route.upbdefs.h +40 -0
  336. data/src/core/ext/upbdefs-generated/envoy/config/route/v3/route_components.upbdefs.c +915 -0
  337. data/src/core/ext/upbdefs-generated/envoy/config/route/v3/route_components.upbdefs.h +280 -0
  338. data/src/core/ext/upbdefs-generated/envoy/config/route/v3/scoped_route.upbdefs.c +71 -0
  339. data/src/core/ext/upbdefs-generated/envoy/config/route/v3/scoped_route.upbdefs.h +45 -0
  340. data/src/core/ext/upbdefs-generated/envoy/config/trace/v3/http_tracer.upbdefs.c +64 -0
  341. data/src/core/ext/upbdefs-generated/envoy/config/trace/v3/http_tracer.upbdefs.h +40 -0
  342. data/src/core/ext/upbdefs-generated/envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.upbdefs.c +511 -0
  343. data/src/core/ext/upbdefs-generated/envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.upbdefs.h +115 -0
  344. data/src/core/ext/upbdefs-generated/envoy/extensions/transport_sockets/tls/v3/cert.upbdefs.c +48 -0
  345. data/src/core/ext/upbdefs-generated/envoy/extensions/transport_sockets/tls/v3/cert.upbdefs.h +30 -0
  346. data/src/core/ext/upbdefs-generated/envoy/extensions/transport_sockets/tls/v3/common.upbdefs.c +166 -0
  347. data/src/core/ext/upbdefs-generated/envoy/extensions/transport_sockets/tls/v3/common.upbdefs.h +55 -0
  348. data/src/core/ext/upbdefs-generated/envoy/extensions/transport_sockets/tls/v3/secret.upbdefs.c +105 -0
  349. data/src/core/ext/upbdefs-generated/envoy/extensions/transport_sockets/tls/v3/secret.upbdefs.h +45 -0
  350. data/src/core/ext/upbdefs-generated/envoy/extensions/transport_sockets/tls/v3/tls.upbdefs.c +249 -0
  351. data/src/core/ext/upbdefs-generated/envoy/extensions/transport_sockets/tls/v3/tls.upbdefs.h +60 -0
  352. data/src/core/ext/upbdefs-generated/envoy/service/cluster/v3/cds.upbdefs.c +72 -0
  353. data/src/core/ext/upbdefs-generated/envoy/service/cluster/v3/cds.upbdefs.h +35 -0
  354. data/src/core/ext/upbdefs-generated/envoy/service/discovery/v3/ads.upbdefs.c +60 -0
  355. data/src/core/ext/upbdefs-generated/envoy/service/discovery/v3/ads.upbdefs.h +35 -0
  356. data/src/core/ext/upbdefs-generated/envoy/service/discovery/v3/discovery.upbdefs.c +152 -0
  357. data/src/core/ext/upbdefs-generated/envoy/service/discovery/v3/discovery.upbdefs.h +60 -0
  358. data/src/core/ext/upbdefs-generated/envoy/service/endpoint/v3/eds.upbdefs.c +83 -0
  359. data/src/core/ext/upbdefs-generated/envoy/service/endpoint/v3/eds.upbdefs.h +35 -0
  360. data/src/core/ext/upbdefs-generated/envoy/service/listener/v3/lds.upbdefs.c +82 -0
  361. data/src/core/ext/upbdefs-generated/envoy/service/listener/v3/lds.upbdefs.h +35 -0
  362. data/src/core/ext/upbdefs-generated/envoy/service/load_stats/v3/lrs.upbdefs.c +83 -0
  363. data/src/core/ext/upbdefs-generated/envoy/service/load_stats/v3/lrs.upbdefs.h +40 -0
  364. data/src/core/ext/upbdefs-generated/envoy/service/route/v3/rds.upbdefs.c +86 -0
  365. data/src/core/ext/upbdefs-generated/envoy/service/route/v3/rds.upbdefs.h +35 -0
  366. data/src/core/ext/upbdefs-generated/envoy/service/route/v3/srds.upbdefs.c +74 -0
  367. data/src/core/ext/upbdefs-generated/envoy/service/route/v3/srds.upbdefs.h +35 -0
  368. data/src/core/ext/upbdefs-generated/envoy/type/matcher/v3/metadata.upbdefs.c +64 -0
  369. data/src/core/ext/upbdefs-generated/envoy/type/matcher/v3/metadata.upbdefs.h +40 -0
  370. data/src/core/ext/upbdefs-generated/envoy/type/matcher/v3/number.upbdefs.c +54 -0
  371. data/src/core/ext/upbdefs-generated/envoy/type/matcher/v3/number.upbdefs.h +35 -0
  372. data/src/core/ext/upbdefs-generated/envoy/type/matcher/v3/path.upbdefs.c +53 -0
  373. data/src/core/ext/upbdefs-generated/envoy/type/matcher/v3/path.upbdefs.h +35 -0
  374. data/src/core/ext/upbdefs-generated/envoy/type/matcher/v3/regex.upbdefs.c +73 -0
  375. data/src/core/ext/upbdefs-generated/envoy/type/matcher/v3/regex.upbdefs.h +45 -0
  376. data/src/core/ext/upbdefs-generated/envoy/type/matcher/v3/string.upbdefs.c +72 -0
  377. data/src/core/ext/upbdefs-generated/envoy/type/matcher/v3/string.upbdefs.h +40 -0
  378. data/src/core/ext/upbdefs-generated/envoy/type/matcher/v3/value.upbdefs.c +81 -0
  379. data/src/core/ext/upbdefs-generated/envoy/type/matcher/v3/value.upbdefs.h +45 -0
  380. data/src/core/ext/upbdefs-generated/envoy/type/metadata/v3/metadata.upbdefs.c +92 -0
  381. data/src/core/ext/upbdefs-generated/envoy/type/metadata/v3/metadata.upbdefs.h +65 -0
  382. data/src/core/ext/upbdefs-generated/envoy/type/tracing/v3/custom_tag.upbdefs.c +95 -0
  383. data/src/core/ext/upbdefs-generated/envoy/type/tracing/v3/custom_tag.upbdefs.h +55 -0
  384. data/src/core/ext/upbdefs-generated/envoy/type/v3/http.upbdefs.c +34 -0
  385. data/src/core/ext/{upb-generated/gogoproto/gogo.upb.h → upbdefs-generated/envoy/type/v3/http.upbdefs.h} +10 -9
  386. data/src/core/ext/upbdefs-generated/envoy/type/v3/percent.upbdefs.c +59 -0
  387. data/src/core/ext/upbdefs-generated/envoy/type/v3/percent.upbdefs.h +40 -0
  388. data/src/core/ext/upbdefs-generated/envoy/type/v3/range.upbdefs.c +54 -0
  389. data/src/core/ext/upbdefs-generated/envoy/type/v3/range.upbdefs.h +45 -0
  390. data/src/core/ext/upbdefs-generated/envoy/type/v3/semantic_version.upbdefs.c +47 -0
  391. data/src/core/ext/upbdefs-generated/envoy/type/v3/semantic_version.upbdefs.h +35 -0
  392. data/src/core/ext/upbdefs-generated/google/api/annotations.upbdefs.c +40 -0
  393. data/src/core/ext/upbdefs-generated/google/api/annotations.upbdefs.h +30 -0
  394. data/src/core/ext/upbdefs-generated/google/api/http.upbdefs.c +61 -0
  395. data/src/core/ext/upbdefs-generated/google/api/http.upbdefs.h +45 -0
  396. data/src/core/ext/upbdefs-generated/google/protobuf/any.upbdefs.c +39 -0
  397. data/src/core/ext/upbdefs-generated/google/protobuf/any.upbdefs.h +35 -0
  398. data/src/core/ext/upbdefs-generated/google/protobuf/descriptor.upbdefs.c +386 -0
  399. data/src/core/ext/upbdefs-generated/google/protobuf/descriptor.upbdefs.h +165 -0
  400. data/src/core/ext/upbdefs-generated/google/protobuf/duration.upbdefs.c +40 -0
  401. data/src/core/ext/upbdefs-generated/google/protobuf/duration.upbdefs.h +35 -0
  402. data/src/core/ext/upbdefs-generated/google/protobuf/empty.upbdefs.c +37 -0
  403. data/src/core/ext/upbdefs-generated/google/protobuf/empty.upbdefs.h +35 -0
  404. data/src/core/ext/upbdefs-generated/google/protobuf/struct.upbdefs.c +65 -0
  405. data/src/core/ext/upbdefs-generated/google/protobuf/struct.upbdefs.h +50 -0
  406. data/src/core/ext/upbdefs-generated/google/protobuf/timestamp.upbdefs.c +40 -0
  407. data/src/core/ext/upbdefs-generated/google/protobuf/timestamp.upbdefs.h +35 -0
  408. data/src/core/ext/upbdefs-generated/google/protobuf/wrappers.upbdefs.c +66 -0
  409. data/src/core/ext/upbdefs-generated/google/protobuf/wrappers.upbdefs.h +75 -0
  410. data/src/core/ext/upbdefs-generated/google/rpc/status.upbdefs.c +42 -0
  411. data/src/core/ext/upbdefs-generated/google/rpc/status.upbdefs.h +35 -0
  412. data/src/core/ext/upbdefs-generated/udpa/annotations/migrate.upbdefs.c +70 -0
  413. data/src/core/ext/upbdefs-generated/udpa/annotations/migrate.upbdefs.h +45 -0
  414. data/src/core/ext/upbdefs-generated/udpa/annotations/security.upbdefs.c +56 -0
  415. data/src/core/ext/upbdefs-generated/udpa/annotations/security.upbdefs.h +35 -0
  416. data/src/core/ext/upbdefs-generated/udpa/annotations/sensitive.upbdefs.c +33 -0
  417. data/src/core/ext/upbdefs-generated/udpa/annotations/sensitive.upbdefs.h +30 -0
  418. data/src/core/ext/upbdefs-generated/udpa/annotations/status.upbdefs.c +49 -0
  419. data/src/core/ext/upbdefs-generated/udpa/annotations/status.upbdefs.h +35 -0
  420. data/src/core/ext/upbdefs-generated/udpa/annotations/versioning.upbdefs.c +43 -0
  421. data/src/core/ext/upbdefs-generated/udpa/annotations/versioning.upbdefs.h +35 -0
  422. data/src/core/ext/upbdefs-generated/udpa/core/v1/authority.upbdefs.c +42 -0
  423. data/src/core/ext/upbdefs-generated/udpa/core/v1/authority.upbdefs.h +35 -0
  424. data/src/core/ext/upbdefs-generated/udpa/core/v1/collection_entry.upbdefs.c +62 -0
  425. data/src/core/ext/upbdefs-generated/udpa/core/v1/collection_entry.upbdefs.h +40 -0
  426. data/src/core/ext/upbdefs-generated/udpa/core/v1/context_params.upbdefs.c +45 -0
  427. data/src/core/ext/upbdefs-generated/udpa/core/v1/context_params.upbdefs.h +40 -0
  428. data/src/core/ext/upbdefs-generated/udpa/core/v1/resource.upbdefs.c +49 -0
  429. data/src/core/ext/upbdefs-generated/udpa/core/v1/resource.upbdefs.h +35 -0
  430. data/src/core/ext/upbdefs-generated/udpa/core/v1/resource_locator.upbdefs.c +68 -0
  431. data/src/core/ext/upbdefs-generated/udpa/core/v1/resource_locator.upbdefs.h +40 -0
  432. data/src/core/ext/upbdefs-generated/udpa/core/v1/resource_name.upbdefs.c +51 -0
  433. data/src/core/ext/upbdefs-generated/udpa/core/v1/resource_name.upbdefs.h +35 -0
  434. data/src/core/ext/upbdefs-generated/validate/validate.upbdefs.c +307 -0
  435. data/src/core/ext/upbdefs-generated/validate/validate.upbdefs.h +145 -0
  436. data/src/core/ext/xds/certificate_provider_factory.h +61 -0
  437. data/src/core/ext/xds/certificate_provider_registry.cc +103 -0
  438. data/src/core/ext/xds/certificate_provider_registry.h +57 -0
  439. data/src/core/ext/xds/certificate_provider_store.cc +87 -0
  440. data/src/core/ext/xds/certificate_provider_store.h +112 -0
  441. data/src/core/ext/xds/file_watcher_certificate_provider_factory.cc +144 -0
  442. data/src/core/ext/xds/file_watcher_certificate_provider_factory.h +69 -0
  443. data/src/core/ext/xds/xds_api.cc +687 -767
  444. data/src/core/ext/xds/xds_api.h +207 -98
  445. data/src/core/ext/xds/xds_bootstrap.cc +172 -25
  446. data/src/core/ext/xds/xds_bootstrap.h +23 -8
  447. data/src/core/ext/xds/xds_certificate_provider.cc +299 -0
  448. data/src/core/ext/xds/xds_certificate_provider.h +112 -0
  449. data/src/core/ext/xds/xds_channel_args.h +6 -3
  450. data/src/core/ext/xds/xds_client.cc +617 -494
  451. data/src/core/ext/xds/xds_client.h +118 -58
  452. data/src/core/ext/xds/xds_client_stats.cc +59 -16
  453. data/src/core/ext/xds/xds_client_stats.h +35 -7
  454. data/src/core/ext/xds/xds_server_config_fetcher.cc +131 -0
  455. data/src/core/lib/channel/channel_args.cc +9 -8
  456. data/src/core/lib/channel/channel_args.h +0 -1
  457. data/src/core/lib/channel/channel_trace.cc +4 -2
  458. data/src/core/lib/channel/channel_trace.h +1 -1
  459. data/src/core/lib/channel/channelz.cc +23 -59
  460. data/src/core/lib/channel/channelz.h +13 -22
  461. data/src/core/lib/channel/channelz_registry.cc +12 -11
  462. data/src/core/lib/channel/channelz_registry.h +3 -1
  463. data/src/core/lib/channel/handshaker.cc +2 -2
  464. data/src/core/lib/channel/handshaker.h +2 -2
  465. data/src/core/lib/compression/compression.cc +8 -4
  466. data/src/core/lib/compression/compression_args.cc +3 -2
  467. data/src/core/lib/compression/compression_internal.cc +10 -5
  468. data/src/core/lib/compression/compression_internal.h +2 -1
  469. data/src/core/lib/compression/stream_compression_identity.cc +1 -3
  470. data/src/core/lib/debug/stats.h +2 -2
  471. data/src/core/lib/debug/stats_data.cc +1 -0
  472. data/src/core/lib/debug/stats_data.h +13 -13
  473. data/src/core/lib/gpr/alloc.cc +3 -2
  474. data/src/core/lib/gpr/cpu_iphone.cc +10 -2
  475. data/src/core/lib/gpr/log.cc +53 -16
  476. data/src/core/lib/gpr/log_linux.cc +19 -3
  477. data/src/core/lib/gpr/log_posix.cc +15 -1
  478. data/src/core/lib/gpr/log_windows.cc +18 -4
  479. data/src/core/lib/gpr/murmur_hash.cc +1 -1
  480. data/src/core/lib/gpr/spinlock.h +10 -2
  481. data/src/core/lib/gpr/string.cc +23 -22
  482. data/src/core/lib/gpr/string.h +5 -6
  483. data/src/core/lib/gpr/sync.cc +4 -4
  484. data/src/core/lib/gpr/time.cc +12 -12
  485. data/src/core/lib/gpr/time_precise.cc +5 -2
  486. data/src/core/lib/gpr/time_precise.h +6 -2
  487. data/src/core/lib/gpr/tls.h +4 -0
  488. data/src/core/lib/gpr/tls_msvc.h +2 -0
  489. data/src/core/lib/gpr/tls_stdcpp.h +48 -0
  490. data/src/core/lib/gpr/useful.h +5 -4
  491. data/src/core/lib/gprpp/arena.h +3 -2
  492. data/src/core/lib/gprpp/dual_ref_counted.h +331 -0
  493. data/src/core/lib/gprpp/examine_stack.cc +43 -0
  494. data/src/core/lib/gprpp/examine_stack.h +46 -0
  495. data/src/core/lib/gprpp/fork.cc +2 -2
  496. data/src/core/lib/gprpp/manual_constructor.h +1 -1
  497. data/src/core/lib/gprpp/orphanable.h +4 -8
  498. data/src/core/lib/gprpp/ref_counted.h +91 -68
  499. data/src/core/lib/gprpp/ref_counted_ptr.h +166 -7
  500. data/src/core/lib/{security/authorization/mock_cel/statusor.h → gprpp/stat.h} +13 -25
  501. data/src/core/lib/gprpp/stat_posix.cc +49 -0
  502. data/src/core/lib/gprpp/stat_windows.cc +48 -0
  503. data/src/core/lib/gprpp/thd.h +2 -2
  504. data/src/core/lib/gprpp/thd_posix.cc +42 -37
  505. data/src/core/lib/gprpp/thd_windows.cc +3 -1
  506. data/src/core/lib/http/httpcli.cc +1 -1
  507. data/src/core/lib/http/httpcli.h +2 -3
  508. data/src/core/lib/http/httpcli_security_connector.cc +1 -1
  509. data/src/core/lib/http/parser.cc +47 -27
  510. data/src/core/lib/iomgr/call_combiner.cc +8 -5
  511. data/src/core/lib/iomgr/combiner.cc +2 -1
  512. data/src/core/lib/iomgr/endpoint.h +1 -1
  513. data/src/core/lib/iomgr/endpoint_cfstream.cc +9 -5
  514. data/src/core/lib/iomgr/error.cc +17 -12
  515. data/src/core/lib/iomgr/error_internal.h +1 -1
  516. data/src/core/lib/iomgr/ev_epoll1_linux.cc +20 -13
  517. data/src/core/lib/iomgr/ev_epollex_linux.cc +25 -17
  518. data/src/core/lib/iomgr/ev_poll_posix.cc +9 -7
  519. data/src/core/lib/iomgr/exec_ctx.cc +1 -1
  520. data/src/core/lib/iomgr/exec_ctx.h +16 -12
  521. data/src/core/lib/iomgr/executor.cc +2 -1
  522. data/src/core/lib/iomgr/executor.h +1 -1
  523. data/src/core/lib/iomgr/executor/mpmcqueue.h +5 -5
  524. data/src/core/lib/iomgr/executor/threadpool.h +4 -4
  525. data/src/core/lib/iomgr/iomgr.cc +1 -1
  526. data/src/core/lib/iomgr/load_file.h +1 -1
  527. data/src/core/lib/iomgr/lockfree_event.cc +19 -14
  528. data/src/core/lib/iomgr/lockfree_event.h +2 -2
  529. data/src/core/lib/iomgr/parse_address.cc +127 -43
  530. data/src/core/lib/iomgr/parse_address.h +32 -8
  531. data/src/core/lib/iomgr/poller/eventmanager_libuv.cc +2 -1
  532. data/src/core/lib/iomgr/poller/eventmanager_libuv.h +1 -1
  533. data/src/core/lib/iomgr/pollset_set_custom.cc +1 -1
  534. data/src/core/lib/iomgr/python_util.h +4 -4
  535. data/src/core/lib/iomgr/resolve_address.cc +4 -4
  536. data/src/core/lib/iomgr/resolve_address_posix.cc +1 -5
  537. data/src/core/lib/iomgr/resource_quota.cc +4 -4
  538. data/src/core/lib/iomgr/sockaddr_utils.cc +10 -10
  539. data/src/core/lib/iomgr/sockaddr_utils.h +1 -1
  540. data/src/core/lib/iomgr/socket_factory_posix.cc +3 -2
  541. data/src/core/lib/iomgr/socket_mutator.cc +3 -2
  542. data/src/core/lib/iomgr/tcp_client.cc +3 -3
  543. data/src/core/lib/iomgr/tcp_client_custom.cc +7 -6
  544. data/src/core/lib/iomgr/tcp_custom.cc +22 -17
  545. data/src/core/lib/iomgr/tcp_posix.cc +12 -8
  546. data/src/core/lib/iomgr/tcp_server_custom.cc +28 -22
  547. data/src/core/lib/iomgr/timer_custom.cc +5 -5
  548. data/src/core/lib/iomgr/timer_generic.cc +3 -3
  549. data/src/core/lib/iomgr/timer_manager.cc +2 -2
  550. data/src/core/lib/iomgr/udp_server.cc +1 -2
  551. data/src/core/lib/iomgr/udp_server.h +1 -2
  552. data/src/core/lib/iomgr/unix_sockets_posix.cc +32 -21
  553. data/src/core/lib/iomgr/unix_sockets_posix.h +5 -0
  554. data/src/core/lib/iomgr/unix_sockets_posix_noop.cc +7 -0
  555. data/src/core/lib/iomgr/wakeup_fd_pipe.cc +2 -2
  556. data/src/core/lib/json/json.h +12 -2
  557. data/src/core/lib/json/json_reader.cc +8 -4
  558. data/src/core/lib/json/json_util.cc +58 -0
  559. data/src/core/lib/json/json_util.h +204 -0
  560. data/src/core/lib/json/json_writer.cc +2 -1
  561. data/src/core/lib/security/authorization/evaluate_args.cc +5 -10
  562. data/src/core/lib/security/authorization/evaluate_args.h +1 -1
  563. data/src/core/lib/security/authorization/mock_cel/cel_expr_builder_factory.h +3 -1
  564. data/src/core/lib/security/authorization/mock_cel/cel_expression.h +5 -4
  565. data/src/core/lib/security/authorization/mock_cel/cel_value.h +4 -0
  566. data/src/core/lib/security/authorization/mock_cel/evaluator_core.h +6 -6
  567. data/src/core/lib/security/authorization/mock_cel/flat_expr_builder.h +10 -9
  568. data/src/core/lib/security/context/security_context.cc +4 -3
  569. data/src/core/lib/security/context/security_context.h +3 -1
  570. data/src/core/lib/security/credentials/alts/check_gcp_environment.cc +1 -1
  571. data/src/core/lib/security/credentials/credentials.cc +7 -7
  572. data/src/core/lib/security/credentials/credentials.h +3 -3
  573. data/src/core/lib/security/credentials/external/aws_external_account_credentials.cc +413 -0
  574. data/src/core/lib/security/credentials/external/aws_external_account_credentials.h +80 -0
  575. data/src/core/lib/security/credentials/external/aws_request_signer.cc +213 -0
  576. data/src/core/lib/security/credentials/external/aws_request_signer.h +72 -0
  577. data/src/core/lib/security/credentials/external/external_account_credentials.cc +497 -0
  578. data/src/core/lib/security/credentials/external/external_account_credentials.h +120 -0
  579. data/src/core/lib/security/credentials/external/file_external_account_credentials.cc +135 -0
  580. data/src/core/lib/security/credentials/external/file_external_account_credentials.h +48 -0
  581. data/src/core/lib/security/credentials/external/url_external_account_credentials.cc +213 -0
  582. data/src/core/lib/security/credentials/external/url_external_account_credentials.h +58 -0
  583. data/src/core/lib/security/credentials/fake/fake_credentials.cc +2 -1
  584. data/src/core/lib/security/credentials/google_default/google_default_credentials.cc +18 -12
  585. data/src/core/lib/security/credentials/insecure/insecure_credentials.cc +64 -0
  586. data/src/core/lib/security/credentials/jwt/json_token.cc +6 -3
  587. data/src/core/lib/security/credentials/jwt/jwt_credentials.h +4 -3
  588. data/src/core/lib/security/credentials/jwt/jwt_verifier.cc +8 -4
  589. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc +39 -46
  590. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.h +5 -4
  591. data/src/core/lib/security/credentials/plugin/plugin_credentials.cc +1 -1
  592. data/src/core/lib/security/credentials/ssl/ssl_credentials.cc +5 -5
  593. data/src/core/lib/security/credentials/ssl/ssl_credentials.h +1 -1
  594. data/src/core/lib/security/credentials/tls/grpc_tls_certificate_distributor.cc +346 -0
  595. data/src/core/lib/security/credentials/tls/grpc_tls_certificate_distributor.h +213 -0
  596. data/src/core/lib/security/credentials/tls/grpc_tls_certificate_provider.cc +399 -0
  597. data/src/core/lib/security/credentials/tls/grpc_tls_certificate_provider.h +138 -0
  598. data/src/core/lib/security/credentials/tls/grpc_tls_credentials_options.cc +78 -150
  599. data/src/core/lib/security/credentials/tls/grpc_tls_credentials_options.h +57 -187
  600. data/src/core/lib/security/credentials/tls/tls_credentials.cc +16 -12
  601. data/src/core/lib/security/credentials/tls/tls_credentials.h +2 -2
  602. data/src/core/lib/security/credentials/tls/tls_utils.cc +91 -0
  603. data/src/core/lib/security/credentials/tls/tls_utils.h +38 -0
  604. data/src/core/lib/security/credentials/xds/xds_credentials.cc +175 -0
  605. data/src/core/lib/security/credentials/xds/xds_credentials.h +69 -0
  606. data/src/core/lib/security/security_connector/alts/alts_security_connector.cc +1 -1
  607. data/src/core/lib/security/security_connector/fake/fake_security_connector.cc +9 -13
  608. data/src/core/lib/security/security_connector/insecure/insecure_security_connector.cc +121 -0
  609. data/src/core/lib/security/security_connector/insecure/insecure_security_connector.h +87 -0
  610. data/src/core/lib/security/security_connector/load_system_roots.h +4 -0
  611. data/src/core/lib/security/security_connector/load_system_roots_linux.h +2 -0
  612. data/src/core/lib/security/security_connector/local/local_security_connector.cc +3 -3
  613. data/src/core/lib/security/security_connector/security_connector.cc +4 -3
  614. data/src/core/lib/security/security_connector/security_connector.h +4 -2
  615. data/src/core/lib/security/security_connector/ssl/ssl_security_connector.cc +4 -4
  616. data/src/core/lib/security/security_connector/ssl_utils.cc +2 -2
  617. data/src/core/lib/security/security_connector/ssl_utils.h +19 -19
  618. data/src/core/lib/security/security_connector/tls/tls_security_connector.cc +342 -279
  619. data/src/core/lib/security/security_connector/tls/tls_security_connector.h +105 -61
  620. data/src/core/lib/security/transport/secure_endpoint.cc +2 -2
  621. data/src/core/lib/security/transport/security_handshaker.cc +3 -3
  622. data/src/core/lib/security/transport/server_auth_filter.cc +2 -1
  623. data/src/core/lib/security/util/json_util.h +1 -0
  624. data/src/core/lib/slice/slice.cc +7 -4
  625. data/src/core/lib/slice/slice_buffer.cc +2 -1
  626. data/src/core/lib/slice/slice_intern.cc +6 -7
  627. data/src/core/lib/slice/slice_internal.h +2 -2
  628. data/src/core/lib/surface/call.cc +41 -32
  629. data/src/core/lib/surface/call_details.cc +8 -8
  630. data/src/core/lib/surface/channel.cc +25 -41
  631. data/src/core/lib/surface/channel.h +9 -3
  632. data/src/core/lib/surface/channel_init.cc +1 -1
  633. data/src/core/lib/surface/completion_queue.cc +30 -24
  634. data/src/core/lib/surface/completion_queue.h +16 -16
  635. data/src/core/lib/surface/init.cc +32 -14
  636. data/src/core/lib/surface/lame_client.cc +20 -46
  637. data/src/core/lib/surface/lame_client.h +4 -0
  638. data/src/core/lib/surface/server.cc +63 -17
  639. data/src/core/lib/surface/server.h +39 -7
  640. data/src/core/lib/surface/validate_metadata.h +3 -0
  641. data/src/core/lib/surface/version.cc +2 -2
  642. data/src/core/lib/transport/authority_override.cc +6 -4
  643. data/src/core/lib/transport/authority_override.h +7 -2
  644. data/src/core/lib/transport/bdp_estimator.cc +1 -1
  645. data/src/core/lib/transport/bdp_estimator.h +2 -1
  646. data/src/core/lib/transport/byte_stream.h +3 -3
  647. data/src/core/lib/transport/connectivity_state.h +11 -9
  648. data/src/core/lib/transport/error_utils.h +1 -1
  649. data/src/core/lib/transport/metadata.cc +11 -1
  650. data/src/core/lib/transport/metadata.h +2 -2
  651. data/src/core/lib/transport/metadata_batch.h +4 -4
  652. data/src/core/lib/transport/static_metadata.cc +1 -1
  653. data/src/core/lib/transport/status_metadata.cc +4 -3
  654. data/src/core/lib/transport/timeout_encoding.cc +4 -4
  655. data/src/core/lib/transport/transport.cc +5 -3
  656. data/src/core/lib/transport/transport.h +8 -8
  657. data/src/core/lib/uri/uri_parser.cc +131 -249
  658. data/src/core/lib/uri/uri_parser.h +57 -21
  659. data/src/core/plugin_registry/grpc_plugin_registry.cc +41 -20
  660. data/src/core/tsi/alts/crypt/gsec.cc +5 -4
  661. data/src/core/tsi/alts/frame_protector/frame_handler.cc +8 -6
  662. data/src/core/tsi/alts/handshaker/alts_handshaker_client.cc +1 -1
  663. data/src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc +27 -26
  664. data/src/core/tsi/alts/zero_copy_frame_protector/alts_iovec_record_protocol.cc +8 -6
  665. data/src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.cc +4 -4
  666. data/src/core/tsi/fake_transport_security.cc +6 -3
  667. data/src/core/tsi/local_transport_security.cc +5 -1
  668. data/src/core/tsi/local_transport_security.h +6 -7
  669. data/src/core/tsi/ssl/session_cache/ssl_session.h +3 -0
  670. data/src/core/tsi/ssl/session_cache/ssl_session_boringssl.cc +1 -1
  671. data/src/core/tsi/ssl/session_cache/ssl_session_cache.h +4 -1
  672. data/src/core/tsi/ssl_transport_security.cc +78 -58
  673. data/src/core/tsi/ssl_transport_security.h +9 -6
  674. data/src/core/tsi/transport_security.cc +10 -8
  675. data/src/core/tsi/transport_security_interface.h +1 -1
  676. data/src/ruby/ext/grpc/extconf.rb +1 -1
  677. data/src/ruby/ext/grpc/rb_event_thread.c +2 -0
  678. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +36 -16
  679. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +70 -40
  680. data/src/ruby/lib/grpc/version.rb +1 -1
  681. data/src/ruby/pb/src/proto/grpc/testing/messages_pb.rb +28 -0
  682. data/src/ruby/pb/src/proto/grpc/testing/test_services_pb.rb +18 -0
  683. data/src/ruby/spec/pb/codegen/package_option_spec.rb +2 -6
  684. data/third_party/abseil-cpp/absl/algorithm/container.h +59 -22
  685. data/third_party/abseil-cpp/absl/base/attributes.h +99 -38
  686. data/third_party/abseil-cpp/absl/base/call_once.h +1 -1
  687. data/third_party/abseil-cpp/absl/base/casts.h +9 -6
  688. data/third_party/abseil-cpp/absl/base/config.h +60 -17
  689. data/third_party/abseil-cpp/absl/base/dynamic_annotations.h +428 -335
  690. data/third_party/abseil-cpp/absl/base/internal/bits.h +17 -16
  691. data/third_party/abseil-cpp/absl/base/internal/direct_mmap.h +5 -0
  692. data/third_party/abseil-cpp/absl/base/internal/dynamic_annotations.h +398 -0
  693. data/third_party/abseil-cpp/absl/base/internal/invoke.h +4 -4
  694. data/third_party/abseil-cpp/absl/base/internal/low_level_alloc.cc +1 -1
  695. data/third_party/abseil-cpp/absl/base/internal/low_level_scheduling.h +29 -1
  696. data/third_party/abseil-cpp/absl/base/internal/raw_logging.cc +2 -2
  697. data/third_party/abseil-cpp/absl/base/internal/raw_logging.h +7 -5
  698. data/third_party/abseil-cpp/absl/base/internal/spinlock.cc +25 -38
  699. data/third_party/abseil-cpp/absl/base/internal/spinlock.h +19 -25
  700. data/third_party/abseil-cpp/absl/base/internal/spinlock_linux.inc +8 -0
  701. data/third_party/abseil-cpp/absl/base/internal/sysinfo.cc +28 -5
  702. data/third_party/abseil-cpp/absl/base/internal/sysinfo.h +8 -0
  703. data/third_party/abseil-cpp/absl/base/internal/tsan_mutex_interface.h +3 -1
  704. data/third_party/abseil-cpp/absl/base/internal/unaligned_access.h +2 -2
  705. data/third_party/abseil-cpp/absl/base/internal/unscaledcycleclock.h +3 -3
  706. data/third_party/abseil-cpp/absl/base/macros.h +36 -109
  707. data/third_party/abseil-cpp/absl/base/optimization.h +61 -1
  708. data/third_party/abseil-cpp/absl/base/options.h +31 -4
  709. data/third_party/abseil-cpp/absl/base/policy_checks.h +1 -1
  710. data/third_party/abseil-cpp/absl/base/thread_annotations.h +94 -39
  711. data/third_party/abseil-cpp/absl/container/fixed_array.h +42 -25
  712. data/third_party/abseil-cpp/absl/container/flat_hash_map.h +606 -0
  713. data/third_party/abseil-cpp/absl/container/flat_hash_set.h +2 -1
  714. data/third_party/abseil-cpp/absl/container/inlined_vector.h +33 -36
  715. data/third_party/abseil-cpp/absl/container/internal/common.h +6 -2
  716. data/third_party/abseil-cpp/absl/container/internal/compressed_tuple.h +33 -8
  717. data/third_party/abseil-cpp/absl/container/internal/container_memory.h +49 -29
  718. data/third_party/abseil-cpp/absl/container/internal/hash_function_defaults.h +15 -0
  719. data/third_party/abseil-cpp/absl/container/internal/hash_policy_traits.h +24 -7
  720. data/third_party/abseil-cpp/absl/container/internal/hashtablez_sampler.cc +2 -1
  721. data/third_party/abseil-cpp/absl/container/internal/hashtablez_sampler.h +35 -11
  722. data/third_party/abseil-cpp/absl/container/internal/have_sse.h +10 -9
  723. data/third_party/abseil-cpp/absl/container/internal/layout.h +7 -5
  724. data/third_party/abseil-cpp/absl/container/internal/raw_hash_map.h +197 -0
  725. data/third_party/abseil-cpp/absl/container/internal/raw_hash_set.h +55 -34
  726. data/third_party/abseil-cpp/absl/debugging/internal/address_is_readable.cc +5 -4
  727. data/third_party/abseil-cpp/absl/debugging/internal/demangle.cc +66 -16
  728. data/third_party/abseil-cpp/absl/debugging/internal/stacktrace_aarch64-inl.inc +4 -0
  729. data/third_party/abseil-cpp/absl/debugging/internal/stacktrace_arm-inl.inc +13 -4
  730. data/third_party/abseil-cpp/absl/debugging/internal/stacktrace_config.h +43 -24
  731. data/third_party/abseil-cpp/absl/debugging/internal/stacktrace_generic-inl.inc +12 -3
  732. data/third_party/abseil-cpp/absl/debugging/internal/stacktrace_win32-inl.inc +10 -2
  733. data/third_party/abseil-cpp/absl/debugging/internal/symbolize.h +22 -1
  734. data/third_party/abseil-cpp/absl/debugging/internal/vdso_support.cc +0 -21
  735. data/third_party/abseil-cpp/absl/debugging/symbolize.cc +12 -1
  736. data/third_party/abseil-cpp/absl/debugging/symbolize_darwin.inc +101 -0
  737. data/third_party/abseil-cpp/absl/debugging/symbolize_elf.inc +100 -20
  738. data/third_party/abseil-cpp/absl/functional/bind_front.h +184 -0
  739. data/third_party/abseil-cpp/absl/functional/function_ref.h +1 -1
  740. data/third_party/abseil-cpp/absl/functional/internal/front_binder.h +95 -0
  741. data/third_party/abseil-cpp/absl/functional/internal/function_ref.h +2 -2
  742. data/third_party/abseil-cpp/absl/hash/hash.h +6 -5
  743. data/third_party/abseil-cpp/absl/hash/internal/hash.h +73 -65
  744. data/third_party/abseil-cpp/absl/memory/memory.h +4 -0
  745. data/third_party/abseil-cpp/absl/meta/type_traits.h +2 -8
  746. data/third_party/abseil-cpp/absl/numeric/int128.cc +13 -27
  747. data/third_party/abseil-cpp/absl/numeric/int128.h +16 -15
  748. data/third_party/abseil-cpp/absl/status/internal/status_internal.h +51 -0
  749. data/third_party/abseil-cpp/absl/status/internal/statusor_internal.h +399 -0
  750. data/third_party/abseil-cpp/absl/status/status.cc +4 -6
  751. data/third_party/abseil-cpp/absl/status/status.h +502 -113
  752. data/third_party/abseil-cpp/absl/status/status_payload_printer.cc +5 -10
  753. data/third_party/abseil-cpp/absl/status/statusor.cc +71 -0
  754. data/third_party/abseil-cpp/absl/status/statusor.h +760 -0
  755. data/third_party/abseil-cpp/absl/strings/charconv.cc +2 -2
  756. data/third_party/abseil-cpp/absl/strings/cord.cc +91 -112
  757. data/third_party/abseil-cpp/absl/strings/cord.h +360 -205
  758. data/third_party/abseil-cpp/absl/strings/escaping.cc +9 -9
  759. data/third_party/abseil-cpp/absl/strings/internal/char_map.h +1 -1
  760. data/third_party/abseil-cpp/absl/strings/internal/charconv_bigint.cc +1 -1
  761. data/third_party/abseil-cpp/absl/strings/internal/charconv_bigint.h +2 -2
  762. data/third_party/abseil-cpp/absl/strings/internal/charconv_parse.cc +2 -2
  763. data/third_party/abseil-cpp/absl/strings/internal/cord_internal.h +45 -23
  764. data/third_party/abseil-cpp/absl/strings/internal/str_format/arg.cc +222 -136
  765. data/third_party/abseil-cpp/absl/strings/internal/str_format/arg.h +136 -64
  766. data/third_party/abseil-cpp/absl/strings/internal/str_format/bind.cc +1 -1
  767. data/third_party/abseil-cpp/absl/strings/internal/str_format/bind.h +14 -21
  768. data/third_party/abseil-cpp/absl/strings/internal/str_format/checker.h +7 -14
  769. data/third_party/abseil-cpp/absl/strings/internal/str_format/extension.cc +31 -7
  770. data/third_party/abseil-cpp/absl/strings/internal/str_format/extension.h +147 -135
  771. data/third_party/abseil-cpp/absl/strings/internal/str_format/float_conversion.cc +999 -87
  772. data/third_party/abseil-cpp/absl/strings/internal/str_format/float_conversion.h +3 -3
  773. data/third_party/abseil-cpp/absl/strings/internal/str_format/output.h +4 -12
  774. data/third_party/abseil-cpp/absl/strings/internal/str_format/parser.cc +8 -6
  775. data/third_party/abseil-cpp/absl/strings/internal/str_format/parser.h +13 -11
  776. data/third_party/abseil-cpp/absl/strings/internal/str_split_internal.h +2 -2
  777. data/third_party/abseil-cpp/absl/strings/str_cat.cc +4 -4
  778. data/third_party/abseil-cpp/absl/strings/str_cat.h +1 -1
  779. data/third_party/abseil-cpp/absl/strings/str_format.h +289 -13
  780. data/third_party/abseil-cpp/absl/strings/str_split.cc +2 -2
  781. data/third_party/abseil-cpp/absl/strings/str_split.h +1 -0
  782. data/third_party/abseil-cpp/absl/strings/string_view.h +26 -19
  783. data/third_party/abseil-cpp/absl/strings/substitute.cc +5 -5
  784. data/third_party/abseil-cpp/absl/strings/substitute.h +32 -29
  785. data/third_party/abseil-cpp/absl/synchronization/internal/create_thread_identity.cc +3 -3
  786. data/third_party/abseil-cpp/absl/synchronization/internal/graphcycles.cc +3 -3
  787. data/third_party/abseil-cpp/absl/synchronization/internal/kernel_timeout.h +28 -28
  788. data/third_party/abseil-cpp/absl/synchronization/internal/mutex_nonprod.inc +4 -16
  789. data/third_party/abseil-cpp/absl/synchronization/internal/per_thread_sem.h +1 -1
  790. data/third_party/abseil-cpp/absl/synchronization/internal/waiter.cc +8 -0
  791. data/third_party/abseil-cpp/absl/synchronization/internal/waiter.h +2 -2
  792. data/third_party/abseil-cpp/absl/synchronization/mutex.cc +75 -64
  793. data/third_party/abseil-cpp/absl/synchronization/mutex.h +15 -6
  794. data/third_party/abseil-cpp/absl/time/civil_time.cc +9 -9
  795. data/third_party/abseil-cpp/absl/time/clock.cc +3 -3
  796. data/third_party/abseil-cpp/absl/time/duration.cc +90 -59
  797. data/third_party/abseil-cpp/absl/time/format.cc +43 -36
  798. data/third_party/abseil-cpp/absl/time/internal/cctz/include/cctz/civil_time_detail.h +26 -16
  799. data/third_party/abseil-cpp/absl/time/internal/cctz/include/cctz/time_zone.h +4 -2
  800. data/third_party/abseil-cpp/absl/time/internal/cctz/include/cctz/zone_info_source.h +1 -1
  801. data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_format.cc +136 -29
  802. data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_impl.cc +13 -21
  803. data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_impl.h +1 -1
  804. data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_info.cc +136 -129
  805. data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_info.h +4 -5
  806. data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_libc.cc +8 -7
  807. data/third_party/abseil-cpp/absl/time/internal/cctz/src/tzfile.h +6 -6
  808. data/third_party/abseil-cpp/absl/time/internal/cctz/src/zone_info_source.cc +2 -1
  809. data/third_party/abseil-cpp/absl/time/time.h +15 -16
  810. data/third_party/abseil-cpp/absl/types/internal/variant.h +4 -4
  811. data/third_party/abseil-cpp/absl/types/optional.h +9 -9
  812. data/third_party/abseil-cpp/absl/types/span.h +49 -36
  813. data/third_party/abseil-cpp/absl/utility/utility.h +2 -2
  814. data/third_party/address_sorting/include/address_sorting/address_sorting.h +2 -0
  815. data/third_party/boringssl-with-bazel/err_data.c +469 -463
  816. data/third_party/boringssl-with-bazel/src/crypto/asn1/asn1_lib.c +0 -6
  817. data/third_party/boringssl-with-bazel/src/crypto/bio/bio.c +2 -0
  818. data/third_party/boringssl-with-bazel/src/crypto/dsa/dsa.c +9 -43
  819. data/third_party/boringssl-with-bazel/src/crypto/dsa/dsa_asn1.c +55 -4
  820. data/third_party/boringssl-with-bazel/src/crypto/dsa/internal.h +34 -0
  821. data/third_party/boringssl-with-bazel/src/crypto/evp/evp.c +4 -0
  822. data/third_party/boringssl-with-bazel/src/crypto/evp/p_dsa_asn1.c +6 -2
  823. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/cipher/e_aes.c +173 -35
  824. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/digest/digest.c +2 -0
  825. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rsa/internal.h +4 -0
  826. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rsa/rsa.c +30 -10
  827. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rsa/rsa_impl.c +56 -22
  828. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/self_check/self_check.c +8 -2
  829. data/third_party/boringssl-with-bazel/src/crypto/hpke/hpke.c +98 -11
  830. data/third_party/boringssl-with-bazel/src/crypto/hpke/internal.h +51 -6
  831. data/third_party/boringssl-with-bazel/src/crypto/trust_token/internal.h +118 -49
  832. data/third_party/boringssl-with-bazel/src/crypto/trust_token/pmbtoken.c +267 -95
  833. data/third_party/boringssl-with-bazel/src/crypto/trust_token/trust_token.c +210 -34
  834. data/third_party/boringssl-with-bazel/src/crypto/trust_token/voprf.c +766 -0
  835. data/third_party/boringssl-with-bazel/src/crypto/x509/a_strex.c +3 -3
  836. data/third_party/boringssl-with-bazel/src/crypto/x509/algorithm.c +6 -4
  837. data/third_party/boringssl-with-bazel/src/crypto/x509/t_crl.c +3 -3
  838. data/third_party/boringssl-with-bazel/src/crypto/x509/t_x509.c +1 -1
  839. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_cmp.c +7 -2
  840. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_ext.c +21 -18
  841. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_obj.c +1 -1
  842. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_set.c +24 -3
  843. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_trs.c +3 -3
  844. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_txt.c +67 -67
  845. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_v3.c +3 -3
  846. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_vfy.c +29 -35
  847. data/third_party/boringssl-with-bazel/src/crypto/x509/x509cset.c +13 -2
  848. data/third_party/boringssl-with-bazel/src/crypto/x509/x509name.c +9 -8
  849. data/third_party/boringssl-with-bazel/src/crypto/x509/x_all.c +10 -10
  850. data/third_party/boringssl-with-bazel/src/crypto/x509/x_crl.c +2 -2
  851. data/third_party/boringssl-with-bazel/src/crypto/x509/x_name.c +28 -40
  852. data/third_party/boringssl-with-bazel/src/crypto/x509/x_x509.c +3 -1
  853. data/third_party/boringssl-with-bazel/src/crypto/x509v3/ext_dat.h +1 -4
  854. data/third_party/boringssl-with-bazel/src/crypto/x509v3/pcy_data.c +5 -3
  855. data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_alt.c +14 -14
  856. data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_conf.c +7 -3
  857. data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_genn.c +2 -2
  858. data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_info.c +1 -1
  859. data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_prn.c +1 -1
  860. data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_purp.c +55 -8
  861. data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_skey.c +1 -1
  862. data/third_party/boringssl-with-bazel/src/include/openssl/aead.h +24 -0
  863. data/third_party/boringssl-with-bazel/src/include/openssl/arm_arch.h +7 -5
  864. data/third_party/boringssl-with-bazel/src/include/openssl/asn1.h +0 -1
  865. data/third_party/boringssl-with-bazel/src/include/openssl/base.h +6 -3
  866. data/third_party/boringssl-with-bazel/src/include/openssl/bio.h +4 -0
  867. data/third_party/boringssl-with-bazel/src/include/openssl/cipher.h +6 -0
  868. data/third_party/boringssl-with-bazel/src/include/openssl/crypto.h +1 -1
  869. data/third_party/boringssl-with-bazel/src/include/openssl/des.h +6 -0
  870. data/third_party/boringssl-with-bazel/src/include/openssl/dh.h +12 -0
  871. data/third_party/boringssl-with-bazel/src/include/openssl/digest.h +9 -0
  872. data/third_party/boringssl-with-bazel/src/include/openssl/evp.h +4 -1
  873. data/third_party/boringssl-with-bazel/src/include/openssl/opensslconf.h +3 -0
  874. data/third_party/boringssl-with-bazel/src/include/openssl/pem.h +202 -134
  875. data/third_party/boringssl-with-bazel/src/include/openssl/ssl.h +64 -3
  876. data/third_party/boringssl-with-bazel/src/include/openssl/tls1.h +4 -0
  877. data/third_party/boringssl-with-bazel/src/include/openssl/trust_token.h +42 -14
  878. data/third_party/boringssl-with-bazel/src/include/openssl/x509.h +188 -78
  879. data/third_party/boringssl-with-bazel/src/include/openssl/x509v3.h +482 -432
  880. data/third_party/boringssl-with-bazel/src/ssl/bio_ssl.cc +18 -5
  881. data/third_party/boringssl-with-bazel/src/ssl/handoff.cc +35 -0
  882. data/third_party/boringssl-with-bazel/src/ssl/handshake.cc +18 -18
  883. data/third_party/boringssl-with-bazel/src/ssl/handshake_client.cc +2 -3
  884. data/third_party/boringssl-with-bazel/src/ssl/handshake_server.cc +1 -1
  885. data/third_party/boringssl-with-bazel/src/ssl/internal.h +45 -10
  886. data/third_party/boringssl-with-bazel/src/ssl/ssl_asn1.cc +42 -1
  887. data/third_party/boringssl-with-bazel/src/ssl/ssl_cipher.cc +8 -9
  888. data/third_party/boringssl-with-bazel/src/ssl/ssl_lib.cc +67 -0
  889. data/third_party/boringssl-with-bazel/src/ssl/ssl_session.cc +11 -14
  890. data/third_party/boringssl-with-bazel/src/ssl/t1_lib.cc +216 -11
  891. data/third_party/boringssl-with-bazel/src/ssl/tls13_both.cc +1 -2
  892. data/third_party/boringssl-with-bazel/src/ssl/tls13_client.cc +57 -19
  893. data/third_party/boringssl-with-bazel/src/ssl/tls13_server.cc +135 -41
  894. data/third_party/upb/third_party/wyhash/wyhash.h +145 -0
  895. data/third_party/upb/upb/decode.c +248 -167
  896. data/third_party/upb/upb/decode.h +20 -1
  897. data/third_party/upb/upb/decode.int.h +163 -0
  898. data/third_party/upb/upb/decode_fast.c +1040 -0
  899. data/third_party/upb/upb/decode_fast.h +126 -0
  900. data/third_party/upb/upb/def.c +2178 -0
  901. data/third_party/upb/upb/def.h +315 -0
  902. data/third_party/upb/upb/def.hpp +439 -0
  903. data/third_party/upb/upb/encode.c +227 -169
  904. data/third_party/upb/upb/encode.h +27 -2
  905. data/third_party/upb/upb/json_decode.c +1443 -0
  906. data/third_party/upb/upb/json_decode.h +23 -0
  907. data/third_party/upb/upb/json_encode.c +713 -0
  908. data/third_party/upb/upb/json_encode.h +36 -0
  909. data/third_party/upb/upb/msg.c +167 -88
  910. data/third_party/upb/upb/msg.h +174 -34
  911. data/third_party/upb/upb/port_def.inc +74 -61
  912. data/third_party/upb/upb/port_undef.inc +3 -7
  913. data/third_party/upb/upb/reflection.c +408 -0
  914. data/third_party/upb/upb/reflection.h +168 -0
  915. data/third_party/upb/upb/table.c +34 -197
  916. data/third_party/upb/upb/table.int.h +14 -5
  917. data/third_party/upb/upb/text_encode.c +421 -0
  918. data/third_party/upb/upb/text_encode.h +38 -0
  919. data/third_party/upb/upb/upb.c +18 -41
  920. data/third_party/upb/upb/upb.h +36 -7
  921. data/third_party/upb/upb/upb.hpp +4 -4
  922. data/third_party/upb/upb/upb.int.h +29 -0
  923. metadata +288 -54
  924. data/src/core/ext/filters/client_channel/lb_policy/xds/eds.cc +0 -946
  925. data/src/core/ext/filters/client_channel/lb_policy/xds/lrs.cc +0 -537
  926. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_routing.cc +0 -1141
  927. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.cc +0 -485
  928. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_fallback.cc +0 -68
  929. data/src/core/ext/filters/client_channel/resolving_lb_policy.cc +0 -354
  930. data/src/core/ext/filters/client_channel/resolving_lb_policy.h +0 -142
  931. data/src/core/ext/upb-generated/gogoproto/gogo.upb.c +0 -17
  932. data/src/core/ext/xds/xds_channel.h +0 -46
  933. data/src/core/ext/xds/xds_channel_secure.cc +0 -103
  934. data/src/core/lib/gprpp/map.h +0 -53
  935. data/third_party/abseil-cpp/absl/base/dynamic_annotations.cc +0 -129
  936. data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_pku.c +0 -110
  937. data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_sxnet.c +0 -274
  938. data/third_party/upb/upb/port.c +0 -26
@@ -17,10 +17,13 @@
17
17
  #ifndef GRPC_CORE_EXT_XDS_XDS_CHANNEL_ARGS_H
18
18
  #define GRPC_CORE_EXT_XDS_XDS_CHANNEL_ARGS_H
19
19
 
20
- // Boolean channel arg indicating whether the target is an xds server.
21
- #define GRPC_ARG_ADDRESS_IS_XDS_SERVER "grpc.address_is_xds_server"
22
-
23
20
  // Pointer channel arg containing a ref to the XdsClient object.
24
21
  #define GRPC_ARG_XDS_CLIENT "grpc.xds_client"
25
22
 
23
+ // Timeout in milliseconds to wait for a resource to be returned from
24
+ // the xds server before assuming that it does not exist.
25
+ // The default is 15 seconds.
26
+ #define GRPC_ARG_XDS_RESOURCE_DOES_NOT_EXIST_TIMEOUT_MS \
27
+ "grpc.xds_resource_does_not_exist_timeout_ms"
28
+
26
29
  #endif /* GRPC_CORE_EXT_XDS_XDS_CHANNEL_ARGS_H */
@@ -35,7 +35,6 @@
35
35
  #include "src/core/ext/filters/client_channel/client_channel.h"
36
36
  #include "src/core/ext/filters/client_channel/service_config.h"
37
37
  #include "src/core/ext/xds/xds_api.h"
38
- #include "src/core/ext/xds/xds_channel.h"
39
38
  #include "src/core/ext/xds/xds_channel_args.h"
40
39
  #include "src/core/ext/xds/xds_client.h"
41
40
  #include "src/core/ext/xds/xds_client_stats.h"
@@ -43,7 +42,6 @@
43
42
  #include "src/core/lib/channel/channel_args.h"
44
43
  #include "src/core/lib/channel/channel_stack.h"
45
44
  #include "src/core/lib/gpr/string.h"
46
- #include "src/core/lib/gprpp/map.h"
47
45
  #include "src/core/lib/gprpp/memory.h"
48
46
  #include "src/core/lib/gprpp/orphanable.h"
49
47
  #include "src/core/lib/gprpp/ref_counted_ptr.h"
@@ -51,7 +49,6 @@
51
49
  #include "src/core/lib/iomgr/sockaddr.h"
52
50
  #include "src/core/lib/iomgr/sockaddr_utils.h"
53
51
  #include "src/core/lib/iomgr/timer.h"
54
- #include "src/core/lib/iomgr/work_serializer.h"
55
52
  #include "src/core/lib/slice/slice_internal.h"
56
53
  #include "src/core/lib/slice/slice_string_helpers.h"
57
54
  #include "src/core/lib/surface/call.h"
@@ -68,6 +65,15 @@
68
65
  namespace grpc_core {
69
66
 
70
67
  TraceFlag grpc_xds_client_trace(false, "xds_client");
68
+ TraceFlag grpc_xds_client_refcount_trace(false, "xds_client_refcount");
69
+
70
+ namespace {
71
+
72
+ Mutex* g_mu = nullptr;
73
+ const grpc_channel_args* g_channel_args = nullptr;
74
+ XdsClient* g_xds_client = nullptr;
75
+
76
+ } // namespace
71
77
 
72
78
  //
73
79
  // Internal class declarations
@@ -135,22 +141,25 @@ class XdsClient::ChannelState::AdsCallState
135
141
  private:
136
142
  class ResourceState : public InternallyRefCounted<ResourceState> {
137
143
  public:
138
- ResourceState(const std::string& type_url, const std::string& name)
139
- : type_url_(type_url), name_(name) {
144
+ ResourceState(const std::string& type_url, const std::string& name,
145
+ bool sent_initial_request)
146
+ : type_url_(type_url),
147
+ name_(name),
148
+ sent_initial_request_(sent_initial_request) {
140
149
  GRPC_CLOSURE_INIT(&timer_callback_, OnTimer, this,
141
150
  grpc_schedule_on_exec_ctx);
142
151
  }
143
152
 
144
153
  void Orphan() override {
145
154
  Finish();
146
- Unref();
155
+ Unref(DEBUG_LOCATION, "Orphan");
147
156
  }
148
157
 
149
158
  void Start(RefCountedPtr<AdsCallState> ads_calld) {
150
- if (sent_) return;
151
- sent_ = true;
159
+ if (sent_initial_request_) return;
160
+ sent_initial_request_ = true;
152
161
  ads_calld_ = std::move(ads_calld);
153
- Ref().release();
162
+ Ref(DEBUG_LOCATION, "timer").release();
154
163
  timer_pending_ = true;
155
164
  grpc_timer_init(
156
165
  &timer_,
@@ -168,9 +177,12 @@ class XdsClient::ChannelState::AdsCallState
168
177
  private:
169
178
  static void OnTimer(void* arg, grpc_error* error) {
170
179
  ResourceState* self = static_cast<ResourceState*>(arg);
171
- GRPC_ERROR_REF(error); // ref owned by lambda
172
- self->ads_calld_->xds_client()->work_serializer_->Run(
173
- [self, error]() { self->OnTimerLocked(error); }, DEBUG_LOCATION);
180
+ {
181
+ MutexLock lock(&self->ads_calld_->xds_client()->mu_);
182
+ self->OnTimerLocked(GRPC_ERROR_REF(error));
183
+ }
184
+ self->ads_calld_.reset();
185
+ self->Unref(DEBUG_LOCATION, "timer");
174
186
  }
175
187
 
176
188
  void OnTimerLocked(grpc_error* error) {
@@ -185,27 +197,32 @@ class XdsClient::ChannelState::AdsCallState
185
197
  gpr_log(GPR_INFO, "[xds_client %p] %s", ads_calld_->xds_client(),
186
198
  grpc_error_string(watcher_error));
187
199
  }
188
- if (type_url_ == XdsApi::kLdsTypeUrl ||
189
- type_url_ == XdsApi::kRdsTypeUrl) {
190
- ads_calld_->xds_client()->listener_watcher_->OnError(watcher_error);
200
+ if (type_url_ == XdsApi::kLdsTypeUrl) {
201
+ ListenerState& state = ads_calld_->xds_client()->listener_map_[name_];
202
+ for (const auto& p : state.watchers) {
203
+ p.first->OnError(GRPC_ERROR_REF(watcher_error));
204
+ }
205
+ } else if (type_url_ == XdsApi::kRdsTypeUrl) {
206
+ RouteConfigState& state =
207
+ ads_calld_->xds_client()->route_config_map_[name_];
208
+ for (const auto& p : state.watchers) {
209
+ p.first->OnError(GRPC_ERROR_REF(watcher_error));
210
+ }
191
211
  } else if (type_url_ == XdsApi::kCdsTypeUrl) {
192
212
  ClusterState& state = ads_calld_->xds_client()->cluster_map_[name_];
193
213
  for (const auto& p : state.watchers) {
194
214
  p.first->OnError(GRPC_ERROR_REF(watcher_error));
195
215
  }
196
- GRPC_ERROR_UNREF(watcher_error);
197
216
  } else if (type_url_ == XdsApi::kEdsTypeUrl) {
198
217
  EndpointState& state = ads_calld_->xds_client()->endpoint_map_[name_];
199
218
  for (const auto& p : state.watchers) {
200
219
  p.first->OnError(GRPC_ERROR_REF(watcher_error));
201
220
  }
202
- GRPC_ERROR_UNREF(watcher_error);
203
221
  } else {
204
222
  GPR_UNREACHABLE_CODE(return );
205
223
  }
224
+ GRPC_ERROR_UNREF(watcher_error);
206
225
  }
207
- ads_calld_.reset();
208
- Unref();
209
226
  GRPC_ERROR_UNREF(error);
210
227
  }
211
228
 
@@ -213,7 +230,7 @@ class XdsClient::ChannelState::AdsCallState
213
230
  const std::string name_;
214
231
 
215
232
  RefCountedPtr<AdsCallState> ads_calld_;
216
- bool sent_ = false;
233
+ bool sent_initial_request_;
217
234
  bool timer_pending_ = false;
218
235
  grpc_timer timer_;
219
236
  grpc_closure timer_callback_;
@@ -222,8 +239,7 @@ class XdsClient::ChannelState::AdsCallState
222
239
  struct ResourceTypeState {
223
240
  ~ResourceTypeState() { GRPC_ERROR_UNREF(error); }
224
241
 
225
- // Version, nonce, and error for this resource type.
226
- std::string version;
242
+ // Nonce and error for this resource type.
227
243
  std::string nonce;
228
244
  grpc_error* error = GRPC_ERROR_NONE;
229
245
 
@@ -234,15 +250,15 @@ class XdsClient::ChannelState::AdsCallState
234
250
 
235
251
  void SendMessageLocked(const std::string& type_url);
236
252
 
237
- void AcceptLdsUpdate(absl::optional<XdsApi::LdsUpdate> lds_update);
238
- void AcceptRdsUpdate(absl::optional<XdsApi::RdsUpdate> rds_update);
253
+ void AcceptLdsUpdate(XdsApi::LdsUpdateMap lds_update_map);
254
+ void AcceptRdsUpdate(XdsApi::RdsUpdateMap rds_update_map);
239
255
  void AcceptCdsUpdate(XdsApi::CdsUpdateMap cds_update_map);
240
256
  void AcceptEdsUpdate(XdsApi::EdsUpdateMap eds_update_map);
241
257
 
242
258
  static void OnRequestSent(void* arg, grpc_error* error);
243
259
  void OnRequestSentLocked(grpc_error* error);
244
260
  static void OnResponseReceived(void* arg, grpc_error* error);
245
- void OnResponseReceivedLocked();
261
+ bool OnResponseReceivedLocked();
246
262
  static void OnStatusReceived(void* arg, grpc_error* error);
247
263
  void OnStatusReceivedLocked(grpc_error* error);
248
264
 
@@ -319,10 +335,10 @@ class XdsClient::ChannelState::LrsCallState
319
335
  private:
320
336
  void ScheduleNextReportLocked();
321
337
  static void OnNextReportTimer(void* arg, grpc_error* error);
322
- void OnNextReportTimerLocked(grpc_error* error);
323
- void SendReportLocked();
338
+ bool OnNextReportTimerLocked(grpc_error* error);
339
+ bool SendReportLocked();
324
340
  static void OnReportDone(void* arg, grpc_error* error);
325
- void OnReportDoneLocked(grpc_error* error);
341
+ bool OnReportDoneLocked(grpc_error* error);
326
342
 
327
343
  bool IsCurrentReporterOnCall() const {
328
344
  return this == parent_->reporter_.get();
@@ -344,7 +360,7 @@ class XdsClient::ChannelState::LrsCallState
344
360
  static void OnInitialRequestSent(void* arg, grpc_error* error);
345
361
  void OnInitialRequestSentLocked();
346
362
  static void OnResponseReceived(void* arg, grpc_error* error);
347
- void OnResponseReceivedLocked();
363
+ bool OnResponseReceivedLocked();
348
364
  static void OnStatusReceived(void* arg, grpc_error* error);
349
365
  void OnStatusReceivedLocked(grpc_error* error);
350
366
 
@@ -389,13 +405,12 @@ class XdsClient::ChannelState::StateWatcher
389
405
  : public AsyncConnectivityStateWatcherInterface {
390
406
  public:
391
407
  explicit StateWatcher(RefCountedPtr<ChannelState> parent)
392
- : AsyncConnectivityStateWatcherInterface(
393
- parent->xds_client()->work_serializer_),
394
- parent_(std::move(parent)) {}
408
+ : parent_(std::move(parent)) {}
395
409
 
396
410
  private:
397
411
  void OnConnectivityStateChange(grpc_connectivity_state new_state,
398
412
  const absl::Status& status) override {
413
+ MutexLock lock(&parent_->xds_client_->mu_);
399
414
  if (!parent_->shutting_down_ &&
400
415
  new_state == GRPC_CHANNEL_TRANSIENT_FAILURE) {
401
416
  // In TRANSIENT_FAILURE. Notify all watchers of error.
@@ -403,8 +418,9 @@ class XdsClient::ChannelState::StateWatcher
403
418
  "[xds_client %p] xds channel in state:TRANSIENT_FAILURE "
404
419
  "status_message:(%s)",
405
420
  parent_->xds_client(), status.ToString().c_str());
406
- parent_->xds_client()->NotifyOnError(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
407
- "xds channel in TRANSIENT_FAILURE"));
421
+ parent_->xds_client()->NotifyOnErrorLocked(
422
+ GRPC_ERROR_CREATE_FROM_STATIC_STRING(
423
+ "xds channel in TRANSIENT_FAILURE"));
408
424
  }
409
425
  }
410
426
 
@@ -417,69 +433,43 @@ class XdsClient::ChannelState::StateWatcher
417
433
 
418
434
  namespace {
419
435
 
420
- // Returns the channel args for the xds channel.
421
- grpc_channel_args* BuildXdsChannelArgs(const grpc_channel_args& args) {
422
- static const char* args_to_remove[] = {
423
- // LB policy name, since we want to use the default (pick_first) in
424
- // the LB channel.
425
- GRPC_ARG_LB_POLICY_NAME,
426
- // The service config that contains the LB config. We don't want to
427
- // recursively use xds in the LB channel.
428
- GRPC_ARG_SERVICE_CONFIG,
429
- // The channel arg for the server URI, since that will be different for
430
- // the xds channel than for the parent channel. The client channel
431
- // factory will re-add this arg with the right value.
432
- GRPC_ARG_SERVER_URI,
433
- // The xds channel should use the authority indicated by the target
434
- // authority table (see \a ModifyXdsChannelArgs),
435
- // as opposed to the authority from the parent channel.
436
- GRPC_ARG_DEFAULT_AUTHORITY,
437
- // Just as for \a GRPC_ARG_DEFAULT_AUTHORITY, the xds channel should be
438
- // treated as a stand-alone channel and not inherit this argument from the
439
- // args of the parent channel.
440
- GRPC_SSL_TARGET_NAME_OVERRIDE_ARG,
441
- // Don't want to pass down channelz node from parent; the balancer
442
- // channel will get its own.
443
- GRPC_ARG_CHANNELZ_CHANNEL_NODE,
444
- // Keepalive interval. We are explicitly setting our own value below.
445
- GRPC_ARG_KEEPALIVE_TIME_MS,
436
+ grpc_channel* CreateXdsChannel(const XdsBootstrap::XdsServer& server) {
437
+ // Build channel args.
438
+ absl::InlinedVector<grpc_arg, 2> args_to_add = {
439
+ grpc_channel_arg_integer_create(
440
+ const_cast<char*>(GRPC_ARG_KEEPALIVE_TIME_MS),
441
+ 5 * 60 * GPR_MS_PER_SEC),
442
+ grpc_channel_arg_integer_create(
443
+ const_cast<char*>(GRPC_ARG_CHANNELZ_IS_INTERNAL_CHANNEL), 1),
446
444
  };
447
- // Channel args to add.
448
- absl::InlinedVector<grpc_arg, 3> args_to_add;
449
- // Keepalive interval.
450
- args_to_add.emplace_back(grpc_channel_arg_integer_create(
451
- const_cast<char*>(GRPC_ARG_KEEPALIVE_TIME_MS), 5000));
452
- // A channel arg indicating that the target is an xds server.
453
- // TODO(roth): Once we figure out our fallback and credentials story, decide
454
- // whether this is actually needed. Note that it's currently used by the
455
- // fake security connector as well.
456
- args_to_add.emplace_back(grpc_channel_arg_integer_create(
457
- const_cast<char*>(GRPC_ARG_ADDRESS_IS_XDS_SERVER), 1));
458
- // The parent channel's channelz uuid.
459
- channelz::ChannelNode* channelz_node = nullptr;
460
- const grpc_arg* arg =
461
- grpc_channel_args_find(&args, GRPC_ARG_CHANNELZ_CHANNEL_NODE);
462
- if (arg != nullptr && arg->type == GRPC_ARG_POINTER &&
463
- arg->value.pointer.p != nullptr) {
464
- channelz_node = static_cast<channelz::ChannelNode*>(arg->value.pointer.p);
465
- args_to_add.emplace_back(
466
- channelz::MakeParentUuidArg(channelz_node->uuid()));
467
- }
468
- // Construct channel args.
469
- grpc_channel_args* new_args = grpc_channel_args_copy_and_add_and_remove(
470
- &args, args_to_remove, GPR_ARRAY_SIZE(args_to_remove), args_to_add.data(),
471
- args_to_add.size());
472
- // Make any necessary modifications for security.
473
- return ModifyXdsChannelArgs(new_args);
445
+ grpc_channel_args* new_args = grpc_channel_args_copy_and_add(
446
+ g_channel_args, args_to_add.data(), args_to_add.size());
447
+ // Create channel creds.
448
+ RefCountedPtr<grpc_channel_credentials> channel_creds =
449
+ XdsChannelCredsRegistry::MakeChannelCreds(server.channel_creds_type,
450
+ server.channel_creds_config);
451
+ // Create channel.
452
+ grpc_channel* channel = grpc_secure_channel_create(
453
+ channel_creds.get(), server.server_uri.c_str(), new_args, nullptr);
454
+ grpc_channel_args_destroy(new_args);
455
+ return channel;
474
456
  }
475
457
 
476
458
  } // namespace
477
459
 
478
- XdsClient::ChannelState::ChannelState(RefCountedPtr<XdsClient> xds_client,
479
- grpc_channel* channel)
480
- : InternallyRefCounted<ChannelState>(&grpc_xds_client_trace),
460
+ XdsClient::ChannelState::ChannelState(WeakRefCountedPtr<XdsClient> xds_client,
461
+ const XdsBootstrap::XdsServer& server)
462
+ : InternallyRefCounted<ChannelState>(
463
+ GRPC_TRACE_FLAG_ENABLED(grpc_xds_client_refcount_trace)
464
+ ? "ChannelState"
465
+ : nullptr),
481
466
  xds_client_(std::move(xds_client)),
482
- channel_(channel) {
467
+ server_(server) {
468
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_client_trace)) {
469
+ gpr_log(GPR_INFO, "[xds_client %p] creating channel to %s",
470
+ xds_client_.get(), server.server_uri.c_str());
471
+ }
472
+ channel_ = CreateXdsChannel(server);
483
473
  GPR_ASSERT(channel_ != nullptr);
484
474
  StartConnectivityWatchLocked();
485
475
  }
@@ -490,6 +480,7 @@ XdsClient::ChannelState::~ChannelState() {
490
480
  this);
491
481
  }
492
482
  grpc_channel_destroy(channel_);
483
+ xds_client_.reset(DEBUG_LOCATION, "ChannelState");
493
484
  }
494
485
 
495
486
  void XdsClient::ChannelState::Orphan() {
@@ -526,7 +517,7 @@ void XdsClient::ChannelState::StartConnectivityWatchLocked() {
526
517
  grpc_channel_element* client_channel_elem =
527
518
  grpc_channel_stack_last_element(grpc_channel_get_channel_stack(channel_));
528
519
  GPR_ASSERT(client_channel_elem->filter == &grpc_client_channel_filter);
529
- watcher_ = new StateWatcher(Ref());
520
+ watcher_ = new StateWatcher(Ref(DEBUG_LOCATION, "ChannelState+watch"));
530
521
  grpc_client_channel_start_connectivity_watch(
531
522
  client_channel_elem, GRPC_CHANNEL_IDLE,
532
523
  OrphanablePtr<AsyncConnectivityStateWatcherInterface>(watcher_));
@@ -561,8 +552,11 @@ void XdsClient::ChannelState::Unsubscribe(const std::string& type_url,
561
552
  const std::string& name,
562
553
  bool delay_unsubscription) {
563
554
  if (ads_calld_ != nullptr) {
564
- ads_calld_->calld()->Unsubscribe(type_url, name, delay_unsubscription);
565
- if (!ads_calld_->calld()->HasSubscribedResources()) ads_calld_.reset();
555
+ auto* calld = ads_calld_->calld();
556
+ if (calld != nullptr) {
557
+ calld->Unsubscribe(type_url, name, delay_unsubscription);
558
+ if (!calld->HasSubscribedResources()) ads_calld_.reset();
559
+ }
566
560
  }
567
561
  }
568
562
 
@@ -645,9 +639,11 @@ template <typename T>
645
639
  void XdsClient::ChannelState::RetryableCall<T>::OnRetryTimer(
646
640
  void* arg, grpc_error* error) {
647
641
  RetryableCall* calld = static_cast<RetryableCall*>(arg);
648
- GRPC_ERROR_REF(error); // ref owned by lambda
649
- calld->chand_->xds_client()->work_serializer_->Run(
650
- [calld, error]() { calld->OnRetryTimerLocked(error); }, DEBUG_LOCATION);
642
+ {
643
+ MutexLock lock(&calld->chand_->xds_client()->mu_);
644
+ calld->OnRetryTimerLocked(GRPC_ERROR_REF(error));
645
+ }
646
+ calld->Unref(DEBUG_LOCATION, "RetryableCall+retry_timer_done");
651
647
  }
652
648
 
653
649
  template <typename T>
@@ -663,7 +659,6 @@ void XdsClient::ChannelState::RetryableCall<T>::OnRetryTimerLocked(
663
659
  }
664
660
  StartNewCallLocked();
665
661
  }
666
- this->Unref(DEBUG_LOCATION, "RetryableCall+retry_timer_done");
667
662
  GRPC_ERROR_UNREF(error);
668
663
  }
669
664
 
@@ -673,16 +668,18 @@ void XdsClient::ChannelState::RetryableCall<T>::OnRetryTimerLocked(
673
668
 
674
669
  XdsClient::ChannelState::AdsCallState::AdsCallState(
675
670
  RefCountedPtr<RetryableCall<AdsCallState>> parent)
676
- : InternallyRefCounted<AdsCallState>(&grpc_xds_client_trace),
671
+ : InternallyRefCounted<AdsCallState>(
672
+ GRPC_TRACE_FLAG_ENABLED(grpc_xds_client_refcount_trace)
673
+ ? "AdsCallState"
674
+ : nullptr),
677
675
  parent_(std::move(parent)) {
678
676
  // Init the ADS call. Note that the call will progress every time there's
679
677
  // activity in xds_client()->interested_parties_, which is comprised of
680
678
  // the polling entities from client_channel.
681
679
  GPR_ASSERT(xds_client() != nullptr);
682
- GPR_ASSERT(!xds_client()->server_name_.empty());
683
680
  // Create a call with the specified method name.
684
681
  const auto& method =
685
- xds_client()->bootstrap_->server().ShouldUseV3()
682
+ chand()->server_.ShouldUseV3()
686
683
  ? GRPC_MDSTR_SLASH_ENVOY_DOT_SERVICE_DOT_DISCOVERY_DOT_V3_DOT_AGGREGATEDDISCOVERYSERVICE_SLASH_STREAMAGGREGATEDRESOURCES
687
684
  : GRPC_MDSTR_SLASH_ENVOY_DOT_SERVICE_DOT_DISCOVERY_DOT_V2_DOT_AGGREGATEDDISCOVERYSERVICE_SLASH_STREAMAGGREGATEDRESOURCES;
688
685
  call_ = grpc_channel_create_pollset_set_call(
@@ -712,19 +709,17 @@ XdsClient::ChannelState::AdsCallState::AdsCallState(
712
709
  GRPC_INITIAL_METADATA_WAIT_FOR_READY_EXPLICITLY_SET;
713
710
  op->reserved = nullptr;
714
711
  op++;
715
- call_error = grpc_call_start_batch_and_execute(call_, ops, (size_t)(op - ops),
716
- nullptr);
712
+ call_error = grpc_call_start_batch_and_execute(
713
+ call_, ops, static_cast<size_t>(op - ops), nullptr);
717
714
  GPR_ASSERT(GRPC_CALL_OK == call_error);
718
715
  // Op: send request message.
719
716
  GRPC_CLOSURE_INIT(&on_request_sent_, OnRequestSent, this,
720
717
  grpc_schedule_on_exec_ctx);
721
- if (xds_client()->listener_watcher_ != nullptr) {
722
- Subscribe(XdsApi::kLdsTypeUrl, xds_client()->server_name_);
723
- if (xds_client()->lds_result_.has_value() &&
724
- !xds_client()->lds_result_->route_config_name.empty()) {
725
- Subscribe(XdsApi::kRdsTypeUrl,
726
- xds_client()->lds_result_->route_config_name);
727
- }
718
+ for (const auto& p : xds_client()->listener_map_) {
719
+ Subscribe(XdsApi::kLdsTypeUrl, std::string(p.first));
720
+ }
721
+ for (const auto& p : xds_client()->route_config_map_) {
722
+ Subscribe(XdsApi::kRdsTypeUrl, std::string(p.first));
728
723
  }
729
724
  for (const auto& p : xds_client()->cluster_map_) {
730
725
  Subscribe(XdsApi::kCdsTypeUrl, std::string(p.first));
@@ -749,8 +744,8 @@ XdsClient::ChannelState::AdsCallState::AdsCallState(
749
744
  Ref(DEBUG_LOCATION, "ADS+OnResponseReceivedLocked").release();
750
745
  GRPC_CLOSURE_INIT(&on_response_received_, OnResponseReceived, this,
751
746
  grpc_schedule_on_exec_ctx);
752
- call_error = grpc_call_start_batch_and_execute(call_, ops, (size_t)(op - ops),
753
- &on_response_received_);
747
+ call_error = grpc_call_start_batch_and_execute(
748
+ call_, ops, static_cast<size_t>(op - ops), &on_response_received_);
754
749
  GPR_ASSERT(GRPC_CALL_OK == call_error);
755
750
  // Op: recv server status.
756
751
  op = ops;
@@ -766,8 +761,8 @@ XdsClient::ChannelState::AdsCallState::AdsCallState(
766
761
  // unreffed.
767
762
  GRPC_CLOSURE_INIT(&on_status_received_, OnStatusReceived, this,
768
763
  grpc_schedule_on_exec_ctx);
769
- call_error = grpc_call_start_batch_and_execute(call_, ops, (size_t)(op - ops),
770
- &on_status_received_);
764
+ call_error = grpc_call_start_batch_and_execute(
765
+ call_, ops, static_cast<size_t>(op - ops), &on_status_received_);
771
766
  GPR_ASSERT(GRPC_CALL_OK == call_error);
772
767
  }
773
768
 
@@ -805,7 +800,8 @@ void XdsClient::ChannelState::AdsCallState::SendMessageLocked(
805
800
  std::set<absl::string_view> resource_names =
806
801
  ResourceNamesForRequest(type_url);
807
802
  request_payload_slice = xds_client()->api_.CreateAdsRequest(
808
- type_url, resource_names, state.version, state.nonce,
803
+ chand()->server_, type_url, resource_names,
804
+ xds_client()->resource_version_map_[type_url], state.nonce,
809
805
  GRPC_ERROR_REF(state.error), !sent_initial_message_);
810
806
  if (type_url != XdsApi::kLdsTypeUrl && type_url != XdsApi::kRdsTypeUrl &&
811
807
  type_url != XdsApi::kCdsTypeUrl && type_url != XdsApi::kEdsTypeUrl) {
@@ -816,7 +812,8 @@ void XdsClient::ChannelState::AdsCallState::SendMessageLocked(
816
812
  gpr_log(GPR_INFO,
817
813
  "[xds_client %p] sending ADS request: type=%s version=%s nonce=%s "
818
814
  "error=%s resources=%s",
819
- xds_client(), type_url.c_str(), state.version.c_str(),
815
+ xds_client(), type_url.c_str(),
816
+ xds_client()->resource_version_map_[type_url].c_str(),
820
817
  state.nonce.c_str(), grpc_error_string(state.error),
821
818
  absl::StrJoin(resource_names, " ").c_str());
822
819
  }
@@ -848,7 +845,8 @@ void XdsClient::ChannelState::AdsCallState::Subscribe(
848
845
  const std::string& type_url, const std::string& name) {
849
846
  auto& state = state_map_[type_url].subscribed_resources[name];
850
847
  if (state == nullptr) {
851
- state = MakeOrphanable<ResourceState>(type_url, name);
848
+ state = MakeOrphanable<ResourceState>(
849
+ type_url, name, !xds_client()->resource_version_map_[type_url].empty());
852
850
  SendMessageLocked(type_url);
853
851
  }
854
852
  }
@@ -868,118 +866,139 @@ bool XdsClient::ChannelState::AdsCallState::HasSubscribedResources() const {
868
866
  }
869
867
 
870
868
  void XdsClient::ChannelState::AdsCallState::AcceptLdsUpdate(
871
- absl::optional<XdsApi::LdsUpdate> lds_update) {
872
- if (!lds_update.has_value()) {
873
- gpr_log(GPR_INFO,
874
- "[xds_client %p] LDS update does not include requested resource",
875
- xds_client());
876
- if (xds_client()->lds_result_.has_value() &&
877
- !xds_client()->lds_result_->route_config_name.empty()) {
878
- Unsubscribe(XdsApi::kRdsTypeUrl,
879
- xds_client()->lds_result_->route_config_name,
880
- /*delay_unsubscription=*/false);
881
- xds_client()->rds_result_.reset();
882
- }
883
- xds_client()->lds_result_.reset();
884
- xds_client()->listener_watcher_->OnResourceDoesNotExist();
885
- return;
886
- }
869
+ XdsApi::LdsUpdateMap lds_update_map) {
887
870
  if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_client_trace)) {
888
871
  gpr_log(GPR_INFO,
889
- "[xds_client %p] LDS update received: route_config_name=%s",
890
- xds_client(),
891
- (!lds_update->route_config_name.empty()
892
- ? lds_update->route_config_name.c_str()
893
- : "<inlined>"));
894
- if (lds_update->rds_update.has_value()) {
895
- gpr_log(GPR_INFO, "RouteConfiguration: %s",
896
- lds_update->rds_update->ToString().c_str());
897
- }
872
+ "[xds_client %p] LDS update received containing %" PRIuPTR
873
+ " resources",
874
+ xds_client(), lds_update_map.size());
898
875
  }
899
876
  auto& lds_state = state_map_[XdsApi::kLdsTypeUrl];
900
- auto& state = lds_state.subscribed_resources[xds_client()->server_name_];
901
- if (state != nullptr) state->Finish();
902
- // Ignore identical update.
903
- if (xds_client()->lds_result_ == lds_update) {
877
+ std::set<std::string> rds_resource_names_seen;
878
+ for (auto& p : lds_update_map) {
879
+ const std::string& listener_name = p.first;
880
+ XdsApi::LdsUpdate& lds_update = p.second;
881
+ auto& state = lds_state.subscribed_resources[listener_name];
882
+ if (state != nullptr) state->Finish();
904
883
  if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_client_trace)) {
905
- gpr_log(GPR_INFO,
906
- "[xds_client %p] LDS update identical to current, ignoring.",
907
- xds_client());
884
+ gpr_log(GPR_INFO, "[xds_client %p] LDS resource %s: route_config_name=%s",
885
+ xds_client(), listener_name.c_str(),
886
+ (!lds_update.route_config_name.empty()
887
+ ? lds_update.route_config_name.c_str()
888
+ : "<inlined>"));
889
+ if (lds_update.rds_update.has_value()) {
890
+ gpr_log(GPR_INFO, "RouteConfiguration: %s",
891
+ lds_update.rds_update->ToString().c_str());
892
+ }
893
+ }
894
+ // Record the RDS resource names seen.
895
+ if (!lds_update.route_config_name.empty()) {
896
+ rds_resource_names_seen.insert(lds_update.route_config_name);
897
+ }
898
+ // Ignore identical update.
899
+ ListenerState& listener_state = xds_client()->listener_map_[listener_name];
900
+ if (listener_state.update.has_value() &&
901
+ *listener_state.update == lds_update) {
902
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_client_trace)) {
903
+ gpr_log(GPR_INFO,
904
+ "[xds_client %p] LDS update for %s identical to current, "
905
+ "ignoring.",
906
+ xds_client(), listener_name.c_str());
907
+ }
908
+ continue;
909
+ }
910
+ // Update the listener state.
911
+ listener_state.update = std::move(lds_update);
912
+ // Notify watchers.
913
+ for (const auto& p : listener_state.watchers) {
914
+ p.first->OnListenerChanged(*listener_state.update);
908
915
  }
909
- return;
910
916
  }
911
- if (xds_client()->lds_result_.has_value() &&
912
- !xds_client()->lds_result_->route_config_name.empty()) {
913
- Unsubscribe(
914
- XdsApi::kRdsTypeUrl, xds_client()->lds_result_->route_config_name,
915
- /*delay_unsubscription=*/!lds_update->route_config_name.empty());
916
- xds_client()->rds_result_.reset();
917
- }
918
- xds_client()->lds_result_ = std::move(lds_update);
919
- if (xds_client()->lds_result_->rds_update.has_value()) {
920
- // If the RouteConfiguration was found inlined in LDS response, notify
921
- // the watcher immediately.
922
- const XdsApi::RdsUpdate::VirtualHost* vhost =
923
- xds_client()->lds_result_->rds_update->FindVirtualHostForDomain(
924
- xds_client()->server_name_);
925
- if (vhost == nullptr) {
926
- xds_client()->listener_watcher_->OnError(
927
- GRPC_ERROR_CREATE_FROM_STATIC_STRING(
928
- "no VirtualHost found for domain"));
929
- } else {
930
- xds_client()->listener_watcher_->OnListenerChanged(vhost->routes);
917
+ // For any subscribed resource that is not present in the update,
918
+ // remove it from the cache and notify watchers that it does not exist.
919
+ for (const auto& p : lds_state.subscribed_resources) {
920
+ const std::string& listener_name = p.first;
921
+ if (lds_update_map.find(listener_name) == lds_update_map.end()) {
922
+ ListenerState& listener_state =
923
+ xds_client()->listener_map_[listener_name];
924
+ // If the resource was newly requested but has not yet been received,
925
+ // we don't want to generate an error for the watchers, because this LDS
926
+ // response may be in reaction to an earlier request that did not yet
927
+ // request the new resource, so its absence from the response does not
928
+ // necessarily indicate that the resource does not exist.
929
+ // For that case, we rely on the request timeout instead.
930
+ if (!listener_state.update.has_value()) continue;
931
+ listener_state.update.reset();
932
+ for (const auto& p : listener_state.watchers) {
933
+ p.first->OnResourceDoesNotExist();
934
+ }
935
+ }
936
+ }
937
+ // For any RDS resource that is no longer referred to by any LDS
938
+ // resources, remove it from the cache and notify watchers that it
939
+ // does not exist.
940
+ auto& rds_state = state_map_[XdsApi::kRdsTypeUrl];
941
+ for (const auto& p : rds_state.subscribed_resources) {
942
+ const std::string& rds_resource_name = p.first;
943
+ if (rds_resource_names_seen.find(rds_resource_name) ==
944
+ rds_resource_names_seen.end()) {
945
+ RouteConfigState& route_config_state =
946
+ xds_client()->route_config_map_[rds_resource_name];
947
+ route_config_state.update.reset();
948
+ for (const auto& p : route_config_state.watchers) {
949
+ p.first->OnResourceDoesNotExist();
950
+ }
931
951
  }
932
- } else {
933
- // Send RDS request for dynamic resolution.
934
- Subscribe(XdsApi::kRdsTypeUrl,
935
- xds_client()->lds_result_->route_config_name);
936
952
  }
937
953
  }
938
954
 
939
955
  void XdsClient::ChannelState::AdsCallState::AcceptRdsUpdate(
940
- absl::optional<XdsApi::RdsUpdate> rds_update) {
941
- if (!rds_update.has_value()) {
942
- gpr_log(GPR_INFO,
943
- "[xds_client %p] RDS update does not include requested resource",
944
- xds_client());
945
- xds_client()->rds_result_.reset();
946
- xds_client()->listener_watcher_->OnResourceDoesNotExist();
947
- return;
948
- }
956
+ XdsApi::RdsUpdateMap rds_update_map) {
949
957
  if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_client_trace)) {
950
- gpr_log(GPR_INFO, "[xds_client %p] RDS update received:\n%s", xds_client(),
951
- rds_update->ToString().c_str());
958
+ gpr_log(GPR_INFO,
959
+ "[xds_client %p] RDS update received containing %" PRIuPTR
960
+ " resources",
961
+ xds_client(), rds_update_map.size());
952
962
  }
953
963
  auto& rds_state = state_map_[XdsApi::kRdsTypeUrl];
954
- auto& state =
955
- rds_state
956
- .subscribed_resources[xds_client()->lds_result_->route_config_name];
957
- if (state != nullptr) state->Finish();
958
- // Ignore identical update.
959
- if (xds_client()->rds_result_ == rds_update) {
964
+ for (auto& p : rds_update_map) {
965
+ const std::string& route_config_name = p.first;
966
+ XdsApi::RdsUpdate& rds_update = p.second;
967
+ auto& state = rds_state.subscribed_resources[route_config_name];
968
+ if (state != nullptr) state->Finish();
960
969
  if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_client_trace)) {
961
- gpr_log(GPR_INFO,
962
- "[xds_client %p] RDS update identical to current, ignoring.",
963
- xds_client());
970
+ gpr_log(GPR_INFO, "[xds_client %p] RDS resource:\n%s", xds_client(),
971
+ rds_update.ToString().c_str());
972
+ }
973
+ RouteConfigState& route_config_state =
974
+ xds_client()->route_config_map_[route_config_name];
975
+ // Ignore identical update.
976
+ if (route_config_state.update.has_value() &&
977
+ *route_config_state.update == rds_update) {
978
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_client_trace)) {
979
+ gpr_log(GPR_INFO,
980
+ "[xds_client %p] RDS resource identical to current, ignoring",
981
+ xds_client());
982
+ }
983
+ continue;
984
+ }
985
+ // Update the cache.
986
+ route_config_state.update = std::move(rds_update);
987
+ // Notify all watchers.
988
+ for (const auto& p : route_config_state.watchers) {
989
+ p.first->OnRouteConfigChanged(*route_config_state.update);
964
990
  }
965
- return;
966
- }
967
- xds_client()->rds_result_ = std::move(rds_update);
968
- // Notify the watcher.
969
- const XdsApi::RdsUpdate::VirtualHost* vhost =
970
- xds_client()->rds_result_->FindVirtualHostForDomain(
971
- xds_client()->server_name_);
972
- if (vhost == nullptr) {
973
- xds_client()->listener_watcher_->OnError(
974
- GRPC_ERROR_CREATE_FROM_STATIC_STRING(
975
- "no VirtualHost found for domain"));
976
- } else {
977
- xds_client()->listener_watcher_->OnListenerChanged(vhost->routes);
978
991
  }
979
992
  }
980
993
 
981
994
  void XdsClient::ChannelState::AdsCallState::AcceptCdsUpdate(
982
995
  XdsApi::CdsUpdateMap cds_update_map) {
996
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_client_trace)) {
997
+ gpr_log(GPR_INFO,
998
+ "[xds_client %p] CDS update received containing %" PRIuPTR
999
+ " resources",
1000
+ xds_client(), cds_update_map.size());
1001
+ }
983
1002
  auto& cds_state = state_map_[XdsApi::kCdsTypeUrl];
984
1003
  std::set<std::string> eds_resource_names_seen;
985
1004
  for (auto& p : cds_update_map) {
@@ -988,13 +1007,8 @@ void XdsClient::ChannelState::AdsCallState::AcceptCdsUpdate(
988
1007
  auto& state = cds_state.subscribed_resources[cluster_name];
989
1008
  if (state != nullptr) state->Finish();
990
1009
  if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_client_trace)) {
991
- gpr_log(GPR_INFO,
992
- "[xds_client %p] CDS update (cluster=%s) received: "
993
- "eds_service_name=%s, lrs_load_reporting_server_name=%s",
994
- xds_client(), cluster_name, cds_update.eds_service_name.c_str(),
995
- cds_update.lrs_load_reporting_server_name.has_value()
996
- ? cds_update.lrs_load_reporting_server_name.value().c_str()
997
- : "(N/A)");
1010
+ gpr_log(GPR_INFO, "[xds_client %p] cluster=%s: %s", xds_client(),
1011
+ cluster_name, cds_update.ToString().c_str());
998
1012
  }
999
1013
  // Record the EDS resource names seen.
1000
1014
  eds_resource_names_seen.insert(cds_update.eds_service_name.empty()
@@ -1003,9 +1017,7 @@ void XdsClient::ChannelState::AdsCallState::AcceptCdsUpdate(
1003
1017
  // Ignore identical update.
1004
1018
  ClusterState& cluster_state = xds_client()->cluster_map_[cluster_name];
1005
1019
  if (cluster_state.update.has_value() &&
1006
- cds_update.eds_service_name == cluster_state.update->eds_service_name &&
1007
- cds_update.lrs_load_reporting_server_name ==
1008
- cluster_state.update->lrs_load_reporting_server_name) {
1020
+ *cluster_state.update == cds_update) {
1009
1021
  if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_client_trace)) {
1010
1022
  gpr_log(GPR_INFO,
1011
1023
  "[xds_client %p] CDS update identical to current, ignoring.",
@@ -1059,6 +1071,12 @@ void XdsClient::ChannelState::AdsCallState::AcceptCdsUpdate(
1059
1071
 
1060
1072
  void XdsClient::ChannelState::AdsCallState::AcceptEdsUpdate(
1061
1073
  XdsApi::EdsUpdateMap eds_update_map) {
1074
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_client_trace)) {
1075
+ gpr_log(GPR_INFO,
1076
+ "[xds_client %p] EDS update received containing %" PRIuPTR
1077
+ " resources",
1078
+ xds_client(), eds_update_map.size());
1079
+ }
1062
1080
  auto& eds_state = state_map_[XdsApi::kEdsTypeUrl];
1063
1081
  for (auto& p : eds_update_map) {
1064
1082
  const char* eds_service_name = p.first.c_str();
@@ -1066,71 +1084,20 @@ void XdsClient::ChannelState::AdsCallState::AcceptEdsUpdate(
1066
1084
  auto& state = eds_state.subscribed_resources[eds_service_name];
1067
1085
  if (state != nullptr) state->Finish();
1068
1086
  if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_client_trace)) {
1069
- gpr_log(GPR_INFO,
1070
- "[xds_client %p] EDS response with %" PRIuPTR
1071
- " priorities and %" PRIuPTR
1072
- " drop categories received (drop_all=%d)",
1073
- xds_client(), eds_update.priority_list_update.size(),
1074
- eds_update.drop_config->drop_category_list().size(),
1075
- eds_update.drop_config->drop_all());
1076
- for (size_t priority = 0;
1077
- priority < eds_update.priority_list_update.size(); ++priority) {
1078
- const auto* locality_map_update = eds_update.priority_list_update.Find(
1079
- static_cast<uint32_t>(priority));
1080
- gpr_log(GPR_INFO,
1081
- "[xds_client %p] Priority %" PRIuPTR " contains %" PRIuPTR
1082
- " localities",
1083
- xds_client(), priority, locality_map_update->size());
1084
- size_t locality_count = 0;
1085
- for (const auto& p : locality_map_update->localities) {
1086
- const auto& locality = p.second;
1087
- gpr_log(GPR_INFO,
1088
- "[xds_client %p] Priority %" PRIuPTR ", locality %" PRIuPTR
1089
- " %s has weight %d, contains %" PRIuPTR " server addresses",
1090
- xds_client(), priority, locality_count,
1091
- locality.name->AsHumanReadableString().c_str(),
1092
- locality.lb_weight, locality.serverlist.size());
1093
- for (size_t i = 0; i < locality.serverlist.size(); ++i) {
1094
- std::string ipport = grpc_sockaddr_to_string(
1095
- &locality.serverlist[i].address(), false);
1096
- gpr_log(GPR_INFO,
1097
- "[xds_client %p] Priority %" PRIuPTR ", locality %" PRIuPTR
1098
- " %s, server address %" PRIuPTR ": %s",
1099
- xds_client(), priority, locality_count,
1100
- locality.name->AsHumanReadableString().c_str(), i,
1101
- ipport.c_str());
1102
- }
1103
- ++locality_count;
1104
- }
1105
- }
1106
- for (size_t i = 0;
1107
- i < eds_update.drop_config->drop_category_list().size(); ++i) {
1108
- const XdsApi::DropConfig::DropCategory& drop_category =
1109
- eds_update.drop_config->drop_category_list()[i];
1110
- gpr_log(GPR_INFO,
1111
- "[xds_client %p] Drop category %s has drop rate %d per million",
1112
- xds_client(), drop_category.name.c_str(),
1113
- drop_category.parts_per_million);
1114
- }
1087
+ gpr_log(GPR_INFO, "[xds_client %p] EDS resource %s: %s", xds_client(),
1088
+ eds_service_name, eds_update.ToString().c_str());
1115
1089
  }
1116
1090
  EndpointState& endpoint_state =
1117
1091
  xds_client()->endpoint_map_[eds_service_name];
1118
1092
  // Ignore identical update.
1119
- if (endpoint_state.update.has_value()) {
1120
- const XdsApi::EdsUpdate& prev_update = endpoint_state.update.value();
1121
- const bool priority_list_changed =
1122
- prev_update.priority_list_update != eds_update.priority_list_update;
1123
- const bool drop_config_changed =
1124
- prev_update.drop_config == nullptr ||
1125
- *prev_update.drop_config != *eds_update.drop_config;
1126
- if (!priority_list_changed && !drop_config_changed) {
1127
- if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_client_trace)) {
1128
- gpr_log(GPR_INFO,
1129
- "[xds_client %p] EDS update identical to current, ignoring.",
1130
- xds_client());
1131
- }
1132
- continue;
1093
+ if (endpoint_state.update.has_value() &&
1094
+ *endpoint_state.update == eds_update) {
1095
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_client_trace)) {
1096
+ gpr_log(GPR_INFO,
1097
+ "[xds_client %p] EDS update identical to current, ignoring.",
1098
+ xds_client());
1133
1099
  }
1100
+ continue;
1134
1101
  }
1135
1102
  // Update the cluster state.
1136
1103
  endpoint_state.update = std::move(eds_update);
@@ -1144,10 +1111,11 @@ void XdsClient::ChannelState::AdsCallState::AcceptEdsUpdate(
1144
1111
  void XdsClient::ChannelState::AdsCallState::OnRequestSent(void* arg,
1145
1112
  grpc_error* error) {
1146
1113
  AdsCallState* ads_calld = static_cast<AdsCallState*>(arg);
1147
- GRPC_ERROR_REF(error); // ref owned by lambda
1148
- ads_calld->xds_client()->work_serializer_->Run(
1149
- [ads_calld, error]() { ads_calld->OnRequestSentLocked(error); },
1150
- DEBUG_LOCATION);
1114
+ {
1115
+ MutexLock lock(&ads_calld->xds_client()->mu_);
1116
+ ads_calld->OnRequestSentLocked(GRPC_ERROR_REF(error));
1117
+ }
1118
+ ads_calld->Unref(DEBUG_LOCATION, "ADS+OnRequestSentLocked");
1151
1119
  }
1152
1120
 
1153
1121
  void XdsClient::ChannelState::AdsCallState::OnRequestSentLocked(
@@ -1171,22 +1139,24 @@ void XdsClient::ChannelState::AdsCallState::OnRequestSentLocked(
1171
1139
  buffered_requests_.erase(it);
1172
1140
  }
1173
1141
  }
1174
- Unref(DEBUG_LOCATION, "ADS+OnRequestSentLocked");
1175
1142
  GRPC_ERROR_UNREF(error);
1176
1143
  }
1177
1144
 
1178
1145
  void XdsClient::ChannelState::AdsCallState::OnResponseReceived(
1179
1146
  void* arg, grpc_error* /* error */) {
1180
1147
  AdsCallState* ads_calld = static_cast<AdsCallState*>(arg);
1181
- ads_calld->xds_client()->work_serializer_->Run(
1182
- [ads_calld]() { ads_calld->OnResponseReceivedLocked(); }, DEBUG_LOCATION);
1148
+ bool done;
1149
+ {
1150
+ MutexLock lock(&ads_calld->xds_client()->mu_);
1151
+ done = ads_calld->OnResponseReceivedLocked();
1152
+ }
1153
+ if (done) ads_calld->Unref(DEBUG_LOCATION, "ADS+OnResponseReceivedLocked");
1183
1154
  }
1184
1155
 
1185
- void XdsClient::ChannelState::AdsCallState::OnResponseReceivedLocked() {
1156
+ bool XdsClient::ChannelState::AdsCallState::OnResponseReceivedLocked() {
1186
1157
  // Empty payload means the call was cancelled.
1187
1158
  if (!IsCurrentCallOnChannel() || recv_message_payload_ == nullptr) {
1188
- Unref(DEBUG_LOCATION, "ADS+OnResponseReceivedLocked");
1189
- return;
1159
+ return true;
1190
1160
  }
1191
1161
  // Read the response.
1192
1162
  grpc_byte_buffer_reader bbr;
@@ -1197,7 +1167,7 @@ void XdsClient::ChannelState::AdsCallState::OnResponseReceivedLocked() {
1197
1167
  recv_message_payload_ = nullptr;
1198
1168
  // Parse and validate the response.
1199
1169
  XdsApi::AdsParseResult result = xds_client()->api_.ParseAdsResponse(
1200
- response_slice, xds_client()->server_name_,
1170
+ response_slice, ResourceNamesForRequest(XdsApi::kLdsTypeUrl),
1201
1171
  ResourceNamesForRequest(XdsApi::kRdsTypeUrl),
1202
1172
  ResourceNamesForRequest(XdsApi::kCdsTypeUrl),
1203
1173
  ResourceNamesForRequest(XdsApi::kEdsTypeUrl));
@@ -1227,15 +1197,16 @@ void XdsClient::ChannelState::AdsCallState::OnResponseReceivedLocked() {
1227
1197
  seen_response_ = true;
1228
1198
  // Accept the ADS response according to the type_url.
1229
1199
  if (result.type_url == XdsApi::kLdsTypeUrl) {
1230
- AcceptLdsUpdate(std::move(result.lds_update));
1200
+ AcceptLdsUpdate(std::move(result.lds_update_map));
1231
1201
  } else if (result.type_url == XdsApi::kRdsTypeUrl) {
1232
- AcceptRdsUpdate(std::move(result.rds_update));
1202
+ AcceptRdsUpdate(std::move(result.rds_update_map));
1233
1203
  } else if (result.type_url == XdsApi::kCdsTypeUrl) {
1234
1204
  AcceptCdsUpdate(std::move(result.cds_update_map));
1235
1205
  } else if (result.type_url == XdsApi::kEdsTypeUrl) {
1236
1206
  AcceptEdsUpdate(std::move(result.eds_update_map));
1237
1207
  }
1238
- state.version = std::move(result.version);
1208
+ xds_client()->resource_version_map_[result.type_url] =
1209
+ std::move(result.version);
1239
1210
  // ACK the update.
1240
1211
  SendMessageLocked(result.type_url);
1241
1212
  // Start load reporting if needed.
@@ -1246,10 +1217,7 @@ void XdsClient::ChannelState::AdsCallState::OnResponseReceivedLocked() {
1246
1217
  }
1247
1218
  }
1248
1219
  }
1249
- if (xds_client()->shutting_down_) {
1250
- Unref(DEBUG_LOCATION, "ADS+OnResponseReceivedLocked+xds_shutdown");
1251
- return;
1252
- }
1220
+ if (xds_client()->shutting_down_) return true;
1253
1221
  // Keep listening for updates.
1254
1222
  grpc_op op;
1255
1223
  memset(&op, 0, sizeof(op));
@@ -1262,15 +1230,17 @@ void XdsClient::ChannelState::AdsCallState::OnResponseReceivedLocked() {
1262
1230
  const grpc_call_error call_error =
1263
1231
  grpc_call_start_batch_and_execute(call_, &op, 1, &on_response_received_);
1264
1232
  GPR_ASSERT(GRPC_CALL_OK == call_error);
1233
+ return false;
1265
1234
  }
1266
1235
 
1267
1236
  void XdsClient::ChannelState::AdsCallState::OnStatusReceived(
1268
1237
  void* arg, grpc_error* error) {
1269
1238
  AdsCallState* ads_calld = static_cast<AdsCallState*>(arg);
1270
- GRPC_ERROR_REF(error); // ref owned by lambda
1271
- ads_calld->xds_client()->work_serializer_->Run(
1272
- [ads_calld, error]() { ads_calld->OnStatusReceivedLocked(error); },
1273
- DEBUG_LOCATION);
1239
+ {
1240
+ MutexLock lock(&ads_calld->xds_client()->mu_);
1241
+ ads_calld->OnStatusReceivedLocked(GRPC_ERROR_REF(error));
1242
+ }
1243
+ ads_calld->Unref(DEBUG_LOCATION, "ADS+OnStatusReceivedLocked");
1274
1244
  }
1275
1245
 
1276
1246
  void XdsClient::ChannelState::AdsCallState::OnStatusReceivedLocked(
@@ -1289,10 +1259,9 @@ void XdsClient::ChannelState::AdsCallState::OnStatusReceivedLocked(
1289
1259
  // Try to restart the call.
1290
1260
  parent_->OnCallFinishedLocked();
1291
1261
  // Send error to all watchers.
1292
- xds_client()->NotifyOnError(
1262
+ xds_client()->NotifyOnErrorLocked(
1293
1263
  GRPC_ERROR_CREATE_FROM_STATIC_STRING("xds call failed"));
1294
1264
  }
1295
- Unref(DEBUG_LOCATION, "ADS+OnStatusReceivedLocked");
1296
1265
  GRPC_ERROR_UNREF(error);
1297
1266
  }
1298
1267
 
@@ -1312,7 +1281,7 @@ XdsClient::ChannelState::AdsCallState::ResourceNamesForRequest(
1312
1281
  for (auto& p : it->second.subscribed_resources) {
1313
1282
  resource_names.insert(p.first);
1314
1283
  OrphanablePtr<ResourceState>& state = p.second;
1315
- state->Start(Ref());
1284
+ state->Start(Ref(DEBUG_LOCATION, "ResourceState"));
1316
1285
  }
1317
1286
  }
1318
1287
  return resource_names;
@@ -1339,21 +1308,22 @@ void XdsClient::ChannelState::LrsCallState::Reporter::
1339
1308
  void XdsClient::ChannelState::LrsCallState::Reporter::OnNextReportTimer(
1340
1309
  void* arg, grpc_error* error) {
1341
1310
  Reporter* self = static_cast<Reporter*>(arg);
1342
- GRPC_ERROR_REF(error); // ref owned by lambda
1343
- self->xds_client()->work_serializer_->Run(
1344
- [self, error]() { self->OnNextReportTimerLocked(error); },
1345
- DEBUG_LOCATION);
1311
+ bool done;
1312
+ {
1313
+ MutexLock lock(&self->xds_client()->mu_);
1314
+ done = self->OnNextReportTimerLocked(GRPC_ERROR_REF(error));
1315
+ }
1316
+ if (done) self->Unref(DEBUG_LOCATION, "Reporter+timer");
1346
1317
  }
1347
1318
 
1348
- void XdsClient::ChannelState::LrsCallState::Reporter::OnNextReportTimerLocked(
1319
+ bool XdsClient::ChannelState::LrsCallState::Reporter::OnNextReportTimerLocked(
1349
1320
  grpc_error* error) {
1350
1321
  next_report_timer_callback_pending_ = false;
1351
1322
  if (error != GRPC_ERROR_NONE || !IsCurrentReporterOnCall()) {
1352
- Unref(DEBUG_LOCATION, "Reporter+timer");
1353
- } else {
1354
- SendReportLocked();
1323
+ GRPC_ERROR_UNREF(error);
1324
+ return true;
1355
1325
  }
1356
- GRPC_ERROR_UNREF(error);
1326
+ return SendReportLocked();
1357
1327
  }
1358
1328
 
1359
1329
  namespace {
@@ -1361,9 +1331,7 @@ namespace {
1361
1331
  bool LoadReportCountersAreZero(const XdsApi::ClusterLoadReportMap& snapshot) {
1362
1332
  for (const auto& p : snapshot) {
1363
1333
  const XdsApi::ClusterLoadReport& cluster_snapshot = p.second;
1364
- for (const auto& q : cluster_snapshot.dropped_requests) {
1365
- if (q.second > 0) return false;
1366
- }
1334
+ if (!cluster_snapshot.dropped_requests.IsZero()) return false;
1367
1335
  for (const auto& q : cluster_snapshot.locality_stats) {
1368
1336
  const XdsClusterLocalityStats::Snapshot& locality_snapshot = q.second;
1369
1337
  if (!locality_snapshot.IsZero()) return false;
@@ -1374,17 +1342,22 @@ bool LoadReportCountersAreZero(const XdsApi::ClusterLoadReportMap& snapshot) {
1374
1342
 
1375
1343
  } // namespace
1376
1344
 
1377
- void XdsClient::ChannelState::LrsCallState::Reporter::SendReportLocked() {
1345
+ bool XdsClient::ChannelState::LrsCallState::Reporter::SendReportLocked() {
1378
1346
  // Construct snapshot from all reported stats.
1379
- XdsApi::ClusterLoadReportMap snapshot = xds_client()->BuildLoadReportSnapshot(
1380
- parent_->send_all_clusters_, parent_->cluster_names_);
1347
+ XdsApi::ClusterLoadReportMap snapshot =
1348
+ xds_client()->BuildLoadReportSnapshotLocked(parent_->send_all_clusters_,
1349
+ parent_->cluster_names_);
1381
1350
  // Skip client load report if the counters were all zero in the last
1382
1351
  // report and they are still zero in this one.
1383
1352
  const bool old_val = last_report_counters_were_zero_;
1384
1353
  last_report_counters_were_zero_ = LoadReportCountersAreZero(snapshot);
1385
1354
  if (old_val && last_report_counters_were_zero_) {
1355
+ if (xds_client()->load_report_map_.empty()) {
1356
+ parent_->chand()->StopLrsCall();
1357
+ return true;
1358
+ }
1386
1359
  ScheduleNextReportLocked();
1387
- return;
1360
+ return false;
1388
1361
  }
1389
1362
  // Create a request that contains the snapshot.
1390
1363
  grpc_slice request_payload_slice =
@@ -1405,37 +1378,41 @@ void XdsClient::ChannelState::LrsCallState::Reporter::SendReportLocked() {
1405
1378
  xds_client(), this, call_error);
1406
1379
  GPR_ASSERT(GRPC_CALL_OK == call_error);
1407
1380
  }
1381
+ return false;
1408
1382
  }
1409
1383
 
1410
1384
  void XdsClient::ChannelState::LrsCallState::Reporter::OnReportDone(
1411
1385
  void* arg, grpc_error* error) {
1412
1386
  Reporter* self = static_cast<Reporter*>(arg);
1413
- GRPC_ERROR_REF(error); // ref owned by lambda
1414
- self->xds_client()->work_serializer_->Run(
1415
- [self, error]() { self->OnReportDoneLocked(error); }, DEBUG_LOCATION);
1387
+ bool done;
1388
+ {
1389
+ MutexLock lock(&self->xds_client()->mu_);
1390
+ done = self->OnReportDoneLocked(GRPC_ERROR_REF(error));
1391
+ }
1392
+ if (done) self->Unref(DEBUG_LOCATION, "Reporter+report_done");
1416
1393
  }
1417
1394
 
1418
- void XdsClient::ChannelState::LrsCallState::Reporter::OnReportDoneLocked(
1395
+ bool XdsClient::ChannelState::LrsCallState::Reporter::OnReportDoneLocked(
1419
1396
  grpc_error* error) {
1420
1397
  grpc_byte_buffer_destroy(parent_->send_message_payload_);
1421
1398
  parent_->send_message_payload_ = nullptr;
1422
1399
  // If there are no more registered stats to report, cancel the call.
1423
1400
  if (xds_client()->load_report_map_.empty()) {
1424
1401
  parent_->chand()->StopLrsCall();
1425
- Unref(DEBUG_LOCATION, "Reporter+report_done+no_more_reporters");
1426
- return;
1402
+ GRPC_ERROR_UNREF(error);
1403
+ return true;
1427
1404
  }
1428
1405
  if (error != GRPC_ERROR_NONE || !IsCurrentReporterOnCall()) {
1406
+ GRPC_ERROR_UNREF(error);
1429
1407
  // If this reporter is no longer the current one on the call, the reason
1430
1408
  // might be that it was orphaned for a new one due to config update.
1431
1409
  if (!IsCurrentReporterOnCall()) {
1432
1410
  parent_->MaybeStartReportingLocked();
1433
1411
  }
1434
- Unref(DEBUG_LOCATION, "Reporter+report_done");
1435
- } else {
1436
- ScheduleNextReportLocked();
1412
+ return true;
1437
1413
  }
1438
- GRPC_ERROR_UNREF(error);
1414
+ ScheduleNextReportLocked();
1415
+ return false;
1439
1416
  }
1440
1417
 
1441
1418
  //
@@ -1444,15 +1421,17 @@ void XdsClient::ChannelState::LrsCallState::Reporter::OnReportDoneLocked(
1444
1421
 
1445
1422
  XdsClient::ChannelState::LrsCallState::LrsCallState(
1446
1423
  RefCountedPtr<RetryableCall<LrsCallState>> parent)
1447
- : InternallyRefCounted<LrsCallState>(&grpc_xds_client_trace),
1424
+ : InternallyRefCounted<LrsCallState>(
1425
+ GRPC_TRACE_FLAG_ENABLED(grpc_xds_client_refcount_trace)
1426
+ ? "LrsCallState"
1427
+ : nullptr),
1448
1428
  parent_(std::move(parent)) {
1449
1429
  // Init the LRS call. Note that the call will progress every time there's
1450
1430
  // activity in xds_client()->interested_parties_, which is comprised of
1451
1431
  // the polling entities from client_channel.
1452
1432
  GPR_ASSERT(xds_client() != nullptr);
1453
- GPR_ASSERT(!xds_client()->server_name_.empty());
1454
1433
  const auto& method =
1455
- xds_client()->bootstrap_->server().ShouldUseV3()
1434
+ chand()->server_.ShouldUseV3()
1456
1435
  ? GRPC_MDSTR_SLASH_ENVOY_DOT_SERVICE_DOT_LOAD_STATS_DOT_V3_DOT_LOADREPORTINGSERVICE_SLASH_STREAMLOADSTATS
1457
1436
  : GRPC_MDSTR_SLASH_ENVOY_DOT_SERVICE_DOT_LOAD_STATS_DOT_V2_DOT_LOADREPORTINGSERVICE_SLASH_STREAMLOADSTATS;
1458
1437
  call_ = grpc_channel_create_pollset_set_call(
@@ -1462,7 +1441,7 @@ XdsClient::ChannelState::LrsCallState::LrsCallState(
1462
1441
  GPR_ASSERT(call_ != nullptr);
1463
1442
  // Init the request payload.
1464
1443
  grpc_slice request_payload_slice =
1465
- xds_client()->api_.CreateLrsInitialRequest(xds_client()->server_name_);
1444
+ xds_client()->api_.CreateLrsInitialRequest(chand()->server_);
1466
1445
  send_message_payload_ =
1467
1446
  grpc_raw_byte_buffer_create(&request_payload_slice, 1);
1468
1447
  grpc_slice_unref_internal(request_payload_slice);
@@ -1498,8 +1477,8 @@ XdsClient::ChannelState::LrsCallState::LrsCallState(
1498
1477
  Ref(DEBUG_LOCATION, "LRS+OnInitialRequestSentLocked").release();
1499
1478
  GRPC_CLOSURE_INIT(&on_initial_request_sent_, OnInitialRequestSent, this,
1500
1479
  grpc_schedule_on_exec_ctx);
1501
- call_error = grpc_call_start_batch_and_execute(call_, ops, (size_t)(op - ops),
1502
- &on_initial_request_sent_);
1480
+ call_error = grpc_call_start_batch_and_execute(
1481
+ call_, ops, static_cast<size_t>(op - ops), &on_initial_request_sent_);
1503
1482
  GPR_ASSERT(GRPC_CALL_OK == call_error);
1504
1483
  // Op: recv initial metadata.
1505
1484
  op = ops;
@@ -1518,8 +1497,8 @@ XdsClient::ChannelState::LrsCallState::LrsCallState(
1518
1497
  Ref(DEBUG_LOCATION, "LRS+OnResponseReceivedLocked").release();
1519
1498
  GRPC_CLOSURE_INIT(&on_response_received_, OnResponseReceived, this,
1520
1499
  grpc_schedule_on_exec_ctx);
1521
- call_error = grpc_call_start_batch_and_execute(call_, ops, (size_t)(op - ops),
1522
- &on_response_received_);
1500
+ call_error = grpc_call_start_batch_and_execute(
1501
+ call_, ops, static_cast<size_t>(op - ops), &on_response_received_);
1523
1502
  GPR_ASSERT(GRPC_CALL_OK == call_error);
1524
1503
  // Op: recv server status.
1525
1504
  op = ops;
@@ -1535,8 +1514,8 @@ XdsClient::ChannelState::LrsCallState::LrsCallState(
1535
1514
  // unreffed.
1536
1515
  GRPC_CLOSURE_INIT(&on_status_received_, OnStatusReceived, this,
1537
1516
  grpc_schedule_on_exec_ctx);
1538
- call_error = grpc_call_start_batch_and_execute(call_, ops, (size_t)(op - ops),
1539
- &on_status_received_);
1517
+ call_error = grpc_call_start_batch_and_execute(
1518
+ call_, ops, static_cast<size_t>(op - ops), &on_status_received_);
1540
1519
  GPR_ASSERT(GRPC_CALL_OK == call_error);
1541
1520
  }
1542
1521
 
@@ -1586,9 +1565,11 @@ void XdsClient::ChannelState::LrsCallState::MaybeStartReportingLocked() {
1586
1565
  void XdsClient::ChannelState::LrsCallState::OnInitialRequestSent(
1587
1566
  void* arg, grpc_error* /*error*/) {
1588
1567
  LrsCallState* lrs_calld = static_cast<LrsCallState*>(arg);
1589
- lrs_calld->xds_client()->work_serializer_->Run(
1590
- [lrs_calld]() { lrs_calld->OnInitialRequestSentLocked(); },
1591
- DEBUG_LOCATION);
1568
+ {
1569
+ MutexLock lock(&lrs_calld->xds_client()->mu_);
1570
+ lrs_calld->OnInitialRequestSentLocked();
1571
+ }
1572
+ lrs_calld->Unref(DEBUG_LOCATION, "LRS+OnInitialRequestSentLocked");
1592
1573
  }
1593
1574
 
1594
1575
  void XdsClient::ChannelState::LrsCallState::OnInitialRequestSentLocked() {
@@ -1596,21 +1577,23 @@ void XdsClient::ChannelState::LrsCallState::OnInitialRequestSentLocked() {
1596
1577
  grpc_byte_buffer_destroy(send_message_payload_);
1597
1578
  send_message_payload_ = nullptr;
1598
1579
  MaybeStartReportingLocked();
1599
- Unref(DEBUG_LOCATION, "LRS+OnInitialRequestSentLocked");
1600
1580
  }
1601
1581
 
1602
1582
  void XdsClient::ChannelState::LrsCallState::OnResponseReceived(
1603
1583
  void* arg, grpc_error* /*error*/) {
1604
1584
  LrsCallState* lrs_calld = static_cast<LrsCallState*>(arg);
1605
- lrs_calld->xds_client()->work_serializer_->Run(
1606
- [lrs_calld]() { lrs_calld->OnResponseReceivedLocked(); }, DEBUG_LOCATION);
1585
+ bool done;
1586
+ {
1587
+ MutexLock lock(&lrs_calld->xds_client()->mu_);
1588
+ done = lrs_calld->OnResponseReceivedLocked();
1589
+ }
1590
+ if (done) lrs_calld->Unref(DEBUG_LOCATION, "LRS+OnResponseReceivedLocked");
1607
1591
  }
1608
1592
 
1609
- void XdsClient::ChannelState::LrsCallState::OnResponseReceivedLocked() {
1593
+ bool XdsClient::ChannelState::LrsCallState::OnResponseReceivedLocked() {
1610
1594
  // Empty payload means the call was cancelled.
1611
1595
  if (!IsCurrentCallOnChannel() || recv_message_payload_ == nullptr) {
1612
- Unref(DEBUG_LOCATION, "LRS+OnResponseReceivedLocked");
1613
- return;
1596
+ return true;
1614
1597
  }
1615
1598
  // Read the response.
1616
1599
  grpc_byte_buffer_reader bbr;
@@ -1683,10 +1666,7 @@ void XdsClient::ChannelState::LrsCallState::OnResponseReceivedLocked() {
1683
1666
  MaybeStartReportingLocked();
1684
1667
  }();
1685
1668
  grpc_slice_unref_internal(response_slice);
1686
- if (xds_client()->shutting_down_) {
1687
- Unref(DEBUG_LOCATION, "LRS+OnResponseReceivedLocked+xds_shutdown");
1688
- return;
1689
- }
1669
+ if (xds_client()->shutting_down_) return true;
1690
1670
  // Keep listening for LRS config updates.
1691
1671
  grpc_op op;
1692
1672
  memset(&op, 0, sizeof(op));
@@ -1699,15 +1679,17 @@ void XdsClient::ChannelState::LrsCallState::OnResponseReceivedLocked() {
1699
1679
  const grpc_call_error call_error =
1700
1680
  grpc_call_start_batch_and_execute(call_, &op, 1, &on_response_received_);
1701
1681
  GPR_ASSERT(GRPC_CALL_OK == call_error);
1682
+ return false;
1702
1683
  }
1703
1684
 
1704
1685
  void XdsClient::ChannelState::LrsCallState::OnStatusReceived(
1705
1686
  void* arg, grpc_error* error) {
1706
1687
  LrsCallState* lrs_calld = static_cast<LrsCallState*>(arg);
1707
- GRPC_ERROR_REF(error); // ref owned by lambda
1708
- lrs_calld->xds_client()->work_serializer_->Run(
1709
- [lrs_calld, error]() { lrs_calld->OnStatusReceivedLocked(error); },
1710
- DEBUG_LOCATION);
1688
+ {
1689
+ MutexLock lock(&lrs_calld->xds_client()->mu_);
1690
+ lrs_calld->OnStatusReceivedLocked(GRPC_ERROR_REF(error));
1691
+ }
1692
+ lrs_calld->Unref(DEBUG_LOCATION, "LRS+OnStatusReceivedLocked");
1711
1693
  }
1712
1694
 
1713
1695
  void XdsClient::ChannelState::LrsCallState::OnStatusReceivedLocked(
@@ -1728,7 +1710,6 @@ void XdsClient::ChannelState::LrsCallState::OnStatusReceivedLocked(
1728
1710
  // Try to restart the call.
1729
1711
  parent_->OnCallFinishedLocked();
1730
1712
  }
1731
- Unref(DEBUG_LOCATION, "LRS+OnStatusReceivedLocked");
1732
1713
  GRPC_ERROR_UNREF(error);
1733
1714
  }
1734
1715
 
@@ -1745,28 +1726,28 @@ bool XdsClient::ChannelState::LrsCallState::IsCurrentCallOnChannel() const {
1745
1726
 
1746
1727
  namespace {
1747
1728
 
1748
- grpc_millis GetRequestTimeout(const grpc_channel_args& args) {
1729
+ grpc_millis GetRequestTimeout() {
1749
1730
  return grpc_channel_args_find_integer(
1750
- &args, GRPC_ARG_XDS_RESOURCE_DOES_NOT_EXIST_TIMEOUT_MS,
1731
+ g_channel_args, GRPC_ARG_XDS_RESOURCE_DOES_NOT_EXIST_TIMEOUT_MS,
1751
1732
  {15000, 0, INT_MAX});
1752
1733
  }
1753
1734
 
1754
1735
  } // namespace
1755
1736
 
1756
- XdsClient::XdsClient(std::shared_ptr<WorkSerializer> work_serializer,
1757
- grpc_pollset_set* interested_parties,
1758
- absl::string_view server_name,
1759
- std::unique_ptr<ListenerWatcherInterface> watcher,
1760
- const grpc_channel_args& channel_args, grpc_error** error)
1761
- : InternallyRefCounted<XdsClient>(&grpc_xds_client_trace),
1762
- request_timeout_(GetRequestTimeout(channel_args)),
1763
- work_serializer_(std::move(work_serializer)),
1764
- interested_parties_(interested_parties),
1737
+ XdsClient::XdsClient(grpc_error** error)
1738
+ : DualRefCounted<XdsClient>(
1739
+ GRPC_TRACE_FLAG_ENABLED(grpc_xds_client_refcount_trace) ? "XdsClient"
1740
+ : nullptr),
1741
+ request_timeout_(GetRequestTimeout()),
1742
+ interested_parties_(grpc_pollset_set_create()),
1765
1743
  bootstrap_(
1766
1744
  XdsBootstrap::ReadFromFile(this, &grpc_xds_client_trace, error)),
1767
- api_(this, &grpc_xds_client_trace, bootstrap_.get()),
1768
- server_name_(server_name),
1769
- listener_watcher_(std::move(watcher)) {
1745
+ certificate_provider_store_(MakeOrphanable<CertificateProviderStore>(
1746
+ bootstrap_ == nullptr
1747
+ ? CertificateProviderStore::PluginDefinitionMap()
1748
+ : bootstrap_->certificate_providers())),
1749
+ api_(this, &grpc_xds_client_trace,
1750
+ bootstrap_ == nullptr ? nullptr : bootstrap_->node()) {
1770
1751
  if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_client_trace)) {
1771
1752
  gpr_log(GPR_INFO, "[xds_client %p] creating xds client", this);
1772
1753
  }
@@ -1775,58 +1756,150 @@ XdsClient::XdsClient(std::shared_ptr<WorkSerializer> work_serializer,
1775
1756
  this, grpc_error_string(*error));
1776
1757
  return;
1777
1758
  }
1778
- if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_client_trace)) {
1779
- gpr_log(GPR_INFO, "[xds_client %p] creating channel to %s", this,
1780
- bootstrap_->server().server_uri.c_str());
1781
- }
1782
- grpc_channel_args* new_args = BuildXdsChannelArgs(channel_args);
1783
- grpc_channel* channel = CreateXdsChannel(*bootstrap_, *new_args, error);
1784
- grpc_channel_args_destroy(new_args);
1785
- if (*error != GRPC_ERROR_NONE) {
1786
- gpr_log(GPR_ERROR, "[xds_client %p] failed to create xds channel: %s", this,
1787
- grpc_error_string(*error));
1788
- return;
1789
- }
1759
+ // Create ChannelState object.
1790
1760
  chand_ = MakeOrphanable<ChannelState>(
1791
- Ref(DEBUG_LOCATION, "XdsClient+ChannelState"), channel);
1792
- if (listener_watcher_ != nullptr) {
1793
- chand_->Subscribe(XdsApi::kLdsTypeUrl, std::string(server_name));
1794
- }
1761
+ WeakRef(DEBUG_LOCATION, "XdsClient+ChannelState"), bootstrap_->server());
1795
1762
  }
1796
1763
 
1797
1764
  XdsClient::~XdsClient() {
1798
1765
  if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_client_trace)) {
1799
1766
  gpr_log(GPR_INFO, "[xds_client %p] destroying xds client", this);
1800
1767
  }
1768
+ grpc_pollset_set_destroy(interested_parties_);
1769
+ }
1770
+
1771
+ void XdsClient::AddChannelzLinkage(
1772
+ channelz::ChannelNode* parent_channelz_node) {
1773
+ channelz::ChannelNode* xds_channelz_node =
1774
+ grpc_channel_get_channelz_node(chand_->channel());
1775
+ if (xds_channelz_node != nullptr) {
1776
+ parent_channelz_node->AddChildChannel(xds_channelz_node->uuid());
1777
+ }
1778
+ }
1779
+
1780
+ void XdsClient::RemoveChannelzLinkage(
1781
+ channelz::ChannelNode* parent_channelz_node) {
1782
+ channelz::ChannelNode* xds_channelz_node =
1783
+ grpc_channel_get_channelz_node(chand_->channel());
1784
+ if (xds_channelz_node != nullptr) {
1785
+ parent_channelz_node->RemoveChildChannel(xds_channelz_node->uuid());
1786
+ }
1801
1787
  }
1802
1788
 
1803
1789
  void XdsClient::Orphan() {
1804
1790
  if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_client_trace)) {
1805
1791
  gpr_log(GPR_INFO, "[xds_client %p] shutting down xds client", this);
1806
1792
  }
1807
- shutting_down_ = true;
1808
- chand_.reset();
1809
- // We do not clear cluster_map_ and endpoint_map_ if the xds client was
1810
- // created by the XdsResolver because the maps contain refs for watchers which
1811
- // in turn hold refs to the loadbalancing policies. At this point, it is
1812
- // possible for ADS calls to be in progress. Unreffing the loadbalancing
1813
- // policies before those calls are done would lead to issues such as
1814
- // https://github.com/grpc/grpc/issues/20928.
1815
- if (listener_watcher_ != nullptr) {
1816
- cluster_map_.clear();
1817
- endpoint_map_.clear();
1793
+ {
1794
+ MutexLock lock(g_mu);
1795
+ if (g_xds_client == this) g_xds_client = nullptr;
1796
+ }
1797
+ {
1798
+ MutexLock lock(&mu_);
1799
+ shutting_down_ = true;
1800
+ // Orphan ChannelState object.
1801
+ chand_.reset();
1802
+ // We do not clear cluster_map_ and endpoint_map_ if the xds client was
1803
+ // created by the XdsResolver because the maps contain refs for watchers
1804
+ // which in turn hold refs to the loadbalancing policies. At this point, it
1805
+ // is possible for ADS calls to be in progress. Unreffing the loadbalancing
1806
+ // policies before those calls are done would lead to issues such as
1807
+ // https://github.com/grpc/grpc/issues/20928.
1808
+ if (!listener_map_.empty()) {
1809
+ cluster_map_.clear();
1810
+ endpoint_map_.clear();
1811
+ }
1812
+ }
1813
+ }
1814
+
1815
+ void XdsClient::WatchListenerData(
1816
+ absl::string_view listener_name,
1817
+ std::unique_ptr<ListenerWatcherInterface> watcher) {
1818
+ std::string listener_name_str = std::string(listener_name);
1819
+ MutexLock lock(&mu_);
1820
+ ListenerState& listener_state = listener_map_[listener_name_str];
1821
+ ListenerWatcherInterface* w = watcher.get();
1822
+ listener_state.watchers[w] = std::move(watcher);
1823
+ // If we've already received an LDS update, notify the new watcher
1824
+ // immediately.
1825
+ if (listener_state.update.has_value()) {
1826
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_client_trace)) {
1827
+ gpr_log(GPR_INFO, "[xds_client %p] returning cached listener data for %s",
1828
+ this, listener_name_str.c_str());
1829
+ }
1830
+ w->OnListenerChanged(*listener_state.update);
1831
+ }
1832
+ chand_->Subscribe(XdsApi::kLdsTypeUrl, listener_name_str);
1833
+ }
1834
+
1835
+ void XdsClient::CancelListenerDataWatch(absl::string_view listener_name,
1836
+ ListenerWatcherInterface* watcher,
1837
+ bool delay_unsubscription) {
1838
+ MutexLock lock(&mu_);
1839
+ if (shutting_down_) return;
1840
+ std::string listener_name_str = std::string(listener_name);
1841
+ ListenerState& listener_state = listener_map_[listener_name_str];
1842
+ auto it = listener_state.watchers.find(watcher);
1843
+ if (it != listener_state.watchers.end()) {
1844
+ listener_state.watchers.erase(it);
1845
+ if (listener_state.watchers.empty()) {
1846
+ listener_map_.erase(listener_name_str);
1847
+ chand_->Unsubscribe(XdsApi::kLdsTypeUrl, listener_name_str,
1848
+ delay_unsubscription);
1849
+ }
1850
+ }
1851
+ }
1852
+
1853
+ void XdsClient::WatchRouteConfigData(
1854
+ absl::string_view route_config_name,
1855
+ std::unique_ptr<RouteConfigWatcherInterface> watcher) {
1856
+ std::string route_config_name_str = std::string(route_config_name);
1857
+ MutexLock lock(&mu_);
1858
+ RouteConfigState& route_config_state =
1859
+ route_config_map_[route_config_name_str];
1860
+ RouteConfigWatcherInterface* w = watcher.get();
1861
+ route_config_state.watchers[w] = std::move(watcher);
1862
+ // If we've already received an RDS update, notify the new watcher
1863
+ // immediately.
1864
+ if (route_config_state.update.has_value()) {
1865
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_client_trace)) {
1866
+ gpr_log(GPR_INFO,
1867
+ "[xds_client %p] returning cached route config data for %s", this,
1868
+ route_config_name_str.c_str());
1869
+ }
1870
+ w->OnRouteConfigChanged(*route_config_state.update);
1871
+ }
1872
+ chand_->Subscribe(XdsApi::kRdsTypeUrl, route_config_name_str);
1873
+ }
1874
+
1875
+ void XdsClient::CancelRouteConfigDataWatch(absl::string_view route_config_name,
1876
+ RouteConfigWatcherInterface* watcher,
1877
+ bool delay_unsubscription) {
1878
+ MutexLock lock(&mu_);
1879
+ if (shutting_down_) return;
1880
+ std::string route_config_name_str = std::string(route_config_name);
1881
+ RouteConfigState& route_config_state =
1882
+ route_config_map_[route_config_name_str];
1883
+ auto it = route_config_state.watchers.find(watcher);
1884
+ if (it != route_config_state.watchers.end()) {
1885
+ route_config_state.watchers.erase(it);
1886
+ if (route_config_state.watchers.empty()) {
1887
+ route_config_map_.erase(route_config_name_str);
1888
+ chand_->Unsubscribe(XdsApi::kRdsTypeUrl, route_config_name_str,
1889
+ delay_unsubscription);
1890
+ }
1818
1891
  }
1819
- Unref(DEBUG_LOCATION, "XdsClient::Orphan()");
1820
1892
  }
1821
1893
 
1822
1894
  void XdsClient::WatchClusterData(
1823
1895
  absl::string_view cluster_name,
1824
1896
  std::unique_ptr<ClusterWatcherInterface> watcher) {
1825
1897
  std::string cluster_name_str = std::string(cluster_name);
1898
+ MutexLock lock(&mu_);
1826
1899
  ClusterState& cluster_state = cluster_map_[cluster_name_str];
1827
1900
  ClusterWatcherInterface* w = watcher.get();
1828
1901
  cluster_state.watchers[w] = std::move(watcher);
1829
- // If we've already received an CDS update, notify the new watcher
1902
+ // If we've already received a CDS update, notify the new watcher
1830
1903
  // immediately.
1831
1904
  if (cluster_state.update.has_value()) {
1832
1905
  if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_client_trace)) {
@@ -1841,6 +1914,7 @@ void XdsClient::WatchClusterData(
1841
1914
  void XdsClient::CancelClusterDataWatch(absl::string_view cluster_name,
1842
1915
  ClusterWatcherInterface* watcher,
1843
1916
  bool delay_unsubscription) {
1917
+ MutexLock lock(&mu_);
1844
1918
  if (shutting_down_) return;
1845
1919
  std::string cluster_name_str = std::string(cluster_name);
1846
1920
  ClusterState& cluster_state = cluster_map_[cluster_name_str];
@@ -1859,6 +1933,7 @@ void XdsClient::WatchEndpointData(
1859
1933
  absl::string_view eds_service_name,
1860
1934
  std::unique_ptr<EndpointWatcherInterface> watcher) {
1861
1935
  std::string eds_service_name_str = std::string(eds_service_name);
1936
+ MutexLock lock(&mu_);
1862
1937
  EndpointState& endpoint_state = endpoint_map_[eds_service_name_str];
1863
1938
  EndpointWatcherInterface* w = watcher.get();
1864
1939
  endpoint_state.watchers[w] = std::move(watcher);
@@ -1877,6 +1952,7 @@ void XdsClient::WatchEndpointData(
1877
1952
  void XdsClient::CancelEndpointDataWatch(absl::string_view eds_service_name,
1878
1953
  EndpointWatcherInterface* watcher,
1879
1954
  bool delay_unsubscription) {
1955
+ MutexLock lock(&mu_);
1880
1956
  if (shutting_down_) return;
1881
1957
  std::string eds_service_name_str = std::string(eds_service_name);
1882
1958
  EndpointState& endpoint_state = endpoint_map_[eds_service_name_str];
@@ -1898,16 +1974,29 @@ RefCountedPtr<XdsClusterDropStats> XdsClient::AddClusterDropStats(
1898
1974
  // server name specified in lrs_server.
1899
1975
  auto key =
1900
1976
  std::make_pair(std::string(cluster_name), std::string(eds_service_name));
1977
+ MutexLock lock(&mu_);
1901
1978
  // We jump through some hoops here to make sure that the absl::string_views
1902
1979
  // stored in the XdsClusterDropStats object point to the strings
1903
1980
  // in the load_report_map_ key, so that they have the same lifetime.
1904
1981
  auto it = load_report_map_
1905
1982
  .emplace(std::make_pair(std::move(key), LoadReportState()))
1906
1983
  .first;
1907
- auto cluster_drop_stats = MakeRefCounted<XdsClusterDropStats>(
1908
- Ref(DEBUG_LOCATION, "DropStats"), lrs_server,
1909
- it->first.first /*cluster_name*/, it->first.second /*eds_service_name*/);
1910
- it->second.drop_stats.insert(cluster_drop_stats.get());
1984
+ LoadReportState& load_report_state = it->second;
1985
+ RefCountedPtr<XdsClusterDropStats> cluster_drop_stats;
1986
+ if (load_report_state.drop_stats != nullptr) {
1987
+ cluster_drop_stats = load_report_state.drop_stats->RefIfNonZero();
1988
+ }
1989
+ if (cluster_drop_stats == nullptr) {
1990
+ if (load_report_state.drop_stats != nullptr) {
1991
+ load_report_state.deleted_drop_stats +=
1992
+ load_report_state.drop_stats->GetSnapshotAndReset();
1993
+ }
1994
+ cluster_drop_stats = MakeRefCounted<XdsClusterDropStats>(
1995
+ Ref(DEBUG_LOCATION, "DropStats"), lrs_server,
1996
+ it->first.first /*cluster_name*/,
1997
+ it->first.second /*eds_service_name*/);
1998
+ load_report_state.drop_stats = cluster_drop_stats.get();
1999
+ }
1911
2000
  chand_->MaybeStartLrsCall();
1912
2001
  return cluster_drop_stats;
1913
2002
  }
@@ -1916,20 +2005,19 @@ void XdsClient::RemoveClusterDropStats(
1916
2005
  absl::string_view /*lrs_server*/, absl::string_view cluster_name,
1917
2006
  absl::string_view eds_service_name,
1918
2007
  XdsClusterDropStats* cluster_drop_stats) {
1919
- auto load_report_it = load_report_map_.find(
1920
- std::make_pair(std::string(cluster_name), std::string(eds_service_name)));
1921
- if (load_report_it == load_report_map_.end()) return;
1922
- LoadReportState& load_report_state = load_report_it->second;
2008
+ MutexLock lock(&mu_);
1923
2009
  // TODO(roth): When we add support for direct federation, use the
1924
2010
  // server name specified in lrs_server.
1925
- auto it = load_report_state.drop_stats.find(cluster_drop_stats);
1926
- if (it != load_report_state.drop_stats.end()) {
1927
- // Record final drop stats in deleted_drop_stats, which will be
2011
+ auto it = load_report_map_.find(
2012
+ std::make_pair(std::string(cluster_name), std::string(eds_service_name)));
2013
+ if (it == load_report_map_.end()) return;
2014
+ LoadReportState& load_report_state = it->second;
2015
+ if (load_report_state.drop_stats == cluster_drop_stats) {
2016
+ // Record final snapshot in deleted_drop_stats, which will be
1928
2017
  // added to the next load report.
1929
- for (const auto& p : cluster_drop_stats->GetSnapshotAndReset()) {
1930
- load_report_state.deleted_drop_stats[p.first] += p.second;
1931
- }
1932
- load_report_state.drop_stats.erase(it);
2018
+ load_report_state.deleted_drop_stats +=
2019
+ load_report_state.drop_stats->GetSnapshotAndReset();
2020
+ load_report_state.drop_stats = nullptr;
1933
2021
  }
1934
2022
  }
1935
2023
 
@@ -1941,18 +2029,31 @@ RefCountedPtr<XdsClusterLocalityStats> XdsClient::AddClusterLocalityStats(
1941
2029
  // server name specified in lrs_server.
1942
2030
  auto key =
1943
2031
  std::make_pair(std::string(cluster_name), std::string(eds_service_name));
2032
+ MutexLock lock(&mu_);
1944
2033
  // We jump through some hoops here to make sure that the absl::string_views
1945
2034
  // stored in the XdsClusterLocalityStats object point to the strings
1946
2035
  // in the load_report_map_ key, so that they have the same lifetime.
1947
2036
  auto it = load_report_map_
1948
2037
  .emplace(std::make_pair(std::move(key), LoadReportState()))
1949
2038
  .first;
1950
- auto cluster_locality_stats = MakeRefCounted<XdsClusterLocalityStats>(
1951
- Ref(DEBUG_LOCATION, "LocalityStats"), lrs_server,
1952
- it->first.first /*cluster_name*/, it->first.second /*eds_service_name*/,
1953
- locality);
1954
- it->second.locality_stats[std::move(locality)].locality_stats.insert(
1955
- cluster_locality_stats.get());
2039
+ LoadReportState& load_report_state = it->second;
2040
+ LoadReportState::LocalityState& locality_state =
2041
+ load_report_state.locality_stats[locality];
2042
+ RefCountedPtr<XdsClusterLocalityStats> cluster_locality_stats;
2043
+ if (locality_state.locality_stats != nullptr) {
2044
+ cluster_locality_stats = locality_state.locality_stats->RefIfNonZero();
2045
+ }
2046
+ if (cluster_locality_stats == nullptr) {
2047
+ if (locality_state.locality_stats != nullptr) {
2048
+ locality_state.deleted_locality_stats +=
2049
+ locality_state.locality_stats->GetSnapshotAndReset();
2050
+ }
2051
+ cluster_locality_stats = MakeRefCounted<XdsClusterLocalityStats>(
2052
+ Ref(DEBUG_LOCATION, "LocalityStats"), lrs_server,
2053
+ it->first.first /*cluster_name*/, it->first.second /*eds_service_name*/,
2054
+ std::move(locality));
2055
+ locality_state.locality_stats = cluster_locality_stats.get();
2056
+ }
1956
2057
  chand_->MaybeStartLrsCall();
1957
2058
  return cluster_locality_stats;
1958
2059
  }
@@ -1962,33 +2063,65 @@ void XdsClient::RemoveClusterLocalityStats(
1962
2063
  absl::string_view eds_service_name,
1963
2064
  const RefCountedPtr<XdsLocalityName>& locality,
1964
2065
  XdsClusterLocalityStats* cluster_locality_stats) {
1965
- auto load_report_it = load_report_map_.find(
1966
- std::make_pair(std::string(cluster_name), std::string(eds_service_name)));
1967
- if (load_report_it == load_report_map_.end()) return;
1968
- LoadReportState& load_report_state = load_report_it->second;
2066
+ MutexLock lock(&mu_);
1969
2067
  // TODO(roth): When we add support for direct federation, use the
1970
2068
  // server name specified in lrs_server.
2069
+ auto it = load_report_map_.find(
2070
+ std::make_pair(std::string(cluster_name), std::string(eds_service_name)));
2071
+ if (it == load_report_map_.end()) return;
2072
+ LoadReportState& load_report_state = it->second;
1971
2073
  auto locality_it = load_report_state.locality_stats.find(locality);
1972
2074
  if (locality_it == load_report_state.locality_stats.end()) return;
1973
- auto& locality_set = locality_it->second.locality_stats;
1974
- auto it = locality_set.find(cluster_locality_stats);
1975
- if (it != locality_set.end()) {
2075
+ LoadReportState::LocalityState& locality_state = locality_it->second;
2076
+ if (locality_state.locality_stats == cluster_locality_stats) {
1976
2077
  // Record final snapshot in deleted_locality_stats, which will be
1977
2078
  // added to the next load report.
1978
- locality_it->second.deleted_locality_stats.emplace_back(
1979
- cluster_locality_stats->GetSnapshotAndReset());
1980
- locality_set.erase(it);
2079
+ locality_state.deleted_locality_stats +=
2080
+ locality_state.locality_stats->GetSnapshotAndReset();
2081
+ locality_state.locality_stats = nullptr;
1981
2082
  }
1982
2083
  }
1983
2084
 
1984
2085
  void XdsClient::ResetBackoff() {
2086
+ MutexLock lock(&mu_);
1985
2087
  if (chand_ != nullptr) {
1986
2088
  grpc_channel_reset_connect_backoff(chand_->channel());
1987
2089
  }
1988
2090
  }
1989
2091
 
1990
- XdsApi::ClusterLoadReportMap XdsClient::BuildLoadReportSnapshot(
2092
+ void XdsClient::NotifyOnErrorLocked(grpc_error* error) {
2093
+ for (const auto& p : listener_map_) {
2094
+ const ListenerState& listener_state = p.second;
2095
+ for (const auto& p : listener_state.watchers) {
2096
+ p.first->OnError(GRPC_ERROR_REF(error));
2097
+ }
2098
+ }
2099
+ for (const auto& p : route_config_map_) {
2100
+ const RouteConfigState& route_config_state = p.second;
2101
+ for (const auto& p : route_config_state.watchers) {
2102
+ p.first->OnError(GRPC_ERROR_REF(error));
2103
+ }
2104
+ }
2105
+ for (const auto& p : cluster_map_) {
2106
+ const ClusterState& cluster_state = p.second;
2107
+ for (const auto& p : cluster_state.watchers) {
2108
+ p.first->OnError(GRPC_ERROR_REF(error));
2109
+ }
2110
+ }
2111
+ for (const auto& p : endpoint_map_) {
2112
+ const EndpointState& endpoint_state = p.second;
2113
+ for (const auto& p : endpoint_state.watchers) {
2114
+ p.first->OnError(GRPC_ERROR_REF(error));
2115
+ }
2116
+ }
2117
+ GRPC_ERROR_UNREF(error);
2118
+ }
2119
+
2120
+ XdsApi::ClusterLoadReportMap XdsClient::BuildLoadReportSnapshotLocked(
1991
2121
  bool send_all_clusters, const std::set<std::string>& clusters) {
2122
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_client_trace)) {
2123
+ gpr_log(GPR_INFO, "[xds_client %p] start building load report", this);
2124
+ }
1992
2125
  XdsApi::ClusterLoadReportMap snapshot_map;
1993
2126
  for (auto load_report_it = load_report_map_.begin();
1994
2127
  load_report_it != load_report_map_.end();) {
@@ -2007,9 +2140,14 @@ XdsApi::ClusterLoadReportMap XdsClient::BuildLoadReportSnapshot(
2007
2140
  XdsApi::ClusterLoadReport snapshot;
2008
2141
  // Aggregate drop stats.
2009
2142
  snapshot.dropped_requests = std::move(load_report.deleted_drop_stats);
2010
- for (auto& drop_stats : load_report.drop_stats) {
2011
- for (const auto& p : drop_stats->GetSnapshotAndReset()) {
2012
- snapshot.dropped_requests[p.first] += p.second;
2143
+ if (load_report.drop_stats != nullptr) {
2144
+ snapshot.dropped_requests +=
2145
+ load_report.drop_stats->GetSnapshotAndReset();
2146
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_client_trace)) {
2147
+ gpr_log(GPR_INFO,
2148
+ "[xds_client %p] cluster=%s eds_service_name=%s drop_stats=%p",
2149
+ this, cluster_key.first.c_str(), cluster_key.second.c_str(),
2150
+ load_report.drop_stats);
2013
2151
  }
2014
2152
  }
2015
2153
  // Aggregate locality stats.
@@ -2019,34 +2157,39 @@ XdsApi::ClusterLoadReportMap XdsClient::BuildLoadReportSnapshot(
2019
2157
  auto& locality_state = it->second;
2020
2158
  XdsClusterLocalityStats::Snapshot& locality_snapshot =
2021
2159
  snapshot.locality_stats[locality_name];
2022
- for (auto& locality_stats : locality_state.locality_stats) {
2023
- locality_snapshot += locality_stats->GetSnapshotAndReset();
2024
- }
2025
- // Add final snapshots from recently deleted locality stats objects.
2026
- for (auto& deleted_locality_stats :
2027
- locality_state.deleted_locality_stats) {
2028
- locality_snapshot += deleted_locality_stats;
2160
+ locality_snapshot = std::move(locality_state.deleted_locality_stats);
2161
+ if (locality_state.locality_stats != nullptr) {
2162
+ locality_snapshot +=
2163
+ locality_state.locality_stats->GetSnapshotAndReset();
2164
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_client_trace)) {
2165
+ gpr_log(GPR_INFO,
2166
+ "[xds_client %p] cluster=%s eds_service_name=%s "
2167
+ "locality=%s locality_stats=%p",
2168
+ this, cluster_key.first.c_str(), cluster_key.second.c_str(),
2169
+ locality_name->AsHumanReadableString().c_str(),
2170
+ locality_state.locality_stats);
2171
+ }
2029
2172
  }
2030
- locality_state.deleted_locality_stats.clear();
2031
2173
  // If the only thing left in this entry was final snapshots from
2032
2174
  // deleted locality stats objects, remove the entry.
2033
- if (locality_state.locality_stats.empty()) {
2175
+ if (locality_state.locality_stats == nullptr) {
2034
2176
  it = load_report.locality_stats.erase(it);
2035
2177
  } else {
2036
2178
  ++it;
2037
2179
  }
2038
2180
  }
2181
+ // Compute load report interval.
2182
+ const grpc_millis now = ExecCtx::Get()->Now();
2183
+ snapshot.load_report_interval = now - load_report.last_report_time;
2184
+ load_report.last_report_time = now;
2185
+ // Record snapshot.
2039
2186
  if (record_stats) {
2040
- // Compute load report interval.
2041
- const grpc_millis now = ExecCtx::Get()->Now();
2042
- snapshot.load_report_interval = now - load_report.last_report_time;
2043
- load_report.last_report_time = now;
2044
- // Record snapshot.
2045
2187
  snapshot_map[cluster_key] = std::move(snapshot);
2046
2188
  }
2047
2189
  // If the only thing left in this entry was final snapshots from
2048
2190
  // deleted stats objects, remove the entry.
2049
- if (load_report.locality_stats.empty() && load_report.drop_stats.empty()) {
2191
+ if (load_report.locality_stats.empty() &&
2192
+ load_report.drop_stats == nullptr) {
2050
2193
  load_report_it = load_report_map_.erase(load_report_it);
2051
2194
  } else {
2052
2195
  ++load_report_it;
@@ -2055,60 +2198,40 @@ XdsApi::ClusterLoadReportMap XdsClient::BuildLoadReportSnapshot(
2055
2198
  return snapshot_map;
2056
2199
  }
2057
2200
 
2058
- void XdsClient::NotifyOnError(grpc_error* error) {
2059
- if (listener_watcher_ != nullptr) {
2060
- listener_watcher_->OnError(GRPC_ERROR_REF(error));
2061
- }
2062
- for (const auto& p : cluster_map_) {
2063
- const ClusterState& cluster_state = p.second;
2064
- for (const auto& p : cluster_state.watchers) {
2065
- p.first->OnError(GRPC_ERROR_REF(error));
2066
- }
2067
- }
2068
- for (const auto& p : endpoint_map_) {
2069
- const EndpointState& endpoint_state = p.second;
2070
- for (const auto& p : endpoint_state.watchers) {
2071
- p.first->OnError(GRPC_ERROR_REF(error));
2072
- }
2073
- }
2074
- GRPC_ERROR_UNREF(error);
2075
- }
2201
+ //
2202
+ // accessors for global state
2203
+ //
2076
2204
 
2077
- void* XdsClient::ChannelArgCopy(void* p) {
2078
- XdsClient* xds_client = static_cast<XdsClient*>(p);
2079
- xds_client->Ref(DEBUG_LOCATION, "channel arg").release();
2080
- return p;
2081
- }
2205
+ void XdsClientGlobalInit() { g_mu = new Mutex; }
2082
2206
 
2083
- void XdsClient::ChannelArgDestroy(void* p) {
2084
- XdsClient* xds_client = static_cast<XdsClient*>(p);
2085
- xds_client->Unref(DEBUG_LOCATION, "channel arg");
2207
+ void XdsClientGlobalShutdown() {
2208
+ delete g_mu;
2209
+ g_mu = nullptr;
2086
2210
  }
2087
2211
 
2088
- int XdsClient::ChannelArgCmp(void* p, void* q) { return GPR_ICMP(p, q); }
2212
+ RefCountedPtr<XdsClient> XdsClient::GetOrCreate(grpc_error** error) {
2213
+ MutexLock lock(g_mu);
2214
+ if (g_xds_client != nullptr) {
2215
+ auto xds_client = g_xds_client->RefIfNonZero();
2216
+ if (xds_client != nullptr) return xds_client;
2217
+ }
2218
+ auto xds_client = MakeRefCounted<XdsClient>(error);
2219
+ g_xds_client = xds_client.get();
2220
+ return xds_client;
2221
+ }
2089
2222
 
2090
- const grpc_arg_pointer_vtable XdsClient::kXdsClientVtable = {
2091
- XdsClient::ChannelArgCopy, XdsClient::ChannelArgDestroy,
2092
- XdsClient::ChannelArgCmp};
2223
+ namespace internal {
2093
2224
 
2094
- grpc_arg XdsClient::MakeChannelArg() const {
2095
- return grpc_channel_arg_pointer_create(const_cast<char*>(GRPC_ARG_XDS_CLIENT),
2096
- const_cast<XdsClient*>(this),
2097
- &XdsClient::kXdsClientVtable);
2225
+ void SetXdsChannelArgsForTest(grpc_channel_args* args) {
2226
+ MutexLock lock(g_mu);
2227
+ g_channel_args = args;
2098
2228
  }
2099
2229
 
2100
- RefCountedPtr<XdsClient> XdsClient::GetFromChannelArgs(
2101
- const grpc_channel_args& args) {
2102
- XdsClient* xds_client =
2103
- grpc_channel_args_find_pointer<XdsClient>(&args, GRPC_ARG_XDS_CLIENT);
2104
- if (xds_client != nullptr) return xds_client->Ref();
2105
- return nullptr;
2230
+ void UnsetGlobalXdsClientForTest() {
2231
+ MutexLock lock(g_mu);
2232
+ g_xds_client = nullptr;
2106
2233
  }
2107
2234
 
2108
- grpc_channel_args* XdsClient::RemoveFromChannelArgs(
2109
- const grpc_channel_args& args) {
2110
- const char* arg_name = GRPC_ARG_XDS_CLIENT;
2111
- return grpc_channel_args_copy_and_remove(&args, &arg_name, 1);
2112
- }
2235
+ } // namespace internal
2113
2236
 
2114
2237
  } // namespace grpc_core