grpc 1.49.0.pre1-x86_64-linux → 1.50.0.pre1-x86_64-linux

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 (277) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +54 -153
  3. data/include/grpc/event_engine/endpoint_config.h +11 -5
  4. data/include/grpc/event_engine/event_engine.h +1 -1
  5. data/include/grpc/impl/codegen/atm_gcc_atomic.h +19 -28
  6. data/include/grpc/impl/codegen/atm_gcc_sync.h +0 -2
  7. data/include/grpc/impl/codegen/atm_windows.h +0 -2
  8. data/include/grpc/impl/codegen/grpc_types.h +6 -0
  9. data/src/core/ext/filters/channel_idle/channel_idle_filter.cc +3 -3
  10. data/src/core/ext/filters/client_channel/backup_poller.cc +4 -6
  11. data/src/core/ext/filters/client_channel/client_channel.cc +41 -22
  12. data/src/core/ext/filters/client_channel/client_channel.h +1 -1
  13. data/src/core/ext/filters/client_channel/client_channel_plugin.cc +0 -16
  14. data/src/core/ext/filters/client_channel/http_proxy.cc +12 -19
  15. data/src/core/ext/filters/client_channel/http_proxy.h +3 -2
  16. data/src/core/ext/filters/client_channel/lb_policy/child_policy_handler.cc +6 -4
  17. data/src/core/ext/filters/client_channel/lb_policy/child_policy_handler.h +5 -4
  18. data/src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.cc +0 -2
  19. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +114 -103
  20. data/src/core/ext/filters/client_channel/lb_policy/oob_backend_metric.cc +20 -11
  21. data/src/core/ext/filters/client_channel/lb_policy/outlier_detection/outlier_detection.cc +106 -108
  22. data/src/core/ext/filters/client_channel/lb_policy/outlier_detection/outlier_detection.h +16 -0
  23. data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc +20 -13
  24. data/src/core/ext/filters/client_channel/lb_policy/priority/priority.cc +165 -257
  25. data/src/core/ext/filters/client_channel/lb_policy/ring_hash/ring_hash.cc +218 -231
  26. data/src/core/ext/filters/client_channel/lb_policy/ring_hash/ring_hash.h +10 -6
  27. data/src/core/ext/filters/client_channel/lb_policy/rls/rls.cc +389 -444
  28. data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc +16 -16
  29. data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +8 -13
  30. data/src/core/ext/filters/client_channel/lb_policy/weighted_target/weighted_target.cc +87 -96
  31. data/src/core/ext/filters/client_channel/lb_policy/xds/cds.cc +38 -37
  32. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_impl.cc +106 -186
  33. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_manager.cc +106 -93
  34. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_resolver.cc +170 -218
  35. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc +2 -2
  36. data/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc +1 -1
  37. data/src/core/ext/filters/client_channel/resolver/google_c2p/google_c2p_resolver.cc +38 -18
  38. data/src/core/ext/filters/client_channel/resolver/polling_resolver.cc +84 -37
  39. data/src/core/ext/filters/client_channel/resolver/polling_resolver.h +11 -0
  40. data/src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.cc +1 -0
  41. data/src/core/ext/filters/client_channel/resolver/xds/xds_resolver.cc +5 -3
  42. data/src/core/ext/filters/client_channel/resolver_result_parsing.cc +5 -4
  43. data/src/core/ext/filters/client_channel/retry_filter.cc +25 -29
  44. data/src/core/ext/filters/client_channel/subchannel.cc +38 -33
  45. data/src/core/ext/filters/client_channel/subchannel.h +12 -3
  46. data/src/core/ext/filters/client_channel/subchannel_stream_client.cc +1 -2
  47. data/src/core/ext/filters/fault_injection/fault_injection_filter.cc +23 -16
  48. data/src/core/ext/filters/fault_injection/fault_injection_filter.h +8 -0
  49. data/src/core/ext/filters/http/client/http_client_filter.cc +1 -2
  50. data/src/core/ext/filters/http/message_compress/message_compress_filter.cc +2 -4
  51. data/src/core/ext/filters/http/message_compress/message_decompress_filter.cc +0 -2
  52. data/src/core/ext/filters/http/server/http_server_filter.cc +1 -2
  53. data/src/core/ext/transport/chttp2/client/chttp2_connector.cc +12 -8
  54. data/src/core/ext/transport/chttp2/server/chttp2_server.cc +32 -26
  55. data/src/core/ext/transport/chttp2/transport/bin_encoder.cc +1 -1
  56. data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +25 -130
  57. data/src/core/ext/transport/chttp2/transport/decode_huff.cc +287 -0
  58. data/src/core/ext/transport/chttp2/transport/decode_huff.h +1018 -0
  59. data/src/core/ext/transport/chttp2/transport/flow_control.cc +83 -51
  60. data/src/core/ext/transport/chttp2/transport/flow_control.h +11 -6
  61. data/src/core/ext/transport/chttp2/transport/frame_ping.cc +1 -2
  62. data/src/core/ext/transport/chttp2/transport/hpack_encoder.cc +2 -20
  63. data/src/core/ext/transport/chttp2/transport/hpack_parser.cc +28 -28
  64. data/src/core/ext/transport/chttp2/transport/hpack_parser_table.cc +1 -10
  65. data/src/core/ext/transport/chttp2/transport/hpack_parser_table.h +11 -6
  66. data/src/core/ext/transport/chttp2/transport/internal.h +2 -0
  67. data/src/core/ext/transport/chttp2/transport/parsing.cc +44 -0
  68. data/src/core/ext/transport/chttp2/transport/writing.cc +3 -14
  69. data/src/core/ext/transport/inproc/inproc_transport.cc +1 -3
  70. data/src/core/ext/xds/certificate_provider_store.cc +63 -3
  71. data/src/core/ext/xds/certificate_provider_store.h +9 -1
  72. data/src/core/ext/xds/file_watcher_certificate_provider_factory.cc +5 -5
  73. data/src/core/ext/xds/file_watcher_certificate_provider_factory.h +1 -1
  74. data/src/core/ext/xds/xds_api.cc +21 -17
  75. data/src/core/ext/xds/xds_api.h +7 -0
  76. data/src/core/ext/xds/xds_bootstrap.cc +5 -537
  77. data/src/core/ext/xds/xds_bootstrap.h +39 -111
  78. data/src/core/ext/xds/xds_bootstrap_grpc.cc +370 -0
  79. data/src/core/ext/xds/xds_bootstrap_grpc.h +169 -0
  80. data/src/core/ext/xds/xds_client.cc +219 -145
  81. data/src/core/ext/xds/xds_client.h +19 -17
  82. data/src/core/ext/xds/xds_client_grpc.cc +18 -80
  83. data/src/core/ext/xds/xds_client_grpc.h +2 -25
  84. data/src/core/ext/xds/xds_client_stats.cc +4 -4
  85. data/src/core/ext/xds/xds_cluster.cc +87 -79
  86. data/src/core/ext/xds/xds_cluster.h +5 -5
  87. data/src/core/ext/xds/xds_cluster_specifier_plugin.cc +3 -1
  88. data/src/core/ext/xds/xds_common_types.cc +13 -5
  89. data/src/core/ext/xds/xds_endpoint.cc +8 -6
  90. data/src/core/ext/xds/xds_endpoint.h +3 -4
  91. data/src/core/ext/xds/xds_lb_policy_registry.cc +4 -2
  92. data/src/core/ext/xds/xds_listener.cc +25 -20
  93. data/src/core/ext/xds/xds_listener.h +3 -4
  94. data/src/core/ext/xds/xds_resource_type.h +11 -8
  95. data/src/core/ext/xds/xds_route_config.cc +15 -16
  96. data/src/core/ext/xds/xds_route_config.h +3 -3
  97. data/src/core/ext/xds/xds_server_config_fetcher.cc +7 -5
  98. data/src/core/ext/xds/xds_transport_grpc.cc +15 -7
  99. data/src/core/lib/backoff/backoff.cc +2 -4
  100. data/src/core/lib/channel/call_finalization.h +1 -3
  101. data/src/core/lib/channel/channel_args.h +114 -14
  102. data/src/core/lib/channel/channel_trace.cc +3 -4
  103. data/src/core/lib/channel/promise_based_filter.cc +18 -19
  104. data/src/core/lib/channel/status_util.cc +27 -0
  105. data/src/core/lib/channel/status_util.h +10 -0
  106. data/src/core/lib/config/core_configuration.cc +5 -1
  107. data/src/core/lib/config/core_configuration.h +33 -0
  108. data/src/core/lib/debug/stats.cc +26 -30
  109. data/src/core/lib/debug/stats.h +2 -12
  110. data/src/core/lib/debug/stats_data.cc +118 -614
  111. data/src/core/lib/debug/stats_data.h +67 -465
  112. data/src/core/lib/debug/trace.cc +0 -2
  113. data/src/core/lib/event_engine/channel_args_endpoint_config.cc +12 -20
  114. data/src/core/lib/event_engine/channel_args_endpoint_config.h +13 -7
  115. data/src/core/lib/event_engine/forkable.cc +19 -16
  116. data/src/core/lib/event_engine/poller.h +14 -12
  117. data/src/core/lib/event_engine/posix_engine/timer_manager.cc +53 -32
  118. data/src/core/lib/event_engine/posix_engine/timer_manager.h +23 -1
  119. data/src/core/lib/event_engine/thread_pool.cc +131 -94
  120. data/src/core/lib/event_engine/thread_pool.h +56 -23
  121. data/src/core/lib/event_engine/time_util.cc +30 -0
  122. data/src/core/lib/event_engine/time_util.h +32 -0
  123. data/src/core/lib/event_engine/utils.cc +0 -5
  124. data/src/core/lib/event_engine/utils.h +0 -4
  125. data/src/core/lib/event_engine/windows/iocp.cc +13 -7
  126. data/src/core/lib/event_engine/windows/iocp.h +2 -1
  127. data/src/core/lib/event_engine/windows/win_socket.cc +1 -1
  128. data/src/core/lib/experiments/config.cc +146 -0
  129. data/src/core/lib/experiments/config.h +43 -0
  130. data/src/core/lib/experiments/experiments.cc +75 -0
  131. data/src/core/lib/experiments/experiments.h +56 -0
  132. data/src/core/lib/gpr/alloc.cc +1 -9
  133. data/src/core/lib/gpr/log_windows.cc +0 -1
  134. data/src/core/lib/gpr/string_util_windows.cc +3 -30
  135. data/src/core/lib/gpr/sync_abseil.cc +0 -14
  136. data/src/core/lib/gpr/sync_posix.cc +0 -14
  137. data/src/core/lib/gpr/time_posix.cc +0 -6
  138. data/src/core/lib/gpr/time_precise.h +1 -1
  139. data/src/core/lib/gpr/tmpfile_windows.cc +5 -7
  140. data/src/core/lib/gpr/useful.h +11 -0
  141. data/src/core/lib/{gpr → gprpp}/env.h +25 -12
  142. data/src/core/lib/{gpr → gprpp}/env_linux.cc +20 -15
  143. data/src/core/lib/{gpr → gprpp}/env_posix.cc +11 -10
  144. data/src/core/lib/gprpp/env_windows.cc +56 -0
  145. data/src/core/lib/gprpp/fork.cc +14 -22
  146. data/src/core/lib/gprpp/fork.h +0 -8
  147. data/src/core/lib/gprpp/global_config_env.cc +7 -6
  148. data/src/core/lib/gprpp/notification.h +67 -0
  149. data/src/core/lib/gprpp/packed_table.h +40 -0
  150. data/src/core/lib/gprpp/ref_counted_ptr.h +20 -33
  151. data/src/core/lib/gprpp/sorted_pack.h +98 -0
  152. data/src/core/lib/gprpp/status_helper.h +6 -0
  153. data/src/core/lib/gprpp/table.h +9 -1
  154. data/src/core/lib/gprpp/tchar.cc +49 -0
  155. data/src/core/lib/gprpp/tchar.h +33 -0
  156. data/src/core/lib/gprpp/time.cc +21 -0
  157. data/src/core/lib/gprpp/time.h +55 -0
  158. data/src/core/lib/gprpp/validation_errors.cc +61 -0
  159. data/src/core/lib/gprpp/validation_errors.h +110 -0
  160. data/src/core/{ext/filters/client_channel → lib/handshaker}/proxy_mapper.h +3 -3
  161. data/src/core/{ext/filters/client_channel → lib/handshaker}/proxy_mapper_registry.cc +14 -36
  162. data/src/core/lib/handshaker/proxy_mapper_registry.h +75 -0
  163. data/src/core/lib/iomgr/call_combiner.cc +0 -8
  164. data/src/core/lib/iomgr/closure.h +0 -1
  165. data/src/core/lib/iomgr/endpoint_pair_posix.cc +14 -10
  166. data/src/core/lib/iomgr/endpoint_pair_windows.cc +2 -2
  167. data/src/core/lib/iomgr/ev_epoll1_linux.cc +1 -38
  168. data/src/core/lib/iomgr/ev_poll_posix.cc +2 -17
  169. data/src/core/lib/iomgr/exec_ctx.cc +0 -10
  170. data/src/core/lib/iomgr/exec_ctx.h +7 -31
  171. data/src/core/lib/iomgr/iocp_windows.cc +1 -2
  172. data/src/core/lib/iomgr/iomgr.cc +6 -8
  173. data/src/core/lib/iomgr/iomgr_fwd.h +1 -0
  174. data/src/core/lib/iomgr/pollset.h +1 -1
  175. data/src/core/lib/iomgr/pollset_set.h +0 -1
  176. data/src/core/lib/iomgr/resolve_address.h +1 -0
  177. data/src/core/lib/iomgr/resolve_address_impl.h +1 -0
  178. data/src/core/lib/iomgr/resolve_address_posix.cc +5 -0
  179. data/src/core/lib/iomgr/resolve_address_windows.cc +5 -0
  180. data/src/core/lib/iomgr/sockaddr_utils_posix.cc +2 -1
  181. data/src/core/lib/iomgr/socket_utils_common_posix.cc +12 -34
  182. data/src/core/lib/iomgr/socket_utils_posix.cc +83 -1
  183. data/src/core/lib/iomgr/socket_utils_posix.h +98 -6
  184. data/src/core/lib/iomgr/tcp_client.cc +6 -7
  185. data/src/core/lib/iomgr/tcp_client.h +11 -11
  186. data/src/core/lib/iomgr/tcp_client_cfstream.cc +6 -6
  187. data/src/core/lib/iomgr/tcp_client_posix.cc +33 -29
  188. data/src/core/lib/iomgr/tcp_client_posix.h +12 -9
  189. data/src/core/lib/iomgr/tcp_client_windows.cc +6 -6
  190. data/src/core/lib/iomgr/tcp_posix.cc +131 -114
  191. data/src/core/lib/iomgr/tcp_posix.h +3 -1
  192. data/src/core/lib/iomgr/tcp_server.cc +5 -4
  193. data/src/core/lib/iomgr/tcp_server.h +9 -6
  194. data/src/core/lib/iomgr/tcp_server_posix.cc +17 -28
  195. data/src/core/lib/iomgr/tcp_server_utils_posix.h +2 -2
  196. data/src/core/lib/iomgr/tcp_server_utils_posix_common.cc +3 -3
  197. data/src/core/lib/iomgr/tcp_server_windows.cc +6 -7
  198. data/src/core/lib/iomgr/tcp_windows.cc +0 -1
  199. data/src/core/lib/iomgr/tcp_windows.h +0 -1
  200. data/src/core/lib/iomgr/timer_generic.cc +4 -4
  201. data/src/core/lib/iomgr/timer_manager.cc +1 -2
  202. data/src/core/lib/iomgr/wakeup_fd_eventfd.cc +0 -2
  203. data/src/core/lib/json/json_object_loader.cc +21 -52
  204. data/src/core/lib/json/json_object_loader.h +56 -76
  205. data/src/core/lib/json/json_util.cc +2 -1
  206. data/src/core/lib/load_balancing/lb_policy.h +5 -5
  207. data/src/core/lib/load_balancing/lb_policy_registry.cc +29 -55
  208. data/src/core/lib/load_balancing/lb_policy_registry.h +23 -11
  209. data/src/core/lib/promise/activity.h +2 -3
  210. data/src/core/lib/promise/context.h +1 -1
  211. data/src/core/lib/promise/sleep.cc +16 -4
  212. data/src/core/lib/promise/sleep.h +8 -2
  213. data/src/core/lib/resolver/resolver.h +13 -3
  214. data/src/core/lib/resource_quota/api.cc +9 -0
  215. data/src/core/lib/resource_quota/api.h +6 -0
  216. data/src/core/lib/resource_quota/arena.cc +1 -3
  217. data/src/core/lib/resource_quota/memory_quota.cc +8 -24
  218. data/src/core/lib/resource_quota/memory_quota.h +6 -19
  219. data/src/core/lib/resource_quota/periodic_update.cc +2 -3
  220. data/src/core/{ext/xds → lib/security/certificate_provider}/certificate_provider_factory.h +3 -3
  221. data/src/core/lib/security/certificate_provider/certificate_provider_registry.cc +60 -0
  222. data/src/core/lib/security/certificate_provider/certificate_provider_registry.h +70 -0
  223. data/src/core/lib/security/credentials/channel_creds_registry_init.cc +1 -0
  224. data/src/core/lib/security/credentials/external/aws_external_account_credentials.cc +15 -16
  225. data/src/core/lib/security/credentials/external/external_account_credentials.cc +2 -1
  226. data/src/core/lib/security/credentials/google_default/credentials_generic.cc +5 -8
  227. data/src/core/lib/security/credentials/google_default/google_default_credentials.cc +6 -6
  228. data/src/core/lib/security/credentials/jwt/jwt_verifier.cc +3 -2
  229. data/src/core/lib/security/credentials/jwt/jwt_verifier.h +1 -1
  230. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc +1 -2
  231. data/src/core/lib/security/credentials/tls/grpc_tls_certificate_provider.cc +4 -3
  232. data/src/core/lib/security/credentials/tls/grpc_tls_certificate_provider.h +4 -2
  233. data/src/core/lib/security/credentials/tls/tls_utils.cc +3 -1
  234. data/src/core/lib/security/transport/client_auth_filter.cc +12 -1
  235. data/src/core/lib/security/transport/secure_endpoint.cc +0 -4
  236. data/src/core/lib/surface/call.cc +1 -11
  237. data/src/core/lib/surface/channel.cc +3 -2
  238. data/src/core/lib/surface/completion_queue.cc +16 -28
  239. data/src/core/lib/surface/completion_queue.h +1 -1
  240. data/src/core/lib/surface/completion_queue_factory.cc +5 -0
  241. data/src/core/lib/surface/init.cc +16 -11
  242. data/src/core/lib/surface/init_internally.cc +24 -0
  243. data/src/core/lib/surface/init_internally.h +28 -0
  244. data/src/core/lib/surface/server.cc +1 -7
  245. data/src/core/lib/surface/server.h +4 -6
  246. data/src/core/lib/surface/version.cc +2 -2
  247. data/src/core/lib/transport/bdp_estimator.cc +1 -3
  248. data/src/core/lib/transport/metadata_batch.cc +2 -3
  249. data/src/core/lib/transport/metadata_batch.h +9 -7
  250. data/src/core/lib/transport/parsed_metadata.h +4 -2
  251. data/src/core/lib/transport/status_conversion.cc +1 -3
  252. data/src/core/lib/transport/tcp_connect_handshaker.cc +9 -5
  253. data/src/core/lib/transport/transport.h +0 -1
  254. data/src/core/lib/transport/transport_impl.h +0 -1
  255. data/src/core/plugin_registry/grpc_plugin_registry.cc +23 -46
  256. data/src/core/plugin_registry/grpc_plugin_registry_extra.cc +13 -25
  257. data/src/ruby/ext/grpc/extconf.rb +1 -1
  258. data/src/ruby/lib/grpc/2.6/grpc_c.so +0 -0
  259. data/src/ruby/lib/grpc/2.7/grpc_c.so +0 -0
  260. data/src/ruby/lib/grpc/3.0/grpc_c.so +0 -0
  261. data/src/ruby/lib/grpc/3.1/grpc_c.so +0 -0
  262. data/src/ruby/lib/grpc/grpc_c.so +0 -0
  263. data/src/ruby/lib/grpc/version.rb +1 -1
  264. data/src/ruby/spec/channel_spec.rb +5 -0
  265. data/src/ruby/spec/generic/server_interceptors_spec.rb +1 -1
  266. data/src/ruby/spec/user_agent_spec.rb +1 -1
  267. metadata +32 -19
  268. data/src/core/ext/filters/client_channel/proxy_mapper_registry.h +0 -56
  269. data/src/core/ext/xds/certificate_provider_registry.cc +0 -103
  270. data/src/core/ext/xds/certificate_provider_registry.h +0 -59
  271. data/src/core/lib/event_engine/promise.h +0 -78
  272. data/src/core/lib/gpr/env_windows.cc +0 -74
  273. data/src/core/lib/gpr/string_windows.h +0 -32
  274. data/src/core/lib/profiling/basic_timers.cc +0 -295
  275. data/src/core/lib/profiling/stap_timers.cc +0 -50
  276. data/src/core/lib/profiling/timers.h +0 -94
  277. data/src/ruby/lib/grpc/2.5/grpc_c.so +0 -0
@@ -17,11 +17,11 @@
17
17
  #include <grpc/support/port_platform.h>
18
18
 
19
19
  #include <inttypes.h>
20
- #include <stddef.h>
21
20
 
22
21
  #include <algorithm>
23
22
  #include <map>
24
23
  #include <memory>
24
+ #include <set>
25
25
  #include <string>
26
26
  #include <utility>
27
27
  #include <vector>
@@ -41,19 +41,22 @@
41
41
  #include "src/core/ext/filters/client_channel/lb_policy/address_filtering.h"
42
42
  #include "src/core/ext/filters/client_channel/lb_policy/child_policy_handler.h"
43
43
  #include "src/core/lib/channel/channel_args.h"
44
+ #include "src/core/lib/config/core_configuration.h"
44
45
  #include "src/core/lib/debug/trace.h"
45
46
  #include "src/core/lib/gprpp/debug_location.h"
46
47
  #include "src/core/lib/gprpp/orphanable.h"
47
48
  #include "src/core/lib/gprpp/ref_counted.h"
48
49
  #include "src/core/lib/gprpp/ref_counted_ptr.h"
49
50
  #include "src/core/lib/gprpp/time.h"
51
+ #include "src/core/lib/gprpp/validation_errors.h"
50
52
  #include "src/core/lib/gprpp/work_serializer.h"
51
53
  #include "src/core/lib/iomgr/closure.h"
52
54
  #include "src/core/lib/iomgr/error.h"
53
- #include "src/core/lib/iomgr/exec_ctx.h"
54
55
  #include "src/core/lib/iomgr/pollset_set.h"
55
56
  #include "src/core/lib/iomgr/timer.h"
56
57
  #include "src/core/lib/json/json.h"
58
+ #include "src/core/lib/json/json_args.h"
59
+ #include "src/core/lib/json/json_object_loader.h"
57
60
  #include "src/core/lib/load_balancing/lb_policy.h"
58
61
  #include "src/core/lib/load_balancing/lb_policy_factory.h"
59
62
  #include "src/core/lib/load_balancing/lb_policy_registry.h"
@@ -84,11 +87,19 @@ class PriorityLbConfig : public LoadBalancingPolicy::Config {
84
87
  struct PriorityLbChild {
85
88
  RefCountedPtr<LoadBalancingPolicy::Config> config;
86
89
  bool ignore_reresolution_requests = false;
90
+
91
+ static const JsonLoaderInterface* JsonLoader(const JsonArgs&);
92
+ void JsonPostLoad(const Json& json, const JsonArgs&,
93
+ ValidationErrors* errors);
87
94
  };
88
95
 
89
- PriorityLbConfig(std::map<std::string, PriorityLbChild> children,
90
- std::vector<std::string> priorities)
91
- : children_(std::move(children)), priorities_(std::move(priorities)) {}
96
+ PriorityLbConfig() = default;
97
+
98
+ PriorityLbConfig(const PriorityLbConfig&) = delete;
99
+ PriorityLbConfig& operator=(const PriorityLbConfig&) = delete;
100
+
101
+ PriorityLbConfig(PriorityLbConfig&& other) = delete;
102
+ PriorityLbConfig& operator=(PriorityLbConfig&& other) = delete;
92
103
 
93
104
  absl::string_view name() const override { return kPriority; }
94
105
 
@@ -97,9 +108,13 @@ class PriorityLbConfig : public LoadBalancingPolicy::Config {
97
108
  }
98
109
  const std::vector<std::string>& priorities() const { return priorities_; }
99
110
 
111
+ static const JsonLoaderInterface* JsonLoader(const JsonArgs&);
112
+ void JsonPostLoad(const Json& json, const JsonArgs&,
113
+ ValidationErrors* errors);
114
+
100
115
  private:
101
- const std::map<std::string, PriorityLbChild> children_;
102
- const std::vector<std::string> priorities_;
116
+ std::map<std::string, PriorityLbChild> children_;
117
+ std::vector<std::string> priorities_;
103
118
  };
104
119
 
105
120
  // priority LB policy.
@@ -109,7 +124,7 @@ class PriorityLb : public LoadBalancingPolicy {
109
124
 
110
125
  absl::string_view name() const override { return kPriority; }
111
126
 
112
- void UpdateLocked(UpdateArgs args) override;
127
+ absl::Status UpdateLocked(UpdateArgs args) override;
113
128
  void ExitIdleLocked() override;
114
129
  void ResetBackoffLocked() override;
115
130
 
@@ -125,8 +140,8 @@ class PriorityLb : public LoadBalancingPolicy {
125
140
 
126
141
  const std::string& name() const { return name_; }
127
142
 
128
- void UpdateLocked(RefCountedPtr<LoadBalancingPolicy::Config> config,
129
- bool ignore_reresolution_requests);
143
+ absl::Status UpdateLocked(RefCountedPtr<LoadBalancingPolicy::Config> config,
144
+ bool ignore_reresolution_requests);
130
145
  void ExitIdleLocked();
131
146
  void ResetBackoffLocked();
132
147
  void MaybeDeactivateLocked();
@@ -254,11 +269,6 @@ class PriorityLb : public LoadBalancingPolicy {
254
269
  // the child is not in the current priority list.
255
270
  uint32_t GetChildPriorityLocked(const std::string& child_name) const;
256
271
 
257
- // Called when a child's connectivity state has changed.
258
- // May propagate the update to the channel or trigger choosing a new
259
- // priority.
260
- void HandleChildConnectivityStateChangeLocked(ChildPriority* child);
261
-
262
272
  // Deletes a child. Called when the child's deactivation timer fires.
263
273
  void DeleteChild(ChildPriority* child);
264
274
 
@@ -276,9 +286,11 @@ class PriorityLb : public LoadBalancingPolicy {
276
286
  void ChoosePriorityLocked();
277
287
 
278
288
  // Sets the specified priority as the current priority.
279
- // Deactivates any children at lower priorities.
289
+ // Optionally deactivates any children at lower priorities.
280
290
  // Returns the child's picker to the channel.
281
- void SetCurrentPriorityLocked(uint32_t priority);
291
+ void SetCurrentPriorityLocked(int32_t priority,
292
+ bool deactivate_lower_priorities,
293
+ const char* reason);
282
294
 
283
295
  const Duration child_failover_timeout_;
284
296
 
@@ -298,10 +310,6 @@ class PriorityLb : public LoadBalancingPolicy {
298
310
  std::map<std::string, OrphanablePtr<ChildPriority>> children_;
299
311
  // The priority that is being used.
300
312
  uint32_t current_priority_ = UINT32_MAX;
301
- // Points to the current child from before the most recent update.
302
- // We will continue to use this child until we decide which of the new
303
- // children to use.
304
- ChildPriority* current_child_from_before_update_ = nullptr;
305
313
  };
306
314
 
307
315
  //
@@ -350,19 +358,10 @@ void PriorityLb::ResetBackoffLocked() {
350
358
  for (const auto& p : children_) p.second->ResetBackoffLocked();
351
359
  }
352
360
 
353
- void PriorityLb::UpdateLocked(UpdateArgs args) {
361
+ absl::Status PriorityLb::UpdateLocked(UpdateArgs args) {
354
362
  if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_priority_trace)) {
355
363
  gpr_log(GPR_INFO, "[priority_lb %p] received update", this);
356
364
  }
357
- // Save current child.
358
- if (current_priority_ != UINT32_MAX) {
359
- const std::string& child_name = config_->priorities()[current_priority_];
360
- auto* child = children_[child_name].get();
361
- GPR_ASSERT(child != nullptr);
362
- if (child->connectivity_state() == GRPC_CHANNEL_READY) {
363
- current_child_from_before_update_ = children_[child_name].get();
364
- }
365
- }
366
365
  // Update config.
367
366
  config_ = std::move(args.config);
368
367
  // Update args.
@@ -372,6 +371,7 @@ void PriorityLb::UpdateLocked(UpdateArgs args) {
372
371
  resolution_note_ = std::move(args.resolution_note);
373
372
  // Check all existing children against the new config.
374
373
  update_in_progress_ = true;
374
+ std::vector<std::string> errors;
375
375
  for (const auto& p : children_) {
376
376
  const std::string& child_name = p.first;
377
377
  auto& child = p.second;
@@ -381,13 +381,24 @@ void PriorityLb::UpdateLocked(UpdateArgs args) {
381
381
  child->MaybeDeactivateLocked();
382
382
  } else {
383
383
  // Existing child found in new config. Update it.
384
- child->UpdateLocked(config_it->second.config,
385
- config_it->second.ignore_reresolution_requests);
384
+ absl::Status status =
385
+ child->UpdateLocked(config_it->second.config,
386
+ config_it->second.ignore_reresolution_requests);
387
+ if (!status.ok()) {
388
+ errors.emplace_back(
389
+ absl::StrCat("child ", child_name, ": ", status.ToString()));
390
+ }
386
391
  }
387
392
  }
388
393
  update_in_progress_ = false;
389
394
  // Try to get connected.
390
395
  ChoosePriorityLocked();
396
+ // Return status.
397
+ if (!errors.empty()) {
398
+ return absl::UnavailableError(absl::StrCat(
399
+ "errors from children: [", absl::StrJoin(errors, "; "), "]"));
400
+ }
401
+ return absl::OkStatus();
391
402
  }
392
403
 
393
404
  uint32_t PriorityLb::GetChildPriorityLocked(
@@ -399,71 +410,13 @@ uint32_t PriorityLb::GetChildPriorityLocked(
399
410
  return UINT32_MAX;
400
411
  }
401
412
 
402
- void PriorityLb::HandleChildConnectivityStateChangeLocked(
403
- ChildPriority* child) {
404
- // If we're in the process of propagating an update from our parent to
405
- // our children, ignore any updates that come from the children. We
406
- // will instead choose a new priority once the update has been seen by
407
- // all children. This ensures that we don't incorrectly do the wrong
408
- // thing while state is inconsistent.
409
- if (update_in_progress_) return;
410
- // Special case for the child that was the current child before the
411
- // most recent update.
412
- if (child == current_child_from_before_update_) {
413
- if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_priority_trace)) {
414
- gpr_log(GPR_INFO,
415
- "[priority_lb %p] state update for current child from before "
416
- "config update",
417
- this);
418
- }
419
- if (child->connectivity_state() == GRPC_CHANNEL_READY ||
420
- child->connectivity_state() == GRPC_CHANNEL_IDLE) {
421
- // If it's still READY or IDLE, we stick with this child, so pass
422
- // the new picker up to our parent.
423
- channel_control_helper()->UpdateState(child->connectivity_state(),
424
- child->connectivity_status(),
425
- child->GetPicker());
426
- } else {
427
- // If it's no longer READY or IDLE, we should stop using it.
428
- // We already started trying other priorities as a result of the
429
- // update, but calling ChoosePriorityLocked() ensures that we will
430
- // properly select between CONNECTING and TRANSIENT_FAILURE as the
431
- // new state to report to our parent.
432
- current_child_from_before_update_ = nullptr;
433
- ChoosePriorityLocked();
434
- }
435
- return;
436
- }
437
- // Otherwise, find the child's priority.
438
- uint32_t child_priority = GetChildPriorityLocked(child->name());
439
- if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_priority_trace)) {
440
- gpr_log(GPR_INFO,
441
- "[priority_lb %p] state update for priority %u, child %s, current "
442
- "priority %u",
443
- this, child_priority, child->name().c_str(), current_priority_);
444
- }
445
- // Unconditionally call ChoosePriorityLocked(). It should do the
446
- // right thing based on the state of all children.
447
- ChoosePriorityLocked();
448
- }
449
-
450
413
  void PriorityLb::DeleteChild(ChildPriority* child) {
451
- // If this was the current child from before the most recent update,
452
- // stop using it. We already started trying other priorities as a
453
- // result of the update, but calling ChoosePriorityLocked() ensures that
454
- // we will properly select between CONNECTING and TRANSIENT_FAILURE as the
455
- // new state to report to our parent.
456
- if (current_child_from_before_update_ == child) {
457
- current_child_from_before_update_ = nullptr;
458
- ChoosePriorityLocked();
459
- }
460
414
  children_.erase(child->name());
461
415
  }
462
416
 
463
417
  void PriorityLb::ChoosePriorityLocked() {
464
418
  // If priority list is empty, report TF.
465
419
  if (config_->priorities().empty()) {
466
- current_child_from_before_update_ = nullptr;
467
420
  absl::Status status =
468
421
  absl::UnavailableError("priority policy has empty priority list");
469
422
  channel_control_helper()->UpdateState(
@@ -483,52 +436,33 @@ void PriorityLb::ChoosePriorityLocked() {
483
436
  priority, child_name.c_str());
484
437
  }
485
438
  auto& child = children_[child_name];
439
+ // Create child if needed.
486
440
  if (child == nullptr) {
487
- // If we're not still using an old child from before the last
488
- // update, report CONNECTING here.
489
- // This is probably not strictly necessary, since the child should
490
- // immediately report CONNECTING and cause us to report that state
491
- // anyway, but we do this just in case the child fails to report
492
- // state before UpdateLocked() returns.
493
- if (current_child_from_before_update_ == nullptr) {
494
- channel_control_helper()->UpdateState(
495
- GRPC_CHANNEL_CONNECTING, absl::Status(),
496
- absl::make_unique<QueuePicker>(Ref(DEBUG_LOCATION, "QueuePicker")));
497
- }
498
- current_priority_ = priority;
499
441
  child = MakeOrphanable<ChildPriority>(
500
442
  Ref(DEBUG_LOCATION, "ChildPriority"), child_name);
501
443
  auto child_config = config_->children().find(child_name);
502
444
  GPR_DEBUG_ASSERT(child_config != config_->children().end());
503
- child->UpdateLocked(child_config->second.config,
504
- child_config->second.ignore_reresolution_requests);
505
- return;
445
+ // TODO(roth): If the child reports a non-OK status with the
446
+ // update, we need to propagate that back to the resolver somehow.
447
+ (void)child->UpdateLocked(
448
+ child_config->second.config,
449
+ child_config->second.ignore_reresolution_requests);
450
+ } else {
451
+ // The child already exists. Reactivate if needed.
452
+ child->MaybeReactivateLocked();
506
453
  }
507
- // The child already exists.
508
- child->MaybeReactivateLocked();
509
- // If the child is in state READY or IDLE, switch to it.
454
+ // Select this child if it is in states READY or IDLE.
510
455
  if (child->connectivity_state() == GRPC_CHANNEL_READY ||
511
456
  child->connectivity_state() == GRPC_CHANNEL_IDLE) {
512
- SetCurrentPriorityLocked(priority);
457
+ SetCurrentPriorityLocked(
458
+ priority, /*deactivate_lower_priorities=*/true,
459
+ ConnectivityStateName(child->connectivity_state()));
513
460
  return;
514
461
  }
515
- // Child is not READY or IDLE.
516
- // If its failover timer is still pending, give it time to fire.
462
+ // Select this child if its failover timer is pending.
517
463
  if (child->FailoverTimerPending()) {
518
- if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_priority_trace)) {
519
- gpr_log(GPR_INFO,
520
- "[priority_lb %p] priority %u, child %s: child still "
521
- "attempting to connect, will wait",
522
- this, priority, child_name.c_str());
523
- }
524
- current_priority_ = priority;
525
- // If we're not still using an old child from before the last
526
- // update, report CONNECTING here.
527
- if (current_child_from_before_update_ == nullptr) {
528
- channel_control_helper()->UpdateState(child->connectivity_state(),
529
- child->connectivity_status(),
530
- child->GetPicker());
531
- }
464
+ SetCurrentPriorityLocked(priority, /*deactivate_lower_priorities=*/false,
465
+ "failover timer pending");
532
466
  return;
533
467
  }
534
468
  // Child has been failing for a while. Move on to the next priority.
@@ -559,42 +493,37 @@ void PriorityLb::ChoosePriorityLocked() {
559
493
  auto& child = children_[child_name];
560
494
  GPR_ASSERT(child != nullptr);
561
495
  if (child->connectivity_state() == GRPC_CHANNEL_CONNECTING) {
562
- channel_control_helper()->UpdateState(child->connectivity_state(),
563
- child->connectivity_status(),
564
- child->GetPicker());
496
+ SetCurrentPriorityLocked(priority, /*deactivate_lower_priorities=*/false,
497
+ "CONNECTING (pass 2)");
565
498
  return;
566
499
  }
567
500
  }
568
501
  // Did not find any child in CONNECTING, delegate to last child.
569
- const std::string& child_name = config_->priorities().back();
570
- if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_priority_trace)) {
571
- gpr_log(GPR_INFO,
572
- "[priority_lb %p] no priority in CONNECTING, delegating to "
573
- "lowest priority child %s",
574
- this, child_name.c_str());
575
- }
576
- auto& child = children_[child_name];
577
- GPR_ASSERT(child != nullptr);
578
- channel_control_helper()->UpdateState(child->connectivity_state(),
579
- child->connectivity_status(),
580
- child->GetPicker());
502
+ SetCurrentPriorityLocked(config_->priorities().size() - 1,
503
+ /*deactivate_lower_priorities=*/false,
504
+ "no usable children");
581
505
  }
582
506
 
583
- void PriorityLb::SetCurrentPriorityLocked(uint32_t priority) {
507
+ void PriorityLb::SetCurrentPriorityLocked(int32_t priority,
508
+ bool deactivate_lower_priorities,
509
+ const char* reason) {
584
510
  if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_priority_trace)) {
585
- gpr_log(GPR_INFO, "[priority_lb %p] selected priority %u, child %s", this,
586
- priority, config_->priorities()[priority].c_str());
511
+ gpr_log(GPR_INFO,
512
+ "[priority_lb %p] selecting priority %u, child %s (%s, "
513
+ "deactivate_lower_priorities=%d)",
514
+ this, priority, config_->priorities()[priority].c_str(), reason,
515
+ deactivate_lower_priorities);
587
516
  }
588
517
  current_priority_ = priority;
589
- current_child_from_before_update_ = nullptr;
590
- // Deactivate lower priorities.
591
- for (uint32_t p = priority + 1; p < config_->priorities().size(); ++p) {
592
- const std::string& child_name = config_->priorities()[p];
593
- auto it = children_.find(child_name);
594
- if (it != children_.end()) it->second->MaybeDeactivateLocked();
518
+ if (deactivate_lower_priorities) {
519
+ for (uint32_t p = priority + 1; p < config_->priorities().size(); ++p) {
520
+ const std::string& child_name = config_->priorities()[p];
521
+ auto it = children_.find(child_name);
522
+ if (it != children_.end()) it->second->MaybeDeactivateLocked();
523
+ }
595
524
  }
596
- // Update picker.
597
525
  auto& child = children_[config_->priorities()[priority]];
526
+ GPR_ASSERT(child != nullptr);
598
527
  channel_control_helper()->UpdateState(child->connectivity_state(),
599
528
  child->connectivity_status(),
600
529
  child->GetPicker());
@@ -617,7 +546,7 @@ PriorityLb::ChildPriority::DeactivationTimer::DeactivationTimer(
617
546
  }
618
547
  GRPC_CLOSURE_INIT(&on_timer_, OnTimer, this, nullptr);
619
548
  Ref(DEBUG_LOCATION, "Timer").release();
620
- grpc_timer_init(&timer_, ExecCtx::Get()->Now() + kChildRetentionInterval,
549
+ grpc_timer_init(&timer_, Timestamp::Now() + kChildRetentionInterval,
621
550
  &on_timer_);
622
551
  }
623
552
 
@@ -679,7 +608,7 @@ PriorityLb::ChildPriority::FailoverTimer::FailoverTimer(
679
608
  Ref(DEBUG_LOCATION, "Timer").release();
680
609
  grpc_timer_init(
681
610
  &timer_,
682
- ExecCtx::Get()->Now() +
611
+ Timestamp::Now() +
683
612
  child_priority_->priority_policy_->child_failover_timeout_,
684
613
  &on_timer_);
685
614
  }
@@ -768,10 +697,10 @@ PriorityLb::ChildPriority::GetPicker() {
768
697
  return absl::make_unique<RefCountedPickerWrapper>(picker_wrapper_);
769
698
  }
770
699
 
771
- void PriorityLb::ChildPriority::UpdateLocked(
700
+ absl::Status PriorityLb::ChildPriority::UpdateLocked(
772
701
  RefCountedPtr<LoadBalancingPolicy::Config> config,
773
702
  bool ignore_reresolution_requests) {
774
- if (priority_policy_->shutting_down_) return;
703
+ if (priority_policy_->shutting_down_) return absl::OkStatus();
775
704
  if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_priority_trace)) {
776
705
  gpr_log(GPR_INFO, "[priority_lb %p] child %s (%p): start update",
777
706
  priority_policy_.get(), name_.c_str(), this);
@@ -797,7 +726,7 @@ void PriorityLb::ChildPriority::UpdateLocked(
797
726
  "[priority_lb %p] child %s (%p): updating child policy handler %p",
798
727
  priority_policy_.get(), name_.c_str(), this, child_policy_.get());
799
728
  }
800
- child_policy_->UpdateLocked(std::move(update_args));
729
+ return child_policy_->UpdateLocked(std::move(update_args));
801
730
  }
802
731
 
803
732
  OrphanablePtr<LoadBalancingPolicy>
@@ -845,7 +774,14 @@ void PriorityLb::ChildPriority::OnConnectivityStateUpdateLocked(
845
774
  // Store the state and picker.
846
775
  connectivity_state_ = state;
847
776
  connectivity_status_ = status;
848
- picker_wrapper_ = MakeRefCounted<RefCountedPicker>(std::move(picker));
777
+ // When the failover timer fires, this method will be called with picker
778
+ // set to null, because we want to consider the child to be in
779
+ // TRANSIENT_FAILURE, but we have no new picker to report. In that case,
780
+ // just keep using the old picker, in case we wind up delegating to this
781
+ // child when all priorities are failing.
782
+ if (picker != nullptr) {
783
+ picker_wrapper_ = MakeRefCounted<RefCountedPicker>(std::move(picker));
784
+ }
849
785
  // If we transition to state CONNECTING and we've not seen
850
786
  // TRANSIENT_FAILURE more recently than READY or IDLE, start failover
851
787
  // timer if not already pending.
@@ -863,8 +799,17 @@ void PriorityLb::ChildPriority::OnConnectivityStateUpdateLocked(
863
799
  seen_ready_or_idle_since_transient_failure_ = false;
864
800
  failover_timer_.reset();
865
801
  }
866
- // Notify the parent policy.
867
- priority_policy_->HandleChildConnectivityStateChangeLocked(this);
802
+ // Call the LB policy's ChoosePriorityLocked() to choose a priority to
803
+ // use based on the updated state of this child.
804
+ //
805
+ // Note that if we're in the process of propagating an update from our
806
+ // parent to our children, we skip this, because we don't want to
807
+ // choose a new priority based on inconsistent state. Instead, the
808
+ // policy will choose a new priority once the update has been seen by
809
+ // all children.
810
+ if (!priority_policy_->update_in_progress_) {
811
+ priority_policy_->ChoosePriorityLocked();
812
+ }
868
813
  }
869
814
 
870
815
  void PriorityLb::ChildPriority::MaybeDeactivateLocked() {
@@ -920,6 +865,61 @@ void PriorityLb::ChildPriority::Helper::AddTraceEvent(
920
865
  // factory
921
866
  //
922
867
 
868
+ const JsonLoaderInterface* PriorityLbConfig::PriorityLbChild::JsonLoader(
869
+ const JsonArgs&) {
870
+ static const auto* loader =
871
+ JsonObjectLoader<PriorityLbChild>()
872
+ // Note: The "config" field requires custom parsing, so it's
873
+ // handled in JsonPostLoad() instead of here.
874
+ .OptionalField("ignore_reresolution_requests",
875
+ &PriorityLbChild::ignore_reresolution_requests)
876
+ .Finish();
877
+ return loader;
878
+ }
879
+
880
+ void PriorityLbConfig::PriorityLbChild::JsonPostLoad(const Json& json,
881
+ const JsonArgs&,
882
+ ValidationErrors* errors) {
883
+ ValidationErrors::ScopedField field(errors, ".config");
884
+ auto it = json.object_value().find("config");
885
+ if (it == json.object_value().end()) {
886
+ errors->AddError("field not present");
887
+ return;
888
+ }
889
+ auto lb_config =
890
+ CoreConfiguration::Get().lb_policy_registry().ParseLoadBalancingConfig(
891
+ it->second);
892
+ if (!lb_config.ok()) {
893
+ errors->AddError(lb_config.status().message());
894
+ return;
895
+ }
896
+ config = std::move(*lb_config);
897
+ }
898
+
899
+ const JsonLoaderInterface* PriorityLbConfig::JsonLoader(const JsonArgs&) {
900
+ static const auto* loader =
901
+ JsonObjectLoader<PriorityLbConfig>()
902
+ .Field("children", &PriorityLbConfig::children_)
903
+ .Field("priorities", &PriorityLbConfig::priorities_)
904
+ .Finish();
905
+ return loader;
906
+ }
907
+
908
+ void PriorityLbConfig::JsonPostLoad(const Json& /*json*/, const JsonArgs&,
909
+ ValidationErrors* errors) {
910
+ std::set<std::string> unknown_priorities;
911
+ for (const std::string& priority : priorities_) {
912
+ if (children_.find(priority) == children_.end()) {
913
+ unknown_priorities.insert(priority);
914
+ }
915
+ }
916
+ if (!unknown_priorities.empty()) {
917
+ errors->AddError(absl::StrCat("unknown priorit(ies): [",
918
+ absl::StrJoin(unknown_priorities, ", "),
919
+ "]"));
920
+ }
921
+ }
922
+
923
923
  class PriorityLbFactory : public LoadBalancingPolicyFactory {
924
924
  public:
925
925
  OrphanablePtr<LoadBalancingPolicy> CreateLoadBalancingPolicy(
@@ -939,108 +939,16 @@ class PriorityLbFactory : public LoadBalancingPolicyFactory {
939
939
  "configuration. Please use loadBalancingConfig field of service "
940
940
  "config instead.");
941
941
  }
942
- std::vector<std::string> errors;
943
- // Children.
944
- std::map<std::string, PriorityLbConfig::PriorityLbChild> children;
945
- auto it = json.object_value().find("children");
946
- if (it == json.object_value().end()) {
947
- errors.emplace_back("field:children error:required field missing");
948
- } else if (it->second.type() != Json::Type::OBJECT) {
949
- errors.emplace_back("field:children error:type should be object");
950
- } else {
951
- const Json::Object& object = it->second.object_value();
952
- for (const auto& p : object) {
953
- const std::string& child_name = p.first;
954
- const Json& element = p.second;
955
- if (element.type() != Json::Type::OBJECT) {
956
- errors.emplace_back(absl::StrCat("field:children key:", child_name,
957
- " error:should be type object"));
958
- } else {
959
- auto it2 = element.object_value().find("config");
960
- if (it2 == element.object_value().end()) {
961
- errors.emplace_back(absl::StrCat("field:children key:", child_name,
962
- " error:missing 'config' field"));
963
- } else {
964
- bool ignore_resolution_requests = false;
965
- // If present, ignore_reresolution_requests must be of type
966
- // boolean.
967
- auto it3 =
968
- element.object_value().find("ignore_reresolution_requests");
969
- if (it3 != element.object_value().end()) {
970
- if (it3->second.type() == Json::Type::JSON_TRUE) {
971
- ignore_resolution_requests = true;
972
- } else if (it3->second.type() != Json::Type::JSON_FALSE) {
973
- errors.emplace_back(
974
- absl::StrCat("field:children key:", child_name,
975
- " field:ignore_reresolution_requests:should "
976
- "be type boolean"));
977
- }
978
- }
979
- auto config = LoadBalancingPolicyRegistry::ParseLoadBalancingConfig(
980
- it2->second);
981
- if (!config.ok()) {
982
- errors.emplace_back(
983
- absl::StrCat("field:children key:", child_name, ": ",
984
- config.status().message()));
985
- } else {
986
- children[child_name].config = std::move(*config);
987
- children[child_name].ignore_reresolution_requests =
988
- ignore_resolution_requests;
989
- }
990
- }
991
- }
992
- }
993
- }
994
- // Priorities.
995
- std::vector<std::string> priorities;
996
- it = json.object_value().find("priorities");
997
- if (it == json.object_value().end()) {
998
- errors.emplace_back("field:priorities error:required field missing");
999
- } else if (it->second.type() != Json::Type::ARRAY) {
1000
- errors.emplace_back("field:priorities error:type should be array");
1001
- } else {
1002
- const Json::Array& array = it->second.array_value();
1003
- for (size_t i = 0; i < array.size(); ++i) {
1004
- const Json& element = array[i];
1005
- if (element.type() != Json::Type::STRING) {
1006
- errors.emplace_back(absl::StrCat("field:priorities element:", i,
1007
- " error:should be type string"));
1008
- } else if (children.find(element.string_value()) == children.end()) {
1009
- errors.emplace_back(absl::StrCat("field:priorities element:", i,
1010
- " error:unknown child '",
1011
- element.string_value(), "'"));
1012
- } else {
1013
- priorities.emplace_back(element.string_value());
1014
- }
1015
- }
1016
- if (priorities.size() != children.size()) {
1017
- errors.emplace_back(absl::StrCat(
1018
- "field:priorities error:priorities size (", priorities.size(),
1019
- ") != children size (", children.size(), ")"));
1020
- }
1021
- }
1022
- if (!errors.empty()) {
1023
- return absl::InvalidArgumentError(
1024
- absl::StrCat("priority_experimental LB policy config: [",
1025
- absl::StrJoin(errors, "; "), "]"));
1026
- }
1027
- return MakeRefCounted<PriorityLbConfig>(std::move(children),
1028
- std::move(priorities));
942
+ return LoadRefCountedFromJson<PriorityLbConfig>(
943
+ json, JsonArgs(), "errors validating priority LB policy config");
1029
944
  }
1030
945
  };
1031
946
 
1032
947
  } // namespace
1033
948
 
1034
- } // namespace grpc_core
1035
-
1036
- //
1037
- // Plugin registration
1038
- //
1039
-
1040
- void grpc_lb_policy_priority_init() {
1041
- grpc_core::LoadBalancingPolicyRegistry::Builder::
1042
- RegisterLoadBalancingPolicyFactory(
1043
- absl::make_unique<grpc_core::PriorityLbFactory>());
949
+ void RegisterPriorityLbPolicy(CoreConfiguration::Builder* builder) {
950
+ builder->lb_policy_registry()->RegisterLoadBalancingPolicyFactory(
951
+ absl::make_unique<PriorityLbFactory>());
1044
952
  }
1045
953
 
1046
- void grpc_lb_policy_priority_shutdown() {}
954
+ } // namespace grpc_core