grpc 1.41.0 → 1.42.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 (519) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +57 -44
  3. data/etc/roots.pem +335 -326
  4. data/include/grpc/event_engine/event_engine.h +82 -42
  5. data/include/grpc/event_engine/internal/memory_allocator_impl.h +98 -0
  6. data/include/grpc/event_engine/memory_allocator.h +210 -0
  7. data/include/grpc/grpc.h +4 -0
  8. data/include/grpc/grpc_security.h +18 -0
  9. data/include/grpc/grpc_security_constants.h +1 -0
  10. data/include/grpc/impl/codegen/port_platform.h +7 -0
  11. data/src/core/ext/filters/client_channel/backend_metric.cc +18 -19
  12. data/src/core/ext/filters/client_channel/backup_poller.cc +2 -1
  13. data/src/core/ext/filters/client_channel/channel_connectivity.cc +71 -89
  14. data/src/core/ext/filters/client_channel/client_channel.cc +187 -252
  15. data/src/core/ext/filters/client_channel/client_channel.h +74 -27
  16. data/src/core/ext/filters/client_channel/client_channel_factory.cc +1 -1
  17. data/src/core/ext/filters/client_channel/client_channel_factory.h +17 -19
  18. data/src/core/ext/filters/client_channel/client_channel_plugin.cc +8 -14
  19. data/src/core/ext/filters/client_channel/config_selector.cc +1 -1
  20. data/src/core/ext/filters/client_channel/config_selector.h +4 -5
  21. data/src/core/ext/filters/client_channel/connector.h +18 -18
  22. data/src/core/ext/filters/client_channel/dynamic_filters.cc +1 -1
  23. data/src/core/ext/filters/client_channel/global_subchannel_pool.h +0 -1
  24. data/src/core/ext/filters/client_channel/health/health_check_client.cc +12 -11
  25. data/src/core/ext/filters/client_channel/http_connect_handshaker.h +1 -1
  26. data/src/core/ext/filters/client_channel/lb_policy/child_policy_handler.cc +4 -0
  27. data/src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.cc +6 -15
  28. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +166 -82
  29. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.h +4 -0
  30. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_balancer_addresses.cc +1 -1
  31. data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.cc +2 -4
  32. data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc +23 -7
  33. data/src/core/ext/filters/client_channel/lb_policy/priority/priority.cc +15 -10
  34. data/src/core/ext/filters/client_channel/lb_policy/ring_hash/ring_hash.cc +2 -3
  35. data/src/core/ext/filters/client_channel/lb_policy/rls/rls.cc +2502 -0
  36. data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc +6 -1
  37. data/src/core/ext/filters/client_channel/lb_policy/weighted_target/weighted_target.cc +7 -1
  38. data/src/core/ext/filters/client_channel/lb_policy/xds/cds.cc +6 -2
  39. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_channel_args.h +1 -1
  40. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_impl.cc +5 -0
  41. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_manager.cc +8 -1
  42. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_resolver.cc +7 -16
  43. data/src/core/ext/filters/client_channel/lb_policy.h +11 -1
  44. data/src/core/ext/filters/client_channel/lb_policy_factory.h +1 -0
  45. data/src/core/ext/filters/client_channel/resolver/binder/binder_resolver.cc +139 -0
  46. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +11 -5
  47. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_windows.cc +3 -3
  48. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc +12 -39
  49. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h +21 -1
  50. data/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc +6 -2
  51. data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc +3 -1
  52. data/src/core/ext/filters/client_channel/resolver/xds/xds_resolver.cc +77 -68
  53. data/src/core/ext/filters/client_channel/resolver.h +1 -1
  54. data/src/core/ext/filters/client_channel/resolver_factory.h +2 -0
  55. data/src/core/ext/filters/client_channel/resolver_registry.cc +6 -8
  56. data/src/core/ext/filters/client_channel/resolver_result_parsing.cc +1 -1
  57. data/src/core/ext/filters/client_channel/resolver_result_parsing.h +1 -1
  58. data/src/core/ext/filters/client_channel/retry_filter.cc +48 -86
  59. data/src/core/ext/filters/client_channel/retry_service_config.h +1 -1
  60. data/src/core/ext/filters/client_channel/retry_throttle.cc +17 -48
  61. data/src/core/ext/filters/client_channel/server_address.h +1 -1
  62. data/src/core/ext/filters/client_channel/service_config_channel_arg_filter.cc +49 -36
  63. data/src/core/ext/filters/client_channel/subchannel.cc +85 -143
  64. data/src/core/ext/filters/client_channel/subchannel.h +29 -49
  65. data/src/core/ext/filters/client_channel/subchannel_pool_interface.cc +22 -7
  66. data/src/core/ext/filters/client_channel/subchannel_pool_interface.h +11 -2
  67. data/src/core/ext/filters/client_idle/client_idle_filter.cc +27 -210
  68. data/src/core/ext/filters/client_idle/idle_filter_state.cc +96 -0
  69. data/src/core/ext/filters/client_idle/idle_filter_state.h +66 -0
  70. data/src/core/ext/filters/deadline/deadline_filter.cc +23 -26
  71. data/src/core/ext/filters/fault_injection/fault_injection_filter.cc +19 -19
  72. data/src/core/ext/filters/fault_injection/service_config_parser.cc +0 -1
  73. data/src/core/ext/filters/fault_injection/service_config_parser.h +1 -1
  74. data/src/core/ext/filters/http/client/http_client_filter.cc +41 -44
  75. data/src/core/ext/filters/http/client_authority_filter.cc +14 -15
  76. data/src/core/ext/filters/http/http_filters_plugin.cc +53 -71
  77. data/src/core/ext/filters/http/message_compress/message_compress_filter.cc +17 -12
  78. data/src/core/ext/filters/http/message_compress/message_decompress_filter.cc +1 -1
  79. data/src/core/ext/filters/http/server/http_server_filter.cc +72 -69
  80. data/src/core/ext/filters/max_age/max_age_filter.cc +24 -26
  81. data/src/core/ext/filters/message_size/message_size_filter.cc +19 -16
  82. data/src/core/ext/filters/message_size/message_size_filter.h +1 -1
  83. data/src/core/ext/{filters/client_channel → service_config}/service_config.cc +2 -2
  84. data/src/core/ext/{filters/client_channel → service_config}/service_config.h +4 -4
  85. data/src/core/ext/service_config/service_config_call_data.h +72 -0
  86. data/src/core/ext/{filters/client_channel → service_config}/service_config_parser.cc +3 -3
  87. data/src/core/ext/{filters/client_channel → service_config}/service_config_parser.h +8 -6
  88. data/src/core/ext/transport/chttp2/client/chttp2_connector.cc +2 -5
  89. data/src/core/ext/transport/chttp2/client/insecure/channel_create.cc +19 -24
  90. data/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc +27 -50
  91. data/src/core/ext/transport/chttp2/server/chttp2_server.cc +14 -16
  92. data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +59 -58
  93. data/src/core/ext/transport/chttp2/transport/flow_control.cc +19 -16
  94. data/src/core/ext/transport/chttp2/transport/flow_control.h +4 -4
  95. data/src/core/ext/transport/chttp2/transport/frame_data.cc +4 -4
  96. data/src/core/ext/transport/chttp2/transport/frame_goaway.cc +2 -1
  97. data/src/core/ext/transport/chttp2/transport/frame_ping.cc +2 -1
  98. data/src/core/ext/transport/chttp2/transport/frame_rst_stream.cc +2 -3
  99. data/src/core/ext/transport/chttp2/transport/frame_settings.cc +2 -2
  100. data/src/core/ext/transport/chttp2/transport/hpack_constants.h +1 -1
  101. data/src/core/ext/transport/chttp2/transport/hpack_encoder.cc +41 -1
  102. data/src/core/ext/transport/chttp2/transport/hpack_encoder.h +8 -4
  103. data/src/core/ext/transport/chttp2/transport/hpack_encoder_index.h +1 -1
  104. data/src/core/ext/transport/chttp2/transport/hpack_parser.cc +136 -98
  105. data/src/core/ext/transport/chttp2/transport/hpack_parser.h +27 -8
  106. data/src/core/ext/transport/chttp2/transport/hpack_parser_table.cc +12 -25
  107. data/src/core/ext/transport/chttp2/transport/hpack_parser_table.h +37 -30
  108. data/src/core/ext/transport/chttp2/transport/internal.h +4 -3
  109. data/src/core/ext/transport/chttp2/transport/parsing.cc +30 -173
  110. data/src/core/ext/transport/chttp2/transport/popularity_count.h +1 -1
  111. data/src/core/ext/transport/chttp2/transport/writing.cc +29 -22
  112. data/src/core/ext/transport/inproc/inproc_transport.cc +105 -109
  113. data/src/core/ext/upb-generated/envoy/config/cluster/v3/cluster.upb.c +68 -34
  114. data/src/core/ext/upb-generated/envoy/config/cluster/v3/cluster.upb.h +139 -1
  115. data/src/core/ext/upb-generated/envoy/config/core/v3/base.upb.c +16 -4
  116. data/src/core/ext/upb-generated/envoy/config/core/v3/base.upb.h +53 -4
  117. data/src/core/ext/upb-generated/envoy/config/core/v3/health_check.upb.c +3 -2
  118. data/src/core/ext/upb-generated/envoy/config/core/v3/health_check.upb.h +15 -0
  119. data/src/core/ext/upb-generated/envoy/config/core/v3/protocol.upb.c +13 -8
  120. data/src/core/ext/upb-generated/envoy/config/core/v3/protocol.upb.h +23 -0
  121. data/src/core/ext/upb-generated/envoy/config/endpoint/v3/endpoint_components.upb.c +0 -1
  122. data/src/core/ext/upb-generated/envoy/config/rbac/v3/rbac.upb.c +14 -11
  123. data/src/core/ext/upb-generated/envoy/config/rbac/v3/rbac.upb.h +17 -0
  124. data/src/core/ext/upb-generated/envoy/config/route/v3/route_components.upb.c +15 -12
  125. data/src/core/ext/upb-generated/envoy/config/route/v3/route_components.upb.h +49 -19
  126. data/src/core/ext/upb-generated/src/proto/grpc/lookup/v1/rls.upb.c +55 -0
  127. data/src/core/ext/upb-generated/src/proto/grpc/lookup/v1/rls.upb.h +154 -0
  128. data/src/core/ext/upb-generated/udpa/annotations/security.upb.c +0 -2
  129. data/src/core/ext/upb-generated/xds/annotations/v3/status.upb.c +58 -0
  130. data/src/core/ext/upb-generated/xds/annotations/v3/status.upb.h +182 -0
  131. data/src/core/ext/upb-generated/xds/core/v3/authority.upb.c +1 -1
  132. data/src/core/ext/upb-generated/xds/core/v3/collection_entry.upb.c +1 -1
  133. data/src/core/ext/upb-generated/xds/core/v3/context_params.upb.c +1 -1
  134. data/src/core/ext/upb-generated/xds/core/v3/resource.upb.c +1 -1
  135. data/src/core/ext/upb-generated/xds/core/v3/resource_locator.upb.c +1 -1
  136. data/src/core/ext/upb-generated/xds/core/v3/resource_name.upb.c +1 -1
  137. data/src/core/ext/upb-generated/xds/data/orca/v3/orca_load_report.upb.c +58 -0
  138. data/src/core/ext/upb-generated/xds/data/orca/v3/orca_load_report.upb.h +130 -0
  139. data/src/core/ext/upb-generated/{udpa/type/v1 → xds/type/v3}/typed_struct.upb.c +7 -7
  140. data/src/core/ext/upb-generated/xds/type/v3/typed_struct.upb.h +83 -0
  141. data/src/core/ext/upbdefs-generated/envoy/config/cluster/v3/cluster.upbdefs.c +310 -286
  142. data/src/core/ext/upbdefs-generated/envoy/config/cluster/v3/cluster.upbdefs.h +10 -0
  143. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/base.upbdefs.c +101 -88
  144. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/base.upbdefs.h +5 -0
  145. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/health_check.upbdefs.c +59 -56
  146. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/protocol.upbdefs.c +59 -46
  147. data/src/core/ext/upbdefs-generated/envoy/config/endpoint/v3/endpoint_components.upbdefs.c +78 -82
  148. data/src/core/ext/upbdefs-generated/envoy/config/route/v3/route_components.upbdefs.c +323 -316
  149. data/src/core/ext/upbdefs-generated/udpa/annotations/migrate.upbdefs.c +5 -4
  150. data/src/core/ext/upbdefs-generated/udpa/annotations/security.upbdefs.c +19 -23
  151. data/src/core/ext/upbdefs-generated/udpa/annotations/sensitive.upbdefs.c +4 -3
  152. data/src/core/ext/upbdefs-generated/udpa/annotations/status.upbdefs.c +5 -3
  153. data/src/core/ext/upbdefs-generated/udpa/annotations/versioning.upbdefs.c +5 -4
  154. data/src/core/ext/upbdefs-generated/xds/annotations/v3/status.upbdefs.c +75 -0
  155. data/src/core/ext/upbdefs-generated/xds/annotations/v3/status.upbdefs.h +50 -0
  156. data/src/core/ext/upbdefs-generated/xds/core/v3/authority.upbdefs.c +13 -12
  157. data/src/core/ext/upbdefs-generated/xds/core/v3/collection_entry.upbdefs.c +25 -24
  158. data/src/core/ext/upbdefs-generated/xds/core/v3/context_params.upbdefs.c +16 -15
  159. data/src/core/ext/upbdefs-generated/xds/core/v3/resource.upbdefs.c +17 -16
  160. data/src/core/ext/upbdefs-generated/xds/core/v3/resource_locator.upbdefs.c +33 -32
  161. data/src/core/ext/upbdefs-generated/xds/core/v3/resource_name.upbdefs.c +19 -18
  162. data/src/core/ext/upbdefs-generated/xds/type/v3/typed_struct.upbdefs.c +45 -0
  163. data/src/core/ext/upbdefs-generated/xds/type/v3/typed_struct.upbdefs.h +35 -0
  164. data/src/core/ext/xds/xds_api.cc +325 -362
  165. data/src/core/ext/xds/xds_api.h +134 -82
  166. data/src/core/ext/xds/xds_bootstrap.h +10 -0
  167. data/src/core/ext/xds/xds_certificate_provider.cc +3 -3
  168. data/src/core/ext/xds/xds_channel_stack_modifier.cc +113 -0
  169. data/src/core/ext/xds/xds_channel_stack_modifier.h +52 -0
  170. data/src/core/ext/xds/xds_client.cc +527 -314
  171. data/src/core/ext/xds/xds_client.h +42 -37
  172. data/src/core/ext/xds/xds_client_stats.h +1 -1
  173. data/src/core/ext/xds/xds_server_config_fetcher.cc +5 -7
  174. data/src/core/lib/address_utils/parse_address.cc +2 -0
  175. data/src/core/lib/avl/avl.cc +5 -5
  176. data/src/core/lib/backoff/backoff.cc +1 -1
  177. data/src/core/lib/channel/channel_args.cc +24 -6
  178. data/src/core/lib/channel/channel_args.h +9 -0
  179. data/src/core/lib/channel/channel_stack_builder.cc +3 -3
  180. data/src/core/lib/channel/channel_trace.cc +1 -1
  181. data/src/core/lib/channel/channel_trace.h +1 -1
  182. data/src/core/lib/channel/channelz.cc +3 -3
  183. data/src/core/lib/channel/channelz.h +2 -2
  184. data/src/core/lib/channel/channelz_registry.cc +1 -1
  185. data/src/core/lib/channel/channelz_registry.h +1 -1
  186. data/src/core/lib/channel/connected_channel.cc +1 -3
  187. data/src/core/lib/channel/connected_channel.h +1 -2
  188. data/src/core/lib/compression/compression.cc +2 -2
  189. data/src/core/lib/compression/compression_args.cc +6 -4
  190. data/src/core/lib/compression/compression_internal.cc +2 -2
  191. data/src/core/lib/compression/compression_internal.h +1 -1
  192. data/src/core/lib/config/core_configuration.cc +44 -2
  193. data/src/core/lib/config/core_configuration.h +39 -1
  194. data/src/core/lib/debug/stats.cc +1 -1
  195. data/src/core/lib/debug/stats_data.cc +13 -13
  196. data/src/core/lib/gpr/atm.cc +1 -1
  197. data/src/core/lib/gpr/cpu_posix.cc +1 -1
  198. data/src/core/lib/gpr/string.cc +2 -2
  199. data/src/core/lib/gpr/tls.h +1 -1
  200. data/src/core/lib/gpr/useful.h +79 -32
  201. data/src/core/lib/gprpp/arena.h +10 -0
  202. data/src/core/lib/gprpp/bitset.h +38 -16
  203. data/src/core/lib/gprpp/chunked_vector.h +211 -0
  204. data/src/core/lib/gprpp/construct_destruct.h +1 -1
  205. data/src/core/lib/gprpp/match.h +1 -1
  206. data/src/core/lib/gprpp/memory.h +6 -0
  207. data/src/core/lib/gprpp/overload.h +1 -1
  208. data/src/core/lib/gprpp/status_helper.cc +23 -3
  209. data/src/core/lib/gprpp/status_helper.h +12 -1
  210. data/src/core/lib/gprpp/table.h +411 -0
  211. data/src/core/lib/http/httpcli.cc +200 -182
  212. data/src/core/lib/http/parser.cc +2 -2
  213. data/src/core/lib/iomgr/call_combiner.cc +28 -10
  214. data/src/core/lib/iomgr/combiner.cc +6 -21
  215. data/src/core/lib/iomgr/endpoint_cfstream.cc +7 -6
  216. data/src/core/lib/iomgr/error.cc +113 -52
  217. data/src/core/lib/iomgr/error.h +50 -9
  218. data/src/core/lib/iomgr/error_cfstream.cc +5 -0
  219. data/src/core/lib/iomgr/ev_epoll1_linux.cc +3 -2
  220. data/src/core/lib/iomgr/ev_epollex_linux.cc +7 -7
  221. data/src/core/lib/iomgr/ev_poll_posix.cc +29 -20
  222. data/src/core/lib/iomgr/event_engine/closure.cc +41 -18
  223. data/src/core/lib/iomgr/event_engine/closure.h +10 -1
  224. data/src/core/lib/iomgr/event_engine/endpoint.cc +3 -3
  225. data/src/core/lib/iomgr/event_engine/iomgr.cc +1 -1
  226. data/src/core/lib/iomgr/event_engine/pollset.cc +5 -4
  227. data/src/core/lib/iomgr/event_engine/resolver.cc +10 -7
  228. data/src/core/lib/iomgr/event_engine/tcp.cc +9 -8
  229. data/src/core/lib/iomgr/event_engine/timer.cc +7 -2
  230. data/src/core/lib/iomgr/exec_ctx.cc +1 -9
  231. data/src/core/lib/iomgr/executor/mpmcqueue.cc +5 -7
  232. data/src/core/lib/iomgr/executor/mpmcqueue.h +3 -8
  233. data/src/core/lib/iomgr/executor.cc +6 -20
  234. data/src/core/lib/iomgr/iomgr.cc +3 -1
  235. data/src/core/lib/iomgr/iomgr_internal.cc +4 -9
  236. data/src/core/lib/iomgr/iomgr_internal.h +3 -2
  237. data/src/core/lib/iomgr/load_file.cc +2 -2
  238. data/src/core/lib/iomgr/lockfree_event.cc +18 -0
  239. data/src/core/lib/iomgr/pollset_custom.cc +1 -1
  240. data/src/core/lib/iomgr/pollset_custom.h +1 -1
  241. data/src/core/lib/iomgr/resolve_address_posix.cc +5 -7
  242. data/src/core/lib/iomgr/resource_quota.cc +13 -11
  243. data/src/core/lib/iomgr/socket_factory_posix.cc +2 -2
  244. data/src/core/lib/iomgr/socket_mutator.cc +2 -2
  245. data/src/core/lib/iomgr/socket_utils_common_posix.cc +1 -2
  246. data/src/core/lib/iomgr/tcp_client_cfstream.cc +5 -3
  247. data/src/core/lib/iomgr/tcp_client_custom.cc +1 -1
  248. data/src/core/lib/iomgr/tcp_client_posix.cc +9 -18
  249. data/src/core/lib/iomgr/tcp_client_windows.cc +2 -3
  250. data/src/core/lib/iomgr/tcp_posix.cc +4 -5
  251. data/src/core/lib/iomgr/tcp_server_custom.cc +2 -1
  252. data/src/core/lib/iomgr/tcp_server_posix.cc +3 -4
  253. data/src/core/lib/iomgr/tcp_server_windows.cc +4 -5
  254. data/src/core/lib/iomgr/tcp_windows.cc +2 -2
  255. data/src/core/lib/iomgr/timer_generic.cc +13 -13
  256. data/src/core/lib/iomgr/timer_heap.cc +1 -1
  257. data/src/core/lib/json/json_util.cc +68 -0
  258. data/src/core/lib/json/json_util.h +57 -99
  259. data/src/core/lib/json/json_writer.cc +0 -3
  260. data/src/core/lib/security/authorization/authorization_policy_provider.h +1 -1
  261. data/src/core/lib/security/authorization/authorization_policy_provider_vtable.cc +1 -1
  262. data/src/core/lib/security/authorization/evaluate_args.cc +14 -12
  263. data/src/core/lib/security/authorization/sdk_server_authz_filter.cc +13 -1
  264. data/src/core/lib/security/context/security_context.cc +4 -2
  265. data/src/core/lib/security/credentials/composite/composite_credentials.cc +1 -1
  266. data/src/core/lib/security/credentials/credentials.cc +4 -2
  267. data/src/core/lib/security/credentials/credentials.h +6 -1
  268. data/src/core/lib/security/credentials/external/external_account_credentials.cc +47 -11
  269. data/src/core/lib/security/credentials/external/external_account_credentials.h +1 -0
  270. data/src/core/lib/security/credentials/google_default/google_default_credentials.cc +1 -1
  271. data/src/core/lib/security/credentials/jwt/jwt_verifier.cc +5 -9
  272. data/src/core/lib/security/credentials/plugin/plugin_credentials.cc +2 -2
  273. data/src/core/lib/security/security_connector/fake/fake_security_connector.cc +2 -2
  274. data/src/core/lib/security/security_connector/security_connector.cc +9 -4
  275. data/src/core/lib/security/security_connector/security_connector.h +1 -1
  276. data/src/core/lib/security/security_connector/ssl_utils.cc +1 -1
  277. data/src/core/lib/security/security_connector/tls/tls_security_connector.cc +1 -0
  278. data/src/core/lib/security/security_connector/tls/tls_security_connector.h +0 -2
  279. data/src/core/lib/security/transport/client_auth_filter.cc +5 -5
  280. data/src/core/lib/security/transport/security_handshaker.cc +73 -43
  281. data/src/core/lib/security/transport/server_auth_filter.cc +3 -5
  282. data/src/core/lib/security/transport/tsi_error.cc +3 -5
  283. data/src/core/lib/slice/slice.cc +0 -16
  284. data/src/core/lib/slice/slice_api.cc +39 -0
  285. data/src/core/lib/slice/slice_buffer.cc +5 -5
  286. data/src/core/lib/slice/slice_intern.cc +8 -13
  287. data/src/core/lib/slice/slice_internal.h +1 -244
  288. data/src/core/lib/slice/slice_refcount.cc +17 -0
  289. data/src/core/lib/slice/slice_refcount.h +121 -0
  290. data/src/core/lib/slice/slice_refcount_base.h +173 -0
  291. data/src/core/lib/slice/slice_split.cc +100 -0
  292. data/src/core/lib/slice/slice_split.h +40 -0
  293. data/src/core/lib/slice/slice_string_helpers.cc +0 -83
  294. data/src/core/lib/slice/slice_string_helpers.h +0 -11
  295. data/src/core/lib/slice/static_slice.cc +529 -0
  296. data/src/core/lib/slice/static_slice.h +331 -0
  297. data/src/core/lib/surface/builtins.cc +49 -0
  298. data/src/core/{ext/filters/workarounds/workaround_cronet_compression_filter.h → lib/surface/builtins.h} +8 -9
  299. data/src/core/lib/surface/call.cc +103 -120
  300. data/src/core/lib/surface/call.h +0 -6
  301. data/src/core/lib/surface/channel.cc +19 -32
  302. data/src/core/lib/surface/channel.h +0 -9
  303. data/src/core/lib/surface/channel_init.cc +23 -76
  304. data/src/core/lib/surface/channel_init.h +52 -44
  305. data/src/core/lib/surface/completion_queue.cc +6 -5
  306. data/src/core/lib/surface/init.cc +0 -39
  307. data/src/core/lib/surface/init_secure.cc +17 -14
  308. data/src/core/lib/surface/lame_client.cc +18 -11
  309. data/src/core/lib/surface/lame_client.h +1 -1
  310. data/src/core/lib/surface/server.cc +25 -17
  311. data/src/core/lib/surface/server.h +17 -10
  312. data/src/core/lib/surface/validate_metadata.cc +5 -2
  313. data/src/core/lib/surface/version.cc +2 -2
  314. data/src/core/lib/transport/bdp_estimator.cc +1 -1
  315. data/src/core/lib/transport/error_utils.cc +42 -17
  316. data/src/core/lib/transport/error_utils.h +1 -1
  317. data/src/core/lib/transport/metadata.cc +31 -10
  318. data/src/core/lib/transport/metadata.h +2 -1
  319. data/src/core/lib/transport/metadata_batch.cc +35 -371
  320. data/src/core/lib/transport/metadata_batch.h +905 -71
  321. data/src/core/lib/transport/parsed_metadata.h +263 -0
  322. data/src/core/lib/transport/pid_controller.cc +4 -4
  323. data/src/core/lib/transport/static_metadata.cc +714 -846
  324. data/src/core/lib/transport/static_metadata.h +115 -379
  325. data/src/core/lib/transport/status_metadata.cc +1 -0
  326. data/src/core/lib/transport/transport.cc +4 -5
  327. data/src/core/lib/transport/transport_op_string.cc +40 -20
  328. data/src/core/plugin_registry/grpc_plugin_registry.cc +64 -43
  329. data/src/core/tsi/alts/crypt/aes_gcm.cc +3 -1
  330. data/src/core/tsi/alts/frame_protector/alts_frame_protector.cc +13 -12
  331. data/src/core/tsi/alts/frame_protector/frame_handler.cc +10 -11
  332. data/src/core/tsi/alts/handshaker/alts_handshaker_client.cc +1 -2
  333. data/src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc +12 -2
  334. data/src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol_common.cc +1 -1
  335. data/src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.cc +2 -2
  336. data/src/core/tsi/fake_transport_security.cc +15 -7
  337. data/src/core/tsi/local_transport_security.cc +36 -73
  338. data/src/core/tsi/ssl/session_cache/ssl_session_cache.cc +16 -50
  339. data/src/core/tsi/ssl/session_cache/ssl_session_cache.h +4 -3
  340. data/src/core/tsi/ssl_transport_security.cc +10 -2
  341. data/src/core/tsi/transport_security.cc +12 -0
  342. data/src/core/tsi/transport_security.h +16 -1
  343. data/src/core/tsi/transport_security_interface.h +26 -0
  344. data/src/ruby/ext/grpc/extconf.rb +12 -9
  345. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +4 -0
  346. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +6 -0
  347. data/src/ruby/lib/grpc/version.rb +1 -1
  348. data/src/ruby/pb/src/proto/grpc/testing/test_pb.rb +2 -2
  349. data/src/ruby/spec/client_server_spec.rb +1 -1
  350. data/third_party/abseil-cpp/absl/base/internal/thread_identity.cc +4 -4
  351. data/third_party/abseil-cpp/absl/base/internal/thread_identity.h +11 -6
  352. data/third_party/address_sorting/address_sorting_posix.c +1 -0
  353. data/third_party/boringssl-with-bazel/err_data.c +278 -272
  354. data/third_party/boringssl-with-bazel/src/crypto/asn1/a_bool.c +21 -22
  355. data/third_party/boringssl-with-bazel/src/crypto/asn1/a_d2i_fp.c +0 -2
  356. data/third_party/boringssl-with-bazel/src/crypto/asn1/a_gentm.c +5 -0
  357. data/third_party/boringssl-with-bazel/src/crypto/asn1/a_mbstr.c +15 -22
  358. data/third_party/boringssl-with-bazel/src/crypto/asn1/a_object.c +13 -7
  359. data/third_party/boringssl-with-bazel/src/crypto/asn1/a_print.c +19 -29
  360. data/third_party/boringssl-with-bazel/src/crypto/{x509 → asn1}/a_strex.c +268 -271
  361. data/third_party/boringssl-with-bazel/src/crypto/asn1/a_strnid.c +106 -153
  362. data/third_party/boringssl-with-bazel/src/crypto/asn1/a_time.c +2 -2
  363. data/third_party/boringssl-with-bazel/src/crypto/asn1/a_utctm.c +0 -39
  364. data/third_party/boringssl-with-bazel/src/crypto/asn1/asn1_par.c +1 -1
  365. data/third_party/boringssl-with-bazel/src/crypto/{x509 → asn1}/charmap.h +0 -0
  366. data/third_party/boringssl-with-bazel/src/crypto/asn1/internal.h +38 -0
  367. data/third_party/boringssl-with-bazel/src/crypto/asn1/tasn_dec.c +8 -8
  368. data/third_party/boringssl-with-bazel/src/crypto/asn1/tasn_enc.c +289 -198
  369. data/third_party/boringssl-with-bazel/src/crypto/asn1/tasn_fre.c +8 -8
  370. data/third_party/boringssl-with-bazel/src/crypto/asn1/tasn_new.c +9 -13
  371. data/third_party/boringssl-with-bazel/src/crypto/asn1/tasn_utl.c +1 -0
  372. data/third_party/boringssl-with-bazel/src/crypto/base64/base64.c +11 -8
  373. data/third_party/boringssl-with-bazel/src/crypto/bio/bio_mem.c +1 -7
  374. data/third_party/boringssl-with-bazel/src/crypto/bio/connect.c +1 -5
  375. data/third_party/boringssl-with-bazel/src/crypto/bio/fd.c +0 -4
  376. data/third_party/boringssl-with-bazel/src/crypto/bio/file.c +1 -7
  377. data/third_party/boringssl-with-bazel/src/crypto/bio/pair.c +1 -6
  378. data/third_party/boringssl-with-bazel/src/crypto/bio/socket.c +3 -17
  379. data/third_party/boringssl-with-bazel/src/crypto/blake2/blake2.c +4 -6
  380. data/third_party/boringssl-with-bazel/src/crypto/bytestring/cbb.c +9 -0
  381. data/third_party/boringssl-with-bazel/src/crypto/bytestring/cbs.c +8 -0
  382. data/third_party/boringssl-with-bazel/src/crypto/chacha/chacha.c +38 -47
  383. data/third_party/boringssl-with-bazel/src/crypto/cipher_extra/cipher_extra.c +45 -65
  384. data/third_party/boringssl-with-bazel/src/crypto/digest_extra/digest_extra.c +1 -0
  385. data/third_party/boringssl-with-bazel/src/crypto/evp/scrypt.c +32 -34
  386. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/bn/div.c +21 -3
  387. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/bn/gcd_extra.c +3 -2
  388. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/bn/internal.h +5 -2
  389. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/bn/sqrt.c +5 -9
  390. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/cipher/e_aes.c +10 -0
  391. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/des/des.c +10 -11
  392. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/des/internal.h +1 -3
  393. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/md4/md4.c +4 -7
  394. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/md5/md5.c +4 -7
  395. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/modes/gcm_nohw.c +1 -1
  396. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rand/rand.c +1 -1
  397. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rsa/rsa.c +24 -9
  398. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rsa/rsa_impl.c +4 -2
  399. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/sha/sha1.c +35 -35
  400. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/sha/sha256.c +11 -10
  401. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/sha/sha512.c +10 -37
  402. data/third_party/boringssl-with-bazel/src/crypto/internal.h +39 -0
  403. data/third_party/boringssl-with-bazel/src/crypto/mem.c +12 -9
  404. data/third_party/boringssl-with-bazel/src/crypto/pem/pem_all.c +0 -9
  405. data/third_party/boringssl-with-bazel/src/crypto/pem/pem_info.c +0 -2
  406. data/third_party/boringssl-with-bazel/src/crypto/pem/pem_lib.c +0 -8
  407. data/third_party/boringssl-with-bazel/src/crypto/pem/pem_pk8.c +0 -2
  408. data/third_party/boringssl-with-bazel/src/crypto/pem/pem_pkey.c +0 -4
  409. data/third_party/boringssl-with-bazel/src/crypto/pkcs7/internal.h +16 -7
  410. data/third_party/boringssl-with-bazel/src/crypto/pkcs7/pkcs7.c +9 -4
  411. data/third_party/boringssl-with-bazel/src/crypto/pkcs7/pkcs7_x509.c +151 -12
  412. data/third_party/boringssl-with-bazel/src/crypto/pkcs8/pkcs8_x509.c +1 -1
  413. data/third_party/boringssl-with-bazel/src/crypto/siphash/siphash.c +6 -6
  414. data/third_party/boringssl-with-bazel/src/crypto/x509/by_file.c +2 -0
  415. data/third_party/boringssl-with-bazel/src/crypto/x509/internal.h +181 -1
  416. data/third_party/boringssl-with-bazel/src/crypto/x509/name_print.c +246 -0
  417. data/third_party/boringssl-with-bazel/src/crypto/x509/rsa_pss.c +11 -2
  418. data/third_party/boringssl-with-bazel/src/crypto/x509/t_crl.c +0 -2
  419. data/third_party/boringssl-with-bazel/src/crypto/x509/t_x509.c +0 -179
  420. data/third_party/boringssl-with-bazel/src/crypto/x509/t_x509a.c +4 -2
  421. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_lu.c +0 -5
  422. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_obj.c +1 -0
  423. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_vfy.c +11 -50
  424. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_vpm.c +1 -1
  425. data/third_party/boringssl-with-bazel/src/crypto/x509/x509name.c +2 -4
  426. data/third_party/boringssl-with-bazel/src/crypto/x509/x_all.c +0 -16
  427. data/third_party/boringssl-with-bazel/src/crypto/x509/x_name.c +22 -18
  428. data/third_party/boringssl-with-bazel/src/crypto/x509/x_x509.c +11 -8
  429. data/third_party/boringssl-with-bazel/src/crypto/x509v3/internal.h +16 -0
  430. data/third_party/boringssl-with-bazel/src/crypto/x509v3/pcy_cache.c +1 -0
  431. data/third_party/boringssl-with-bazel/src/crypto/x509v3/pcy_data.c +1 -1
  432. data/third_party/boringssl-with-bazel/src/crypto/x509v3/pcy_int.h +1 -1
  433. data/third_party/boringssl-with-bazel/src/crypto/x509v3/pcy_map.c +1 -0
  434. data/third_party/boringssl-with-bazel/src/crypto/x509v3/pcy_tree.c +4 -3
  435. data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_akey.c +24 -5
  436. data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_alt.c +17 -8
  437. data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_bitst.c +3 -0
  438. data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_cpols.c +6 -6
  439. data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_crld.c +4 -0
  440. data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_enum.c +5 -0
  441. data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_ncons.c +112 -55
  442. data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_pci.c +2 -1
  443. data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_prn.c +0 -2
  444. data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_purp.c +1 -1
  445. data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_utl.c +71 -26
  446. data/third_party/boringssl-with-bazel/src/include/openssl/asn1.h +366 -227
  447. data/third_party/boringssl-with-bazel/src/include/openssl/asn1t.h +2 -9
  448. data/third_party/boringssl-with-bazel/src/include/openssl/base.h +10 -4
  449. data/third_party/boringssl-with-bazel/src/include/openssl/bio.h +3 -1
  450. data/third_party/boringssl-with-bazel/src/include/openssl/bn.h +3 -3
  451. data/third_party/boringssl-with-bazel/src/include/openssl/bytestring.h +9 -0
  452. data/third_party/boringssl-with-bazel/src/include/openssl/cipher.h +8 -2
  453. data/third_party/boringssl-with-bazel/src/include/openssl/hkdf.h +4 -0
  454. data/third_party/boringssl-with-bazel/src/include/openssl/mem.h +9 -3
  455. data/third_party/boringssl-with-bazel/src/include/openssl/pem.h +0 -20
  456. data/third_party/boringssl-with-bazel/src/include/openssl/pkcs7.h +12 -5
  457. data/third_party/boringssl-with-bazel/src/include/openssl/rsa.h +5 -0
  458. data/third_party/boringssl-with-bazel/src/include/openssl/span.h +37 -15
  459. data/third_party/boringssl-with-bazel/src/include/openssl/ssl.h +28 -14
  460. data/third_party/boringssl-with-bazel/src/include/openssl/tls1.h +31 -32
  461. data/third_party/boringssl-with-bazel/src/include/openssl/x509.h +529 -91
  462. data/third_party/boringssl-with-bazel/src/include/openssl/x509_vfy.h +16 -695
  463. data/third_party/boringssl-with-bazel/src/include/openssl/x509v3.h +48 -8
  464. data/third_party/boringssl-with-bazel/src/ssl/encrypted_client_hello.cc +266 -357
  465. data/third_party/boringssl-with-bazel/src/ssl/extensions.cc +90 -152
  466. data/third_party/boringssl-with-bazel/src/ssl/handshake.cc +15 -13
  467. data/third_party/boringssl-with-bazel/src/ssl/handshake_client.cc +75 -79
  468. data/third_party/boringssl-with-bazel/src/ssl/handshake_server.cc +96 -97
  469. data/third_party/boringssl-with-bazel/src/ssl/internal.h +63 -43
  470. data/third_party/boringssl-with-bazel/src/ssl/ssl_cipher.cc +2 -2
  471. data/third_party/boringssl-with-bazel/src/ssl/ssl_lib.cc +2 -2
  472. data/third_party/boringssl-with-bazel/src/ssl/ssl_transcript.cc +6 -12
  473. data/third_party/boringssl-with-bazel/src/ssl/ssl_x509.cc +14 -17
  474. data/third_party/boringssl-with-bazel/src/ssl/tls13_both.cc +14 -27
  475. data/third_party/boringssl-with-bazel/src/ssl/tls13_client.cc +203 -203
  476. data/third_party/boringssl-with-bazel/src/ssl/tls13_enc.cc +30 -41
  477. data/third_party/boringssl-with-bazel/src/ssl/tls13_server.cc +47 -33
  478. data/third_party/re2/re2/compile.cc +91 -109
  479. data/third_party/re2/re2/dfa.cc +27 -39
  480. data/third_party/re2/re2/filtered_re2.cc +18 -2
  481. data/third_party/re2/re2/filtered_re2.h +10 -5
  482. data/third_party/re2/re2/nfa.cc +1 -1
  483. data/third_party/re2/re2/parse.cc +42 -23
  484. data/third_party/re2/re2/perl_groups.cc +34 -34
  485. data/third_party/re2/re2/prefilter.cc +3 -2
  486. data/third_party/re2/re2/prog.cc +182 -4
  487. data/third_party/re2/re2/prog.h +28 -9
  488. data/third_party/re2/re2/re2.cc +87 -118
  489. data/third_party/re2/re2/re2.h +156 -141
  490. data/third_party/re2/re2/regexp.cc +12 -5
  491. data/third_party/re2/re2/regexp.h +8 -2
  492. data/third_party/re2/re2/set.cc +31 -9
  493. data/third_party/re2/re2/set.h +9 -4
  494. data/third_party/re2/re2/simplify.cc +11 -3
  495. data/third_party/re2/re2/tostring.cc +1 -1
  496. data/third_party/re2/re2/walker-inl.h +1 -1
  497. data/third_party/re2/util/mutex.h +2 -2
  498. data/third_party/re2/util/pcre.h +3 -3
  499. metadata +77 -64
  500. data/include/grpc/event_engine/slice_allocator.h +0 -71
  501. data/src/core/ext/filters/client_channel/service_config_call_data.h +0 -126
  502. data/src/core/ext/filters/workarounds/workaround_cronet_compression_filter.cc +0 -211
  503. data/src/core/ext/filters/workarounds/workaround_utils.cc +0 -53
  504. data/src/core/ext/filters/workarounds/workaround_utils.h +0 -39
  505. data/src/core/ext/transport/chttp2/client/authority.cc +0 -42
  506. data/src/core/ext/transport/chttp2/client/authority.h +0 -36
  507. data/src/core/ext/transport/chttp2/transport/chttp2_slice_allocator.cc +0 -67
  508. data/src/core/ext/transport/chttp2/transport/chttp2_slice_allocator.h +0 -74
  509. data/src/core/ext/transport/chttp2/transport/incoming_metadata.cc +0 -66
  510. data/src/core/ext/transport/chttp2/transport/incoming_metadata.h +0 -58
  511. data/src/core/ext/upb-generated/udpa/data/orca/v1/orca_load_report.upb.c +0 -58
  512. data/src/core/ext/upb-generated/udpa/data/orca/v1/orca_load_report.upb.h +0 -130
  513. data/src/core/ext/upb-generated/udpa/type/v1/typed_struct.upb.h +0 -83
  514. data/src/core/ext/upbdefs-generated/udpa/type/v1/typed_struct.upbdefs.c +0 -44
  515. data/src/core/ext/upbdefs-generated/udpa/type/v1/typed_struct.upbdefs.h +0 -35
  516. data/src/core/lib/iomgr/udp_server.cc +0 -747
  517. data/src/core/lib/iomgr/udp_server.h +0 -103
  518. data/src/core/lib/transport/authority_override.cc +0 -40
  519. data/src/core/lib/transport/authority_override.h +0 -37
@@ -33,7 +33,6 @@
33
33
  #include <grpc/support/time.h>
34
34
 
35
35
  #include "src/core/ext/filters/client_channel/client_channel.h"
36
- #include "src/core/ext/filters/client_channel/service_config.h"
37
36
  #include "src/core/ext/xds/xds_api.h"
38
37
  #include "src/core/ext/xds/xds_bootstrap.h"
39
38
  #include "src/core/ext/xds/xds_channel_args.h"
@@ -55,8 +54,8 @@
55
54
  #include "src/core/lib/slice/slice_string_helpers.h"
56
55
  #include "src/core/lib/surface/call.h"
57
56
  #include "src/core/lib/surface/channel.h"
58
- #include "src/core/lib/surface/channel_init.h"
59
57
  #include "src/core/lib/transport/static_metadata.h"
58
+ #include "src/core/lib/uri/uri_parser.h"
60
59
 
61
60
  #define GRPC_XDS_INITIAL_CONNECT_BACKOFF_SECONDS 1
62
61
  #define GRPC_XDS_RECONNECT_BACKOFF_MULTIPLIER 1.6
@@ -72,6 +71,7 @@ TraceFlag grpc_xds_client_refcount_trace(false, "xds_client_refcount");
72
71
  namespace {
73
72
 
74
73
  Mutex* g_mu = nullptr;
74
+
75
75
  const grpc_channel_args* g_channel_args ABSL_GUARDED_BY(*g_mu) = nullptr;
76
76
  XdsClient* g_xds_client ABSL_GUARDED_BY(*g_mu) = nullptr;
77
77
  char* g_fallback_bootstrap_config ABSL_GUARDED_BY(*g_mu) = nullptr;
@@ -88,7 +88,7 @@ template <typename T>
88
88
  class XdsClient::ChannelState::RetryableCall
89
89
  : public InternallyRefCounted<RetryableCall<T>> {
90
90
  public:
91
- explicit RetryableCall(RefCountedPtr<ChannelState> chand);
91
+ explicit RetryableCall(WeakRefCountedPtr<ChannelState> chand);
92
92
 
93
93
  void Orphan() override;
94
94
 
@@ -109,7 +109,7 @@ class XdsClient::ChannelState::RetryableCall
109
109
  // every time we start a new call. It's null during call retry backoff.
110
110
  OrphanablePtr<T> calld_;
111
111
  // The owning xds channel.
112
- RefCountedPtr<ChannelState> chand_;
112
+ WeakRefCountedPtr<ChannelState> chand_;
113
113
 
114
114
  // Retry state.
115
115
  BackOff backoff_;
@@ -135,9 +135,11 @@ class XdsClient::ChannelState::AdsCallState
135
135
  XdsClient* xds_client() const { return chand()->xds_client(); }
136
136
  bool seen_response() const { return seen_response_; }
137
137
 
138
- void SubscribeLocked(const std::string& type_url, const std::string& name)
138
+ void SubscribeLocked(const std::string& type_url,
139
+ const XdsApi::ResourceName& resource)
139
140
  ABSL_EXCLUSIVE_LOCKS_REQUIRED(&XdsClient::mu_);
140
- void UnsubscribeLocked(const std::string& type_url, const std::string& name,
141
+ void UnsubscribeLocked(const std::string& type_url,
142
+ const XdsApi::ResourceName& resource,
141
143
  bool delay_unsubscription)
142
144
  ABSL_EXCLUSIVE_LOCKS_REQUIRED(&XdsClient::mu_);
143
145
 
@@ -146,10 +148,11 @@ class XdsClient::ChannelState::AdsCallState
146
148
  private:
147
149
  class ResourceState : public InternallyRefCounted<ResourceState> {
148
150
  public:
149
- ResourceState(const std::string& type_url, const std::string& name,
151
+ ResourceState(const std::string& type_url,
152
+ const XdsApi::ResourceName& resource,
150
153
  bool sent_initial_request)
151
154
  : type_url_(type_url),
152
- name_(name),
155
+ resource_(resource),
153
156
  sent_initial_request_(sent_initial_request) {
154
157
  GRPC_CLOSURE_INIT(&timer_callback_, OnTimer, this,
155
158
  grpc_schedule_on_exec_ctx);
@@ -197,34 +200,38 @@ class XdsClient::ChannelState::AdsCallState
197
200
  grpc_error_handle watcher_error =
198
201
  GRPC_ERROR_CREATE_FROM_CPP_STRING(absl::StrFormat(
199
202
  "timeout obtaining resource {type=%s name=%s} from xds server",
200
- type_url_, name_));
203
+ type_url_,
204
+ XdsApi::ConstructFullResourceName(resource_.authority,
205
+ type_url_, resource_.id)));
201
206
  watcher_error = grpc_error_set_int(
202
207
  watcher_error, GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_UNAVAILABLE);
203
208
  if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_client_trace)) {
204
209
  gpr_log(GPR_INFO, "[xds_client %p] %s", ads_calld_->xds_client(),
205
210
  grpc_error_std_string(watcher_error).c_str());
206
211
  }
212
+ auto& authority_state =
213
+ ads_calld_->xds_client()->authority_state_map_[resource_.authority];
207
214
  if (type_url_ == XdsApi::kLdsTypeUrl) {
208
- ListenerState& state = ads_calld_->xds_client()->listener_map_[name_];
215
+ ListenerState& state = authority_state.listener_map[resource_.id];
209
216
  state.meta.client_status = XdsApi::ResourceMetadata::DOES_NOT_EXIST;
210
217
  for (const auto& p : state.watchers) {
211
218
  p.first->OnError(GRPC_ERROR_REF(watcher_error));
212
219
  }
213
220
  } else if (type_url_ == XdsApi::kRdsTypeUrl) {
214
221
  RouteConfigState& state =
215
- ads_calld_->xds_client()->route_config_map_[name_];
222
+ authority_state.route_config_map[resource_.id];
216
223
  state.meta.client_status = XdsApi::ResourceMetadata::DOES_NOT_EXIST;
217
224
  for (const auto& p : state.watchers) {
218
225
  p.first->OnError(GRPC_ERROR_REF(watcher_error));
219
226
  }
220
227
  } else if (type_url_ == XdsApi::kCdsTypeUrl) {
221
- ClusterState& state = ads_calld_->xds_client()->cluster_map_[name_];
228
+ ClusterState& state = authority_state.cluster_map[resource_.id];
222
229
  state.meta.client_status = XdsApi::ResourceMetadata::DOES_NOT_EXIST;
223
230
  for (const auto& p : state.watchers) {
224
231
  p.first->OnError(GRPC_ERROR_REF(watcher_error));
225
232
  }
226
233
  } else if (type_url_ == XdsApi::kEdsTypeUrl) {
227
- EndpointState& state = ads_calld_->xds_client()->endpoint_map_[name_];
234
+ EndpointState& state = authority_state.endpoint_map[resource_.id];
228
235
  state.meta.client_status = XdsApi::ResourceMetadata::DOES_NOT_EXIST;
229
236
  for (const auto& p : state.watchers) {
230
237
  p.first->OnError(GRPC_ERROR_REF(watcher_error));
@@ -238,7 +245,7 @@ class XdsClient::ChannelState::AdsCallState
238
245
  }
239
246
 
240
247
  const std::string type_url_;
241
- const std::string name_;
248
+ const XdsApi::ResourceName resource_;
242
249
 
243
250
  RefCountedPtr<AdsCallState> ads_calld_;
244
251
  bool sent_initial_request_;
@@ -255,32 +262,41 @@ class XdsClient::ChannelState::AdsCallState
255
262
  grpc_error_handle error = GRPC_ERROR_NONE;
256
263
 
257
264
  // Subscribed resources of this type.
258
- std::map<std::string /* name */, OrphanablePtr<ResourceState>>
265
+ std::map<std::string /*authority*/,
266
+ std::map<std::string /*name*/, OrphanablePtr<ResourceState>>>
259
267
  subscribed_resources;
260
268
  };
261
269
 
262
270
  void SendMessageLocked(const std::string& type_url)
263
271
  ABSL_EXCLUSIVE_LOCKS_REQUIRED(&XdsClient::mu_);
264
272
 
265
- void AcceptLdsUpdateLocked(std::string version, grpc_millis update_time,
266
- XdsApi::LdsUpdateMap lds_update_map,
267
- const std::set<std::string>& resource_names_failed)
273
+ void AcceptLdsUpdateLocked(
274
+ std::string version, grpc_millis update_time,
275
+ XdsApi::LdsUpdateMap lds_update_map,
276
+ const std::set<XdsApi::ResourceName>& resource_names_failed)
268
277
  ABSL_EXCLUSIVE_LOCKS_REQUIRED(&XdsClient::mu_);
269
278
  void AcceptRdsUpdateLocked(std::string version, grpc_millis update_time,
270
279
  XdsApi::RdsUpdateMap rds_update_map)
271
280
  ABSL_EXCLUSIVE_LOCKS_REQUIRED(&XdsClient::mu_);
272
- void AcceptCdsUpdateLocked(std::string version, grpc_millis update_time,
273
- XdsApi::CdsUpdateMap cds_update_map,
274
- const std::set<std::string>& resource_names_failed)
281
+ void AcceptCdsUpdateLocked(
282
+ std::string version, grpc_millis update_time,
283
+ XdsApi::CdsUpdateMap cds_update_map,
284
+ const std::set<XdsApi::ResourceName>& resource_names_failed)
275
285
  ABSL_EXCLUSIVE_LOCKS_REQUIRED(&XdsClient::mu_);
276
286
  void AcceptEdsUpdateLocked(std::string version, grpc_millis update_time,
277
287
  XdsApi::EdsUpdateMap eds_update_map)
278
288
  ABSL_EXCLUSIVE_LOCKS_REQUIRED(&XdsClient::mu_);
279
289
 
280
290
  template <typename StateMap>
291
+ void RejectAdsUpdateHelperLocked(const std::string& resource_name,
292
+ grpc_millis update_time,
293
+ const XdsApi::AdsParseResult& result,
294
+ const std::string& error_details,
295
+ StateMap* state_map)
296
+ ABSL_EXCLUSIVE_LOCKS_REQUIRED(&XdsClient::mu_);
297
+
281
298
  void RejectAdsUpdateLocked(grpc_millis update_time,
282
- const XdsApi::AdsParseResult& result,
283
- StateMap* state_map)
299
+ const XdsApi::AdsParseResult& result)
284
300
  ABSL_EXCLUSIVE_LOCKS_REQUIRED(&XdsClient::mu_);
285
301
 
286
302
  static void OnRequestSent(void* arg, grpc_error_handle error);
@@ -295,8 +311,9 @@ class XdsClient::ChannelState::AdsCallState
295
311
 
296
312
  bool IsCurrentCallOnChannel() const;
297
313
 
298
- std::set<absl::string_view> ResourceNamesForRequest(
299
- const std::string& type_url);
314
+ std::map<absl::string_view /*authority*/,
315
+ std::set<absl::string_view /*name*/>>
316
+ ResourceNamesForRequest(const std::string& type_url);
300
317
 
301
318
  // The owning RetryableCall<>.
302
319
  RefCountedPtr<RetryableCall<AdsCallState>> parent_;
@@ -441,7 +458,7 @@ class XdsClient::ChannelState::LrsCallState
441
458
  class XdsClient::ChannelState::StateWatcher
442
459
  : public AsyncConnectivityStateWatcherInterface {
443
460
  public:
444
- explicit StateWatcher(RefCountedPtr<ChannelState> parent)
461
+ explicit StateWatcher(WeakRefCountedPtr<ChannelState> parent)
445
462
  : parent_(std::move(parent)) {}
446
463
 
447
464
  private:
@@ -461,7 +478,7 @@ class XdsClient::ChannelState::StateWatcher
461
478
  }
462
479
  }
463
480
 
464
- RefCountedPtr<ChannelState> parent_;
481
+ WeakRefCountedPtr<ChannelState> parent_;
465
482
  };
466
483
 
467
484
  //
@@ -483,7 +500,7 @@ grpc_channel* CreateXdsChannel(grpc_channel_args* args,
483
500
 
484
501
  XdsClient::ChannelState::ChannelState(WeakRefCountedPtr<XdsClient> xds_client,
485
502
  const XdsBootstrap::XdsServer& server)
486
- : InternallyRefCounted<ChannelState>(
503
+ : DualRefCounted<ChannelState>(
487
504
  GRPC_TRACE_FLAG_ENABLED(grpc_xds_client_refcount_trace)
488
505
  ? "ChannelState"
489
506
  : nullptr),
@@ -507,12 +524,19 @@ XdsClient::ChannelState::~ChannelState() {
507
524
  xds_client_.reset(DEBUG_LOCATION, "ChannelState");
508
525
  }
509
526
 
510
- void XdsClient::ChannelState::Orphan() {
527
+ // This method should only ever be called when holding the lock, but we can't
528
+ // use a ABSL_EXCLUSIVE_LOCKS_REQUIRED annotation, because Orphan() will be
529
+ // called from DualRefCounted::Unref, which cannot have a lock annotation for a
530
+ // lock in this subclass.
531
+ void XdsClient::ChannelState::Orphan() ABSL_NO_THREAD_SAFETY_ANALYSIS {
511
532
  shutting_down_ = true;
512
533
  CancelConnectivityWatchLocked();
534
+ // At this time, all strong refs are removed, remove from channel map to
535
+ // prevent subsequent subscription from trying to use this ChannelState as it
536
+ // is shutting down.
537
+ xds_client_->xds_server_channel_map_.erase(server_);
513
538
  ads_calld_.reset();
514
539
  lrs_calld_.reset();
515
- Unref(DEBUG_LOCATION, "ChannelState+orphaned");
516
540
  }
517
541
 
518
542
  XdsClient::ChannelState::AdsCallState* XdsClient::ChannelState::ads_calld()
@@ -531,8 +555,8 @@ bool XdsClient::ChannelState::HasActiveAdsCall() const {
531
555
 
532
556
  void XdsClient::ChannelState::MaybeStartLrsCall() {
533
557
  if (lrs_calld_ != nullptr) return;
534
- lrs_calld_.reset(
535
- new RetryableCall<LrsCallState>(Ref(DEBUG_LOCATION, "ChannelState+lrs")));
558
+ lrs_calld_.reset(new RetryableCall<LrsCallState>(
559
+ WeakRef(DEBUG_LOCATION, "ChannelState+lrs")));
536
560
  }
537
561
 
538
562
  void XdsClient::ChannelState::StopLrsCall() { lrs_calld_.reset(); }
@@ -540,7 +564,7 @@ void XdsClient::ChannelState::StopLrsCall() { lrs_calld_.reset(); }
540
564
  void XdsClient::ChannelState::StartConnectivityWatchLocked() {
541
565
  ClientChannel* client_channel = ClientChannel::GetFromChannel(channel_);
542
566
  GPR_ASSERT(client_channel != nullptr);
543
- watcher_ = new StateWatcher(Ref(DEBUG_LOCATION, "ChannelState+watch"));
567
+ watcher_ = new StateWatcher(WeakRef(DEBUG_LOCATION, "ChannelState+watch"));
544
568
  client_channel->AddConnectivityWatcher(
545
569
  GRPC_CHANNEL_IDLE,
546
570
  OrphanablePtr<AsyncConnectivityStateWatcherInterface>(watcher_));
@@ -552,12 +576,12 @@ void XdsClient::ChannelState::CancelConnectivityWatchLocked() {
552
576
  client_channel->RemoveConnectivityWatcher(watcher_);
553
577
  }
554
578
 
555
- void XdsClient::ChannelState::SubscribeLocked(const std::string& type_url,
556
- const std::string& name) {
579
+ void XdsClient::ChannelState::SubscribeLocked(
580
+ const std::string& type_url, const XdsApi::ResourceName& resource) {
557
581
  if (ads_calld_ == nullptr) {
558
582
  // Start the ADS call if this is the first request.
559
583
  ads_calld_.reset(new RetryableCall<AdsCallState>(
560
- Ref(DEBUG_LOCATION, "ChannelState+ads")));
584
+ WeakRef(DEBUG_LOCATION, "ChannelState+ads")));
561
585
  // Note: AdsCallState's ctor will automatically subscribe to all
562
586
  // resources that the XdsClient already has watchers for, so we can
563
587
  // return here.
@@ -567,17 +591,19 @@ void XdsClient::ChannelState::SubscribeLocked(const std::string& type_url,
567
591
  // because when the call is restarted it will resend all necessary requests.
568
592
  if (ads_calld() == nullptr) return;
569
593
  // Subscribe to this resource if the ADS call is active.
570
- ads_calld()->SubscribeLocked(type_url, name);
594
+ ads_calld()->SubscribeLocked(type_url, resource);
571
595
  }
572
596
 
573
- void XdsClient::ChannelState::UnsubscribeLocked(const std::string& type_url,
574
- const std::string& name,
575
- bool delay_unsubscription) {
597
+ void XdsClient::ChannelState::UnsubscribeLocked(
598
+ const std::string& type_url, const XdsApi::ResourceName& resource,
599
+ bool delay_unsubscription) {
576
600
  if (ads_calld_ != nullptr) {
577
601
  auto* calld = ads_calld_->calld();
578
602
  if (calld != nullptr) {
579
- calld->UnsubscribeLocked(type_url, name, delay_unsubscription);
580
- if (!calld->HasSubscribedResources()) ads_calld_.reset();
603
+ calld->UnsubscribeLocked(type_url, resource, delay_unsubscription);
604
+ if (!calld->HasSubscribedResources()) {
605
+ ads_calld_.reset();
606
+ }
581
607
  }
582
608
  }
583
609
  }
@@ -588,7 +614,7 @@ void XdsClient::ChannelState::UnsubscribeLocked(const std::string& type_url,
588
614
 
589
615
  template <typename T>
590
616
  XdsClient::ChannelState::RetryableCall<T>::RetryableCall(
591
- RefCountedPtr<ChannelState> chand)
617
+ WeakRefCountedPtr<ChannelState> chand)
592
618
  : chand_(std::move(chand)),
593
619
  backoff_(
594
620
  BackOff::Options()
@@ -646,7 +672,8 @@ void XdsClient::ChannelState::RetryableCall<T>::StartRetryTimerLocked() {
646
672
  if (shutting_down_) return;
647
673
  const grpc_millis next_attempt_time = backoff_.NextAttemptTime();
648
674
  if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_client_trace)) {
649
- grpc_millis timeout = GPR_MAX(next_attempt_time - ExecCtx::Get()->Now(), 0);
675
+ grpc_millis timeout =
676
+ std::max(next_attempt_time - ExecCtx::Get()->Now(), grpc_millis(0));
650
677
  gpr_log(GPR_INFO,
651
678
  "[xds_client %p] Failed to connect to xds server (chand: %p) "
652
679
  "retry timer will fire in %" PRId64 "ms.",
@@ -737,17 +764,26 @@ XdsClient::ChannelState::AdsCallState::AdsCallState(
737
764
  // Op: send request message.
738
765
  GRPC_CLOSURE_INIT(&on_request_sent_, OnRequestSent, this,
739
766
  grpc_schedule_on_exec_ctx);
740
- for (const auto& p : xds_client()->listener_map_) {
741
- SubscribeLocked(XdsApi::kLdsTypeUrl, std::string(p.first));
742
- }
743
- for (const auto& p : xds_client()->route_config_map_) {
744
- SubscribeLocked(XdsApi::kRdsTypeUrl, std::string(p.first));
745
- }
746
- for (const auto& p : xds_client()->cluster_map_) {
747
- SubscribeLocked(XdsApi::kCdsTypeUrl, std::string(p.first));
748
- }
749
- for (const auto& p : xds_client()->endpoint_map_) {
750
- SubscribeLocked(XdsApi::kEdsTypeUrl, std::string(p.first));
767
+ for (const auto& a : xds_client()->authority_state_map_) {
768
+ const std::string& authority = a.first;
769
+ // Skip authorities that are not using this xDS channel.
770
+ if (a.second.channel_state != chand()) continue;
771
+ for (const auto& l : a.second.listener_map) {
772
+ const std::string& listener_name = l.first;
773
+ SubscribeLocked(XdsApi::kLdsTypeUrl, {authority, listener_name});
774
+ }
775
+ for (const auto& r : a.second.route_config_map) {
776
+ const std::string& route_config_name = r.first;
777
+ SubscribeLocked(XdsApi::kRdsTypeUrl, {authority, route_config_name});
778
+ }
779
+ for (const auto& c : a.second.cluster_map) {
780
+ const std::string& cluster_name = c.first;
781
+ SubscribeLocked(XdsApi::kCdsTypeUrl, {authority, cluster_name});
782
+ }
783
+ for (const auto& e : a.second.endpoint_map) {
784
+ const std::string& endpoint_name = e.first;
785
+ SubscribeLocked(XdsApi::kEdsTypeUrl, {authority, endpoint_name});
786
+ }
751
787
  }
752
788
  // Op: recv initial metadata.
753
789
  op = ops;
@@ -820,11 +856,12 @@ void XdsClient::ChannelState::AdsCallState::SendMessageLocked(
820
856
  }
821
857
  auto& state = state_map_[type_url];
822
858
  grpc_slice request_payload_slice;
823
- std::set<absl::string_view> resource_names =
824
- ResourceNamesForRequest(type_url);
859
+ std::map<absl::string_view /*authority*/,
860
+ std::set<absl::string_view /*name*/>>
861
+ resource_map = ResourceNamesForRequest(type_url);
825
862
  request_payload_slice = xds_client()->api_.CreateAdsRequest(
826
- chand()->server_, type_url, resource_names,
827
- xds_client()->resource_version_map_[type_url], state.nonce,
863
+ chand()->server_, type_url, resource_map,
864
+ chand()->resource_type_version_map_[type_url], state.nonce,
828
865
  GRPC_ERROR_REF(state.error), !sent_initial_message_);
829
866
  if (type_url != XdsApi::kLdsTypeUrl && type_url != XdsApi::kRdsTypeUrl &&
830
867
  type_url != XdsApi::kCdsTypeUrl && type_url != XdsApi::kEdsTypeUrl) {
@@ -834,11 +871,10 @@ void XdsClient::ChannelState::AdsCallState::SendMessageLocked(
834
871
  if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_client_trace)) {
835
872
  gpr_log(GPR_INFO,
836
873
  "[xds_client %p] sending ADS request: type=%s version=%s nonce=%s "
837
- "error=%s resources=%s",
874
+ "error=%s",
838
875
  xds_client(), type_url.c_str(),
839
- xds_client()->resource_version_map_[type_url].c_str(),
840
- state.nonce.c_str(), grpc_error_std_string(state.error).c_str(),
841
- absl::StrJoin(resource_names, " ").c_str());
876
+ chand()->resource_type_version_map_[type_url].c_str(),
877
+ state.nonce.c_str(), grpc_error_std_string(state.error).c_str());
842
878
  }
843
879
  GRPC_ERROR_UNREF(state.error);
844
880
  state.error = GRPC_ERROR_NONE;
@@ -865,19 +901,26 @@ void XdsClient::ChannelState::AdsCallState::SendMessageLocked(
865
901
  }
866
902
 
867
903
  void XdsClient::ChannelState::AdsCallState::SubscribeLocked(
868
- const std::string& type_url, const std::string& name) {
869
- auto& state = state_map_[type_url].subscribed_resources[name];
904
+ const std::string& type_url, const XdsApi::ResourceName& resource) {
905
+ auto& state = state_map_[type_url]
906
+ .subscribed_resources[resource.authority][resource.id];
870
907
  if (state == nullptr) {
871
908
  state = MakeOrphanable<ResourceState>(
872
- type_url, name, !xds_client()->resource_version_map_[type_url].empty());
909
+ type_url, resource,
910
+ !chand()->resource_type_version_map_[type_url].empty());
873
911
  SendMessageLocked(type_url);
874
912
  }
875
913
  }
876
914
 
877
915
  void XdsClient::ChannelState::AdsCallState::UnsubscribeLocked(
878
- const std::string& type_url, const std::string& name,
916
+ const std::string& type_url, const XdsApi::ResourceName& resource,
879
917
  bool delay_unsubscription) {
880
- state_map_[type_url].subscribed_resources.erase(name);
918
+ auto& type_state_map = state_map_[type_url];
919
+ auto& authority_map = type_state_map.subscribed_resources[resource.authority];
920
+ authority_map.erase(resource.id);
921
+ if (authority_map.empty()) {
922
+ type_state_map.subscribed_resources.erase(resource.authority);
923
+ }
881
924
  if (!delay_unsubscription) SendMessageLocked(type_url);
882
925
  }
883
926
 
@@ -907,7 +950,7 @@ XdsApi::ResourceMetadata CreateResourceMetadataAcked(
907
950
  void XdsClient::ChannelState::AdsCallState::AcceptLdsUpdateLocked(
908
951
  std::string version, grpc_millis update_time,
909
952
  XdsApi::LdsUpdateMap lds_update_map,
910
- const std::set<std::string>& resource_names_failed) {
953
+ const std::set<XdsApi::ResourceName>& resource_names_failed) {
911
954
  if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_client_trace)) {
912
955
  gpr_log(GPR_INFO,
913
956
  "[xds_client %p] LDS update received containing %" PRIuPTR
@@ -917,28 +960,38 @@ void XdsClient::ChannelState::AdsCallState::AcceptLdsUpdateLocked(
917
960
  auto& lds_state = state_map_[XdsApi::kLdsTypeUrl];
918
961
  std::set<std::string> rds_resource_names_seen;
919
962
  for (auto& p : lds_update_map) {
920
- const std::string& listener_name = p.first;
963
+ const XdsApi::ResourceName& resource = p.first;
921
964
  XdsApi::LdsUpdate& lds_update = p.second.resource;
922
- auto& state = lds_state.subscribed_resources[listener_name];
965
+ auto& state =
966
+ lds_state.subscribed_resources[resource.authority][resource.id];
923
967
  if (state != nullptr) state->Finish();
924
968
  if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_client_trace)) {
925
969
  gpr_log(GPR_INFO, "[xds_client %p] LDS resource %s: %s", xds_client(),
926
- listener_name.c_str(), lds_update.ToString().c_str());
970
+ XdsApi::ConstructFullResourceName(
971
+ resource.authority, XdsApi::kLdsTypeUrl, resource.id)
972
+ .c_str(),
973
+ lds_update.ToString().c_str());
927
974
  }
928
975
  // Record the RDS resource names seen.
929
976
  if (!lds_update.http_connection_manager.route_config_name.empty()) {
930
977
  rds_resource_names_seen.insert(
931
978
  lds_update.http_connection_manager.route_config_name);
932
979
  }
980
+ ListenerState& listener_state =
981
+ xds_client()
982
+ ->authority_state_map_[resource.authority]
983
+ .listener_map[resource.id];
933
984
  // Ignore identical update.
934
- ListenerState& listener_state = xds_client()->listener_map_[listener_name];
935
985
  if (listener_state.update.has_value() &&
936
986
  *listener_state.update == lds_update) {
937
987
  if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_client_trace)) {
938
988
  gpr_log(GPR_INFO,
939
989
  "[xds_client %p] LDS update for %s identical to current, "
940
990
  "ignoring.",
941
- xds_client(), listener_name.c_str());
991
+ xds_client(),
992
+ XdsApi::ConstructFullResourceName(
993
+ resource.authority, XdsApi::kLdsTypeUrl, resource.id)
994
+ .c_str());
942
995
  }
943
996
  continue;
944
997
  }
@@ -954,35 +1007,43 @@ void XdsClient::ChannelState::AdsCallState::AcceptLdsUpdateLocked(
954
1007
  // For invalid resources in the update, if they are already in the
955
1008
  // cache, pretend that they are present in the update, so that we
956
1009
  // don't incorrectly consider them deleted below.
957
- for (const std::string& listener_name : resource_names_failed) {
958
- auto it = xds_client()->listener_map_.find(listener_name);
959
- if (it != xds_client()->listener_map_.end()) {
960
- auto& resource = it->second.update;
961
- if (!resource.has_value()) continue;
962
- lds_update_map[listener_name];
963
- if (!resource->http_connection_manager.route_config_name.empty()) {
1010
+ for (const auto& resource : resource_names_failed) {
1011
+ auto& listener_map =
1012
+ xds_client()->authority_state_map_[resource.authority].listener_map;
1013
+ auto it = listener_map.find(resource.id);
1014
+ if (it != listener_map.end()) {
1015
+ auto& update = it->second.update;
1016
+ if (!update.has_value()) continue;
1017
+ lds_update_map[resource];
1018
+ if (!update->http_connection_manager.route_config_name.empty()) {
964
1019
  rds_resource_names_seen.insert(
965
- resource->http_connection_manager.route_config_name);
1020
+ update->http_connection_manager.route_config_name);
966
1021
  }
967
1022
  }
968
1023
  }
969
1024
  // For any subscribed resource that is not present in the update,
970
1025
  // remove it from the cache and notify watchers that it does not exist.
971
- for (const auto& p : lds_state.subscribed_resources) {
972
- const std::string& listener_name = p.first;
973
- if (lds_update_map.find(listener_name) == lds_update_map.end()) {
974
- ListenerState& listener_state =
975
- xds_client()->listener_map_[listener_name];
976
- // If the resource was newly requested but has not yet been received,
977
- // we don't want to generate an error for the watchers, because this LDS
978
- // response may be in reaction to an earlier request that did not yet
979
- // request the new resource, so its absence from the response does not
980
- // necessarily indicate that the resource does not exist.
981
- // For that case, we rely on the request timeout instead.
982
- if (!listener_state.update.has_value()) continue;
983
- listener_state.update.reset();
984
- for (const auto& p : listener_state.watchers) {
985
- p.first->OnResourceDoesNotExist();
1026
+ for (const auto& a : lds_state.subscribed_resources) {
1027
+ const std::string& authority_name = a.first;
1028
+ for (const auto& p : a.second) {
1029
+ const std::string& listener_name = p.first;
1030
+ if (lds_update_map.find({authority_name, listener_name}) ==
1031
+ lds_update_map.end()) {
1032
+ ListenerState& listener_state =
1033
+ xds_client()
1034
+ ->authority_state_map_[authority_name]
1035
+ .listener_map[listener_name];
1036
+ // If the resource was newly requested but has not yet been received,
1037
+ // we don't want to generate an error for the watchers, because this LDS
1038
+ // response may be in reaction to an earlier request that did not yet
1039
+ // request the new resource, so its absence from the response does not
1040
+ // necessarily indicate that the resource does not exist.
1041
+ // For that case, we rely on the request timeout instead.
1042
+ if (!listener_state.update.has_value()) continue;
1043
+ listener_state.update.reset();
1044
+ for (const auto& p : listener_state.watchers) {
1045
+ p.first->OnResourceDoesNotExist();
1046
+ }
986
1047
  }
987
1048
  }
988
1049
  }
@@ -990,15 +1051,21 @@ void XdsClient::ChannelState::AdsCallState::AcceptLdsUpdateLocked(
990
1051
  // resources, remove it from the cache and notify watchers that it
991
1052
  // does not exist.
992
1053
  auto& rds_state = state_map_[XdsApi::kRdsTypeUrl];
993
- for (const auto& p : rds_state.subscribed_resources) {
994
- const std::string& rds_resource_name = p.first;
995
- if (rds_resource_names_seen.find(rds_resource_name) ==
996
- rds_resource_names_seen.end()) {
997
- RouteConfigState& route_config_state =
998
- xds_client()->route_config_map_[rds_resource_name];
999
- route_config_state.update.reset();
1000
- for (const auto& p : route_config_state.watchers) {
1001
- p.first->OnResourceDoesNotExist();
1054
+ for (const auto& a : rds_state.subscribed_resources) {
1055
+ const std::string& authority_name = a.first;
1056
+ for (const auto& p : a.second) {
1057
+ const std::string& listener_name = p.first;
1058
+ if (rds_resource_names_seen.find(XdsApi::ConstructFullResourceName(
1059
+ authority_name, XdsApi::kRdsTypeUrl, listener_name)) ==
1060
+ rds_resource_names_seen.end()) {
1061
+ RouteConfigState& route_config_state =
1062
+ xds_client()
1063
+ ->authority_state_map_[authority_name]
1064
+ .route_config_map[listener_name];
1065
+ route_config_state.update.reset();
1066
+ for (const auto& p : route_config_state.watchers) {
1067
+ p.first->OnResourceDoesNotExist();
1068
+ }
1002
1069
  }
1003
1070
  }
1004
1071
  }
@@ -1015,16 +1082,19 @@ void XdsClient::ChannelState::AdsCallState::AcceptRdsUpdateLocked(
1015
1082
  }
1016
1083
  auto& rds_state = state_map_[XdsApi::kRdsTypeUrl];
1017
1084
  for (auto& p : rds_update_map) {
1018
- const std::string& route_config_name = p.first;
1085
+ const XdsApi::ResourceName& resource = p.first;
1019
1086
  XdsApi::RdsUpdate& rds_update = p.second.resource;
1020
- auto& state = rds_state.subscribed_resources[route_config_name];
1087
+ auto& state =
1088
+ rds_state.subscribed_resources[resource.authority][resource.id];
1021
1089
  if (state != nullptr) state->Finish();
1022
1090
  if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_client_trace)) {
1023
1091
  gpr_log(GPR_INFO, "[xds_client %p] RDS resource:\n%s", xds_client(),
1024
1092
  rds_update.ToString().c_str());
1025
1093
  }
1026
1094
  RouteConfigState& route_config_state =
1027
- xds_client()->route_config_map_[route_config_name];
1095
+ xds_client()
1096
+ ->authority_state_map_[resource.authority]
1097
+ .route_config_map[resource.id];
1028
1098
  // Ignore identical update.
1029
1099
  if (route_config_state.update.has_value() &&
1030
1100
  *route_config_state.update == rds_update) {
@@ -1049,7 +1119,7 @@ void XdsClient::ChannelState::AdsCallState::AcceptRdsUpdateLocked(
1049
1119
  void XdsClient::ChannelState::AdsCallState::AcceptCdsUpdateLocked(
1050
1120
  std::string version, grpc_millis update_time,
1051
1121
  XdsApi::CdsUpdateMap cds_update_map,
1052
- const std::set<std::string>& resource_names_failed) {
1122
+ const std::set<XdsApi::ResourceName>& resource_names_failed) {
1053
1123
  if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_client_trace)) {
1054
1124
  gpr_log(GPR_INFO,
1055
1125
  "[xds_client %p] CDS update received containing %" PRIuPTR
@@ -1059,20 +1129,28 @@ void XdsClient::ChannelState::AdsCallState::AcceptCdsUpdateLocked(
1059
1129
  auto& cds_state = state_map_[XdsApi::kCdsTypeUrl];
1060
1130
  std::set<std::string> eds_resource_names_seen;
1061
1131
  for (auto& p : cds_update_map) {
1062
- const char* cluster_name = p.first.c_str();
1132
+ const XdsApi::ResourceName& resource = p.first;
1063
1133
  XdsApi::CdsUpdate& cds_update = p.second.resource;
1064
- auto& state = cds_state.subscribed_resources[cluster_name];
1134
+ auto& state =
1135
+ cds_state.subscribed_resources[resource.authority][resource.id];
1065
1136
  if (state != nullptr) state->Finish();
1066
1137
  if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_client_trace)) {
1067
1138
  gpr_log(GPR_INFO, "[xds_client %p] cluster=%s: %s", xds_client(),
1068
- cluster_name, cds_update.ToString().c_str());
1139
+ XdsApi::ConstructFullResourceName(
1140
+ resource.authority, XdsApi::kCdsTypeUrl, resource.id)
1141
+ .c_str(),
1142
+ cds_update.ToString().c_str());
1069
1143
  }
1070
1144
  // Record the EDS resource names seen.
1071
- eds_resource_names_seen.insert(cds_update.eds_service_name.empty()
1072
- ? cluster_name
1073
- : cds_update.eds_service_name);
1145
+ eds_resource_names_seen.insert(
1146
+ cds_update.eds_service_name.empty()
1147
+ ? XdsApi::ConstructFullResourceName(
1148
+ resource.authority, XdsApi::kCdsTypeUrl, resource.id)
1149
+ : cds_update.eds_service_name);
1150
+ ClusterState& cluster_state = xds_client()
1151
+ ->authority_state_map_[resource.authority]
1152
+ .cluster_map[resource.id];
1074
1153
  // Ignore identical update.
1075
- ClusterState& cluster_state = xds_client()->cluster_map_[cluster_name];
1076
1154
  if (cluster_state.update.has_value() &&
1077
1155
  *cluster_state.update == cds_update) {
1078
1156
  if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_client_trace)) {
@@ -1094,33 +1172,43 @@ void XdsClient::ChannelState::AdsCallState::AcceptCdsUpdateLocked(
1094
1172
  // For invalid resources in the update, if they are already in the
1095
1173
  // cache, pretend that they are present in the update, so that we
1096
1174
  // don't incorrectly consider them deleted below.
1097
- for (const std::string& cluster_name : resource_names_failed) {
1098
- auto it = xds_client()->cluster_map_.find(cluster_name);
1099
- if (it != xds_client()->cluster_map_.end()) {
1100
- auto& resource = it->second.update;
1101
- if (!resource.has_value()) continue;
1102
- cds_update_map[cluster_name];
1103
- eds_resource_names_seen.insert(resource->eds_service_name.empty()
1104
- ? cluster_name
1105
- : resource->eds_service_name);
1175
+ for (const auto& resource : resource_names_failed) {
1176
+ auto& cluster_map =
1177
+ xds_client()->authority_state_map_[resource.authority].cluster_map;
1178
+ auto it = cluster_map.find(resource.id);
1179
+ if (it != cluster_map.end()) {
1180
+ auto& update = it->second.update;
1181
+ if (!update.has_value()) continue;
1182
+ cds_update_map[resource];
1183
+ eds_resource_names_seen.insert(
1184
+ update->eds_service_name.empty()
1185
+ ? XdsApi::ConstructFullResourceName(
1186
+ resource.authority, XdsApi::kCdsTypeUrl, resource.id)
1187
+ : update->eds_service_name);
1106
1188
  }
1107
1189
  }
1108
1190
  // For any subscribed resource that is not present in the update,
1109
1191
  // remove it from the cache and notify watchers that it does not exist.
1110
- for (const auto& p : cds_state.subscribed_resources) {
1111
- const std::string& cluster_name = p.first;
1112
- if (cds_update_map.find(cluster_name) == cds_update_map.end()) {
1113
- ClusterState& cluster_state = xds_client()->cluster_map_[cluster_name];
1114
- // If the resource was newly requested but has not yet been received,
1115
- // we don't want to generate an error for the watchers, because this CDS
1116
- // response may be in reaction to an earlier request that did not yet
1117
- // request the new resource, so its absence from the response does not
1118
- // necessarily indicate that the resource does not exist.
1119
- // For that case, we rely on the request timeout instead.
1120
- if (!cluster_state.update.has_value()) continue;
1121
- cluster_state.update.reset();
1122
- for (const auto& p : cluster_state.watchers) {
1123
- p.first->OnResourceDoesNotExist();
1192
+ for (const auto& a : cds_state.subscribed_resources) {
1193
+ const std::string& authority = a.first;
1194
+ for (const auto& p : a.second) {
1195
+ const std::string& cluster_name = p.first;
1196
+ if (cds_update_map.find({authority, cluster_name}) ==
1197
+ cds_update_map.end()) {
1198
+ ClusterState& cluster_state = xds_client()
1199
+ ->authority_state_map_[authority]
1200
+ .cluster_map[cluster_name];
1201
+ // If the resource was newly requested but has not yet been received,
1202
+ // we don't want to generate an error for the watchers, because this CDS
1203
+ // response may be in reaction to an earlier request that did not yet
1204
+ // request the new resource, so its absence from the response does not
1205
+ // necessarily indicate that the resource does not exist.
1206
+ // For that case, we rely on the request timeout instead.
1207
+ if (!cluster_state.update.has_value()) continue;
1208
+ cluster_state.update.reset();
1209
+ for (const auto& p : cluster_state.watchers) {
1210
+ p.first->OnResourceDoesNotExist();
1211
+ }
1124
1212
  }
1125
1213
  }
1126
1214
  }
@@ -1128,15 +1216,20 @@ void XdsClient::ChannelState::AdsCallState::AcceptCdsUpdateLocked(
1128
1216
  // resources, remove it from the cache and notify watchers that it
1129
1217
  // does not exist.
1130
1218
  auto& eds_state = state_map_[XdsApi::kEdsTypeUrl];
1131
- for (const auto& p : eds_state.subscribed_resources) {
1132
- const std::string& eds_resource_name = p.first;
1133
- if (eds_resource_names_seen.find(eds_resource_name) ==
1134
- eds_resource_names_seen.end()) {
1135
- EndpointState& endpoint_state =
1136
- xds_client()->endpoint_map_[eds_resource_name];
1137
- endpoint_state.update.reset();
1138
- for (const auto& p : endpoint_state.watchers) {
1139
- p.first->OnResourceDoesNotExist();
1219
+ for (const auto& a : eds_state.subscribed_resources) {
1220
+ const std::string& authority = a.first;
1221
+ for (const auto& p : a.second) {
1222
+ const std::string& eds_resource_name = p.first;
1223
+ if (eds_resource_names_seen.find(XdsApi::ConstructFullResourceName(
1224
+ authority, XdsApi::kEdsTypeUrl, eds_resource_name)) ==
1225
+ eds_resource_names_seen.end()) {
1226
+ EndpointState& endpoint_state = xds_client()
1227
+ ->authority_state_map_[authority]
1228
+ .endpoint_map[eds_resource_name];
1229
+ endpoint_state.update.reset();
1230
+ for (const auto& p : endpoint_state.watchers) {
1231
+ p.first->OnResourceDoesNotExist();
1232
+ }
1140
1233
  }
1141
1234
  }
1142
1235
  }
@@ -1153,16 +1246,22 @@ void XdsClient::ChannelState::AdsCallState::AcceptEdsUpdateLocked(
1153
1246
  }
1154
1247
  auto& eds_state = state_map_[XdsApi::kEdsTypeUrl];
1155
1248
  for (auto& p : eds_update_map) {
1156
- const char* eds_service_name = p.first.c_str();
1249
+ const XdsApi::ResourceName& resource = p.first;
1157
1250
  XdsApi::EdsUpdate& eds_update = p.second.resource;
1158
- auto& state = eds_state.subscribed_resources[eds_service_name];
1251
+ auto& state =
1252
+ eds_state.subscribed_resources[resource.authority][resource.id];
1159
1253
  if (state != nullptr) state->Finish();
1160
1254
  if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_client_trace)) {
1161
1255
  gpr_log(GPR_INFO, "[xds_client %p] EDS resource %s: %s", xds_client(),
1162
- eds_service_name, eds_update.ToString().c_str());
1256
+ XdsApi::ConstructFullResourceName(
1257
+ resource.authority, XdsApi::kCdsTypeUrl, resource.id)
1258
+ .c_str(),
1259
+ eds_update.ToString().c_str());
1163
1260
  }
1164
1261
  EndpointState& endpoint_state =
1165
- xds_client()->endpoint_map_[eds_service_name];
1262
+ xds_client()
1263
+ ->authority_state_map_[resource.authority]
1264
+ .endpoint_map[resource.id];
1166
1265
  // Ignore identical update.
1167
1266
  if (endpoint_state.update.has_value() &&
1168
1267
  *endpoint_state.update == eds_update) {
@@ -1200,9 +1299,22 @@ void UpdateResourceMetadataNacked(const std::string& version,
1200
1299
  } // namespace
1201
1300
 
1202
1301
  template <typename StateMap>
1203
- void XdsClient::ChannelState::AdsCallState::RejectAdsUpdateLocked(
1204
- grpc_millis update_time, const XdsApi::AdsParseResult& result,
1302
+ void XdsClient::ChannelState::AdsCallState::RejectAdsUpdateHelperLocked(
1303
+ const std::string& resource_name, grpc_millis update_time,
1304
+ const XdsApi::AdsParseResult& result, const std::string& error_details,
1205
1305
  StateMap* state_map) {
1306
+ auto it = state_map->find(resource_name);
1307
+ if (it == state_map->end()) return;
1308
+ auto& state = it->second;
1309
+ for (const auto& p : state.watchers) {
1310
+ p.first->OnError(GRPC_ERROR_REF(result.parse_error));
1311
+ }
1312
+ UpdateResourceMetadataNacked(result.version, error_details, update_time,
1313
+ &state.meta);
1314
+ }
1315
+
1316
+ void XdsClient::ChannelState::AdsCallState::RejectAdsUpdateLocked(
1317
+ grpc_millis update_time, const XdsApi::AdsParseResult& result) {
1206
1318
  if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_client_trace)) {
1207
1319
  gpr_log(GPR_INFO,
1208
1320
  "[xds_client %p] %s update NACKed containing %" PRIuPTR
@@ -1211,17 +1323,26 @@ void XdsClient::ChannelState::AdsCallState::RejectAdsUpdateLocked(
1211
1323
  result.resource_names_failed.size());
1212
1324
  }
1213
1325
  std::string details = grpc_error_std_string(result.parse_error);
1214
- for (auto& name : result.resource_names_failed) {
1215
- auto it = state_map->find(name);
1216
- if (it == state_map->end()) continue;
1217
- auto& state = it->second;
1218
- // Notify watchers of error.
1219
- for (const auto& p : state.watchers) {
1220
- p.first->OnError(GRPC_ERROR_REF(result.parse_error));
1326
+ for (auto& resource : result.resource_names_failed) {
1327
+ auto authority_it =
1328
+ xds_client()->authority_state_map_.find(resource.authority);
1329
+ if (authority_it == xds_client()->authority_state_map_.end()) continue;
1330
+ AuthorityState& authority_state = authority_it->second;
1331
+ if (result.type_url == XdsApi::kLdsTypeUrl) {
1332
+ RejectAdsUpdateHelperLocked(resource.id, update_time, result, details,
1333
+ &authority_state.listener_map);
1334
+ } else if (result.type_url == XdsApi::kRdsTypeUrl) {
1335
+ RejectAdsUpdateHelperLocked(resource.id, update_time, result, details,
1336
+ &authority_state.route_config_map);
1337
+ } else if (result.type_url == XdsApi::kCdsTypeUrl) {
1338
+ RejectAdsUpdateHelperLocked(resource.id, update_time, result, details,
1339
+ &authority_state.cluster_map);
1340
+ } else if (result.type_url == XdsApi::kEdsTypeUrl) {
1341
+ RejectAdsUpdateHelperLocked(resource.id, update_time, result, details,
1342
+ &authority_state.endpoint_map);
1343
+ } else {
1344
+ GPR_ASSERT(0);
1221
1345
  }
1222
- // Update resource metadata for CSDS.
1223
- UpdateResourceMetadataNacked(result.version, details, update_time,
1224
- &state.meta);
1225
1346
  }
1226
1347
  }
1227
1348
 
@@ -1314,18 +1435,7 @@ bool XdsClient::ChannelState::AdsCallState::OnResponseReceivedLocked() {
1314
1435
  GRPC_STATUS_UNAVAILABLE);
1315
1436
  GRPC_ERROR_UNREF(state.error);
1316
1437
  state.error = result.parse_error;
1317
- if (result.type_url == XdsApi::kLdsTypeUrl) {
1318
- RejectAdsUpdateLocked(update_time, result,
1319
- &xds_client()->listener_map_);
1320
- } else if (result.type_url == XdsApi::kRdsTypeUrl) {
1321
- RejectAdsUpdateLocked(update_time, result,
1322
- &xds_client()->route_config_map_);
1323
- } else if (result.type_url == XdsApi::kCdsTypeUrl) {
1324
- RejectAdsUpdateLocked(update_time, result, &xds_client()->cluster_map_);
1325
- } else if (result.type_url == XdsApi::kEdsTypeUrl) {
1326
- RejectAdsUpdateLocked(update_time, result,
1327
- &xds_client()->endpoint_map_);
1328
- }
1438
+ RejectAdsUpdateLocked(update_time, result);
1329
1439
  }
1330
1440
  // Process any valid resources.
1331
1441
  bool have_valid_resources = false;
@@ -1350,8 +1460,7 @@ bool XdsClient::ChannelState::AdsCallState::OnResponseReceivedLocked() {
1350
1460
  }
1351
1461
  if (have_valid_resources) {
1352
1462
  seen_response_ = true;
1353
- xds_client()->resource_version_map_[result.type_url] =
1354
- std::move(result.version);
1463
+ chand()->resource_type_version_map_[result.type_url] = result.version;
1355
1464
  // Start load reporting if needed.
1356
1465
  auto& lrs_call = chand()->lrs_calld_;
1357
1466
  if (lrs_call != nullptr) {
@@ -1417,19 +1526,23 @@ bool XdsClient::ChannelState::AdsCallState::IsCurrentCallOnChannel() const {
1417
1526
  return this == chand()->ads_calld_->calld();
1418
1527
  }
1419
1528
 
1420
- std::set<absl::string_view>
1529
+ std::map<absl::string_view /*authority*/, std::set<absl::string_view /*name*/>>
1421
1530
  XdsClient::ChannelState::AdsCallState::ResourceNamesForRequest(
1422
1531
  const std::string& type_url) {
1423
- std::set<absl::string_view> resource_names;
1532
+ std::map<absl::string_view /*authority*/,
1533
+ std::set<absl::string_view /*name*/>>
1534
+ resource_map;
1424
1535
  auto it = state_map_.find(type_url);
1425
1536
  if (it != state_map_.end()) {
1426
- for (auto& p : it->second.subscribed_resources) {
1427
- resource_names.insert(p.first);
1428
- OrphanablePtr<ResourceState>& state = p.second;
1429
- state->Start(Ref(DEBUG_LOCATION, "ResourceState"));
1537
+ for (auto& a : it->second.subscribed_resources) {
1538
+ for (auto& p : a.second) {
1539
+ resource_map[a.first].insert(p.first);
1540
+ OrphanablePtr<ResourceState>& state = p.second;
1541
+ state->Start(Ref(DEBUG_LOCATION, "ResourceState"));
1542
+ }
1430
1543
  }
1431
1544
  }
1432
- return resource_names;
1545
+ return resource_map;
1433
1546
  }
1434
1547
 
1435
1548
  //
@@ -1878,12 +1991,10 @@ grpc_millis GetRequestTimeout(const grpc_channel_args* args) {
1878
1991
  }
1879
1992
 
1880
1993
  grpc_channel_args* ModifyChannelArgs(const grpc_channel_args* args) {
1881
- absl::InlinedVector<grpc_arg, 2> args_to_add = {
1994
+ absl::InlinedVector<grpc_arg, 1> args_to_add = {
1882
1995
  grpc_channel_arg_integer_create(
1883
1996
  const_cast<char*>(GRPC_ARG_KEEPALIVE_TIME_MS),
1884
1997
  5 * 60 * GPR_MS_PER_SEC),
1885
- grpc_channel_arg_integer_create(
1886
- const_cast<char*>(GRPC_ARG_CHANNELZ_IS_INTERNAL_CHANNEL), 1),
1887
1998
  };
1888
1999
  return grpc_channel_args_copy_and_add(args, args_to_add.data(),
1889
2000
  args_to_add.size());
@@ -1907,9 +2018,9 @@ XdsClient::XdsClient(std::unique_ptr<XdsBootstrap> bootstrap,
1907
2018
  if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_client_trace)) {
1908
2019
  gpr_log(GPR_INFO, "[xds_client %p] creating xds client", this);
1909
2020
  }
1910
- // Create ChannelState object.
1911
- chand_ = MakeOrphanable<ChannelState>(
1912
- WeakRef(DEBUG_LOCATION, "XdsClient+ChannelState"), bootstrap_->server());
2021
+ // Calling grpc_init to ensure gRPC does not shut down until the XdsClient is
2022
+ // destroyed.
2023
+ grpc_init();
1913
2024
  }
1914
2025
 
1915
2026
  XdsClient::~XdsClient() {
@@ -1918,26 +2029,9 @@ XdsClient::~XdsClient() {
1918
2029
  }
1919
2030
  grpc_channel_args_destroy(args_);
1920
2031
  grpc_pollset_set_destroy(interested_parties_);
1921
- }
1922
-
1923
- void XdsClient::AddChannelzLinkage(
1924
- channelz::ChannelNode* parent_channelz_node) {
1925
- MutexLock lock(&mu_);
1926
- channelz::ChannelNode* xds_channelz_node =
1927
- grpc_channel_get_channelz_node(chand_->channel());
1928
- if (xds_channelz_node != nullptr) {
1929
- parent_channelz_node->AddChildChannel(xds_channelz_node->uuid());
1930
- }
1931
- }
1932
-
1933
- void XdsClient::RemoveChannelzLinkage(
1934
- channelz::ChannelNode* parent_channelz_node) {
1935
- MutexLock lock(&mu_);
1936
- channelz::ChannelNode* xds_channelz_node =
1937
- grpc_channel_get_channelz_node(chand_->channel());
1938
- if (xds_channelz_node != nullptr) {
1939
- parent_channelz_node->RemoveChildChannel(xds_channelz_node->uuid());
1940
- }
2032
+ // Calling grpc_shutdown to ensure gRPC does not shut down until the XdsClient
2033
+ // is destroyed.
2034
+ grpc_shutdown();
1941
2035
  }
1942
2036
 
1943
2037
  void XdsClient::Orphan() {
@@ -1951,28 +2045,56 @@ void XdsClient::Orphan() {
1951
2045
  {
1952
2046
  MutexLock lock(&mu_);
1953
2047
  shutting_down_ = true;
1954
- // Orphan ChannelState object.
1955
- chand_.reset();
1956
2048
  // We do not clear cluster_map_ and endpoint_map_ if the xds client was
1957
2049
  // created by the XdsResolver because the maps contain refs for watchers
1958
2050
  // which in turn hold refs to the loadbalancing policies. At this point, it
1959
2051
  // is possible for ADS calls to be in progress. Unreffing the loadbalancing
1960
2052
  // policies before those calls are done would lead to issues such as
1961
2053
  // https://github.com/grpc/grpc/issues/20928.
1962
- if (!listener_map_.empty()) {
1963
- cluster_map_.clear();
1964
- endpoint_map_.clear();
2054
+ for (auto& a : authority_state_map_) {
2055
+ a.second.channel_state.reset();
2056
+ if (!a.second.listener_map.empty()) {
2057
+ a.second.cluster_map.clear();
2058
+ a.second.endpoint_map.clear();
2059
+ }
1965
2060
  }
2061
+ // We clear these invalid resource watchers as cancel never came.
2062
+ invalid_listener_watchers_.clear();
2063
+ invalid_route_config_watchers_.clear();
2064
+ invalid_cluster_watchers_.clear();
2065
+ invalid_endpoint_watchers_.clear();
1966
2066
  }
1967
2067
  }
1968
2068
 
2069
+ RefCountedPtr<XdsClient::ChannelState> XdsClient::GetOrCreateChannelStateLocked(
2070
+ const XdsBootstrap::XdsServer& server) {
2071
+ auto it = xds_server_channel_map_.find(server);
2072
+ if (it != xds_server_channel_map_.end()) {
2073
+ return it->second->Ref(DEBUG_LOCATION, "Authority");
2074
+ }
2075
+ // Channel not found, so create a new one.
2076
+ auto channel_state = MakeRefCounted<ChannelState>(
2077
+ WeakRef(DEBUG_LOCATION, "ChannelState"), server);
2078
+ xds_server_channel_map_[server] = channel_state.get();
2079
+ return channel_state;
2080
+ }
2081
+
1969
2082
  void XdsClient::WatchListenerData(
1970
2083
  absl::string_view listener_name,
1971
2084
  std::unique_ptr<ListenerWatcherInterface> watcher) {
1972
2085
  std::string listener_name_str = std::string(listener_name);
1973
2086
  MutexLock lock(&mu_);
1974
- ListenerState& listener_state = listener_map_[listener_name_str];
1975
2087
  ListenerWatcherInterface* w = watcher.get();
2088
+ auto resource = XdsApi::ParseResourceName(listener_name, XdsApi::IsLds);
2089
+ if (!resource.ok()) {
2090
+ invalid_listener_watchers_[w] = std::move(watcher);
2091
+ grpc_error_handle error = GRPC_ERROR_CREATE_FROM_CPP_STRING(absl::StrFormat(
2092
+ "Unable to parse resource name for listener %s", listener_name));
2093
+ w->OnError(GRPC_ERROR_REF(error));
2094
+ return;
2095
+ }
2096
+ AuthorityState& authority_state = authority_state_map_[resource->authority];
2097
+ ListenerState& listener_state = authority_state.listener_map[resource->id];
1976
2098
  listener_state.watchers[w] = std::move(watcher);
1977
2099
  // If we've already received an LDS update, notify the new watcher
1978
2100
  // immediately.
@@ -1983,7 +2105,13 @@ void XdsClient::WatchListenerData(
1983
2105
  }
1984
2106
  w->OnListenerChanged(*listener_state.update);
1985
2107
  }
1986
- chand_->SubscribeLocked(XdsApi::kLdsTypeUrl, listener_name_str);
2108
+ // If the authority doesn't yet have a channel, set it, creating it if needed.
2109
+ if (authority_state.channel_state == nullptr) {
2110
+ authority_state.channel_state =
2111
+ GetOrCreateChannelStateLocked(bootstrap_->server());
2112
+ }
2113
+ authority_state.channel_state->SubscribeLocked(XdsApi::kLdsTypeUrl,
2114
+ *resource);
1987
2115
  }
1988
2116
 
1989
2117
  void XdsClient::CancelListenerDataWatch(absl::string_view listener_name,
@@ -1991,16 +2119,22 @@ void XdsClient::CancelListenerDataWatch(absl::string_view listener_name,
1991
2119
  bool delay_unsubscription) {
1992
2120
  MutexLock lock(&mu_);
1993
2121
  if (shutting_down_) return;
1994
- std::string listener_name_str = std::string(listener_name);
1995
- ListenerState& listener_state = listener_map_[listener_name_str];
2122
+ auto resource = XdsApi::ParseResourceName(listener_name, XdsApi::IsLds);
2123
+ if (!resource.ok()) return;
2124
+ auto& authority_state = authority_state_map_[resource->authority];
2125
+ ListenerState& listener_state = authority_state.listener_map[resource->id];
1996
2126
  auto it = listener_state.watchers.find(watcher);
1997
- if (it != listener_state.watchers.end()) {
1998
- listener_state.watchers.erase(it);
1999
- if (listener_state.watchers.empty()) {
2000
- listener_map_.erase(listener_name_str);
2001
- chand_->UnsubscribeLocked(XdsApi::kLdsTypeUrl, listener_name_str,
2002
- delay_unsubscription);
2003
- }
2127
+ if (it == listener_state.watchers.end()) {
2128
+ invalid_listener_watchers_.erase(watcher);
2129
+ return;
2130
+ }
2131
+ listener_state.watchers.erase(it);
2132
+ if (!listener_state.watchers.empty()) return;
2133
+ authority_state.listener_map.erase(resource->id);
2134
+ xds_server_channel_map_[bootstrap_->server()]->UnsubscribeLocked(
2135
+ XdsApi::kLdsTypeUrl, *resource, delay_unsubscription);
2136
+ if (!authority_state.HasSubscribedResources()) {
2137
+ authority_state.channel_state.reset();
2004
2138
  }
2005
2139
  }
2006
2140
 
@@ -2009,9 +2143,19 @@ void XdsClient::WatchRouteConfigData(
2009
2143
  std::unique_ptr<RouteConfigWatcherInterface> watcher) {
2010
2144
  std::string route_config_name_str = std::string(route_config_name);
2011
2145
  MutexLock lock(&mu_);
2012
- RouteConfigState& route_config_state =
2013
- route_config_map_[route_config_name_str];
2014
2146
  RouteConfigWatcherInterface* w = watcher.get();
2147
+ auto resource = XdsApi::ParseResourceName(route_config_name, XdsApi::IsRds);
2148
+ if (!resource.ok()) {
2149
+ invalid_route_config_watchers_[w] = std::move(watcher);
2150
+ grpc_error_handle error = GRPC_ERROR_CREATE_FROM_CPP_STRING(
2151
+ absl::StrFormat("Unable to parse resource name for route config %s",
2152
+ route_config_name));
2153
+ w->OnError(GRPC_ERROR_REF(error));
2154
+ return;
2155
+ }
2156
+ auto& authority_state = authority_state_map_[resource->authority];
2157
+ RouteConfigState& route_config_state =
2158
+ authority_state.route_config_map[resource->id];
2015
2159
  route_config_state.watchers[w] = std::move(watcher);
2016
2160
  // If we've already received an RDS update, notify the new watcher
2017
2161
  // immediately.
@@ -2023,7 +2167,13 @@ void XdsClient::WatchRouteConfigData(
2023
2167
  }
2024
2168
  w->OnRouteConfigChanged(*route_config_state.update);
2025
2169
  }
2026
- chand_->SubscribeLocked(XdsApi::kRdsTypeUrl, route_config_name_str);
2170
+ // If the authority doesn't yet have a channel, set it, creating it if needed.
2171
+ if (authority_state.channel_state == nullptr) {
2172
+ authority_state.channel_state =
2173
+ GetOrCreateChannelStateLocked(bootstrap_->server());
2174
+ }
2175
+ authority_state.channel_state->SubscribeLocked(XdsApi::kRdsTypeUrl,
2176
+ *resource);
2027
2177
  }
2028
2178
 
2029
2179
  void XdsClient::CancelRouteConfigDataWatch(absl::string_view route_config_name,
@@ -2031,17 +2181,23 @@ void XdsClient::CancelRouteConfigDataWatch(absl::string_view route_config_name,
2031
2181
  bool delay_unsubscription) {
2032
2182
  MutexLock lock(&mu_);
2033
2183
  if (shutting_down_) return;
2034
- std::string route_config_name_str = std::string(route_config_name);
2184
+ auto resource = XdsApi::ParseResourceName(route_config_name, XdsApi::IsRds);
2185
+ if (!resource.ok()) return;
2186
+ auto& authority_state = authority_state_map_[resource->authority];
2035
2187
  RouteConfigState& route_config_state =
2036
- route_config_map_[route_config_name_str];
2188
+ authority_state.route_config_map[resource->id];
2037
2189
  auto it = route_config_state.watchers.find(watcher);
2038
- if (it != route_config_state.watchers.end()) {
2039
- route_config_state.watchers.erase(it);
2040
- if (route_config_state.watchers.empty()) {
2041
- route_config_map_.erase(route_config_name_str);
2042
- chand_->UnsubscribeLocked(XdsApi::kRdsTypeUrl, route_config_name_str,
2043
- delay_unsubscription);
2044
- }
2190
+ if (it == route_config_state.watchers.end()) {
2191
+ invalid_route_config_watchers_.erase(watcher);
2192
+ return;
2193
+ }
2194
+ route_config_state.watchers.erase(it);
2195
+ if (!route_config_state.watchers.empty()) return;
2196
+ authority_state.route_config_map.erase(resource->id);
2197
+ xds_server_channel_map_[bootstrap_->server()]->UnsubscribeLocked(
2198
+ XdsApi::kRdsTypeUrl, *resource, delay_unsubscription);
2199
+ if (!authority_state.HasSubscribedResources()) {
2200
+ authority_state.channel_state.reset();
2045
2201
  }
2046
2202
  }
2047
2203
 
@@ -2050,8 +2206,17 @@ void XdsClient::WatchClusterData(
2050
2206
  std::unique_ptr<ClusterWatcherInterface> watcher) {
2051
2207
  std::string cluster_name_str = std::string(cluster_name);
2052
2208
  MutexLock lock(&mu_);
2053
- ClusterState& cluster_state = cluster_map_[cluster_name_str];
2054
2209
  ClusterWatcherInterface* w = watcher.get();
2210
+ auto resource = XdsApi::ParseResourceName(cluster_name, XdsApi::IsCds);
2211
+ if (!resource.ok()) {
2212
+ invalid_cluster_watchers_[w] = std::move(watcher);
2213
+ grpc_error_handle error = GRPC_ERROR_CREATE_FROM_CPP_STRING(absl::StrFormat(
2214
+ "Unable to parse resource name for cluster %s", cluster_name));
2215
+ w->OnError(GRPC_ERROR_REF(error));
2216
+ return;
2217
+ }
2218
+ auto& authority_state = authority_state_map_[resource->authority];
2219
+ ClusterState& cluster_state = authority_state.cluster_map[resource->id];
2055
2220
  cluster_state.watchers[w] = std::move(watcher);
2056
2221
  // If we've already received a CDS update, notify the new watcher
2057
2222
  // immediately.
@@ -2062,7 +2227,13 @@ void XdsClient::WatchClusterData(
2062
2227
  }
2063
2228
  w->OnClusterChanged(cluster_state.update.value());
2064
2229
  }
2065
- chand_->SubscribeLocked(XdsApi::kCdsTypeUrl, cluster_name_str);
2230
+ // If the authority doesn't yet have a channel, set it, creating it if needed.
2231
+ if (authority_state.channel_state == nullptr) {
2232
+ authority_state.channel_state =
2233
+ GetOrCreateChannelStateLocked(bootstrap_->server());
2234
+ }
2235
+ authority_state.channel_state->SubscribeLocked(XdsApi::kCdsTypeUrl,
2236
+ *resource);
2066
2237
  }
2067
2238
 
2068
2239
  void XdsClient::CancelClusterDataWatch(absl::string_view cluster_name,
@@ -2070,16 +2241,22 @@ void XdsClient::CancelClusterDataWatch(absl::string_view cluster_name,
2070
2241
  bool delay_unsubscription) {
2071
2242
  MutexLock lock(&mu_);
2072
2243
  if (shutting_down_) return;
2073
- std::string cluster_name_str = std::string(cluster_name);
2074
- ClusterState& cluster_state = cluster_map_[cluster_name_str];
2244
+ auto resource = XdsApi::ParseResourceName(cluster_name, XdsApi::IsCds);
2245
+ if (!resource.ok()) return;
2246
+ auto& authority_state = authority_state_map_[resource->authority];
2247
+ ClusterState& cluster_state = authority_state.cluster_map[resource->id];
2075
2248
  auto it = cluster_state.watchers.find(watcher);
2076
- if (it != cluster_state.watchers.end()) {
2077
- cluster_state.watchers.erase(it);
2078
- if (cluster_state.watchers.empty()) {
2079
- cluster_map_.erase(cluster_name_str);
2080
- chand_->UnsubscribeLocked(XdsApi::kCdsTypeUrl, cluster_name_str,
2081
- delay_unsubscription);
2082
- }
2249
+ if (it == cluster_state.watchers.end()) {
2250
+ invalid_cluster_watchers_.erase(watcher);
2251
+ return;
2252
+ }
2253
+ cluster_state.watchers.erase(it);
2254
+ if (!cluster_state.watchers.empty()) return;
2255
+ authority_state.cluster_map.erase(resource->id);
2256
+ xds_server_channel_map_[bootstrap_->server()]->UnsubscribeLocked(
2257
+ XdsApi::kCdsTypeUrl, *resource, delay_unsubscription);
2258
+ if (!authority_state.HasSubscribedResources()) {
2259
+ authority_state.channel_state.reset();
2083
2260
  }
2084
2261
  }
2085
2262
 
@@ -2088,8 +2265,18 @@ void XdsClient::WatchEndpointData(
2088
2265
  std::unique_ptr<EndpointWatcherInterface> watcher) {
2089
2266
  std::string eds_service_name_str = std::string(eds_service_name);
2090
2267
  MutexLock lock(&mu_);
2091
- EndpointState& endpoint_state = endpoint_map_[eds_service_name_str];
2092
2268
  EndpointWatcherInterface* w = watcher.get();
2269
+ auto resource = XdsApi::ParseResourceName(eds_service_name, XdsApi::IsEds);
2270
+ if (!resource.ok()) {
2271
+ invalid_endpoint_watchers_[w] = std::move(watcher);
2272
+ grpc_error_handle error = GRPC_ERROR_CREATE_FROM_CPP_STRING(
2273
+ absl::StrFormat("Unable to parse resource name for endpoint service %s",
2274
+ eds_service_name));
2275
+ w->OnError(GRPC_ERROR_REF(error));
2276
+ return;
2277
+ }
2278
+ auto& authority_state = authority_state_map_[resource->authority];
2279
+ EndpointState& endpoint_state = authority_state.endpoint_map[resource->id];
2093
2280
  endpoint_state.watchers[w] = std::move(watcher);
2094
2281
  // If we've already received an EDS update, notify the new watcher
2095
2282
  // immediately.
@@ -2100,7 +2287,13 @@ void XdsClient::WatchEndpointData(
2100
2287
  }
2101
2288
  w->OnEndpointChanged(endpoint_state.update.value());
2102
2289
  }
2103
- chand_->SubscribeLocked(XdsApi::kEdsTypeUrl, eds_service_name_str);
2290
+ // If the authority doesn't yet have a channel, set it, creating it if needed.
2291
+ if (authority_state.channel_state == nullptr) {
2292
+ authority_state.channel_state =
2293
+ GetOrCreateChannelStateLocked(bootstrap_->server());
2294
+ }
2295
+ authority_state.channel_state->SubscribeLocked(XdsApi::kEdsTypeUrl,
2296
+ *resource);
2104
2297
  }
2105
2298
 
2106
2299
  void XdsClient::CancelEndpointDataWatch(absl::string_view eds_service_name,
@@ -2108,16 +2301,22 @@ void XdsClient::CancelEndpointDataWatch(absl::string_view eds_service_name,
2108
2301
  bool delay_unsubscription) {
2109
2302
  MutexLock lock(&mu_);
2110
2303
  if (shutting_down_) return;
2111
- std::string eds_service_name_str = std::string(eds_service_name);
2112
- EndpointState& endpoint_state = endpoint_map_[eds_service_name_str];
2304
+ auto resource = XdsApi::ParseResourceName(eds_service_name, XdsApi::IsEds);
2305
+ if (!resource.ok()) return;
2306
+ auto& authority_state = authority_state_map_[resource->authority];
2307
+ EndpointState& endpoint_state = authority_state.endpoint_map[resource->id];
2113
2308
  auto it = endpoint_state.watchers.find(watcher);
2114
- if (it != endpoint_state.watchers.end()) {
2115
- endpoint_state.watchers.erase(it);
2116
- if (endpoint_state.watchers.empty()) {
2117
- endpoint_map_.erase(eds_service_name_str);
2118
- chand_->UnsubscribeLocked(XdsApi::kEdsTypeUrl, eds_service_name_str,
2119
- delay_unsubscription);
2120
- }
2309
+ if (it == endpoint_state.watchers.end()) {
2310
+ invalid_endpoint_watchers_.erase(watcher);
2311
+ return;
2312
+ }
2313
+ endpoint_state.watchers.erase(it);
2314
+ if (!endpoint_state.watchers.empty()) return;
2315
+ authority_state.endpoint_map.erase(resource->id);
2316
+ xds_server_channel_map_[bootstrap_->server()]->UnsubscribeLocked(
2317
+ XdsApi::kEdsTypeUrl, *resource, delay_unsubscription);
2318
+ if (!authority_state.HasSubscribedResources()) {
2319
+ authority_state.channel_state.reset();
2121
2320
  }
2122
2321
  }
2123
2322
 
@@ -2151,7 +2350,12 @@ RefCountedPtr<XdsClusterDropStats> XdsClient::AddClusterDropStats(
2151
2350
  it->first.second /*eds_service_name*/);
2152
2351
  load_report_state.drop_stats = cluster_drop_stats.get();
2153
2352
  }
2154
- chand_->MaybeStartLrsCall();
2353
+ auto resource = XdsApi::ParseResourceName(cluster_name, XdsApi::IsCds);
2354
+ GPR_ASSERT(resource.ok());
2355
+ auto a = authority_state_map_.find(resource->authority);
2356
+ if (a != authority_state_map_.end()) {
2357
+ a->second.channel_state->MaybeStartLrsCall();
2358
+ }
2155
2359
  return cluster_drop_stats;
2156
2360
  }
2157
2361
 
@@ -2208,7 +2412,12 @@ RefCountedPtr<XdsClusterLocalityStats> XdsClient::AddClusterLocalityStats(
2208
2412
  std::move(locality));
2209
2413
  locality_state.locality_stats = cluster_locality_stats.get();
2210
2414
  }
2211
- chand_->MaybeStartLrsCall();
2415
+ auto resource = XdsApi::ParseResourceName(cluster_name, XdsApi::IsCds);
2416
+ GPR_ASSERT(resource.ok());
2417
+ auto a = authority_state_map_.find(resource->authority);
2418
+ if (a != authority_state_map_.end()) {
2419
+ a->second.channel_state->MaybeStartLrsCall();
2420
+ }
2212
2421
  return cluster_locality_stats;
2213
2422
  }
2214
2423
 
@@ -2238,34 +2447,36 @@ void XdsClient::RemoveClusterLocalityStats(
2238
2447
 
2239
2448
  void XdsClient::ResetBackoff() {
2240
2449
  MutexLock lock(&mu_);
2241
- if (chand_ != nullptr) {
2242
- grpc_channel_reset_connect_backoff(chand_->channel());
2450
+ for (auto& p : xds_server_channel_map_) {
2451
+ grpc_channel_reset_connect_backoff(p.second->channel());
2243
2452
  }
2244
2453
  }
2245
2454
 
2246
2455
  void XdsClient::NotifyOnErrorLocked(grpc_error_handle error) {
2247
- for (const auto& p : listener_map_) {
2248
- const ListenerState& listener_state = p.second;
2249
- for (const auto& p : listener_state.watchers) {
2250
- p.first->OnError(GRPC_ERROR_REF(error));
2456
+ for (const auto& a : authority_state_map_) {
2457
+ for (const auto& p : a.second.listener_map) {
2458
+ const ListenerState& listener_state = p.second;
2459
+ for (const auto& p : listener_state.watchers) {
2460
+ p.first->OnError(GRPC_ERROR_REF(error));
2461
+ }
2251
2462
  }
2252
- }
2253
- for (const auto& p : route_config_map_) {
2254
- const RouteConfigState& route_config_state = p.second;
2255
- for (const auto& p : route_config_state.watchers) {
2256
- p.first->OnError(GRPC_ERROR_REF(error));
2463
+ for (const auto& p : a.second.route_config_map) {
2464
+ const RouteConfigState& route_config_state = p.second;
2465
+ for (const auto& p : route_config_state.watchers) {
2466
+ p.first->OnError(GRPC_ERROR_REF(error));
2467
+ }
2257
2468
  }
2258
- }
2259
- for (const auto& p : cluster_map_) {
2260
- const ClusterState& cluster_state = p.second;
2261
- for (const auto& p : cluster_state.watchers) {
2262
- p.first->OnError(GRPC_ERROR_REF(error));
2469
+ for (const auto& p : a.second.cluster_map) {
2470
+ const ClusterState& cluster_state = p.second;
2471
+ for (const auto& p : cluster_state.watchers) {
2472
+ p.first->OnError(GRPC_ERROR_REF(error));
2473
+ }
2263
2474
  }
2264
- }
2265
- for (const auto& p : endpoint_map_) {
2266
- const EndpointState& endpoint_state = p.second;
2267
- for (const auto& p : endpoint_state.watchers) {
2268
- p.first->OnError(GRPC_ERROR_REF(error));
2475
+ for (const auto& p : a.second.endpoint_map) {
2476
+ const EndpointState& endpoint_state = p.second;
2477
+ for (const auto& p : endpoint_state.watchers) {
2478
+ p.first->OnError(GRPC_ERROR_REF(error));
2479
+ }
2269
2480
  }
2270
2481
  }
2271
2482
  GRPC_ERROR_UNREF(error);
@@ -2355,34 +2566,36 @@ XdsApi::ClusterLoadReportMap XdsClient::BuildLoadReportSnapshotLocked(
2355
2566
  std::string XdsClient::DumpClientConfigBinary() {
2356
2567
  MutexLock lock(&mu_);
2357
2568
  XdsApi::ResourceTypeMetadataMap resource_type_metadata_map;
2358
- // Update per-xds-type version if available, this version corresponding to the
2359
- // last successful ADS update version.
2360
- for (auto& p : resource_version_map_) {
2361
- resource_type_metadata_map[p.first].version = p.second;
2362
- }
2363
- // Collect resource metadata from listeners
2364
- auto& lds_map =
2365
- resource_type_metadata_map[XdsApi::kLdsTypeUrl].resource_metadata_map;
2366
- for (auto& p : listener_map_) {
2367
- lds_map[p.first] = &p.second.meta;
2368
- }
2369
- // Collect resource metadata from route configs
2370
- auto& rds_map =
2371
- resource_type_metadata_map[XdsApi::kRdsTypeUrl].resource_metadata_map;
2372
- for (auto& p : route_config_map_) {
2373
- rds_map[p.first] = &p.second.meta;
2374
- }
2375
- // Collect resource metadata from clusters
2376
- auto& cds_map =
2377
- resource_type_metadata_map[XdsApi::kCdsTypeUrl].resource_metadata_map;
2378
- for (auto& p : cluster_map_) {
2379
- cds_map[p.first] = &p.second.meta;
2380
- }
2381
- // Collect resource metadata from endpoints
2382
- auto& eds_map =
2383
- resource_type_metadata_map[XdsApi::kEdsTypeUrl].resource_metadata_map;
2384
- for (auto& p : endpoint_map_) {
2385
- eds_map[p.first] = &p.second.meta;
2569
+ auto& lds_map = resource_type_metadata_map[XdsApi::kLdsTypeUrl];
2570
+ auto& rds_map = resource_type_metadata_map[XdsApi::kRdsTypeUrl];
2571
+ auto& cds_map = resource_type_metadata_map[XdsApi::kCdsTypeUrl];
2572
+ auto& eds_map = resource_type_metadata_map[XdsApi::kEdsTypeUrl];
2573
+ for (auto& a : authority_state_map_) {
2574
+ const std::string& authority = a.first;
2575
+ // Collect resource metadata from listeners
2576
+ for (auto& p : a.second.listener_map) {
2577
+ const std::string& listener_name = p.first;
2578
+ lds_map[XdsApi::ConstructFullResourceName(
2579
+ authority, XdsApi::kLdsTypeUrl, listener_name)] = &p.second.meta;
2580
+ }
2581
+ // Collect resource metadata from route configs
2582
+ for (auto& p : a.second.route_config_map) {
2583
+ const std::string& route_config_name = p.first;
2584
+ rds_map[XdsApi::ConstructFullResourceName(
2585
+ authority, XdsApi::kRdsTypeUrl, route_config_name)] = &p.second.meta;
2586
+ }
2587
+ // Collect resource metadata from clusters
2588
+ for (auto& p : a.second.cluster_map) {
2589
+ const std::string& cluster_name = p.first;
2590
+ cds_map[XdsApi::ConstructFullResourceName(authority, XdsApi::kCdsTypeUrl,
2591
+ cluster_name)] = &p.second.meta;
2592
+ }
2593
+ // Collect resource metadata from endpoints
2594
+ for (auto& p : a.second.endpoint_map) {
2595
+ const std::string& endpoint_name = p.first;
2596
+ eds_map[XdsApi::ConstructFullResourceName(
2597
+ authority, XdsApi::kEdsTypeUrl, endpoint_name)] = &p.second.meta;
2598
+ }
2386
2599
  }
2387
2600
  // Assemble config dump messages
2388
2601
  return api_.AssembleClientConfig(resource_type_metadata_map);
@@ -2540,7 +2753,7 @@ void XdsClientArgDestroy(void* p) {
2540
2753
  xds_client->Unref(DEBUG_LOCATION, "channel arg");
2541
2754
  }
2542
2755
 
2543
- int XdsClientArgCmp(void* p, void* q) { return GPR_ICMP(p, q); }
2756
+ int XdsClientArgCmp(void* p, void* q) { return QsortCompare(p, q); }
2544
2757
 
2545
2758
  const grpc_arg_pointer_vtable kXdsClientArgVtable = {
2546
2759
  XdsClientArgCopy, XdsClientArgDestroy, XdsClientArgCmp};