grpc 1.28.0.pre2 → 1.31.0.pre1

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

Potentially problematic release.


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

Files changed (660) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +8313 -11862
  3. data/include/grpc/grpc.h +2 -2
  4. data/include/grpc/grpc_security.h +30 -9
  5. data/include/grpc/grpc_security_constants.h +4 -0
  6. data/include/grpc/impl/codegen/grpc_types.h +23 -23
  7. data/include/grpc/impl/codegen/port_platform.h +6 -34
  8. data/include/grpc/module.modulemap +24 -39
  9. data/src/core/ext/filters/client_channel/backend_metric.cc +18 -12
  10. data/src/core/ext/filters/client_channel/client_channel.cc +618 -482
  11. data/src/core/ext/filters/client_channel/client_channel_plugin.cc +3 -2
  12. data/src/core/ext/filters/client_channel/config_selector.cc +62 -0
  13. data/src/core/ext/filters/client_channel/config_selector.h +93 -0
  14. data/src/core/ext/filters/client_channel/global_subchannel_pool.cc +24 -2
  15. data/src/core/ext/filters/client_channel/health/health_check_client.cc +9 -22
  16. data/src/core/ext/filters/client_channel/health/health_check_client.h +3 -3
  17. data/src/core/ext/filters/client_channel/http_connect_handshaker.cc +6 -5
  18. data/src/core/ext/filters/client_channel/http_proxy.cc +23 -14
  19. data/src/core/ext/filters/client_channel/lb_policy.cc +19 -18
  20. data/src/core/ext/filters/client_channel/lb_policy.h +44 -33
  21. data/src/core/ext/filters/client_channel/lb_policy/address_filtering.cc +83 -0
  22. data/src/core/ext/filters/client_channel/lb_policy/address_filtering.h +99 -0
  23. data/src/core/ext/filters/client_channel/lb_policy/child_policy_handler.cc +297 -0
  24. data/src/core/ext/filters/client_channel/lb_policy/child_policy_handler.h +83 -0
  25. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +311 -497
  26. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_balancer_addresses.cc +89 -0
  27. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_balancer_addresses.h +40 -0
  28. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel_secure.cc +11 -9
  29. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.h +3 -2
  30. data/src/core/ext/filters/client_channel/lb_policy/priority/priority.cc +871 -0
  31. data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc +1 -1
  32. data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +9 -17
  33. data/src/core/ext/filters/client_channel/lb_policy/weighted_target/weighted_target.cc +734 -0
  34. data/src/core/ext/filters/client_channel/lb_policy/xds/cds.cc +117 -41
  35. data/src/core/ext/filters/client_channel/lb_policy/xds/eds.cc +938 -0
  36. data/src/core/ext/filters/client_channel/lb_policy/xds/lrs.cc +528 -0
  37. data/src/core/ext/filters/client_channel/lb_policy/xds/xds.h +1 -2
  38. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_routing.cc +1142 -0
  39. data/src/core/ext/filters/client_channel/lb_policy_registry.cc +10 -7
  40. data/src/core/ext/filters/client_channel/local_subchannel_pool.h +2 -1
  41. data/src/core/ext/filters/client_channel/parse_address.cc +22 -21
  42. data/src/core/ext/filters/client_channel/resolver.cc +5 -8
  43. data/src/core/ext/filters/client_channel/resolver.h +12 -14
  44. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +78 -61
  45. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.cc +41 -40
  46. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.h +8 -7
  47. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_libuv.cc +22 -24
  48. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_posix.cc +12 -10
  49. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_windows.cc +79 -122
  50. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc +199 -163
  51. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h +5 -3
  52. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_fallback.cc +7 -4
  53. data/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc +46 -45
  54. data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc +93 -102
  55. data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.h +0 -4
  56. data/src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.cc +2 -2
  57. data/src/core/ext/filters/client_channel/resolver/xds/xds_resolver.cc +64 -12
  58. data/src/core/ext/filters/client_channel/resolver_factory.h +2 -2
  59. data/src/core/ext/filters/client_channel/resolver_registry.cc +19 -17
  60. data/src/core/ext/filters/client_channel/resolver_registry.h +8 -8
  61. data/src/core/ext/filters/client_channel/resolver_result_parsing.cc +21 -22
  62. data/src/core/ext/filters/client_channel/resolver_result_parsing.h +19 -16
  63. data/src/core/ext/filters/client_channel/resolving_lb_policy.cc +73 -217
  64. data/src/core/ext/filters/client_channel/resolving_lb_policy.h +45 -27
  65. data/src/core/ext/filters/client_channel/server_address.cc +6 -9
  66. data/src/core/ext/filters/client_channel/server_address.h +6 -12
  67. data/src/core/ext/filters/client_channel/service_config.cc +104 -144
  68. data/src/core/ext/filters/client_channel/service_config.h +28 -98
  69. data/src/core/ext/filters/client_channel/service_config_call_data.h +68 -0
  70. data/src/core/ext/filters/client_channel/service_config_channel_arg_filter.cc +142 -0
  71. data/src/core/ext/filters/client_channel/service_config_parser.cc +87 -0
  72. data/src/core/ext/filters/client_channel/service_config_parser.h +89 -0
  73. data/src/core/ext/filters/client_channel/subchannel.cc +55 -25
  74. data/src/core/ext/filters/client_channel/subchannel.h +35 -11
  75. data/src/core/ext/filters/client_channel/xds/xds_api.cc +1200 -246
  76. data/src/core/ext/filters/client_channel/xds/xds_api.h +130 -44
  77. data/src/core/ext/filters/client_channel/xds/xds_bootstrap.cc +90 -29
  78. data/src/core/ext/filters/client_channel/xds/xds_bootstrap.h +9 -4
  79. data/src/core/ext/filters/client_channel/xds/xds_channel_secure.cc +4 -2
  80. data/src/core/ext/filters/client_channel/xds/xds_client.cc +839 -431
  81. data/src/core/ext/filters/client_channel/xds/xds_client.h +84 -33
  82. data/src/core/ext/filters/client_channel/xds/xds_client_stats.cc +11 -12
  83. data/src/core/ext/filters/client_channel/xds/xds_client_stats.h +40 -28
  84. data/src/core/ext/filters/http/client/http_client_filter.cc +28 -33
  85. data/src/core/ext/filters/http/client_authority_filter.cc +4 -4
  86. data/src/core/ext/filters/http/http_filters_plugin.cc +28 -12
  87. data/src/core/ext/filters/http/message_compress/message_compress_filter.cc +258 -221
  88. data/src/core/ext/filters/http/message_compress/message_decompress_filter.cc +399 -0
  89. data/src/core/ext/filters/http/message_compress/message_decompress_filter.h +31 -0
  90. data/src/core/ext/filters/message_size/message_size_filter.cc +61 -88
  91. data/src/core/ext/filters/message_size/message_size_filter.h +10 -4
  92. data/src/core/ext/transport/chttp2/server/chttp2_server.cc +386 -350
  93. data/src/core/ext/transport/chttp2/server/chttp2_server.h +6 -2
  94. data/src/core/ext/transport/chttp2/server/insecure/server_chttp2.cc +1 -1
  95. data/src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.cc +7 -13
  96. data/src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.cc +7 -8
  97. data/src/core/ext/transport/chttp2/transport/bin_encoder.cc +4 -6
  98. data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +42 -26
  99. data/src/core/ext/transport/chttp2/transport/chttp2_transport.h +1 -0
  100. data/src/core/ext/transport/chttp2/transport/flow_control.cc +25 -30
  101. data/src/core/ext/transport/chttp2/transport/flow_control.h +14 -16
  102. data/src/core/ext/transport/chttp2/transport/frame_data.cc +9 -12
  103. data/src/core/ext/transport/chttp2/transport/frame_goaway.cc +4 -6
  104. data/src/core/ext/transport/chttp2/transport/frame_goaway.h +2 -3
  105. data/src/core/ext/transport/chttp2/transport/frame_ping.cc +5 -6
  106. data/src/core/ext/transport/chttp2/transport/frame_ping.h +2 -3
  107. data/src/core/ext/transport/chttp2/transport/frame_rst_stream.cc +12 -13
  108. data/src/core/ext/transport/chttp2/transport/frame_rst_stream.h +2 -3
  109. data/src/core/ext/transport/chttp2/transport/frame_settings.cc +6 -7
  110. data/src/core/ext/transport/chttp2/transport/frame_settings.h +2 -3
  111. data/src/core/ext/transport/chttp2/transport/frame_window_update.cc +9 -12
  112. data/src/core/ext/transport/chttp2/transport/frame_window_update.h +2 -3
  113. data/src/core/ext/transport/chttp2/transport/hpack_encoder.cc +29 -16
  114. data/src/core/ext/transport/chttp2/transport/hpack_encoder.h +2 -3
  115. data/src/core/ext/transport/chttp2/transport/hpack_parser.cc +25 -29
  116. data/src/core/ext/transport/chttp2/transport/hpack_parser.h +2 -3
  117. data/src/core/ext/transport/chttp2/transport/hpack_table.cc +13 -17
  118. data/src/core/ext/transport/chttp2/transport/hpack_table.h +2 -2
  119. data/src/core/ext/transport/chttp2/transport/http2_settings.h +4 -5
  120. data/src/core/ext/transport/chttp2/transport/huffsyms.h +2 -3
  121. data/src/core/ext/transport/chttp2/transport/internal.h +27 -21
  122. data/src/core/ext/transport/chttp2/transport/parsing.cc +33 -43
  123. data/src/core/ext/transport/chttp2/transport/stream_map.h +2 -3
  124. data/src/core/ext/transport/chttp2/transport/writing.cc +24 -22
  125. data/src/core/ext/transport/inproc/inproc_transport.cc +54 -15
  126. data/src/core/ext/upb-generated/envoy/annotations/deprecation.upb.h +0 -1
  127. data/src/core/ext/upb-generated/envoy/annotations/resource.upb.h +3 -4
  128. data/src/core/ext/upb-generated/envoy/api/v2/auth/cert.upb.c +4 -229
  129. data/src/core/ext/upb-generated/envoy/api/v2/auth/cert.upb.h +5 -876
  130. data/src/core/ext/upb-generated/envoy/api/v2/auth/common.upb.c +114 -0
  131. data/src/core/ext/upb-generated/envoy/api/v2/auth/common.upb.h +429 -0
  132. data/src/core/ext/upb-generated/envoy/api/v2/auth/secret.upb.c +72 -0
  133. data/src/core/ext/upb-generated/envoy/api/v2/auth/secret.upb.h +198 -0
  134. data/src/core/ext/upb-generated/envoy/api/v2/auth/tls.upb.c +105 -0
  135. data/src/core/ext/upb-generated/envoy/api/v2/auth/tls.upb.h +388 -0
  136. data/src/core/ext/upb-generated/envoy/api/v2/cds.upb.c +1 -0
  137. data/src/core/ext/upb-generated/envoy/api/v2/cds.upb.h +1 -2
  138. data/src/core/ext/upb-generated/envoy/api/v2/cluster.upb.c +23 -10
  139. data/src/core/ext/upb-generated/envoy/api/v2/cluster.upb.h +352 -310
  140. data/src/core/ext/upb-generated/envoy/api/v2/cluster/circuit_breaker.upb.c +1 -0
  141. data/src/core/ext/upb-generated/envoy/api/v2/cluster/circuit_breaker.upb.h +42 -34
  142. data/src/core/ext/upb-generated/envoy/api/v2/cluster/filter.upb.c +1 -0
  143. data/src/core/ext/upb-generated/envoy/api/v2/cluster/filter.upb.h +7 -7
  144. data/src/core/ext/upb-generated/envoy/api/v2/cluster/outlier_detection.upb.c +1 -0
  145. data/src/core/ext/upb-generated/envoy/api/v2/cluster/outlier_detection.upb.h +79 -61
  146. data/src/core/ext/upb-generated/envoy/api/v2/core/address.upb.c +2 -1
  147. data/src/core/ext/upb-generated/envoy/api/v2/core/address.upb.h +55 -49
  148. data/src/core/ext/upb-generated/envoy/api/v2/core/backoff.upb.c +35 -0
  149. data/src/core/ext/upb-generated/envoy/api/v2/core/backoff.upb.h +79 -0
  150. data/src/core/ext/upb-generated/envoy/api/v2/core/base.upb.c +48 -27
  151. data/src/core/ext/upb-generated/envoy/api/v2/core/base.upb.h +258 -214
  152. data/src/core/ext/upb-generated/envoy/api/v2/core/config_source.upb.c +1 -0
  153. data/src/core/ext/upb-generated/envoy/api/v2/core/config_source.upb.h +51 -45
  154. data/src/core/ext/upb-generated/envoy/api/v2/core/event_service_config.upb.c +34 -0
  155. data/src/core/ext/upb-generated/envoy/api/v2/core/event_service_config.upb.h +71 -0
  156. data/src/core/ext/upb-generated/envoy/api/v2/core/grpc_service.upb.c +2 -1
  157. data/src/core/ext/upb-generated/envoy/api/v2/core/grpc_service.upb.h +107 -100
  158. data/src/core/ext/upb-generated/envoy/api/v2/core/health_check.upb.c +24 -20
  159. data/src/core/ext/upb-generated/envoy/api/v2/core/health_check.upb.h +157 -122
  160. data/src/core/ext/upb-generated/envoy/api/v2/core/http_uri.upb.c +1 -0
  161. data/src/core/ext/upb-generated/envoy/api/v2/core/http_uri.upb.h +9 -9
  162. data/src/core/ext/upb-generated/envoy/api/v2/core/protocol.upb.c +38 -18
  163. data/src/core/ext/upb-generated/envoy/api/v2/core/protocol.upb.h +173 -73
  164. data/src/core/ext/upb-generated/envoy/api/v2/core/socket_option.upb.c +34 -0
  165. data/src/core/ext/upb-generated/envoy/api/v2/core/socket_option.upb.h +88 -0
  166. data/src/core/ext/upb-generated/envoy/api/v2/discovery.upb.c +2 -1
  167. data/src/core/ext/upb-generated/envoy/api/v2/discovery.upb.h +95 -101
  168. data/src/core/ext/upb-generated/envoy/api/v2/eds.upb.c +1 -0
  169. data/src/core/ext/upb-generated/envoy/api/v2/eds.upb.h +1 -2
  170. data/src/core/ext/upb-generated/envoy/api/v2/endpoint.upb.c +2 -1
  171. data/src/core/ext/upb-generated/envoy/api/v2/endpoint.upb.h +49 -65
  172. data/src/core/ext/upb-generated/envoy/api/v2/endpoint/endpoint.upb.c +1 -0
  173. data/src/core/ext/upb-generated/envoy/api/v2/endpoint/endpoint.upb.h +0 -1
  174. data/src/core/ext/upb-generated/envoy/api/v2/endpoint/endpoint_components.upb.c +9 -6
  175. data/src/core/ext/upb-generated/envoy/api/v2/endpoint/endpoint_components.upb.h +53 -38
  176. data/src/core/ext/upb-generated/envoy/api/v2/endpoint/load_report.upb.c +1 -0
  177. data/src/core/ext/upb-generated/envoy/api/v2/endpoint/load_report.upb.h +70 -62
  178. data/src/core/ext/upb-generated/envoy/api/v2/lds.upb.c +1 -0
  179. data/src/core/ext/upb-generated/envoy/api/v2/lds.upb.h +1 -2
  180. data/src/core/ext/upb-generated/envoy/api/v2/listener.upb.c +15 -10
  181. data/src/core/ext/upb-generated/envoy/api/v2/listener.upb.h +95 -63
  182. data/src/core/ext/upb-generated/envoy/api/v2/listener/listener.upb.c +1 -0
  183. data/src/core/ext/upb-generated/envoy/api/v2/listener/listener.upb.h +0 -1
  184. data/src/core/ext/upb-generated/envoy/api/v2/listener/listener_components.upb.c +3 -2
  185. data/src/core/ext/upb-generated/envoy/api/v2/listener/listener_components.upb.h +91 -80
  186. data/src/core/ext/upb-generated/envoy/api/v2/listener/udp_listener_config.upb.c +1 -0
  187. data/src/core/ext/upb-generated/envoy/api/v2/listener/udp_listener_config.upb.h +9 -10
  188. data/src/core/ext/upb-generated/envoy/api/v2/rds.upb.c +1 -0
  189. data/src/core/ext/upb-generated/envoy/api/v2/rds.upb.h +1 -2
  190. data/src/core/ext/upb-generated/envoy/api/v2/route.upb.c +1 -0
  191. data/src/core/ext/upb-generated/envoy/api/v2/route.upb.h +36 -31
  192. data/src/core/ext/upb-generated/envoy/api/v2/route/route.upb.c +1 -0
  193. data/src/core/ext/upb-generated/envoy/api/v2/route/route.upb.h +0 -1
  194. data/src/core/ext/upb-generated/envoy/api/v2/route/route_components.upb.c +68 -46
  195. data/src/core/ext/upb-generated/envoy/api/v2/route/route_components.upb.h +770 -722
  196. data/src/core/ext/upb-generated/envoy/api/v2/scoped_route.upb.c +1 -0
  197. data/src/core/ext/upb-generated/envoy/api/v2/scoped_route.upb.h +16 -15
  198. data/src/core/ext/upb-generated/envoy/api/v2/srds.upb.c +1 -0
  199. data/src/core/ext/upb-generated/envoy/api/v2/srds.upb.h +1 -2
  200. data/src/core/ext/upb-generated/envoy/config/filter/accesslog/v2/accesslog.upb.c +2 -1
  201. data/src/core/ext/upb-generated/envoy/config/filter/accesslog/v2/accesslog.upb.h +95 -88
  202. data/src/core/ext/upb-generated/envoy/config/filter/network/http_connection_manager/v2/http_connection_manager.upb.c +48 -28
  203. data/src/core/ext/upb-generated/envoy/config/filter/network/http_connection_manager/v2/http_connection_manager.upb.h +305 -210
  204. data/src/core/ext/upb-generated/envoy/config/listener/v2/api_listener.upb.c +1 -0
  205. data/src/core/ext/upb-generated/envoy/config/listener/v2/api_listener.upb.h +5 -5
  206. data/src/core/ext/upb-generated/envoy/config/trace/v2/http_tracer.upb.c +51 -0
  207. data/src/core/ext/upb-generated/envoy/config/trace/v2/http_tracer.upb.h +125 -0
  208. data/src/core/ext/upb-generated/envoy/service/discovery/v2/ads.upb.c +1 -0
  209. data/src/core/ext/upb-generated/envoy/service/discovery/v2/ads.upb.h +1 -2
  210. data/src/core/ext/upb-generated/envoy/service/load_stats/v2/lrs.upb.c +4 -2
  211. data/src/core/ext/upb-generated/envoy/service/load_stats/v2/lrs.upb.h +22 -16
  212. data/src/core/ext/upb-generated/envoy/type/http.upb.c +1 -0
  213. data/src/core/ext/upb-generated/envoy/type/http.upb.h +0 -1
  214. data/src/core/ext/upb-generated/envoy/type/matcher/regex.upb.c +16 -0
  215. data/src/core/ext/upb-generated/envoy/type/matcher/regex.upb.h +48 -11
  216. data/src/core/ext/upb-generated/envoy/type/matcher/string.upb.c +1 -0
  217. data/src/core/ext/upb-generated/envoy/type/matcher/string.upb.h +14 -14
  218. data/src/core/ext/upb-generated/envoy/type/metadata/v2/metadata.upb.c +1 -0
  219. data/src/core/ext/upb-generated/envoy/type/metadata/v2/metadata.upb.h +23 -23
  220. data/src/core/ext/upb-generated/envoy/type/percent.upb.c +1 -0
  221. data/src/core/ext/upb-generated/envoy/type/percent.upb.h +8 -9
  222. data/src/core/ext/upb-generated/envoy/type/range.upb.c +1 -0
  223. data/src/core/ext/upb-generated/envoy/type/range.upb.h +15 -16
  224. data/src/core/ext/upb-generated/envoy/type/semantic_version.upb.c +1 -0
  225. data/src/core/ext/upb-generated/envoy/type/semantic_version.upb.h +7 -8
  226. data/src/core/ext/upb-generated/envoy/type/tracing/v2/custom_tag.upb.c +1 -0
  227. data/src/core/ext/upb-generated/envoy/type/tracing/v2/custom_tag.upb.h +36 -35
  228. data/src/core/ext/upb-generated/gogoproto/gogo.upb.h +0 -1
  229. data/src/core/ext/upb-generated/google/api/annotations.upb.h +0 -1
  230. data/src/core/ext/upb-generated/google/api/http.upb.h +29 -28
  231. data/src/core/ext/upb-generated/google/protobuf/any.upb.h +5 -6
  232. data/src/core/ext/upb-generated/google/protobuf/descriptor.upb.c +12 -11
  233. data/src/core/ext/upb-generated/google/protobuf/descriptor.upb.h +421 -389
  234. data/src/core/ext/upb-generated/google/protobuf/duration.upb.h +5 -6
  235. data/src/core/ext/upb-generated/google/protobuf/empty.upb.h +1 -2
  236. data/src/core/ext/upb-generated/google/protobuf/struct.upb.c +1 -1
  237. data/src/core/ext/upb-generated/google/protobuf/struct.upb.h +33 -54
  238. data/src/core/ext/upb-generated/google/protobuf/timestamp.upb.h +5 -6
  239. data/src/core/ext/upb-generated/google/protobuf/wrappers.upb.h +27 -28
  240. data/src/core/ext/upb-generated/google/rpc/status.upb.h +8 -8
  241. data/src/core/ext/upb-generated/src/proto/grpc/gcp/altscontext.upb.c +1 -1
  242. data/src/core/ext/upb-generated/src/proto/grpc/gcp/altscontext.upb.h +32 -45
  243. data/src/core/ext/upb-generated/src/proto/grpc/gcp/handshaker.upb.c +4 -4
  244. data/src/core/ext/upb-generated/src/proto/grpc/gcp/handshaker.upb.h +157 -178
  245. data/src/core/ext/upb-generated/src/proto/grpc/gcp/transport_security_common.upb.h +14 -13
  246. data/src/core/ext/upb-generated/src/proto/grpc/health/v1/health.upb.h +6 -7
  247. data/src/core/ext/upb-generated/src/proto/grpc/lb/v1/load_balancer.upb.h +59 -56
  248. data/src/core/ext/upb-generated/udpa/annotations/migrate.upb.h +11 -12
  249. data/src/core/ext/upb-generated/udpa/annotations/sensitive.upb.h +0 -1
  250. data/src/core/ext/upb-generated/udpa/annotations/status.upb.c +28 -0
  251. data/src/core/ext/upb-generated/udpa/annotations/status.upb.h +64 -0
  252. data/src/core/ext/upb-generated/udpa/data/orca/v1/orca_load_report.upb.c +6 -6
  253. data/src/core/ext/upb-generated/udpa/data/orca/v1/orca_load_report.upb.h +41 -68
  254. data/src/core/ext/upb-generated/validate/validate.upb.c +21 -20
  255. data/src/core/ext/upb-generated/validate/validate.upb.h +569 -562
  256. data/src/core/lib/channel/channel_args.cc +15 -14
  257. data/src/core/lib/channel/channel_args.h +3 -1
  258. data/src/core/lib/channel/channel_stack.h +20 -13
  259. data/src/core/lib/channel/channel_trace.cc +2 -6
  260. data/src/core/lib/channel/channelz.cc +10 -21
  261. data/src/core/lib/channel/channelz.h +3 -2
  262. data/src/core/lib/channel/channelz_registry.cc +5 -3
  263. data/src/core/lib/channel/connected_channel.cc +7 -5
  264. data/src/core/lib/channel/context.h +1 -1
  265. data/src/core/lib/channel/handshaker.cc +11 -13
  266. data/src/core/lib/channel/handshaker.h +4 -2
  267. data/src/core/lib/channel/handshaker_registry.cc +5 -17
  268. data/src/core/lib/channel/status_util.cc +2 -3
  269. data/src/core/lib/compression/message_compress.cc +5 -1
  270. data/src/core/lib/debug/stats.cc +21 -27
  271. data/src/core/lib/debug/stats.h +3 -1
  272. data/src/core/lib/gpr/log_linux.cc +6 -8
  273. data/src/core/lib/gpr/log_posix.cc +6 -8
  274. data/src/core/lib/gpr/spinlock.h +2 -3
  275. data/src/core/lib/gpr/string.cc +10 -33
  276. data/src/core/lib/gpr/string.h +4 -18
  277. data/src/core/lib/gpr/sync_abseil.cc +2 -0
  278. data/src/core/lib/gpr/time.cc +4 -0
  279. data/src/core/lib/gpr/time_posix.cc +1 -1
  280. data/src/core/lib/gprpp/atomic.h +6 -6
  281. data/src/core/lib/gprpp/fork.cc +1 -1
  282. data/src/core/lib/gprpp/global_config_env.cc +8 -6
  283. data/src/core/lib/gprpp/host_port.cc +29 -35
  284. data/src/core/lib/gprpp/host_port.h +14 -17
  285. data/src/core/lib/gprpp/map.h +5 -11
  286. data/src/core/lib/gprpp/ref_counted_ptr.h +5 -0
  287. data/src/core/lib/gprpp/sync.h +9 -0
  288. data/src/core/lib/http/format_request.cc +46 -65
  289. data/src/core/lib/http/httpcli.cc +15 -13
  290. data/src/core/lib/http/httpcli.h +2 -3
  291. data/src/core/lib/http/httpcli_security_connector.cc +10 -10
  292. data/src/core/lib/http/parser.h +2 -3
  293. data/src/core/lib/iomgr/buffer_list.h +22 -21
  294. data/src/core/lib/iomgr/call_combiner.h +3 -2
  295. data/src/core/lib/iomgr/cfstream_handle.cc +4 -2
  296. data/src/core/lib/iomgr/closure.h +2 -3
  297. data/src/core/lib/iomgr/dualstack_socket_posix.cc +47 -0
  298. data/src/core/lib/iomgr/endpoint_cfstream.cc +2 -3
  299. data/src/core/lib/iomgr/endpoint_pair.h +2 -3
  300. data/src/core/lib/iomgr/endpoint_pair_posix.cc +10 -10
  301. data/src/core/lib/iomgr/error.cc +6 -9
  302. data/src/core/lib/iomgr/error.h +0 -1
  303. data/src/core/lib/iomgr/error_cfstream.cc +9 -8
  304. data/src/core/lib/iomgr/ev_apple.cc +356 -0
  305. data/src/core/lib/iomgr/ev_apple.h +43 -0
  306. data/src/core/lib/iomgr/ev_epoll1_linux.cc +25 -29
  307. data/src/core/lib/iomgr/ev_epollex_linux.cc +17 -24
  308. data/src/core/lib/iomgr/ev_poll_posix.cc +9 -8
  309. data/src/core/lib/iomgr/ev_posix.cc +4 -3
  310. data/src/core/lib/iomgr/exec_ctx.h +14 -2
  311. data/src/core/lib/iomgr/iomgr.cc +10 -0
  312. data/src/core/lib/iomgr/iomgr.h +10 -0
  313. data/src/core/lib/iomgr/iomgr_posix_cfstream.cc +84 -20
  314. data/src/core/lib/iomgr/is_epollexclusive_available.cc +14 -0
  315. data/src/core/lib/iomgr/pollset_set_custom.cc +10 -10
  316. data/src/core/lib/{gprpp/optional.h → iomgr/pollset_uv.h} +11 -12
  317. data/src/core/lib/iomgr/port.h +2 -21
  318. data/src/core/lib/iomgr/python_util.h +46 -0
  319. data/src/core/lib/iomgr/resolve_address.h +4 -6
  320. data/src/core/lib/iomgr/resolve_address_custom.cc +42 -57
  321. data/src/core/lib/iomgr/resolve_address_custom.h +4 -2
  322. data/src/core/lib/iomgr/resolve_address_posix.cc +10 -11
  323. data/src/core/lib/iomgr/resolve_address_windows.cc +16 -25
  324. data/src/core/lib/iomgr/resource_quota.cc +38 -37
  325. data/src/core/lib/iomgr/sockaddr_utils.cc +29 -33
  326. data/src/core/lib/iomgr/sockaddr_utils.h +10 -15
  327. data/src/core/lib/iomgr/socket_factory_posix.h +2 -3
  328. data/src/core/lib/iomgr/socket_mutator.h +2 -3
  329. data/src/core/lib/iomgr/socket_utils_common_posix.cc +102 -81
  330. data/src/core/lib/iomgr/socket_utils_posix.h +3 -0
  331. data/src/core/lib/iomgr/socket_windows.cc +4 -5
  332. data/src/core/lib/iomgr/tcp_client_cfstream.cc +14 -18
  333. data/src/core/lib/iomgr/tcp_client_custom.cc +6 -9
  334. data/src/core/lib/iomgr/tcp_client_posix.cc +30 -36
  335. data/src/core/lib/iomgr/tcp_client_windows.cc +10 -11
  336. data/src/core/lib/iomgr/tcp_custom.cc +3 -4
  337. data/src/core/lib/iomgr/tcp_custom.h +1 -1
  338. data/src/core/lib/iomgr/tcp_server.cc +3 -4
  339. data/src/core/lib/iomgr/tcp_server.h +7 -5
  340. data/src/core/lib/iomgr/tcp_server_custom.cc +11 -23
  341. data/src/core/lib/iomgr/tcp_server_posix.cc +38 -44
  342. data/src/core/lib/iomgr/tcp_server_utils_posix.h +3 -4
  343. data/src/core/lib/iomgr/tcp_server_utils_posix_common.cc +7 -8
  344. data/src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc +10 -18
  345. data/src/core/lib/iomgr/tcp_server_windows.cc +16 -16
  346. data/src/core/lib/iomgr/tcp_uv.cc +3 -2
  347. data/src/core/lib/iomgr/time_averaged_stats.h +2 -3
  348. data/src/core/lib/iomgr/timer_generic.cc +15 -15
  349. data/src/core/lib/{gprpp/inlined_vector.h → iomgr/timer_generic.h} +19 -17
  350. data/src/core/lib/iomgr/timer_heap.h +2 -3
  351. data/src/core/lib/iomgr/udp_server.cc +32 -36
  352. data/src/core/lib/iomgr/udp_server.h +5 -2
  353. data/src/core/lib/iomgr/unix_sockets_posix.cc +9 -14
  354. data/src/core/lib/iomgr/unix_sockets_posix.h +3 -1
  355. data/src/core/lib/iomgr/unix_sockets_posix_noop.cc +5 -2
  356. data/src/core/lib/json/json.h +3 -2
  357. data/src/core/lib/json/json_reader.cc +25 -26
  358. data/src/core/lib/json/json_writer.cc +13 -12
  359. data/src/core/lib/security/credentials/composite/composite_credentials.cc +12 -0
  360. data/src/core/lib/security/credentials/composite/composite_credentials.h +6 -3
  361. data/src/core/lib/security/credentials/credentials.cc +0 -84
  362. data/src/core/lib/security/credentials/credentials.h +13 -62
  363. data/src/core/lib/security/credentials/fake/fake_credentials.h +4 -0
  364. data/src/core/lib/security/credentials/google_default/credentials_generic.cc +8 -6
  365. data/src/core/lib/security/credentials/google_default/google_default_credentials.cc +15 -17
  366. data/src/core/lib/security/credentials/iam/iam_credentials.cc +8 -6
  367. data/src/core/lib/security/credentials/iam/iam_credentials.h +4 -0
  368. data/src/core/lib/security/credentials/jwt/json_token.cc +1 -1
  369. data/src/core/lib/security/credentials/jwt/json_token.h +2 -5
  370. data/src/core/lib/security/credentials/jwt/jwt_credentials.cc +7 -4
  371. data/src/core/lib/security/credentials/jwt/jwt_credentials.h +12 -0
  372. data/src/core/lib/security/credentials/jwt/jwt_verifier.cc +8 -15
  373. data/src/core/lib/security/credentials/jwt/jwt_verifier.h +2 -3
  374. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc +73 -54
  375. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.h +9 -3
  376. data/src/core/lib/security/credentials/plugin/plugin_credentials.cc +19 -6
  377. data/src/core/lib/security/credentials/plugin/plugin_credentials.h +2 -0
  378. data/src/core/lib/security/credentials/ssl/ssl_credentials.cc +20 -0
  379. data/src/core/lib/security/credentials/ssl/ssl_credentials.h +10 -0
  380. data/src/core/lib/security/credentials/tls/grpc_tls_credentials_options.cc +23 -13
  381. data/src/core/lib/security/credentials/tls/grpc_tls_credentials_options.h +48 -11
  382. data/src/core/lib/security/security_connector/alts/alts_security_connector.cc +21 -6
  383. data/src/core/lib/security/security_connector/fake/fake_security_connector.cc +17 -17
  384. data/src/core/lib/security/security_connector/load_system_roots_linux.cc +3 -2
  385. data/src/core/lib/security/security_connector/local/local_security_connector.cc +1 -1
  386. data/src/core/lib/security/security_connector/security_connector.cc +2 -0
  387. data/src/core/lib/security/security_connector/security_connector.h +2 -2
  388. data/src/core/lib/security/security_connector/ssl/ssl_security_connector.cc +38 -36
  389. data/src/core/lib/security/security_connector/ssl/ssl_security_connector.h +8 -5
  390. data/src/core/lib/security/security_connector/ssl_utils.cc +89 -21
  391. data/src/core/lib/security/security_connector/ssl_utils.h +18 -12
  392. data/src/core/lib/security/security_connector/tls/tls_security_connector.cc +101 -72
  393. data/src/core/lib/security/security_connector/tls/tls_security_connector.h +27 -5
  394. data/src/core/lib/security/transport/auth_filters.h +0 -5
  395. data/src/core/lib/security/transport/client_auth_filter.cc +11 -11
  396. data/src/core/lib/security/util/json_util.cc +12 -13
  397. data/src/core/lib/slice/slice.cc +38 -1
  398. data/src/core/lib/slice/slice_intern.cc +2 -3
  399. data/src/core/lib/slice/slice_internal.h +15 -0
  400. data/src/core/lib/slice/slice_utils.h +9 -0
  401. data/src/core/lib/surface/byte_buffer_reader.cc +2 -47
  402. data/src/core/lib/surface/call.cc +42 -44
  403. data/src/core/lib/surface/call_log_batch.cc +50 -58
  404. data/src/core/lib/surface/channel.cc +53 -31
  405. data/src/core/lib/surface/channel.h +35 -4
  406. data/src/core/lib/surface/channel_ping.cc +2 -3
  407. data/src/core/lib/surface/completion_queue.cc +304 -47
  408. data/src/core/lib/surface/completion_queue.h +8 -0
  409. data/src/core/lib/surface/event_string.cc +18 -25
  410. data/src/core/lib/surface/event_string.h +3 -1
  411. data/src/core/lib/surface/init.cc +2 -0
  412. data/src/core/lib/surface/init_secure.cc +1 -4
  413. data/src/core/lib/surface/server.cc +971 -837
  414. data/src/core/lib/surface/server.h +66 -12
  415. data/src/core/lib/surface/version.cc +2 -2
  416. data/src/core/lib/transport/byte_stream.h +7 -2
  417. data/src/core/lib/transport/connectivity_state.cc +7 -6
  418. data/src/core/lib/transport/connectivity_state.h +5 -3
  419. data/src/core/lib/transport/metadata.cc +3 -3
  420. data/src/core/lib/transport/metadata_batch.h +2 -3
  421. data/src/core/lib/transport/static_metadata.h +1 -1
  422. data/src/core/lib/transport/status_conversion.cc +6 -14
  423. data/src/core/lib/transport/transport.cc +2 -3
  424. data/src/core/lib/transport/transport.h +9 -2
  425. data/src/core/lib/transport/transport_op_string.cc +61 -102
  426. data/src/core/lib/uri/uri_parser.cc +8 -15
  427. data/src/core/lib/uri/uri_parser.h +2 -3
  428. data/src/core/plugin_registry/grpc_plugin_registry.cc +24 -4
  429. data/src/core/tsi/alts/crypt/aes_gcm.cc +0 -2
  430. data/src/core/tsi/alts/handshaker/alts_handshaker_client.cc +31 -14
  431. data/src/core/tsi/alts/handshaker/alts_handshaker_client.h +8 -4
  432. data/src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc +34 -2
  433. data/src/core/tsi/alts/handshaker/alts_tsi_handshaker.h +9 -1
  434. data/src/core/tsi/alts/handshaker/transport_security_common_api.cc +2 -0
  435. data/src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol_common.h +2 -3
  436. data/src/core/tsi/fake_transport_security.cc +10 -15
  437. data/src/core/tsi/ssl/session_cache/ssl_session.h +0 -2
  438. data/src/core/tsi/ssl/session_cache/ssl_session_cache.h +0 -2
  439. data/src/core/tsi/ssl_transport_security.cc +154 -50
  440. data/src/core/tsi/ssl_transport_security.h +22 -10
  441. data/src/core/tsi/ssl_types.h +0 -2
  442. data/src/core/tsi/transport_security.h +6 -9
  443. data/src/core/tsi/transport_security_grpc.h +2 -3
  444. data/src/core/tsi/transport_security_interface.h +8 -3
  445. data/src/ruby/ext/grpc/extconf.rb +5 -2
  446. data/src/ruby/ext/grpc/rb_call.c +12 -3
  447. data/src/ruby/ext/grpc/rb_call.h +4 -0
  448. data/src/ruby/ext/grpc/rb_call_credentials.c +57 -12
  449. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +4 -0
  450. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +6 -0
  451. data/src/ruby/lib/grpc/errors.rb +103 -42
  452. data/src/ruby/lib/grpc/generic/active_call.rb +2 -3
  453. data/src/ruby/lib/grpc/generic/interceptors.rb +5 -5
  454. data/src/ruby/lib/grpc/generic/rpc_server.rb +9 -10
  455. data/src/ruby/lib/grpc/generic/service.rb +5 -4
  456. data/src/ruby/lib/grpc/structs.rb +1 -1
  457. data/src/ruby/lib/grpc/version.rb +1 -1
  458. data/src/ruby/pb/generate_proto_ruby.sh +5 -3
  459. data/src/ruby/pb/src/proto/grpc/testing/messages_pb.rb +11 -0
  460. data/src/ruby/pb/src/proto/grpc/testing/test_services_pb.rb +16 -0
  461. data/src/ruby/spec/debug_message_spec.rb +134 -0
  462. data/src/ruby/spec/generic/service_spec.rb +2 -0
  463. data/src/ruby/spec/pb/codegen/grpc/testing/package_options_import2.proto +23 -0
  464. data/src/ruby/spec/pb/codegen/grpc/testing/package_options_ruby_style.proto +7 -0
  465. data/src/ruby/spec/pb/codegen/package_option_spec.rb +7 -1
  466. data/src/ruby/spec/support/services.rb +10 -4
  467. data/src/ruby/spec/testdata/ca.pem +18 -13
  468. data/src/ruby/spec/testdata/client.key +26 -14
  469. data/src/ruby/spec/testdata/client.pem +18 -12
  470. data/src/ruby/spec/testdata/server1.key +26 -14
  471. data/src/ruby/spec/testdata/server1.pem +20 -14
  472. data/third_party/abseil-cpp/absl/time/civil_time.cc +175 -0
  473. data/third_party/abseil-cpp/absl/time/civil_time.h +538 -0
  474. data/third_party/abseil-cpp/absl/time/clock.cc +569 -0
  475. data/third_party/abseil-cpp/absl/time/clock.h +74 -0
  476. data/third_party/abseil-cpp/absl/time/duration.cc +922 -0
  477. data/third_party/abseil-cpp/absl/time/format.cc +153 -0
  478. data/third_party/abseil-cpp/absl/time/internal/cctz/include/cctz/civil_time.h +332 -0
  479. data/third_party/abseil-cpp/absl/time/internal/cctz/include/cctz/civil_time_detail.h +622 -0
  480. data/third_party/abseil-cpp/absl/time/internal/cctz/include/cctz/time_zone.h +384 -0
  481. data/third_party/abseil-cpp/absl/time/internal/cctz/include/cctz/zone_info_source.h +102 -0
  482. data/third_party/abseil-cpp/absl/time/internal/cctz/src/civil_time_detail.cc +94 -0
  483. data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_fixed.cc +140 -0
  484. data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_fixed.h +52 -0
  485. data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_format.cc +922 -0
  486. data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_if.cc +45 -0
  487. data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_if.h +76 -0
  488. data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_impl.cc +121 -0
  489. data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_impl.h +93 -0
  490. data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_info.cc +958 -0
  491. data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_info.h +138 -0
  492. data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_libc.cc +308 -0
  493. data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_libc.h +55 -0
  494. data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_lookup.cc +187 -0
  495. data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_posix.cc +159 -0
  496. data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_posix.h +132 -0
  497. data/third_party/abseil-cpp/absl/time/internal/cctz/src/tzfile.h +122 -0
  498. data/third_party/abseil-cpp/absl/time/internal/cctz/src/zone_info_source.cc +115 -0
  499. data/third_party/abseil-cpp/absl/time/internal/get_current_time_chrono.inc +31 -0
  500. data/third_party/abseil-cpp/absl/time/internal/get_current_time_posix.inc +24 -0
  501. data/third_party/abseil-cpp/absl/time/time.cc +499 -0
  502. data/third_party/abseil-cpp/absl/time/time.h +1584 -0
  503. data/third_party/boringssl-with-bazel/err_data.c +335 -297
  504. data/third_party/boringssl-with-bazel/src/crypto/asn1/a_bitstr.c +3 -3
  505. data/third_party/boringssl-with-bazel/src/crypto/asn1/a_enum.c +3 -3
  506. data/third_party/boringssl-with-bazel/src/crypto/asn1/a_int.c +1 -1
  507. data/third_party/boringssl-with-bazel/src/crypto/asn1/a_object.c +3 -3
  508. data/third_party/boringssl-with-bazel/src/crypto/asn1/a_time.c +2 -2
  509. data/third_party/boringssl-with-bazel/src/crypto/asn1/a_type.c +1 -1
  510. data/third_party/boringssl-with-bazel/src/crypto/asn1/asn1_lib.c +1 -1
  511. data/third_party/boringssl-with-bazel/src/crypto/asn1/asn_pack.c +1 -1
  512. data/third_party/boringssl-with-bazel/src/crypto/asn1/f_enum.c +1 -1
  513. data/third_party/boringssl-with-bazel/src/crypto/asn1/f_int.c +1 -1
  514. data/third_party/boringssl-with-bazel/src/crypto/asn1/f_string.c +1 -1
  515. data/third_party/boringssl-with-bazel/src/crypto/cipher_extra/derive_key.c +1 -1
  516. data/third_party/boringssl-with-bazel/src/crypto/cipher_extra/tls_cbc.c +1 -0
  517. data/third_party/boringssl-with-bazel/src/crypto/cpu-arm-linux.c +7 -5
  518. data/third_party/boringssl-with-bazel/src/crypto/cpu-intel.c +13 -4
  519. data/third_party/boringssl-with-bazel/src/crypto/crypto.c +11 -0
  520. data/third_party/boringssl-with-bazel/src/{third_party/fiat → crypto/curve25519}/curve25519.c +18 -26
  521. data/third_party/boringssl-with-bazel/src/{third_party/fiat → crypto/curve25519}/curve25519_tables.h +13 -21
  522. data/third_party/boringssl-with-bazel/src/{third_party/fiat → crypto/curve25519}/internal.h +14 -22
  523. data/third_party/boringssl-with-bazel/src/crypto/curve25519/spake25519.c +1 -1
  524. data/third_party/boringssl-with-bazel/src/crypto/dh/dh.c +15 -0
  525. data/third_party/boringssl-with-bazel/src/crypto/dsa/dsa.c +10 -0
  526. data/third_party/boringssl-with-bazel/src/crypto/ec_extra/hash_to_curve.c +385 -0
  527. data/third_party/boringssl-with-bazel/src/crypto/ec_extra/internal.h +56 -0
  528. data/third_party/boringssl-with-bazel/src/crypto/ecdh_extra/ecdh_extra.c +2 -2
  529. data/third_party/boringssl-with-bazel/src/crypto/err/err.c +33 -32
  530. data/third_party/boringssl-with-bazel/src/crypto/evp/evp_asn1.c +143 -0
  531. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/aes/aes_nohw.c +1 -1
  532. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/aes/mode_wrappers.c +17 -1
  533. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/bcm.c +2 -1
  534. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/bn/exponentiation.c +3 -3
  535. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/bn/internal.h +25 -12
  536. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/bn/montgomery.c +8 -8
  537. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/bn/mul.c +30 -154
  538. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/digest/digests.c +16 -0
  539. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/ec.c +289 -117
  540. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/ec_key.c +13 -27
  541. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/ec_montgomery.c +96 -55
  542. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/felem.c +25 -7
  543. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/internal.h +434 -161
  544. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/oct.c +63 -71
  545. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/p224-64.c +18 -25
  546. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/p256-x86_64-table.h +9481 -9485
  547. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/p256-x86_64.c +104 -122
  548. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/p256.c +740 -0
  549. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/p256_table.h +297 -0
  550. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/scalar.c +90 -11
  551. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/simple.c +125 -148
  552. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/simple_mul.c +189 -3
  553. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/util.c +3 -3
  554. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/wnaf.c +61 -18
  555. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ecdh/ecdh.c +2 -2
  556. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ecdsa/ecdsa.c +20 -5
  557. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rand/fork_detect.c +137 -0
  558. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rand/fork_detect.h +49 -0
  559. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rand/getrandom_fillin.h +64 -0
  560. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rand/internal.h +41 -5
  561. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rand/rand.c +32 -17
  562. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rand/urandom.c +24 -114
  563. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rsa/blinding.c +4 -0
  564. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rsa/internal.h +1 -0
  565. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rsa/rsa.c +51 -38
  566. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rsa/rsa_impl.c +15 -1
  567. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/self_check/self_check.c +62 -0
  568. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/sha/sha512.c +44 -35
  569. data/third_party/boringssl-with-bazel/src/crypto/mem.c +47 -16
  570. data/third_party/boringssl-with-bazel/src/crypto/obj/obj_dat.h +15 -1
  571. data/third_party/boringssl-with-bazel/src/crypto/pkcs8/internal.h +7 -0
  572. data/third_party/boringssl-with-bazel/src/crypto/pkcs8/pkcs8_x509.c +36 -5
  573. data/third_party/boringssl-with-bazel/src/crypto/rand_extra/deterministic.c +6 -10
  574. data/third_party/boringssl-with-bazel/src/crypto/rand_extra/windows.c +16 -0
  575. data/third_party/boringssl-with-bazel/src/crypto/thread_pthread.c +4 -0
  576. data/third_party/boringssl-with-bazel/src/crypto/thread_win.c +4 -0
  577. data/third_party/boringssl-with-bazel/src/crypto/trust_token/internal.h +249 -0
  578. data/third_party/boringssl-with-bazel/src/crypto/trust_token/pmbtoken.c +1227 -0
  579. data/third_party/boringssl-with-bazel/src/crypto/trust_token/trust_token.c +682 -0
  580. data/third_party/boringssl-with-bazel/src/crypto/x509/a_strex.c +4 -4
  581. data/third_party/boringssl-with-bazel/src/crypto/x509/algorithm.c +8 -0
  582. data/third_party/boringssl-with-bazel/src/crypto/x509/asn1_gen.c +4 -4
  583. data/third_party/boringssl-with-bazel/src/crypto/x509/x509.c +0 -67
  584. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_cmp.c +13 -6
  585. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_req.c +10 -0
  586. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_set.c +57 -0
  587. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_trs.c +4 -1
  588. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_vfy.c +33 -9
  589. data/third_party/boringssl-with-bazel/src/crypto/x509/x509cset.c +25 -0
  590. data/third_party/boringssl-with-bazel/src/crypto/x509/x509name.c +4 -3
  591. data/third_party/boringssl-with-bazel/src/crypto/x509/x_crl.c +35 -13
  592. data/third_party/boringssl-with-bazel/src/crypto/x509/x_pubkey.c +0 -154
  593. data/third_party/boringssl-with-bazel/src/crypto/x509/x_x509.c +28 -6
  594. data/third_party/boringssl-with-bazel/src/crypto/x509v3/internal.h +5 -0
  595. data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_purp.c +74 -35
  596. data/third_party/boringssl-with-bazel/src/include/openssl/aes.h +16 -4
  597. data/third_party/boringssl-with-bazel/src/include/openssl/asn1.h +22 -22
  598. data/third_party/boringssl-with-bazel/src/include/openssl/base.h +6 -2
  599. data/third_party/boringssl-with-bazel/src/include/openssl/crypto.h +9 -4
  600. data/third_party/boringssl-with-bazel/src/include/openssl/dh.h +20 -0
  601. data/third_party/boringssl-with-bazel/src/include/openssl/digest.h +1 -0
  602. data/third_party/boringssl-with-bazel/src/include/openssl/dsa.h +16 -0
  603. data/third_party/boringssl-with-bazel/src/include/openssl/ecdsa.h +6 -0
  604. data/third_party/boringssl-with-bazel/src/include/openssl/err.h +2 -0
  605. data/third_party/boringssl-with-bazel/src/include/openssl/evp.h +69 -0
  606. data/third_party/boringssl-with-bazel/src/include/openssl/nid.h +5 -0
  607. data/third_party/boringssl-with-bazel/src/include/openssl/rand.h +3 -17
  608. data/third_party/boringssl-with-bazel/src/include/openssl/rsa.h +31 -0
  609. data/third_party/boringssl-with-bazel/src/include/openssl/sha.h +26 -0
  610. data/third_party/boringssl-with-bazel/src/include/openssl/ssl.h +191 -79
  611. data/third_party/boringssl-with-bazel/src/include/openssl/tls1.h +1 -0
  612. data/third_party/boringssl-with-bazel/src/include/openssl/trust_token.h +282 -0
  613. data/third_party/boringssl-with-bazel/src/include/openssl/x509.h +791 -715
  614. data/third_party/boringssl-with-bazel/src/include/openssl/x509_vfy.h +1 -0
  615. data/third_party/boringssl-with-bazel/src/ssl/d1_both.cc +0 -4
  616. data/third_party/boringssl-with-bazel/src/ssl/d1_lib.cc +3 -3
  617. data/third_party/boringssl-with-bazel/src/ssl/dtls_method.cc +13 -4
  618. data/third_party/boringssl-with-bazel/src/ssl/handoff.cc +146 -57
  619. data/third_party/boringssl-with-bazel/src/ssl/handshake.cc +23 -5
  620. data/third_party/boringssl-with-bazel/src/ssl/handshake_client.cc +30 -22
  621. data/third_party/boringssl-with-bazel/src/ssl/handshake_server.cc +21 -4
  622. data/third_party/boringssl-with-bazel/src/ssl/internal.h +74 -54
  623. data/third_party/boringssl-with-bazel/src/ssl/s3_both.cc +10 -10
  624. data/third_party/boringssl-with-bazel/src/ssl/s3_lib.cc +2 -2
  625. data/third_party/boringssl-with-bazel/src/ssl/s3_pkt.cc +21 -21
  626. data/third_party/boringssl-with-bazel/src/ssl/ssl_asn1.cc +29 -0
  627. data/third_party/boringssl-with-bazel/src/ssl/ssl_cert.cc +4 -0
  628. data/third_party/boringssl-with-bazel/src/ssl/ssl_lib.cc +34 -1
  629. data/third_party/boringssl-with-bazel/src/ssl/ssl_privkey.cc +13 -2
  630. data/third_party/boringssl-with-bazel/src/ssl/ssl_session.cc +44 -5
  631. data/third_party/boringssl-with-bazel/src/ssl/ssl_stat.cc +6 -0
  632. data/third_party/boringssl-with-bazel/src/ssl/ssl_versions.cc +5 -5
  633. data/third_party/boringssl-with-bazel/src/ssl/t1_enc.cc +51 -26
  634. data/third_party/boringssl-with-bazel/src/ssl/t1_lib.cc +47 -53
  635. data/third_party/boringssl-with-bazel/src/ssl/tls13_both.cc +1 -1
  636. data/third_party/boringssl-with-bazel/src/ssl/tls13_client.cc +129 -48
  637. data/third_party/boringssl-with-bazel/src/ssl/tls13_enc.cc +23 -75
  638. data/third_party/boringssl-with-bazel/src/ssl/tls13_server.cc +55 -22
  639. data/third_party/boringssl-with-bazel/src/ssl/tls_method.cc +63 -25
  640. data/third_party/boringssl-with-bazel/src/third_party/fiat/curve25519_32.h +245 -175
  641. data/third_party/boringssl-with-bazel/src/third_party/fiat/curve25519_64.h +135 -75
  642. data/third_party/boringssl-with-bazel/src/third_party/fiat/p256_32.h +1593 -1672
  643. data/third_party/boringssl-with-bazel/src/third_party/fiat/p256_64.h +512 -503
  644. data/third_party/upb/upb/decode.c +467 -504
  645. data/third_party/upb/upb/encode.c +163 -121
  646. data/third_party/upb/upb/msg.c +130 -64
  647. data/third_party/upb/upb/msg.h +418 -14
  648. data/third_party/upb/upb/port_def.inc +35 -6
  649. data/third_party/upb/upb/port_undef.inc +8 -1
  650. data/third_party/upb/upb/table.c +53 -75
  651. data/third_party/upb/upb/table.int.h +11 -43
  652. data/third_party/upb/upb/upb.c +148 -124
  653. data/third_party/upb/upb/upb.h +65 -147
  654. data/third_party/upb/upb/upb.hpp +86 -0
  655. metadata +122 -41
  656. data/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc +0 -1908
  657. data/src/core/lib/gprpp/string_view.h +0 -60
  658. data/src/core/tsi/grpc_shadow_boringssl.h +0 -3311
  659. data/third_party/boringssl-with-bazel/src/third_party/fiat/p256.c +0 -1063
  660. data/third_party/upb/upb/generated_util.h +0 -105
@@ -1,1908 +0,0 @@
1
- /*
2
- *
3
- * Copyright 2018 gRPC authors.
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- * http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- *
17
- */
18
-
19
- #include <grpc/support/port_platform.h>
20
-
21
- #include "src/core/lib/iomgr/sockaddr.h"
22
- #include "src/core/lib/iomgr/socket_utils.h"
23
-
24
- #include <inttypes.h>
25
- #include <limits.h>
26
- #include <string.h>
27
-
28
- #include <grpc/grpc.h>
29
- #include <grpc/support/alloc.h>
30
- #include <grpc/support/string_util.h>
31
- #include <grpc/support/time.h>
32
-
33
- #include "src/core/ext/filters/client_channel/client_channel.h"
34
- #include "src/core/ext/filters/client_channel/lb_policy.h"
35
- #include "src/core/ext/filters/client_channel/lb_policy/xds/xds.h"
36
- #include "src/core/ext/filters/client_channel/lb_policy_factory.h"
37
- #include "src/core/ext/filters/client_channel/lb_policy_registry.h"
38
- #include "src/core/ext/filters/client_channel/parse_address.h"
39
- #include "src/core/ext/filters/client_channel/server_address.h"
40
- #include "src/core/ext/filters/client_channel/service_config.h"
41
- #include "src/core/ext/filters/client_channel/xds/xds_client.h"
42
- #include "src/core/ext/filters/client_channel/xds/xds_client_stats.h"
43
- #include "src/core/lib/backoff/backoff.h"
44
- #include "src/core/lib/channel/channel_args.h"
45
- #include "src/core/lib/channel/channel_stack.h"
46
- #include "src/core/lib/gpr/string.h"
47
- #include "src/core/lib/gprpp/manual_constructor.h"
48
- #include "src/core/lib/gprpp/map.h"
49
- #include "src/core/lib/gprpp/memory.h"
50
- #include "src/core/lib/gprpp/orphanable.h"
51
- #include "src/core/lib/gprpp/ref_counted_ptr.h"
52
- #include "src/core/lib/gprpp/sync.h"
53
- #include "src/core/lib/iomgr/combiner.h"
54
- #include "src/core/lib/iomgr/sockaddr.h"
55
- #include "src/core/lib/iomgr/sockaddr_utils.h"
56
- #include "src/core/lib/iomgr/timer.h"
57
- #include "src/core/lib/slice/slice_hash_table.h"
58
- #include "src/core/lib/slice/slice_internal.h"
59
- #include "src/core/lib/slice/slice_string_helpers.h"
60
- #include "src/core/lib/surface/call.h"
61
- #include "src/core/lib/surface/channel.h"
62
- #include "src/core/lib/surface/channel_init.h"
63
- #include "src/core/lib/transport/static_metadata.h"
64
-
65
- #define GRPC_XDS_DEFAULT_FALLBACK_TIMEOUT_MS 10000
66
- #define GRPC_XDS_DEFAULT_LOCALITY_RETENTION_INTERVAL_MS (15 * 60 * 1000)
67
- #define GRPC_XDS_DEFAULT_FAILOVER_TIMEOUT_MS 10000
68
-
69
- namespace grpc_core {
70
-
71
- TraceFlag grpc_lb_xds_trace(false, "xds");
72
-
73
- namespace {
74
-
75
- constexpr char kXds[] = "xds_experimental";
76
-
77
- class XdsConfig : public LoadBalancingPolicy::Config {
78
- public:
79
- XdsConfig(RefCountedPtr<LoadBalancingPolicy::Config> child_policy,
80
- RefCountedPtr<LoadBalancingPolicy::Config> fallback_policy,
81
- std::string eds_service_name,
82
- Optional<std::string> lrs_load_reporting_server_name)
83
- : child_policy_(std::move(child_policy)),
84
- fallback_policy_(std::move(fallback_policy)),
85
- eds_service_name_(std::move(eds_service_name)),
86
- lrs_load_reporting_server_name_(
87
- std::move(lrs_load_reporting_server_name)) {}
88
-
89
- const char* name() const override { return kXds; }
90
-
91
- RefCountedPtr<LoadBalancingPolicy::Config> child_policy() const {
92
- return child_policy_;
93
- }
94
-
95
- RefCountedPtr<LoadBalancingPolicy::Config> fallback_policy() const {
96
- return fallback_policy_;
97
- }
98
-
99
- const char* eds_service_name() const {
100
- return eds_service_name_.empty() ? nullptr : eds_service_name_.c_str();
101
- };
102
-
103
- const Optional<std::string>& lrs_load_reporting_server_name() const {
104
- return lrs_load_reporting_server_name_;
105
- };
106
-
107
- private:
108
- RefCountedPtr<LoadBalancingPolicy::Config> child_policy_;
109
- RefCountedPtr<LoadBalancingPolicy::Config> fallback_policy_;
110
- std::string eds_service_name_;
111
- Optional<std::string> lrs_load_reporting_server_name_;
112
- };
113
-
114
- class XdsLb : public LoadBalancingPolicy {
115
- public:
116
- explicit XdsLb(Args args);
117
-
118
- const char* name() const override { return kXds; }
119
-
120
- void UpdateLocked(UpdateArgs args) override;
121
- void ResetBackoffLocked() override;
122
-
123
- private:
124
- class EndpointWatcher;
125
-
126
- // A simple wrapper to convert the picker returned from a locality's child
127
- // policy as a unique_ptr<> to a RefCountedPtr<>. This allows it to be
128
- // referenced by both the picker and the locality.
129
- class RefCountedEndpointPicker : public RefCounted<RefCountedEndpointPicker> {
130
- public:
131
- explicit RefCountedEndpointPicker(std::unique_ptr<SubchannelPicker> picker)
132
- : picker_(std::move(picker)) {}
133
- PickResult Pick(PickArgs args) { return picker_->Pick(std::move(args)); }
134
-
135
- private:
136
- std::unique_ptr<SubchannelPicker> picker_;
137
- };
138
-
139
- // A picker that wraps the RefCountedEndpointPicker and performs load
140
- // reporting for the locality.
141
- class LoadReportingPicker : public RefCounted<LoadReportingPicker> {
142
- public:
143
- LoadReportingPicker(RefCountedPtr<RefCountedEndpointPicker> picker,
144
- RefCountedPtr<XdsClusterLocalityStats> locality_stats)
145
- : picker_(std::move(picker)),
146
- locality_stats_(std::move(locality_stats)) {}
147
-
148
- PickResult Pick(PickArgs args);
149
-
150
- RefCountedEndpointPicker* picker() const { return picker_.get(); }
151
- XdsClusterLocalityStats* locality_stats() const {
152
- return locality_stats_.get();
153
- }
154
-
155
- private:
156
- RefCountedPtr<RefCountedEndpointPicker> picker_;
157
- RefCountedPtr<XdsClusterLocalityStats> locality_stats_;
158
- };
159
-
160
- // A picker that uses a stateless weighting algorithm to pick the locality
161
- // to use for each request.
162
- class LocalityPicker : public SubchannelPicker {
163
- public:
164
- // Maintains a weighted list of pickers from each locality that is in ready
165
- // state. The first element in the pair represents the end of a range
166
- // proportional to the locality's weight. The start of the range is the
167
- // previous value in the vector and is 0 for the first element.
168
- using PickerList =
169
- InlinedVector<std::pair<uint32_t, RefCountedPtr<LoadReportingPicker>>,
170
- 1>;
171
- LocalityPicker(XdsLb* xds_policy, PickerList pickers)
172
- : drop_stats_(xds_policy->drop_stats_),
173
- drop_config_(xds_policy->drop_config_),
174
- pickers_(std::move(pickers)) {}
175
-
176
- PickResult Pick(PickArgs args) override;
177
-
178
- private:
179
- // Calls the picker of the locality that the key falls within.
180
- PickResult PickFromLocality(const uint32_t key, PickArgs args);
181
-
182
- RefCountedPtr<XdsClusterDropStats> drop_stats_;
183
- RefCountedPtr<XdsApi::DropConfig> drop_config_;
184
- PickerList pickers_;
185
- };
186
-
187
- class FallbackHelper : public ChannelControlHelper {
188
- public:
189
- explicit FallbackHelper(RefCountedPtr<XdsLb> parent)
190
- : parent_(std::move(parent)) {}
191
-
192
- ~FallbackHelper() { parent_.reset(DEBUG_LOCATION, "FallbackHelper"); }
193
-
194
- RefCountedPtr<SubchannelInterface> CreateSubchannel(
195
- const grpc_channel_args& args) override;
196
- void UpdateState(grpc_connectivity_state state,
197
- std::unique_ptr<SubchannelPicker> picker) override;
198
- void RequestReresolution() override;
199
- void AddTraceEvent(TraceSeverity severity, StringView message) override;
200
-
201
- void set_child(LoadBalancingPolicy* child) { child_ = child; }
202
-
203
- private:
204
- bool CalledByPendingFallback() const;
205
- bool CalledByCurrentFallback() const;
206
-
207
- RefCountedPtr<XdsLb> parent_;
208
- LoadBalancingPolicy* child_ = nullptr;
209
- };
210
-
211
- // Each LocalityMap holds a ref to the XdsLb.
212
- class LocalityMap : public InternallyRefCounted<LocalityMap> {
213
- public:
214
- // Each Locality holds a ref to the LocalityMap it is in.
215
- class Locality : public InternallyRefCounted<Locality> {
216
- public:
217
- Locality(RefCountedPtr<LocalityMap> locality_map,
218
- RefCountedPtr<XdsLocalityName> name);
219
- ~Locality();
220
-
221
- void UpdateLocked(uint32_t locality_weight, ServerAddressList serverlist,
222
- bool update_locality_stats);
223
- void ShutdownLocked();
224
- void ResetBackoffLocked();
225
- void DeactivateLocked();
226
- void Orphan() override;
227
-
228
- uint32_t weight() const { return weight_; }
229
-
230
- grpc_connectivity_state connectivity_state() const {
231
- return connectivity_state_;
232
- }
233
-
234
- RefCountedPtr<LoadReportingPicker> GetLoadReportingPicker() {
235
- // Recreate load reporting picker if stats object has changed.
236
- if (load_reporting_picker_ == nullptr ||
237
- load_reporting_picker_->picker() != picker_wrapper_.get() ||
238
- load_reporting_picker_->locality_stats() != stats_.get()) {
239
- load_reporting_picker_ =
240
- MakeRefCounted<LoadReportingPicker>(picker_wrapper_, stats_);
241
- }
242
- return load_reporting_picker_;
243
- }
244
-
245
- void set_locality_map(RefCountedPtr<LocalityMap> locality_map) {
246
- locality_map_ = std::move(locality_map);
247
- }
248
-
249
- private:
250
- class Helper : public ChannelControlHelper {
251
- public:
252
- explicit Helper(RefCountedPtr<Locality> locality)
253
- : locality_(std::move(locality)) {}
254
-
255
- ~Helper() { locality_.reset(DEBUG_LOCATION, "Helper"); }
256
-
257
- RefCountedPtr<SubchannelInterface> CreateSubchannel(
258
- const grpc_channel_args& args) override;
259
- void UpdateState(grpc_connectivity_state state,
260
- std::unique_ptr<SubchannelPicker> picker) override;
261
- // This is a no-op, because we get the addresses from the xds
262
- // client, which is a watch-based API.
263
- void RequestReresolution() override {}
264
- void AddTraceEvent(TraceSeverity severity, StringView message) override;
265
- void set_child(LoadBalancingPolicy* child) { child_ = child; }
266
-
267
- private:
268
- bool CalledByPendingChild() const;
269
- bool CalledByCurrentChild() const;
270
-
271
- RefCountedPtr<Locality> locality_;
272
- LoadBalancingPolicy* child_ = nullptr;
273
- };
274
-
275
- // Methods for dealing with the child policy.
276
- OrphanablePtr<LoadBalancingPolicy> CreateChildPolicyLocked(
277
- const char* name, const grpc_channel_args* args);
278
- grpc_channel_args* CreateChildPolicyArgsLocked(
279
- const grpc_channel_args* args);
280
-
281
- void UpdateLocalityStats();
282
-
283
- static void OnDelayedRemovalTimer(void* arg, grpc_error* error);
284
- static void OnDelayedRemovalTimerLocked(void* arg, grpc_error* error);
285
-
286
- XdsLb* xds_policy() const { return locality_map_->xds_policy(); }
287
-
288
- // The owning locality map.
289
- RefCountedPtr<LocalityMap> locality_map_;
290
-
291
- RefCountedPtr<XdsLocalityName> name_;
292
- RefCountedPtr<XdsClusterLocalityStats> stats_;
293
- OrphanablePtr<LoadBalancingPolicy> child_policy_;
294
- OrphanablePtr<LoadBalancingPolicy> pending_child_policy_;
295
- RefCountedPtr<RefCountedEndpointPicker> picker_wrapper_;
296
- RefCountedPtr<LoadReportingPicker> load_reporting_picker_;
297
- grpc_connectivity_state connectivity_state_ = GRPC_CHANNEL_IDLE;
298
- uint32_t weight_;
299
-
300
- // States for delayed removal.
301
- grpc_timer delayed_removal_timer_;
302
- grpc_closure on_delayed_removal_timer_;
303
- bool delayed_removal_timer_callback_pending_ = false;
304
- bool shutdown_ = false;
305
- };
306
-
307
- LocalityMap(RefCountedPtr<XdsLb> xds_policy, uint32_t priority);
308
-
309
- ~LocalityMap() { xds_policy_.reset(DEBUG_LOCATION, "LocalityMap"); }
310
-
311
- void UpdateLocked(
312
- const XdsApi::PriorityListUpdate::LocalityMap& locality_map_update,
313
- bool update_locality_stats);
314
- void ResetBackoffLocked();
315
- void UpdateXdsPickerLocked();
316
- OrphanablePtr<Locality> ExtractLocalityLocked(
317
- const RefCountedPtr<XdsLocalityName>& name);
318
- void DeactivateLocked();
319
- // Returns true if this locality map becomes the currently used one (i.e.,
320
- // its priority is selected) after reactivation.
321
- bool MaybeReactivateLocked();
322
- void MaybeCancelFailoverTimerLocked();
323
-
324
- void Orphan() override;
325
-
326
- XdsLb* xds_policy() const { return xds_policy_.get(); }
327
- uint32_t priority() const { return priority_; }
328
- grpc_connectivity_state connectivity_state() const {
329
- return connectivity_state_;
330
- }
331
- bool failover_timer_callback_pending() const {
332
- return failover_timer_callback_pending_;
333
- }
334
-
335
- private:
336
- void OnLocalityStateUpdateLocked();
337
- void UpdateConnectivityStateLocked();
338
- static void OnDelayedRemovalTimer(void* arg, grpc_error* error);
339
- static void OnFailoverTimer(void* arg, grpc_error* error);
340
- static void OnDelayedRemovalTimerLocked(void* arg, grpc_error* error);
341
- static void OnFailoverTimerLocked(void* arg, grpc_error* error);
342
-
343
- const XdsApi::PriorityListUpdate& priority_list_update() const {
344
- return xds_policy_->priority_list_update_;
345
- }
346
- const XdsApi::PriorityListUpdate::LocalityMap* locality_map_update() const {
347
- return xds_policy_->priority_list_update_.Find(priority_);
348
- }
349
-
350
- RefCountedPtr<XdsLb> xds_policy_;
351
-
352
- std::map<RefCountedPtr<XdsLocalityName>, OrphanablePtr<Locality>,
353
- XdsLocalityName::Less>
354
- localities_;
355
- const uint32_t priority_;
356
- grpc_connectivity_state connectivity_state_ = GRPC_CHANNEL_IDLE;
357
-
358
- // States for delayed removal.
359
- grpc_timer delayed_removal_timer_;
360
- grpc_closure on_delayed_removal_timer_;
361
- bool delayed_removal_timer_callback_pending_ = false;
362
-
363
- // States of failover.
364
- grpc_timer failover_timer_;
365
- grpc_closure on_failover_timer_;
366
- bool failover_timer_callback_pending_ = false;
367
- };
368
-
369
- ~XdsLb();
370
-
371
- void ShutdownLocked() override;
372
-
373
- const char* eds_service_name() const {
374
- if (config_ != nullptr && config_->eds_service_name() != nullptr) {
375
- return config_->eds_service_name();
376
- }
377
- return server_name_.c_str();
378
- }
379
-
380
- XdsClient* xds_client() const {
381
- return xds_client_from_channel_ != nullptr ? xds_client_from_channel_.get()
382
- : xds_client_.get();
383
- }
384
-
385
- void UpdatePrioritiesLocked(bool update_locality_stats);
386
- void UpdateXdsPickerLocked();
387
- void MaybeCreateLocalityMapLocked(uint32_t priority);
388
- void FailoverOnConnectionFailureLocked();
389
- void FailoverOnDisconnectionLocked(uint32_t failed_priority);
390
- void SwitchToHigherPriorityLocked(uint32_t priority);
391
- void DeactivatePrioritiesLowerThan(uint32_t priority);
392
- OrphanablePtr<LocalityMap::Locality> ExtractLocalityLocked(
393
- const RefCountedPtr<XdsLocalityName>& name, uint32_t exclude_priority);
394
- // Callers should make sure the priority list is non-empty.
395
- uint32_t LowestPriority() const {
396
- return static_cast<uint32_t>(priorities_.size()) - 1;
397
- }
398
- bool Contains(uint32_t priority) { return priority < priorities_.size(); }
399
-
400
- // Methods for dealing with fallback state.
401
- void MaybeCancelFallbackAtStartupChecks();
402
- static void OnFallbackTimer(void* arg, grpc_error* error);
403
- static void OnFallbackTimerLocked(void* arg, grpc_error* error);
404
- void UpdateFallbackPolicyLocked();
405
- OrphanablePtr<LoadBalancingPolicy> CreateFallbackPolicyLocked(
406
- const char* name, const grpc_channel_args* args);
407
- void MaybeExitFallbackMode();
408
-
409
- // Server name from target URI.
410
- std::string server_name_;
411
-
412
- // Current channel args and config from the resolver.
413
- const grpc_channel_args* args_ = nullptr;
414
- RefCountedPtr<XdsConfig> config_;
415
-
416
- // Internal state.
417
- bool shutting_down_ = false;
418
-
419
- // The xds client and endpoint watcher.
420
- // If we get the XdsClient from the channel, we store it in
421
- // xds_client_from_channel_; if we create it ourselves, we store it in
422
- // xds_client_.
423
- RefCountedPtr<XdsClient> xds_client_from_channel_;
424
- OrphanablePtr<XdsClient> xds_client_;
425
- // A pointer to the endpoint watcher, to be used when cancelling the watch.
426
- // Note that this is not owned, so this pointer must never be derefernced.
427
- EndpointWatcher* endpoint_watcher_ = nullptr;
428
-
429
- // Whether the checks for fallback at startup are ALL pending. There are
430
- // several cases where this can be reset:
431
- // 1. The fallback timer fires, we enter fallback mode.
432
- // 2. Before the fallback timer fires, the endpoint watcher reports an
433
- // error, we enter fallback mode.
434
- // 3. Before the fallback timer fires, if any child policy in the locality map
435
- // becomes READY, we cancel the fallback timer.
436
- bool fallback_at_startup_checks_pending_ = false;
437
- // Timeout in milliseconds for before using fallback backend addresses.
438
- // 0 means not using fallback.
439
- const grpc_millis lb_fallback_timeout_ms_;
440
- // The backend addresses from the resolver.
441
- ServerAddressList fallback_backend_addresses_;
442
- // Fallback timer.
443
- grpc_timer lb_fallback_timer_;
444
- grpc_closure lb_on_fallback_;
445
-
446
- // Non-null iff we are in fallback mode.
447
- OrphanablePtr<LoadBalancingPolicy> fallback_policy_;
448
- OrphanablePtr<LoadBalancingPolicy> pending_fallback_policy_;
449
-
450
- const grpc_millis locality_retention_interval_ms_;
451
- const grpc_millis locality_map_failover_timeout_ms_;
452
- // The list of locality maps, indexed by priority. P0 is the highest
453
- // priority.
454
- InlinedVector<OrphanablePtr<LocalityMap>, 2> priorities_;
455
- // The priority that is being used.
456
- uint32_t current_priority_ = UINT32_MAX;
457
- // The update for priority_list_.
458
- XdsApi::PriorityListUpdate priority_list_update_;
459
-
460
- // The config for dropping calls.
461
- RefCountedPtr<XdsApi::DropConfig> drop_config_;
462
-
463
- // Drop stats for client-side load reporting.
464
- RefCountedPtr<XdsClusterDropStats> drop_stats_;
465
- };
466
-
467
- //
468
- // XdsLb::LoadReportingPicker
469
- //
470
-
471
- LoadBalancingPolicy::PickResult XdsLb::LoadReportingPicker::Pick(
472
- LoadBalancingPolicy::PickArgs args) {
473
- // Forward the pick to the picker returned from the child policy.
474
- PickResult result = picker_->Pick(args);
475
- if (result.type != PickResult::PICK_COMPLETE ||
476
- result.subchannel == nullptr || locality_stats_ == nullptr) {
477
- return result;
478
- }
479
- // Record a call started.
480
- locality_stats_->AddCallStarted();
481
- // Intercept the recv_trailing_metadata op to record call completion.
482
- XdsClusterLocalityStats* locality_stats =
483
- locality_stats_->Ref(DEBUG_LOCATION, "LocalityStats+call").release();
484
- result.recv_trailing_metadata_ready =
485
- // Note: This callback does not run in either the control plane
486
- // combiner or in the data plane mutex.
487
- [locality_stats](grpc_error* error, MetadataInterface* /*metadata*/,
488
- CallState* /*call_state*/) {
489
- const bool call_failed = error != GRPC_ERROR_NONE;
490
- locality_stats->AddCallFinished(call_failed);
491
- locality_stats->Unref(DEBUG_LOCATION, "LocalityStats+call");
492
- };
493
- return result;
494
- }
495
-
496
- //
497
- // XdsLb::LocalityPicker
498
- //
499
-
500
- XdsLb::PickResult XdsLb::LocalityPicker::Pick(PickArgs args) {
501
- // Handle drop.
502
- const std::string* drop_category;
503
- if (drop_config_->ShouldDrop(&drop_category)) {
504
- if (drop_stats_ != nullptr) drop_stats_->AddCallDropped(*drop_category);
505
- PickResult result;
506
- result.type = PickResult::PICK_COMPLETE;
507
- return result;
508
- }
509
- // Generate a random number in [0, total weight).
510
- const uint32_t key = rand() % pickers_[pickers_.size() - 1].first;
511
- // Forward pick to whichever locality maps to the range in which the
512
- // random number falls in.
513
- return PickFromLocality(key, args);
514
- }
515
-
516
- XdsLb::PickResult XdsLb::LocalityPicker::PickFromLocality(const uint32_t key,
517
- PickArgs args) {
518
- size_t mid = 0;
519
- size_t start_index = 0;
520
- size_t end_index = pickers_.size() - 1;
521
- size_t index = 0;
522
- while (end_index > start_index) {
523
- mid = (start_index + end_index) / 2;
524
- if (pickers_[mid].first > key) {
525
- end_index = mid;
526
- } else if (pickers_[mid].first < key) {
527
- start_index = mid + 1;
528
- } else {
529
- index = mid + 1;
530
- break;
531
- }
532
- }
533
- if (index == 0) index = start_index;
534
- GPR_ASSERT(pickers_[index].first > key);
535
- return pickers_[index].second->Pick(args);
536
- }
537
-
538
- //
539
- // XdsLb::FallbackHelper
540
- //
541
-
542
- bool XdsLb::FallbackHelper::CalledByPendingFallback() const {
543
- GPR_ASSERT(child_ != nullptr);
544
- return child_ == parent_->pending_fallback_policy_.get();
545
- }
546
-
547
- bool XdsLb::FallbackHelper::CalledByCurrentFallback() const {
548
- GPR_ASSERT(child_ != nullptr);
549
- return child_ == parent_->fallback_policy_.get();
550
- }
551
-
552
- RefCountedPtr<SubchannelInterface> XdsLb::FallbackHelper::CreateSubchannel(
553
- const grpc_channel_args& args) {
554
- if (parent_->shutting_down_ ||
555
- (!CalledByPendingFallback() && !CalledByCurrentFallback())) {
556
- return nullptr;
557
- }
558
- return parent_->channel_control_helper()->CreateSubchannel(args);
559
- }
560
-
561
- void XdsLb::FallbackHelper::UpdateState(
562
- grpc_connectivity_state state, std::unique_ptr<SubchannelPicker> picker) {
563
- if (parent_->shutting_down_) return;
564
- // If this request is from the pending fallback policy, ignore it until
565
- // it reports READY, at which point we swap it into place.
566
- if (CalledByPendingFallback()) {
567
- if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_xds_trace)) {
568
- gpr_log(
569
- GPR_INFO,
570
- "[xdslb %p helper %p] pending fallback policy %p reports state=%s",
571
- parent_.get(), this, parent_->pending_fallback_policy_.get(),
572
- ConnectivityStateName(state));
573
- }
574
- if (state != GRPC_CHANNEL_READY) return;
575
- grpc_pollset_set_del_pollset_set(
576
- parent_->fallback_policy_->interested_parties(),
577
- parent_->interested_parties());
578
- parent_->fallback_policy_ = std::move(parent_->pending_fallback_policy_);
579
- } else if (!CalledByCurrentFallback()) {
580
- // This request is from an outdated fallback policy, so ignore it.
581
- return;
582
- }
583
- parent_->channel_control_helper()->UpdateState(state, std::move(picker));
584
- }
585
-
586
- void XdsLb::FallbackHelper::RequestReresolution() {
587
- if (parent_->shutting_down_) return;
588
- const LoadBalancingPolicy* latest_fallback_policy =
589
- parent_->pending_fallback_policy_ != nullptr
590
- ? parent_->pending_fallback_policy_.get()
591
- : parent_->fallback_policy_.get();
592
- if (child_ != latest_fallback_policy) return;
593
- if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_xds_trace)) {
594
- gpr_log(GPR_INFO,
595
- "[xdslb %p] Re-resolution requested from the fallback policy (%p).",
596
- parent_.get(), child_);
597
- }
598
- parent_->channel_control_helper()->RequestReresolution();
599
- }
600
-
601
- void XdsLb::FallbackHelper::AddTraceEvent(TraceSeverity severity,
602
- StringView message) {
603
- if (parent_->shutting_down_ ||
604
- (!CalledByPendingFallback() && !CalledByCurrentFallback())) {
605
- return;
606
- }
607
- parent_->channel_control_helper()->AddTraceEvent(severity, message);
608
- }
609
-
610
- //
611
- // XdsLb::EndpointWatcher
612
- //
613
-
614
- class XdsLb::EndpointWatcher : public XdsClient::EndpointWatcherInterface {
615
- public:
616
- explicit EndpointWatcher(RefCountedPtr<XdsLb> xds_policy)
617
- : xds_policy_(std::move(xds_policy)) {}
618
-
619
- ~EndpointWatcher() { xds_policy_.reset(DEBUG_LOCATION, "EndpointWatcher"); }
620
-
621
- void OnEndpointChanged(XdsApi::EdsUpdate update) override {
622
- if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_xds_trace)) {
623
- gpr_log(GPR_INFO, "[xdslb %p] Received EDS update from xds client",
624
- xds_policy_.get());
625
- }
626
- // If the balancer tells us to drop all the calls, we should exit fallback
627
- // mode immediately.
628
- if (update.drop_all) xds_policy_->MaybeExitFallbackMode();
629
- // Update the drop config.
630
- const bool drop_config_changed =
631
- xds_policy_->drop_config_ == nullptr ||
632
- *xds_policy_->drop_config_ != *update.drop_config;
633
- xds_policy_->drop_config_ = std::move(update.drop_config);
634
- // Ignore identical locality update.
635
- if (xds_policy_->priority_list_update_ == update.priority_list_update) {
636
- if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_xds_trace)) {
637
- gpr_log(GPR_INFO,
638
- "[xdslb %p] Incoming locality update identical to current, "
639
- "ignoring. (drop_config_changed=%d)",
640
- xds_policy_.get(), drop_config_changed);
641
- }
642
- if (drop_config_changed) {
643
- xds_policy_->UpdateXdsPickerLocked();
644
- }
645
- return;
646
- }
647
- // Update the priority list.
648
- xds_policy_->priority_list_update_ = std::move(update.priority_list_update);
649
- xds_policy_->UpdatePrioritiesLocked(false /*update_locality_stats*/);
650
- }
651
-
652
- void OnError(grpc_error* error) override {
653
- // If the fallback-at-startup checks are pending, go into fallback mode
654
- // immediately. This short-circuits the timeout for the
655
- // fallback-at-startup case.
656
- if (xds_policy_->fallback_at_startup_checks_pending_) {
657
- gpr_log(GPR_INFO,
658
- "[xdslb %p] xds watcher reported error; entering fallback "
659
- "mode: %s",
660
- xds_policy_.get(), grpc_error_string(error));
661
- xds_policy_->fallback_at_startup_checks_pending_ = false;
662
- grpc_timer_cancel(&xds_policy_->lb_fallback_timer_);
663
- xds_policy_->UpdateFallbackPolicyLocked();
664
- // If the xds call failed, request re-resolution.
665
- // TODO(roth): We check the error string contents here to
666
- // differentiate between the xds call failing and the xds channel
667
- // going into TRANSIENT_FAILURE. This is a pretty ugly hack,
668
- // but it's okay for now, since we're not yet sure whether we will
669
- // continue to support the current fallback functionality. If we
670
- // decide to keep the fallback approach, then we should either
671
- // find a cleaner way to expose the difference between these two
672
- // cases or decide that we're okay re-resolving in both cases.
673
- // Note that even if we do keep the current fallback functionality,
674
- // this re-resolution will only be necessary if we are going to be
675
- // using this LB policy with resolvers other than the xds resolver.
676
- if (strstr(grpc_error_string(error), "xds call failed")) {
677
- xds_policy_->channel_control_helper()->RequestReresolution();
678
- }
679
- }
680
- GRPC_ERROR_UNREF(error);
681
- }
682
-
683
- private:
684
- RefCountedPtr<XdsLb> xds_policy_;
685
- };
686
-
687
- //
688
- // ctor and dtor
689
- //
690
-
691
- XdsLb::XdsLb(Args args)
692
- : LoadBalancingPolicy(std::move(args)),
693
- xds_client_from_channel_(XdsClient::GetFromChannelArgs(*args.args)),
694
- lb_fallback_timeout_ms_(grpc_channel_args_find_integer(
695
- args.args, GRPC_ARG_XDS_FALLBACK_TIMEOUT_MS,
696
- {GRPC_XDS_DEFAULT_FALLBACK_TIMEOUT_MS, 0, INT_MAX})),
697
- locality_retention_interval_ms_(grpc_channel_args_find_integer(
698
- args.args, GRPC_ARG_LOCALITY_RETENTION_INTERVAL_MS,
699
- {GRPC_XDS_DEFAULT_LOCALITY_RETENTION_INTERVAL_MS, 0, INT_MAX})),
700
- locality_map_failover_timeout_ms_(grpc_channel_args_find_integer(
701
- args.args, GRPC_ARG_XDS_FAILOVER_TIMEOUT_MS,
702
- {GRPC_XDS_DEFAULT_FAILOVER_TIMEOUT_MS, 0, INT_MAX})) {
703
- if (xds_client_from_channel_ != nullptr &&
704
- GRPC_TRACE_FLAG_ENABLED(grpc_lb_xds_trace)) {
705
- gpr_log(GPR_INFO, "[xdslb %p] Using xds client %p from channel", this,
706
- xds_client_from_channel_.get());
707
- }
708
- // Record server name.
709
- const grpc_arg* arg = grpc_channel_args_find(args.args, GRPC_ARG_SERVER_URI);
710
- const char* server_uri = grpc_channel_arg_get_string(arg);
711
- GPR_ASSERT(server_uri != nullptr);
712
- grpc_uri* uri = grpc_uri_parse(server_uri, true);
713
- GPR_ASSERT(uri->path[0] != '\0');
714
- server_name_ = uri->path[0] == '/' ? uri->path + 1 : uri->path;
715
- if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_xds_trace)) {
716
- gpr_log(GPR_INFO, "[xdslb %p] server name from channel: %s", this,
717
- server_name_.c_str());
718
- }
719
- grpc_uri_destroy(uri);
720
- }
721
-
722
- XdsLb::~XdsLb() {
723
- if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_xds_trace)) {
724
- gpr_log(GPR_INFO, "[xdslb %p] destroying xds LB policy", this);
725
- }
726
- grpc_channel_args_destroy(args_);
727
- }
728
-
729
- void XdsLb::ShutdownLocked() {
730
- if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_xds_trace)) {
731
- gpr_log(GPR_INFO, "[xdslb %p] shutting down", this);
732
- }
733
- shutting_down_ = true;
734
- MaybeCancelFallbackAtStartupChecks();
735
- priorities_.clear();
736
- drop_stats_.reset();
737
- if (fallback_policy_ != nullptr) {
738
- grpc_pollset_set_del_pollset_set(fallback_policy_->interested_parties(),
739
- interested_parties());
740
- }
741
- if (pending_fallback_policy_ != nullptr) {
742
- grpc_pollset_set_del_pollset_set(
743
- pending_fallback_policy_->interested_parties(), interested_parties());
744
- }
745
- fallback_policy_.reset();
746
- pending_fallback_policy_.reset();
747
- // Cancel the endpoint watch here instead of in our dtor if we are using the
748
- // XdsResolver, because the watcher holds a ref to us and we might not be
749
- // destroying the Xds client leading to a situation where the Xds lb policy is
750
- // never destroyed.
751
- if (xds_client_from_channel_ != nullptr) {
752
- xds_client()->CancelEndpointDataWatch(StringView(eds_service_name()),
753
- endpoint_watcher_);
754
- xds_client_from_channel_.reset();
755
- }
756
- xds_client_.reset();
757
- }
758
-
759
- //
760
- // public methods
761
- //
762
-
763
- void XdsLb::ResetBackoffLocked() {
764
- // When the XdsClient is instantiated in the resolver instead of in this
765
- // LB policy, this is done via the resolver, so we don't need to do it
766
- // for xds_client_from_channel_ here.
767
- if (xds_client_ != nullptr) xds_client_->ResetBackoff();
768
- for (size_t i = 0; i < priorities_.size(); ++i) {
769
- priorities_[i]->ResetBackoffLocked();
770
- }
771
- if (fallback_policy_ != nullptr) {
772
- fallback_policy_->ResetBackoffLocked();
773
- }
774
- if (pending_fallback_policy_ != nullptr) {
775
- pending_fallback_policy_->ResetBackoffLocked();
776
- }
777
- }
778
-
779
- void XdsLb::UpdateLocked(UpdateArgs args) {
780
- if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_xds_trace)) {
781
- gpr_log(GPR_INFO, "[xdslb %p] Received update", this);
782
- }
783
- const bool is_initial_update = args_ == nullptr;
784
- // Update config.
785
- const char* old_eds_service_name = eds_service_name();
786
- auto old_config = std::move(config_);
787
- config_ = std::move(args.config);
788
- // Update fallback address list.
789
- fallback_backend_addresses_ = std::move(args.addresses);
790
- // Update args.
791
- grpc_channel_args_destroy(args_);
792
- args_ = args.args;
793
- args.args = nullptr;
794
- // Update the existing fallback policy. The fallback policy config and/or the
795
- // fallback addresses may be new.
796
- if (fallback_policy_ != nullptr) UpdateFallbackPolicyLocked();
797
- if (is_initial_update) {
798
- // Initialize XdsClient.
799
- if (xds_client_from_channel_ == nullptr) {
800
- grpc_error* error = GRPC_ERROR_NONE;
801
- xds_client_ = MakeOrphanable<XdsClient>(
802
- combiner(), interested_parties(), StringView(eds_service_name()),
803
- nullptr /* service config watcher */, *args_, &error);
804
- // TODO(roth): If we decide that we care about fallback mode, add
805
- // proper error handling here.
806
- GPR_ASSERT(error == GRPC_ERROR_NONE);
807
- if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_xds_trace)) {
808
- gpr_log(GPR_INFO, "[xdslb %p] Created xds client %p", this,
809
- xds_client_.get());
810
- }
811
- }
812
- // Start fallback-at-startup checks.
813
- grpc_millis deadline = ExecCtx::Get()->Now() + lb_fallback_timeout_ms_;
814
- Ref(DEBUG_LOCATION, "on_fallback_timer").release(); // Held by closure
815
- GRPC_CLOSURE_INIT(&lb_on_fallback_, &XdsLb::OnFallbackTimer, this,
816
- grpc_schedule_on_exec_ctx);
817
- fallback_at_startup_checks_pending_ = true;
818
- grpc_timer_init(&lb_fallback_timer_, deadline, &lb_on_fallback_);
819
- }
820
- // Update drop stats for load reporting if needed.
821
- if (is_initial_update || config_->lrs_load_reporting_server_name() !=
822
- old_config->lrs_load_reporting_server_name()) {
823
- drop_stats_.reset();
824
- if (config_->lrs_load_reporting_server_name().has_value()) {
825
- drop_stats_ = xds_client()->AddClusterDropStats(
826
- config_->lrs_load_reporting_server_name().value(),
827
- // TODO(roth): We currently hard-code the assumption that
828
- // cluster name and EDS service name are the same. Fix this
829
- // as part of refectoring this LB policy.
830
- eds_service_name(), eds_service_name());
831
- }
832
- }
833
- // Update priority list.
834
- // Note that this comes after updating drop_stats_, since we want that
835
- // to be used by any new picker we create here.
836
- // No need to do this on the initial update, since there won't be any
837
- // priorities to update yet.
838
- if (!is_initial_update) {
839
- const bool update_locality_stats =
840
- config_->lrs_load_reporting_server_name() !=
841
- old_config->lrs_load_reporting_server_name() ||
842
- strcmp(old_eds_service_name, eds_service_name()) != 0;
843
- UpdatePrioritiesLocked(update_locality_stats);
844
- }
845
- // Update endpoint watcher if needed.
846
- if (is_initial_update ||
847
- strcmp(old_eds_service_name, eds_service_name()) != 0) {
848
- if (!is_initial_update) {
849
- xds_client()->CancelEndpointDataWatch(StringView(old_eds_service_name),
850
- endpoint_watcher_);
851
- }
852
- auto watcher = absl::make_unique<EndpointWatcher>(
853
- Ref(DEBUG_LOCATION, "EndpointWatcher"));
854
- endpoint_watcher_ = watcher.get();
855
- xds_client()->WatchEndpointData(StringView(eds_service_name()),
856
- std::move(watcher));
857
- }
858
- }
859
-
860
- //
861
- // fallback-related methods
862
- //
863
-
864
- void XdsLb::MaybeCancelFallbackAtStartupChecks() {
865
- if (!fallback_at_startup_checks_pending_) return;
866
- if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_xds_trace)) {
867
- gpr_log(GPR_INFO, "[xdslb %p] Cancelling fallback timer", this);
868
- }
869
- grpc_timer_cancel(&lb_fallback_timer_);
870
- fallback_at_startup_checks_pending_ = false;
871
- }
872
-
873
- void XdsLb::OnFallbackTimer(void* arg, grpc_error* error) {
874
- XdsLb* xdslb_policy = static_cast<XdsLb*>(arg);
875
- xdslb_policy->combiner()->Run(
876
- GRPC_CLOSURE_INIT(&xdslb_policy->lb_on_fallback_,
877
- &XdsLb::OnFallbackTimerLocked, xdslb_policy, nullptr),
878
- GRPC_ERROR_REF(error));
879
- }
880
-
881
- void XdsLb::OnFallbackTimerLocked(void* arg, grpc_error* error) {
882
- XdsLb* xdslb_policy = static_cast<XdsLb*>(arg);
883
- // If some fallback-at-startup check is done after the timer fires but before
884
- // this callback actually runs, don't fall back.
885
- if (xdslb_policy->fallback_at_startup_checks_pending_ &&
886
- !xdslb_policy->shutting_down_ && error == GRPC_ERROR_NONE) {
887
- gpr_log(GPR_INFO,
888
- "[xdslb %p] Child policy not ready after fallback timeout; "
889
- "entering fallback mode",
890
- xdslb_policy);
891
- xdslb_policy->fallback_at_startup_checks_pending_ = false;
892
- xdslb_policy->UpdateFallbackPolicyLocked();
893
- }
894
- xdslb_policy->Unref(DEBUG_LOCATION, "on_fallback_timer");
895
- }
896
-
897
- void XdsLb::UpdateFallbackPolicyLocked() {
898
- if (shutting_down_) return;
899
- // Construct update args.
900
- UpdateArgs update_args;
901
- update_args.addresses = fallback_backend_addresses_;
902
- update_args.config = config_->fallback_policy();
903
- update_args.args = grpc_channel_args_copy(args_);
904
- // If the child policy name changes, we need to create a new child
905
- // policy. When this happens, we leave child_policy_ as-is and store
906
- // the new child policy in pending_child_policy_. Once the new child
907
- // policy transitions into state READY, we swap it into child_policy_,
908
- // replacing the original child policy. So pending_child_policy_ is
909
- // non-null only between when we apply an update that changes the child
910
- // policy name and when the new child reports state READY.
911
- //
912
- // Updates can arrive at any point during this transition. We always
913
- // apply updates relative to the most recently created child policy,
914
- // even if the most recent one is still in pending_child_policy_. This
915
- // is true both when applying the updates to an existing child policy
916
- // and when determining whether we need to create a new policy.
917
- //
918
- // As a result of this, there are several cases to consider here:
919
- //
920
- // 1. We have no existing child policy (i.e., we have started up but
921
- // have not yet received a serverlist from the balancer or gone
922
- // into fallback mode; in this case, both child_policy_ and
923
- // pending_child_policy_ are null). In this case, we create a
924
- // new child policy and store it in child_policy_.
925
- //
926
- // 2. We have an existing child policy and have no pending child policy
927
- // from a previous update (i.e., either there has not been a
928
- // previous update that changed the policy name, or we have already
929
- // finished swapping in the new policy; in this case, child_policy_
930
- // is non-null but pending_child_policy_ is null). In this case:
931
- // a. If child_policy_->name() equals child_policy_name, then we
932
- // update the existing child policy.
933
- // b. If child_policy_->name() does not equal child_policy_name,
934
- // we create a new policy. The policy will be stored in
935
- // pending_child_policy_ and will later be swapped into
936
- // child_policy_ by the helper when the new child transitions
937
- // into state READY.
938
- //
939
- // 3. We have an existing child policy and have a pending child policy
940
- // from a previous update (i.e., a previous update set
941
- // pending_child_policy_ as per case 2b above and that policy has
942
- // not yet transitioned into state READY and been swapped into
943
- // child_policy_; in this case, both child_policy_ and
944
- // pending_child_policy_ are non-null). In this case:
945
- // a. If pending_child_policy_->name() equals child_policy_name,
946
- // then we update the existing pending child policy.
947
- // b. If pending_child_policy->name() does not equal
948
- // child_policy_name, then we create a new policy. The new
949
- // policy is stored in pending_child_policy_ (replacing the one
950
- // that was there before, which will be immediately shut down)
951
- // and will later be swapped into child_policy_ by the helper
952
- // when the new child transitions into state READY.
953
- const char* fallback_policy_name = update_args.config == nullptr
954
- ? "round_robin"
955
- : update_args.config->name();
956
- const bool create_policy =
957
- // case 1
958
- fallback_policy_ == nullptr ||
959
- // case 2b
960
- (pending_fallback_policy_ == nullptr &&
961
- strcmp(fallback_policy_->name(), fallback_policy_name) != 0) ||
962
- // case 3b
963
- (pending_fallback_policy_ != nullptr &&
964
- strcmp(pending_fallback_policy_->name(), fallback_policy_name) != 0);
965
- LoadBalancingPolicy* policy_to_update = nullptr;
966
- if (create_policy) {
967
- // Cases 1, 2b, and 3b: create a new child policy.
968
- // If child_policy_ is null, we set it (case 1), else we set
969
- // pending_child_policy_ (cases 2b and 3b).
970
- if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_xds_trace)) {
971
- gpr_log(GPR_INFO, "[xdslb %p] Creating new %sfallback policy %s", this,
972
- fallback_policy_ == nullptr ? "" : "pending ",
973
- fallback_policy_name);
974
- }
975
- auto& lb_policy = fallback_policy_ == nullptr ? fallback_policy_
976
- : pending_fallback_policy_;
977
- lb_policy =
978
- CreateFallbackPolicyLocked(fallback_policy_name, update_args.args);
979
- policy_to_update = lb_policy.get();
980
- } else {
981
- // Cases 2a and 3a: update an existing policy.
982
- // If we have a pending child policy, send the update to the pending
983
- // policy (case 3a), else send it to the current policy (case 2a).
984
- policy_to_update = pending_fallback_policy_ != nullptr
985
- ? pending_fallback_policy_.get()
986
- : fallback_policy_.get();
987
- }
988
- GPR_ASSERT(policy_to_update != nullptr);
989
- // Update the policy.
990
- if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_xds_trace)) {
991
- gpr_log(
992
- GPR_INFO, "[xdslb %p] Updating %sfallback policy %p", this,
993
- policy_to_update == pending_fallback_policy_.get() ? "pending " : "",
994
- policy_to_update);
995
- }
996
- policy_to_update->UpdateLocked(std::move(update_args));
997
- }
998
-
999
- OrphanablePtr<LoadBalancingPolicy> XdsLb::CreateFallbackPolicyLocked(
1000
- const char* name, const grpc_channel_args* args) {
1001
- FallbackHelper* helper =
1002
- new FallbackHelper(Ref(DEBUG_LOCATION, "FallbackHelper"));
1003
- LoadBalancingPolicy::Args lb_policy_args;
1004
- lb_policy_args.combiner = combiner();
1005
- lb_policy_args.args = args;
1006
- lb_policy_args.channel_control_helper =
1007
- std::unique_ptr<ChannelControlHelper>(helper);
1008
- OrphanablePtr<LoadBalancingPolicy> lb_policy =
1009
- LoadBalancingPolicyRegistry::CreateLoadBalancingPolicy(
1010
- name, std::move(lb_policy_args));
1011
- if (GPR_UNLIKELY(lb_policy == nullptr)) {
1012
- gpr_log(GPR_ERROR, "[xdslb %p] Failure creating fallback policy %s", this,
1013
- name);
1014
- return nullptr;
1015
- }
1016
- helper->set_child(lb_policy.get());
1017
- if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_xds_trace)) {
1018
- gpr_log(GPR_INFO, "[xdslb %p] Created new fallback policy %s (%p)", this,
1019
- name, lb_policy.get());
1020
- }
1021
- // Add the xDS's interested_parties pollset_set to that of the newly created
1022
- // child policy. This will make the child policy progress upon activity on xDS
1023
- // LB, which in turn is tied to the application's call.
1024
- grpc_pollset_set_add_pollset_set(lb_policy->interested_parties(),
1025
- interested_parties());
1026
- return lb_policy;
1027
- }
1028
-
1029
- void XdsLb::MaybeExitFallbackMode() {
1030
- if (fallback_policy_ == nullptr) return;
1031
- gpr_log(GPR_INFO, "[xdslb %p] Exiting fallback mode", this);
1032
- fallback_policy_.reset();
1033
- pending_fallback_policy_.reset();
1034
- }
1035
-
1036
- //
1037
- // priority list-related methods
1038
- //
1039
-
1040
- void XdsLb::UpdatePrioritiesLocked(bool update_locality_stats) {
1041
- // 1. Remove from the priority list the priorities that are not in the update.
1042
- DeactivatePrioritiesLowerThan(priority_list_update_.LowestPriority());
1043
- // 2. Update all the existing priorities.
1044
- for (uint32_t priority = 0; priority < priorities_.size(); ++priority) {
1045
- LocalityMap* locality_map = priorities_[priority].get();
1046
- const auto* locality_map_update = priority_list_update_.Find(priority);
1047
- // If we have more current priorities than exist in the update, stop here.
1048
- if (locality_map_update == nullptr) break;
1049
- // Propagate locality_map_update.
1050
- // TODO(juanlishen): Find a clean way to skip duplicate update for a
1051
- // priority.
1052
- locality_map->UpdateLocked(*locality_map_update, update_locality_stats);
1053
- }
1054
- // 3. Only create a new locality map if all the existing ones have failed.
1055
- if (priorities_.empty() ||
1056
- !priorities_[priorities_.size() - 1]->failover_timer_callback_pending()) {
1057
- const uint32_t new_priority = static_cast<uint32_t>(priorities_.size());
1058
- // Create a new locality map. Note that in some rare cases (e.g., the
1059
- // locality map reports TRANSIENT_FAILURE synchronously due to subchannel
1060
- // sharing), the following invocation may result in multiple locality maps
1061
- // to be created.
1062
- MaybeCreateLocalityMapLocked(new_priority);
1063
- }
1064
- // 4. If we updated locality stats and we already have at least one
1065
- // priority, update the picker to start using the new stats object(s).
1066
- if (update_locality_stats && !priorities_.empty()) {
1067
- UpdateXdsPickerLocked();
1068
- }
1069
- }
1070
-
1071
- void XdsLb::UpdateXdsPickerLocked() {
1072
- // If we are in fallback mode, don't generate an xds picker from localities.
1073
- if (fallback_policy_ != nullptr) return;
1074
- if (current_priority_ == UINT32_MAX) {
1075
- grpc_error* error = grpc_error_set_int(
1076
- GRPC_ERROR_CREATE_FROM_STATIC_STRING("no ready locality map"),
1077
- GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_UNAVAILABLE);
1078
- channel_control_helper()->UpdateState(
1079
- GRPC_CHANNEL_TRANSIENT_FAILURE,
1080
- absl::make_unique<TransientFailurePicker>(error));
1081
- return;
1082
- }
1083
- priorities_[current_priority_]->UpdateXdsPickerLocked();
1084
- }
1085
-
1086
- void XdsLb::MaybeCreateLocalityMapLocked(uint32_t priority) {
1087
- // Exhausted priorities in the update.
1088
- if (!priority_list_update_.Contains(priority)) return;
1089
- auto new_locality_map =
1090
- new LocalityMap(Ref(DEBUG_LOCATION, "LocalityMap"), priority);
1091
- priorities_.emplace_back(OrphanablePtr<LocalityMap>(new_locality_map));
1092
- new_locality_map->UpdateLocked(*priority_list_update_.Find(priority),
1093
- false /*update_locality_stats*/);
1094
- }
1095
-
1096
- void XdsLb::FailoverOnConnectionFailureLocked() {
1097
- const uint32_t failed_priority = LowestPriority();
1098
- // If we're failing over from the lowest priority, report TRANSIENT_FAILURE.
1099
- if (failed_priority == priority_list_update_.LowestPriority()) {
1100
- UpdateXdsPickerLocked();
1101
- }
1102
- MaybeCreateLocalityMapLocked(failed_priority + 1);
1103
- }
1104
-
1105
- void XdsLb::FailoverOnDisconnectionLocked(uint32_t failed_priority) {
1106
- current_priority_ = UINT32_MAX;
1107
- for (uint32_t next_priority = failed_priority + 1;
1108
- next_priority <= priority_list_update_.LowestPriority();
1109
- ++next_priority) {
1110
- if (!Contains(next_priority)) {
1111
- MaybeCreateLocalityMapLocked(next_priority);
1112
- return;
1113
- }
1114
- if (priorities_[next_priority]->MaybeReactivateLocked()) return;
1115
- }
1116
- }
1117
-
1118
- void XdsLb::SwitchToHigherPriorityLocked(uint32_t priority) {
1119
- current_priority_ = priority;
1120
- DeactivatePrioritiesLowerThan(current_priority_);
1121
- UpdateXdsPickerLocked();
1122
- }
1123
-
1124
- void XdsLb::DeactivatePrioritiesLowerThan(uint32_t priority) {
1125
- if (priorities_.empty()) return;
1126
- // Deactivate the locality maps from the lowest priority.
1127
- for (uint32_t p = LowestPriority(); p > priority; --p) {
1128
- if (locality_retention_interval_ms_ == 0) {
1129
- priorities_.pop_back();
1130
- } else {
1131
- priorities_[p]->DeactivateLocked();
1132
- }
1133
- }
1134
- }
1135
-
1136
- OrphanablePtr<XdsLb::LocalityMap::Locality> XdsLb::ExtractLocalityLocked(
1137
- const RefCountedPtr<XdsLocalityName>& name, uint32_t exclude_priority) {
1138
- for (uint32_t priority = 0; priority < priorities_.size(); ++priority) {
1139
- if (priority == exclude_priority) continue;
1140
- LocalityMap* locality_map = priorities_[priority].get();
1141
- auto locality = locality_map->ExtractLocalityLocked(name);
1142
- if (locality != nullptr) return locality;
1143
- }
1144
- return nullptr;
1145
- }
1146
-
1147
- //
1148
- // XdsLb::LocalityMap
1149
- //
1150
-
1151
- XdsLb::LocalityMap::LocalityMap(RefCountedPtr<XdsLb> xds_policy,
1152
- uint32_t priority)
1153
- : xds_policy_(std::move(xds_policy)), priority_(priority) {
1154
- if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_xds_trace)) {
1155
- gpr_log(GPR_INFO, "[xdslb %p] Creating priority %" PRIu32,
1156
- xds_policy_.get(), priority_);
1157
- }
1158
- GRPC_CLOSURE_INIT(&on_failover_timer_, OnFailoverTimer, this,
1159
- grpc_schedule_on_exec_ctx);
1160
- // Start the failover timer.
1161
- Ref(DEBUG_LOCATION, "LocalityMap+OnFailoverTimerLocked").release();
1162
- grpc_timer_init(
1163
- &failover_timer_,
1164
- ExecCtx::Get()->Now() + xds_policy_->locality_map_failover_timeout_ms_,
1165
- &on_failover_timer_);
1166
- failover_timer_callback_pending_ = true;
1167
- // This is the first locality map ever created, report CONNECTING.
1168
- if (priority_ == 0) {
1169
- xds_policy_->channel_control_helper()->UpdateState(
1170
- GRPC_CHANNEL_CONNECTING,
1171
- absl::make_unique<QueuePicker>(
1172
- xds_policy_->Ref(DEBUG_LOCATION, "QueuePicker")));
1173
- }
1174
- }
1175
-
1176
- void XdsLb::LocalityMap::UpdateLocked(
1177
- const XdsApi::PriorityListUpdate::LocalityMap& locality_map_update,
1178
- bool update_locality_stats) {
1179
- if (xds_policy_->shutting_down_) return;
1180
- if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_xds_trace)) {
1181
- gpr_log(GPR_INFO, "[xdslb %p] Start Updating priority %" PRIu32,
1182
- xds_policy(), priority_);
1183
- }
1184
- // Maybe reactivate the locality map in case all the active locality maps have
1185
- // failed.
1186
- MaybeReactivateLocked();
1187
- // Remove (later) the localities not in locality_map_update.
1188
- for (auto iter = localities_.begin(); iter != localities_.end();) {
1189
- const auto& name = iter->first;
1190
- Locality* locality = iter->second.get();
1191
- if (locality_map_update.Contains(name)) {
1192
- ++iter;
1193
- continue;
1194
- }
1195
- if (xds_policy()->locality_retention_interval_ms_ == 0) {
1196
- iter = localities_.erase(iter);
1197
- } else {
1198
- locality->DeactivateLocked();
1199
- ++iter;
1200
- }
1201
- }
1202
- // Add or update the localities in locality_map_update.
1203
- for (const auto& p : locality_map_update.localities) {
1204
- const auto& name = p.first;
1205
- const auto& locality_update = p.second;
1206
- OrphanablePtr<Locality>& locality = localities_[name];
1207
- if (locality == nullptr) {
1208
- // Move from another locality map if possible.
1209
- locality = xds_policy_->ExtractLocalityLocked(name, priority_);
1210
- if (locality != nullptr) {
1211
- locality->set_locality_map(
1212
- Ref(DEBUG_LOCATION, "LocalityMap+Locality_move"));
1213
- } else {
1214
- locality = MakeOrphanable<Locality>(
1215
- Ref(DEBUG_LOCATION, "LocalityMap+Locality"), name);
1216
- }
1217
- }
1218
- // Keep a copy of serverlist in the update so that we can compare it
1219
- // with the future ones.
1220
- locality->UpdateLocked(locality_update.lb_weight,
1221
- locality_update.serverlist, update_locality_stats);
1222
- }
1223
- }
1224
-
1225
- void XdsLb::LocalityMap::ResetBackoffLocked() {
1226
- for (auto& p : localities_) p.second->ResetBackoffLocked();
1227
- }
1228
-
1229
- void XdsLb::LocalityMap::UpdateXdsPickerLocked() {
1230
- // Construct a new xds picker which maintains a map of all locality pickers
1231
- // that are ready. Each locality is represented by a portion of the range
1232
- // proportional to its weight, such that the total range is the sum of the
1233
- // weights of all localities.
1234
- LocalityPicker::PickerList picker_list;
1235
- uint32_t end = 0;
1236
- for (auto& p : localities_) {
1237
- const auto& locality_name = p.first;
1238
- Locality* locality = p.second.get();
1239
- // Skip the localities that are not in the latest locality map update.
1240
- if (!locality_map_update()->Contains(locality_name)) continue;
1241
- if (locality->connectivity_state() != GRPC_CHANNEL_READY) continue;
1242
- end += locality->weight();
1243
- picker_list.push_back(
1244
- std::make_pair(end, locality->GetLoadReportingPicker()));
1245
- }
1246
- xds_policy()->channel_control_helper()->UpdateState(
1247
- GRPC_CHANNEL_READY,
1248
- absl::make_unique<LocalityPicker>(xds_policy(), std::move(picker_list)));
1249
- }
1250
-
1251
- OrphanablePtr<XdsLb::LocalityMap::Locality>
1252
- XdsLb::LocalityMap::ExtractLocalityLocked(
1253
- const RefCountedPtr<XdsLocalityName>& name) {
1254
- for (auto iter = localities_.begin(); iter != localities_.end(); ++iter) {
1255
- const auto& name_in_map = iter->first;
1256
- if (*name_in_map == *name) {
1257
- auto locality = std::move(iter->second);
1258
- localities_.erase(iter);
1259
- return locality;
1260
- }
1261
- }
1262
- return nullptr;
1263
- }
1264
-
1265
- void XdsLb::LocalityMap::DeactivateLocked() {
1266
- // If already deactivated, don't do it again.
1267
- if (delayed_removal_timer_callback_pending_) return;
1268
- MaybeCancelFailoverTimerLocked();
1269
- // Start a timer to delete the locality.
1270
- Ref(DEBUG_LOCATION, "LocalityMap+timer").release();
1271
- if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_xds_trace)) {
1272
- gpr_log(GPR_INFO,
1273
- "[xdslb %p] Will remove priority %" PRIu32 " in %" PRId64 " ms.",
1274
- xds_policy(), priority_,
1275
- xds_policy()->locality_retention_interval_ms_);
1276
- }
1277
- GRPC_CLOSURE_INIT(&on_delayed_removal_timer_, OnDelayedRemovalTimer, this,
1278
- grpc_schedule_on_exec_ctx);
1279
- grpc_timer_init(
1280
- &delayed_removal_timer_,
1281
- ExecCtx::Get()->Now() + xds_policy()->locality_retention_interval_ms_,
1282
- &on_delayed_removal_timer_);
1283
- delayed_removal_timer_callback_pending_ = true;
1284
- }
1285
-
1286
- bool XdsLb::LocalityMap::MaybeReactivateLocked() {
1287
- // Don't reactivate a priority that is not higher than the current one.
1288
- if (priority_ >= xds_policy_->current_priority_) return false;
1289
- // Reactivate this priority by cancelling deletion timer.
1290
- if (delayed_removal_timer_callback_pending_) {
1291
- grpc_timer_cancel(&delayed_removal_timer_);
1292
- }
1293
- // Switch to this higher priority if it's READY.
1294
- if (connectivity_state_ != GRPC_CHANNEL_READY) return false;
1295
- xds_policy_->SwitchToHigherPriorityLocked(priority_);
1296
- return true;
1297
- }
1298
-
1299
- void XdsLb::LocalityMap::MaybeCancelFailoverTimerLocked() {
1300
- if (failover_timer_callback_pending_) grpc_timer_cancel(&failover_timer_);
1301
- }
1302
-
1303
- void XdsLb::LocalityMap::Orphan() {
1304
- if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_xds_trace)) {
1305
- gpr_log(GPR_INFO, "[xdslb %p] Priority %" PRIu32 " orphaned.", xds_policy(),
1306
- priority_);
1307
- }
1308
- MaybeCancelFailoverTimerLocked();
1309
- if (delayed_removal_timer_callback_pending_) {
1310
- grpc_timer_cancel(&delayed_removal_timer_);
1311
- }
1312
- localities_.clear();
1313
- Unref(DEBUG_LOCATION, "LocalityMap+Orphan");
1314
- }
1315
-
1316
- void XdsLb::LocalityMap::OnLocalityStateUpdateLocked() {
1317
- UpdateConnectivityStateLocked();
1318
- // Ignore priorities not in priority_list_update.
1319
- if (!priority_list_update().Contains(priority_)) return;
1320
- const uint32_t current_priority = xds_policy_->current_priority_;
1321
- // Ignore lower-than-current priorities.
1322
- if (priority_ > current_priority) return;
1323
- // Maybe update fallback state.
1324
- if (connectivity_state_ == GRPC_CHANNEL_READY) {
1325
- xds_policy_->MaybeCancelFallbackAtStartupChecks();
1326
- xds_policy_->MaybeExitFallbackMode();
1327
- }
1328
- // Update is for a higher-than-current priority. (Special case: update is for
1329
- // any active priority if there is no current priority.)
1330
- if (priority_ < current_priority) {
1331
- if (connectivity_state_ == GRPC_CHANNEL_READY) {
1332
- MaybeCancelFailoverTimerLocked();
1333
- // If a higher-than-current priority becomes READY, switch to use it.
1334
- xds_policy_->SwitchToHigherPriorityLocked(priority_);
1335
- } else if (connectivity_state_ == GRPC_CHANNEL_TRANSIENT_FAILURE) {
1336
- // If a higher-than-current priority becomes TRANSIENT_FAILURE, only
1337
- // handle it if it's the priority that is still in failover timeout.
1338
- if (failover_timer_callback_pending_) {
1339
- MaybeCancelFailoverTimerLocked();
1340
- xds_policy_->FailoverOnConnectionFailureLocked();
1341
- }
1342
- }
1343
- return;
1344
- }
1345
- // Update is for current priority.
1346
- if (connectivity_state_ != GRPC_CHANNEL_READY) {
1347
- // Fail over if it's no longer READY.
1348
- xds_policy_->FailoverOnDisconnectionLocked(priority_);
1349
- }
1350
- // At this point, one of the following things has happened to the current
1351
- // priority.
1352
- // 1. It remained the same (but received picker update from its localities).
1353
- // 2. It changed to a lower priority due to failover.
1354
- // 3. It became invalid because failover didn't yield a READY priority.
1355
- // In any case, update the xds picker.
1356
- xds_policy_->UpdateXdsPickerLocked();
1357
- }
1358
-
1359
- void XdsLb::LocalityMap::UpdateConnectivityStateLocked() {
1360
- size_t num_ready = 0;
1361
- size_t num_connecting = 0;
1362
- size_t num_idle = 0;
1363
- size_t num_transient_failures = 0;
1364
- for (const auto& p : localities_) {
1365
- const auto& locality_name = p.first;
1366
- const Locality* locality = p.second.get();
1367
- // Skip the localities that are not in the latest locality map update.
1368
- if (!locality_map_update()->Contains(locality_name)) continue;
1369
- switch (locality->connectivity_state()) {
1370
- case GRPC_CHANNEL_READY: {
1371
- ++num_ready;
1372
- break;
1373
- }
1374
- case GRPC_CHANNEL_CONNECTING: {
1375
- ++num_connecting;
1376
- break;
1377
- }
1378
- case GRPC_CHANNEL_IDLE: {
1379
- ++num_idle;
1380
- break;
1381
- }
1382
- case GRPC_CHANNEL_TRANSIENT_FAILURE: {
1383
- ++num_transient_failures;
1384
- break;
1385
- }
1386
- default:
1387
- GPR_UNREACHABLE_CODE(return );
1388
- }
1389
- }
1390
- if (num_ready > 0) {
1391
- connectivity_state_ = GRPC_CHANNEL_READY;
1392
- } else if (num_connecting > 0) {
1393
- connectivity_state_ = GRPC_CHANNEL_CONNECTING;
1394
- } else if (num_idle > 0) {
1395
- connectivity_state_ = GRPC_CHANNEL_IDLE;
1396
- } else {
1397
- connectivity_state_ = GRPC_CHANNEL_TRANSIENT_FAILURE;
1398
- }
1399
- if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_xds_trace)) {
1400
- gpr_log(GPR_INFO,
1401
- "[xdslb %p] Priority %" PRIu32 " (%p) connectivity changed to %s",
1402
- xds_policy(), priority_, this,
1403
- ConnectivityStateName(connectivity_state_));
1404
- }
1405
- }
1406
-
1407
- void XdsLb::LocalityMap::OnDelayedRemovalTimer(void* arg, grpc_error* error) {
1408
- LocalityMap* self = static_cast<LocalityMap*>(arg);
1409
- self->xds_policy_->combiner()->Run(
1410
- GRPC_CLOSURE_INIT(&self->on_delayed_removal_timer_,
1411
- OnDelayedRemovalTimerLocked, self, nullptr),
1412
- GRPC_ERROR_REF(error));
1413
- }
1414
-
1415
- void XdsLb::LocalityMap::OnDelayedRemovalTimerLocked(void* arg,
1416
- grpc_error* error) {
1417
- LocalityMap* self = static_cast<LocalityMap*>(arg);
1418
- self->delayed_removal_timer_callback_pending_ = false;
1419
- if (error == GRPC_ERROR_NONE && !self->xds_policy_->shutting_down_) {
1420
- const bool keep = self->priority_list_update().Contains(self->priority_) &&
1421
- self->priority_ <= self->xds_policy_->current_priority_;
1422
- if (!keep) {
1423
- // This check is to make sure we always delete the locality maps from
1424
- // the lowest priority even if the closures of the back-to-back timers
1425
- // are not run in FIFO order.
1426
- // TODO(juanlishen): Eliminate unnecessary maintenance overhead for some
1427
- // deactivated locality maps when out-of-order closures are run.
1428
- // TODO(juanlishen): Check the timer implementation to see if this
1429
- // defense is necessary.
1430
- if (self->priority_ == self->xds_policy_->LowestPriority()) {
1431
- self->xds_policy_->priorities_.pop_back();
1432
- } else {
1433
- gpr_log(GPR_ERROR,
1434
- "[xdslb %p] Priority %" PRIu32
1435
- " is not the lowest priority (highest numeric value) but is "
1436
- "attempted to be deleted.",
1437
- self->xds_policy(), self->priority_);
1438
- }
1439
- }
1440
- }
1441
- self->Unref(DEBUG_LOCATION, "LocalityMap+timer");
1442
- }
1443
-
1444
- void XdsLb::LocalityMap::OnFailoverTimer(void* arg, grpc_error* error) {
1445
- LocalityMap* self = static_cast<LocalityMap*>(arg);
1446
- self->xds_policy_->combiner()->Run(
1447
- GRPC_CLOSURE_INIT(&self->on_failover_timer_, OnFailoverTimerLocked, self,
1448
- nullptr),
1449
- GRPC_ERROR_REF(error));
1450
- }
1451
-
1452
- void XdsLb::LocalityMap::OnFailoverTimerLocked(void* arg, grpc_error* error) {
1453
- LocalityMap* self = static_cast<LocalityMap*>(arg);
1454
- self->failover_timer_callback_pending_ = false;
1455
- if (error == GRPC_ERROR_NONE && !self->xds_policy_->shutting_down_) {
1456
- self->xds_policy_->FailoverOnConnectionFailureLocked();
1457
- }
1458
- self->Unref(DEBUG_LOCATION, "LocalityMap+OnFailoverTimerLocked");
1459
- }
1460
-
1461
- //
1462
- // XdsLb::LocalityMap::Locality
1463
- //
1464
-
1465
- XdsLb::LocalityMap::Locality::Locality(RefCountedPtr<LocalityMap> locality_map,
1466
- RefCountedPtr<XdsLocalityName> name)
1467
- : locality_map_(std::move(locality_map)), name_(std::move(name)) {
1468
- if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_xds_trace)) {
1469
- gpr_log(GPR_INFO, "[xdslb %p] created Locality %p for %s", xds_policy(),
1470
- this, name_->AsHumanReadableString());
1471
- }
1472
- // Initialize locality stats if load reporting is enabled.
1473
- UpdateLocalityStats();
1474
- }
1475
-
1476
- XdsLb::LocalityMap::Locality::~Locality() {
1477
- if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_xds_trace)) {
1478
- gpr_log(GPR_INFO, "[xdslb %p] Locality %p %s: destroying locality",
1479
- xds_policy(), this, name_->AsHumanReadableString());
1480
- }
1481
- locality_map_.reset(DEBUG_LOCATION, "Locality");
1482
- }
1483
-
1484
- void XdsLb::LocalityMap::Locality::UpdateLocalityStats() {
1485
- stats_.reset();
1486
- if (xds_policy()->config_->lrs_load_reporting_server_name().has_value()) {
1487
- stats_ = xds_policy()->xds_client()->AddClusterLocalityStats(
1488
- xds_policy()->config_->lrs_load_reporting_server_name().value(),
1489
- // TODO(roth): We currently hard-code the assumption that
1490
- // cluster name and EDS service name are the same. Fix this
1491
- // as part of refectoring this LB policy.
1492
- xds_policy()->eds_service_name(), xds_policy()->eds_service_name(),
1493
- name_);
1494
- }
1495
- }
1496
-
1497
- grpc_channel_args* XdsLb::LocalityMap::Locality::CreateChildPolicyArgsLocked(
1498
- const grpc_channel_args* args_in) {
1499
- const grpc_arg args_to_add[] = {
1500
- // A channel arg indicating if the target is a backend inferred from a
1501
- // grpclb load balancer.
1502
- grpc_channel_arg_integer_create(
1503
- const_cast<char*>(GRPC_ARG_ADDRESS_IS_BACKEND_FROM_XDS_LOAD_BALANCER),
1504
- 1),
1505
- // Inhibit client-side health checking, since the balancer does
1506
- // this for us.
1507
- grpc_channel_arg_integer_create(
1508
- const_cast<char*>(GRPC_ARG_INHIBIT_HEALTH_CHECKING), 1),
1509
- };
1510
- return grpc_channel_args_copy_and_add(args_in, args_to_add,
1511
- GPR_ARRAY_SIZE(args_to_add));
1512
- }
1513
-
1514
- OrphanablePtr<LoadBalancingPolicy>
1515
- XdsLb::LocalityMap::Locality::CreateChildPolicyLocked(
1516
- const char* name, const grpc_channel_args* args) {
1517
- Helper* helper = new Helper(this->Ref(DEBUG_LOCATION, "Helper"));
1518
- LoadBalancingPolicy::Args lb_policy_args;
1519
- lb_policy_args.combiner = xds_policy()->combiner();
1520
- lb_policy_args.args = args;
1521
- lb_policy_args.channel_control_helper =
1522
- std::unique_ptr<ChannelControlHelper>(helper);
1523
- OrphanablePtr<LoadBalancingPolicy> lb_policy =
1524
- LoadBalancingPolicyRegistry::CreateLoadBalancingPolicy(
1525
- name, std::move(lb_policy_args));
1526
- if (GPR_UNLIKELY(lb_policy == nullptr)) {
1527
- gpr_log(GPR_ERROR,
1528
- "[xdslb %p] Locality %p %s: failure creating child policy %s",
1529
- xds_policy(), this, name_->AsHumanReadableString(), name);
1530
- return nullptr;
1531
- }
1532
- helper->set_child(lb_policy.get());
1533
- if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_xds_trace)) {
1534
- gpr_log(GPR_INFO,
1535
- "[xdslb %p] Locality %p %s: Created new child policy %s (%p)",
1536
- xds_policy(), this, name_->AsHumanReadableString(), name,
1537
- lb_policy.get());
1538
- }
1539
- // Add the xDS's interested_parties pollset_set to that of the newly created
1540
- // child policy. This will make the child policy progress upon activity on
1541
- // xDS LB, which in turn is tied to the application's call.
1542
- grpc_pollset_set_add_pollset_set(lb_policy->interested_parties(),
1543
- xds_policy()->interested_parties());
1544
- return lb_policy;
1545
- }
1546
-
1547
- void XdsLb::LocalityMap::Locality::UpdateLocked(uint32_t locality_weight,
1548
- ServerAddressList serverlist,
1549
- bool update_locality_stats) {
1550
- if (xds_policy()->shutting_down_) return;
1551
- // Update locality weight.
1552
- weight_ = locality_weight;
1553
- if (delayed_removal_timer_callback_pending_) {
1554
- grpc_timer_cancel(&delayed_removal_timer_);
1555
- }
1556
- // Update locality stats.
1557
- if (update_locality_stats) UpdateLocalityStats();
1558
- // Construct update args.
1559
- UpdateArgs update_args;
1560
- update_args.addresses = std::move(serverlist);
1561
- update_args.config = xds_policy()->config_->child_policy();
1562
- update_args.args = CreateChildPolicyArgsLocked(xds_policy()->args_);
1563
- // If the child policy name changes, we need to create a new child
1564
- // policy. When this happens, we leave child_policy_ as-is and store
1565
- // the new child policy in pending_child_policy_. Once the new child
1566
- // policy transitions into state READY, we swap it into child_policy_,
1567
- // replacing the original child policy. So pending_child_policy_ is
1568
- // non-null only between when we apply an update that changes the child
1569
- // policy name and when the new child reports state READY.
1570
- //
1571
- // Updates can arrive at any point during this transition. We always
1572
- // apply updates relative to the most recently created child policy,
1573
- // even if the most recent one is still in pending_child_policy_. This
1574
- // is true both when applying the updates to an existing child policy
1575
- // and when determining whether we need to create a new policy.
1576
- //
1577
- // As a result of this, there are several cases to consider here:
1578
- //
1579
- // 1. We have no existing child policy (i.e., we have started up but
1580
- // have not yet received a serverlist from the balancer or gone
1581
- // into fallback mode; in this case, both child_policy_ and
1582
- // pending_child_policy_ are null). In this case, we create a
1583
- // new child policy and store it in child_policy_.
1584
- //
1585
- // 2. We have an existing child policy and have no pending child policy
1586
- // from a previous update (i.e., either there has not been a
1587
- // previous update that changed the policy name, or we have already
1588
- // finished swapping in the new policy; in this case, child_policy_
1589
- // is non-null but pending_child_policy_ is null). In this case:
1590
- // a. If child_policy_->name() equals child_policy_name, then we
1591
- // update the existing child policy.
1592
- // b. If child_policy_->name() does not equal child_policy_name,
1593
- // we create a new policy. The policy will be stored in
1594
- // pending_child_policy_ and will later be swapped into
1595
- // child_policy_ by the helper when the new child transitions
1596
- // into state READY.
1597
- //
1598
- // 3. We have an existing child policy and have a pending child policy
1599
- // from a previous update (i.e., a previous update set
1600
- // pending_child_policy_ as per case 2b above and that policy has
1601
- // not yet transitioned into state READY and been swapped into
1602
- // child_policy_; in this case, both child_policy_ and
1603
- // pending_child_policy_ are non-null). In this case:
1604
- // a. If pending_child_policy_->name() equals child_policy_name,
1605
- // then we update the existing pending child policy.
1606
- // b. If pending_child_policy->name() does not equal
1607
- // child_policy_name, then we create a new policy. The new
1608
- // policy is stored in pending_child_policy_ (replacing the one
1609
- // that was there before, which will be immediately shut down)
1610
- // and will later be swapped into child_policy_ by the helper
1611
- // when the new child transitions into state READY.
1612
- // TODO(juanlishen): If the child policy is not configured via service config,
1613
- // use whatever algorithm is specified by the balancer.
1614
- const char* child_policy_name = update_args.config == nullptr
1615
- ? "round_robin"
1616
- : update_args.config->name();
1617
- const bool create_policy =
1618
- // case 1
1619
- child_policy_ == nullptr ||
1620
- // case 2b
1621
- (pending_child_policy_ == nullptr &&
1622
- strcmp(child_policy_->name(), child_policy_name) != 0) ||
1623
- // case 3b
1624
- (pending_child_policy_ != nullptr &&
1625
- strcmp(pending_child_policy_->name(), child_policy_name) != 0);
1626
- LoadBalancingPolicy* policy_to_update = nullptr;
1627
- if (create_policy) {
1628
- // Cases 1, 2b, and 3b: create a new child policy.
1629
- // If child_policy_ is null, we set it (case 1), else we set
1630
- // pending_child_policy_ (cases 2b and 3b).
1631
- if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_xds_trace)) {
1632
- gpr_log(GPR_INFO,
1633
- "[xdslb %p] Locality %p %s: Creating new %schild policy %s",
1634
- xds_policy(), this, name_->AsHumanReadableString(),
1635
- child_policy_ == nullptr ? "" : "pending ", child_policy_name);
1636
- }
1637
- auto& lb_policy =
1638
- child_policy_ == nullptr ? child_policy_ : pending_child_policy_;
1639
- lb_policy = CreateChildPolicyLocked(child_policy_name, update_args.args);
1640
- policy_to_update = lb_policy.get();
1641
- } else {
1642
- // Cases 2a and 3a: update an existing policy.
1643
- // If we have a pending child policy, send the update to the pending
1644
- // policy (case 3a), else send it to the current policy (case 2a).
1645
- policy_to_update = pending_child_policy_ != nullptr
1646
- ? pending_child_policy_.get()
1647
- : child_policy_.get();
1648
- }
1649
- GPR_ASSERT(policy_to_update != nullptr);
1650
- // Update the policy.
1651
- if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_xds_trace)) {
1652
- gpr_log(GPR_INFO, "[xdslb %p] Locality %p %s: Updating %schild policy %p",
1653
- xds_policy(), this, name_->AsHumanReadableString(),
1654
- policy_to_update == pending_child_policy_.get() ? "pending " : "",
1655
- policy_to_update);
1656
- }
1657
- policy_to_update->UpdateLocked(std::move(update_args));
1658
- }
1659
-
1660
- void XdsLb::LocalityMap::Locality::ShutdownLocked() {
1661
- if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_xds_trace)) {
1662
- gpr_log(GPR_INFO, "[xdslb %p] Locality %p %s: shutting down locality",
1663
- xds_policy(), this, name_->AsHumanReadableString());
1664
- }
1665
- stats_.reset();
1666
- // Remove the child policy's interested_parties pollset_set from the
1667
- // xDS policy.
1668
- grpc_pollset_set_del_pollset_set(child_policy_->interested_parties(),
1669
- xds_policy()->interested_parties());
1670
- child_policy_.reset();
1671
- if (pending_child_policy_ != nullptr) {
1672
- grpc_pollset_set_del_pollset_set(
1673
- pending_child_policy_->interested_parties(),
1674
- xds_policy()->interested_parties());
1675
- pending_child_policy_.reset();
1676
- }
1677
- // Drop our ref to the child's picker, in case it's holding a ref to
1678
- // the child.
1679
- load_reporting_picker_.reset();
1680
- picker_wrapper_.reset();
1681
- if (delayed_removal_timer_callback_pending_) {
1682
- grpc_timer_cancel(&delayed_removal_timer_);
1683
- }
1684
- shutdown_ = true;
1685
- }
1686
-
1687
- void XdsLb::LocalityMap::Locality::ResetBackoffLocked() {
1688
- child_policy_->ResetBackoffLocked();
1689
- if (pending_child_policy_ != nullptr) {
1690
- pending_child_policy_->ResetBackoffLocked();
1691
- }
1692
- }
1693
-
1694
- void XdsLb::LocalityMap::Locality::Orphan() {
1695
- ShutdownLocked();
1696
- Unref();
1697
- }
1698
-
1699
- void XdsLb::LocalityMap::Locality::DeactivateLocked() {
1700
- // If already deactivated, don't do that again.
1701
- if (weight_ == 0) return;
1702
- // Set the locality weight to 0 so that future xds picker won't contain this
1703
- // locality.
1704
- weight_ = 0;
1705
- // Start a timer to delete the locality.
1706
- Ref(DEBUG_LOCATION, "Locality+timer").release();
1707
- GRPC_CLOSURE_INIT(&on_delayed_removal_timer_, OnDelayedRemovalTimer, this,
1708
- grpc_schedule_on_exec_ctx);
1709
- grpc_timer_init(
1710
- &delayed_removal_timer_,
1711
- ExecCtx::Get()->Now() + xds_policy()->locality_retention_interval_ms_,
1712
- &on_delayed_removal_timer_);
1713
- delayed_removal_timer_callback_pending_ = true;
1714
- }
1715
-
1716
- void XdsLb::LocalityMap::Locality::OnDelayedRemovalTimer(void* arg,
1717
- grpc_error* error) {
1718
- Locality* self = static_cast<Locality*>(arg);
1719
- self->xds_policy()->combiner()->Run(
1720
- GRPC_CLOSURE_INIT(&self->on_delayed_removal_timer_,
1721
- OnDelayedRemovalTimerLocked, self, nullptr),
1722
- GRPC_ERROR_REF(error));
1723
- }
1724
-
1725
- void XdsLb::LocalityMap::Locality::OnDelayedRemovalTimerLocked(
1726
- void* arg, grpc_error* error) {
1727
- Locality* self = static_cast<Locality*>(arg);
1728
- self->delayed_removal_timer_callback_pending_ = false;
1729
- if (error == GRPC_ERROR_NONE && !self->shutdown_ && self->weight_ == 0) {
1730
- self->locality_map_->localities_.erase(self->name_);
1731
- }
1732
- self->Unref(DEBUG_LOCATION, "Locality+timer");
1733
- }
1734
-
1735
- //
1736
- // XdsLb::LocalityMap::Locality::Helper
1737
- //
1738
-
1739
- bool XdsLb::LocalityMap::Locality::Helper::CalledByPendingChild() const {
1740
- GPR_ASSERT(child_ != nullptr);
1741
- return child_ == locality_->pending_child_policy_.get();
1742
- }
1743
-
1744
- bool XdsLb::LocalityMap::Locality::Helper::CalledByCurrentChild() const {
1745
- GPR_ASSERT(child_ != nullptr);
1746
- return child_ == locality_->child_policy_.get();
1747
- }
1748
-
1749
- RefCountedPtr<SubchannelInterface>
1750
- XdsLb::LocalityMap::Locality::Helper::CreateSubchannel(
1751
- const grpc_channel_args& args) {
1752
- if (locality_->xds_policy()->shutting_down_ ||
1753
- (!CalledByPendingChild() && !CalledByCurrentChild())) {
1754
- return nullptr;
1755
- }
1756
- return locality_->xds_policy()->channel_control_helper()->CreateSubchannel(
1757
- args);
1758
- }
1759
-
1760
- void XdsLb::LocalityMap::Locality::Helper::UpdateState(
1761
- grpc_connectivity_state state, std::unique_ptr<SubchannelPicker> picker) {
1762
- if (locality_->xds_policy()->shutting_down_) return;
1763
- // If this request is from the pending child policy, ignore it until
1764
- // it reports READY, at which point we swap it into place.
1765
- if (CalledByPendingChild()) {
1766
- if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_xds_trace)) {
1767
- gpr_log(GPR_INFO,
1768
- "[xdslb %p helper %p] pending child policy %p reports state=%s",
1769
- locality_->xds_policy(), this,
1770
- locality_->pending_child_policy_.get(),
1771
- ConnectivityStateName(state));
1772
- }
1773
- if (state != GRPC_CHANNEL_READY) return;
1774
- grpc_pollset_set_del_pollset_set(
1775
- locality_->child_policy_->interested_parties(),
1776
- locality_->xds_policy()->interested_parties());
1777
- locality_->child_policy_ = std::move(locality_->pending_child_policy_);
1778
- } else if (!CalledByCurrentChild()) {
1779
- // This request is from an outdated child, so ignore it.
1780
- return;
1781
- }
1782
- // Cache the state and picker in the locality.
1783
- locality_->connectivity_state_ = state;
1784
- locality_->picker_wrapper_ =
1785
- MakeRefCounted<RefCountedEndpointPicker>(std::move(picker));
1786
- // Notify the locality map.
1787
- locality_->locality_map_->OnLocalityStateUpdateLocked();
1788
- }
1789
-
1790
- void XdsLb::LocalityMap::Locality::Helper::AddTraceEvent(TraceSeverity severity,
1791
- StringView message) {
1792
- if (locality_->xds_policy()->shutting_down_ ||
1793
- (!CalledByPendingChild() && !CalledByCurrentChild())) {
1794
- return;
1795
- }
1796
- locality_->xds_policy()->channel_control_helper()->AddTraceEvent(severity,
1797
- message);
1798
- }
1799
-
1800
- //
1801
- // factory
1802
- //
1803
-
1804
- class XdsFactory : public LoadBalancingPolicyFactory {
1805
- public:
1806
- OrphanablePtr<LoadBalancingPolicy> CreateLoadBalancingPolicy(
1807
- LoadBalancingPolicy::Args args) const override {
1808
- return MakeOrphanable<XdsLb>(std::move(args));
1809
- }
1810
-
1811
- const char* name() const override { return kXds; }
1812
-
1813
- RefCountedPtr<LoadBalancingPolicy::Config> ParseLoadBalancingConfig(
1814
- const Json& json, grpc_error** error) const override {
1815
- GPR_DEBUG_ASSERT(error != nullptr && *error == GRPC_ERROR_NONE);
1816
- if (json.type() == Json::Type::JSON_NULL) {
1817
- // xds was mentioned as a policy in the deprecated loadBalancingPolicy
1818
- // field or in the client API.
1819
- *error = GRPC_ERROR_CREATE_FROM_STATIC_STRING(
1820
- "field:loadBalancingPolicy error:xds policy requires configuration. "
1821
- "Please use loadBalancingConfig field of service config instead.");
1822
- return nullptr;
1823
- }
1824
- std::vector<grpc_error*> error_list;
1825
- // Child policy.
1826
- RefCountedPtr<LoadBalancingPolicy::Config> child_policy;
1827
- auto it = json.object_value().find("childPolicy");
1828
- if (it != json.object_value().end()) {
1829
- grpc_error* parse_error = GRPC_ERROR_NONE;
1830
- child_policy = LoadBalancingPolicyRegistry::ParseLoadBalancingConfig(
1831
- it->second, &parse_error);
1832
- if (child_policy == nullptr) {
1833
- GPR_DEBUG_ASSERT(parse_error != GRPC_ERROR_NONE);
1834
- std::vector<grpc_error*> child_errors;
1835
- child_errors.push_back(parse_error);
1836
- error_list.push_back(
1837
- GRPC_ERROR_CREATE_FROM_VECTOR("field:childPolicy", &child_errors));
1838
- }
1839
- }
1840
- // Fallback policy.
1841
- RefCountedPtr<LoadBalancingPolicy::Config> fallback_policy;
1842
- it = json.object_value().find("fallbackPolicy");
1843
- if (it != json.object_value().end()) {
1844
- grpc_error* parse_error = GRPC_ERROR_NONE;
1845
- fallback_policy = LoadBalancingPolicyRegistry::ParseLoadBalancingConfig(
1846
- it->second, &parse_error);
1847
- if (fallback_policy == nullptr) {
1848
- GPR_DEBUG_ASSERT(parse_error != GRPC_ERROR_NONE);
1849
- std::vector<grpc_error*> child_errors;
1850
- child_errors.push_back(parse_error);
1851
- error_list.push_back(GRPC_ERROR_CREATE_FROM_VECTOR(
1852
- "field:fallbackPolicy", &child_errors));
1853
- }
1854
- }
1855
- // EDS service name.
1856
- const char* eds_service_name = nullptr;
1857
- it = json.object_value().find("edsServiceName");
1858
- if (it != json.object_value().end()) {
1859
- if (it->second.type() != Json::Type::STRING) {
1860
- error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
1861
- "field:edsServiceName error:type should be string"));
1862
- } else {
1863
- eds_service_name = it->second.string_value().c_str();
1864
- }
1865
- }
1866
- // LRS load reporting server name.
1867
- const char* lrs_load_reporting_server_name = nullptr;
1868
- it = json.object_value().find("lrsLoadReportingServerName");
1869
- if (it != json.object_value().end()) {
1870
- if (it->second.type() != Json::Type::STRING) {
1871
- error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
1872
- "field:lrsLoadReportingServerName error:type should be string"));
1873
- } else {
1874
- lrs_load_reporting_server_name = it->second.string_value().c_str();
1875
- }
1876
- }
1877
- if (error_list.empty()) {
1878
- Optional<std::string> optional_lrs_load_reporting_server_name;
1879
- if (lrs_load_reporting_server_name != nullptr) {
1880
- optional_lrs_load_reporting_server_name.emplace(
1881
- std::string(lrs_load_reporting_server_name));
1882
- }
1883
- return MakeRefCounted<XdsConfig>(
1884
- std::move(child_policy), std::move(fallback_policy),
1885
- eds_service_name == nullptr ? "" : eds_service_name,
1886
- std::move(optional_lrs_load_reporting_server_name));
1887
- } else {
1888
- *error = GRPC_ERROR_CREATE_FROM_VECTOR("Xds Parser", &error_list);
1889
- return nullptr;
1890
- }
1891
- }
1892
- };
1893
-
1894
- } // namespace
1895
-
1896
- } // namespace grpc_core
1897
-
1898
- //
1899
- // Plugin registration
1900
- //
1901
-
1902
- void grpc_lb_policy_xds_init() {
1903
- grpc_core::LoadBalancingPolicyRegistry::Builder::
1904
- RegisterLoadBalancingPolicyFactory(
1905
- absl::make_unique<grpc_core::XdsFactory>());
1906
- }
1907
-
1908
- void grpc_lb_policy_xds_shutdown() {}