grpc 1.49.1 → 1.50.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 (270) 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 +33 -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 +112 -96
  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 +84 -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 +13 -15
  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 +1 -1
  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 +1 -0
  179. data/src/core/lib/iomgr/resolve_address_windows.cc +1 -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/lib/grpc/version.rb +1 -1
  258. data/src/ruby/spec/channel_spec.rb +5 -0
  259. data/src/ruby/spec/generic/server_interceptors_spec.rb +1 -1
  260. data/src/ruby/spec/user_agent_spec.rb +1 -1
  261. metadata +33 -19
  262. data/src/core/ext/filters/client_channel/proxy_mapper_registry.h +0 -56
  263. data/src/core/ext/xds/certificate_provider_registry.cc +0 -103
  264. data/src/core/ext/xds/certificate_provider_registry.h +0 -59
  265. data/src/core/lib/event_engine/promise.h +0 -78
  266. data/src/core/lib/gpr/env_windows.cc +0 -74
  267. data/src/core/lib/gpr/string_windows.h +0 -32
  268. data/src/core/lib/profiling/basic_timers.cc +0 -295
  269. data/src/core/lib/profiling/stap_timers.cc +0 -50
  270. data/src/core/lib/profiling/timers.h +0 -94
@@ -114,6 +114,7 @@
114
114
  #include "src/core/lib/gprpp/ref_counted.h"
115
115
  #include "src/core/lib/gprpp/ref_counted_ptr.h"
116
116
  #include "src/core/lib/gprpp/time.h"
117
+ #include "src/core/lib/gprpp/validation_errors.h"
117
118
  #include "src/core/lib/gprpp/work_serializer.h"
118
119
  #include "src/core/lib/iomgr/closure.h"
119
120
  #include "src/core/lib/iomgr/error.h"
@@ -124,6 +125,8 @@
124
125
  #include "src/core/lib/iomgr/socket_utils.h"
125
126
  #include "src/core/lib/iomgr/timer.h"
126
127
  #include "src/core/lib/json/json.h"
128
+ #include "src/core/lib/json/json_args.h"
129
+ #include "src/core/lib/json/json_object_loader.h"
127
130
  #include "src/core/lib/load_balancing/lb_policy.h"
128
131
  #include "src/core/lib/load_balancing/lb_policy_factory.h"
129
132
  #include "src/core/lib/load_balancing/lb_policy_registry.h"
@@ -164,10 +167,47 @@ constexpr absl::string_view kGrpclb = "grpclb";
164
167
 
165
168
  class GrpcLbConfig : public LoadBalancingPolicy::Config {
166
169
  public:
167
- GrpcLbConfig(RefCountedPtr<LoadBalancingPolicy::Config> child_policy,
168
- std::string service_name)
169
- : child_policy_(std::move(child_policy)),
170
- service_name_(std::move(service_name)) {}
170
+ GrpcLbConfig() = default;
171
+
172
+ GrpcLbConfig(const GrpcLbConfig&) = delete;
173
+ GrpcLbConfig& operator=(const GrpcLbConfig&) = delete;
174
+
175
+ GrpcLbConfig(GrpcLbConfig&& other) = delete;
176
+ GrpcLbConfig& operator=(GrpcLbConfig&& other) = delete;
177
+
178
+ static const JsonLoaderInterface* JsonLoader(const JsonArgs&) {
179
+ static const auto* loader =
180
+ JsonObjectLoader<GrpcLbConfig>()
181
+ // Note: "childPolicy" field requires custom parsing, so
182
+ // it's handled in JsonPostLoad() instead.
183
+ .OptionalField("serviceName", &GrpcLbConfig::service_name_)
184
+ .Finish();
185
+ return loader;
186
+ }
187
+
188
+ void JsonPostLoad(const Json& json, const JsonArgs&,
189
+ ValidationErrors* errors) {
190
+ ValidationErrors::ScopedField field(errors, ".childPolicy");
191
+ Json child_policy_config_json_tmp;
192
+ const Json* child_policy_config_json;
193
+ auto it = json.object_value().find("childPolicy");
194
+ if (it == json.object_value().end()) {
195
+ child_policy_config_json_tmp = Json::Array{Json::Object{
196
+ {"round_robin", Json::Object()},
197
+ }};
198
+ child_policy_config_json = &child_policy_config_json_tmp;
199
+ } else {
200
+ child_policy_config_json = &it->second;
201
+ }
202
+ auto child_policy_config =
203
+ CoreConfiguration::Get().lb_policy_registry().ParseLoadBalancingConfig(
204
+ *child_policy_config_json);
205
+ if (!child_policy_config.ok()) {
206
+ errors->AddError(child_policy_config.status().message());
207
+ return;
208
+ }
209
+ child_policy_ = std::move(*child_policy_config);
210
+ }
171
211
 
172
212
  absl::string_view name() const override { return kGrpclb; }
173
213
 
@@ -188,7 +228,7 @@ class GrpcLb : public LoadBalancingPolicy {
188
228
 
189
229
  absl::string_view name() const override { return kGrpclb; }
190
230
 
191
- void UpdateLocked(UpdateArgs args) override;
231
+ absl::Status UpdateLocked(UpdateArgs args) override;
192
232
  void ResetBackoffLocked() override;
193
233
 
194
234
  private:
@@ -472,7 +512,7 @@ class GrpcLb : public LoadBalancingPolicy {
472
512
  void ShutdownLocked() override;
473
513
 
474
514
  // Helper functions used in UpdateLocked().
475
- void UpdateBalancerChannelLocked(const ChannelArgs& args);
515
+ absl::Status UpdateBalancerChannelLocked(const ChannelArgs& args);
476
516
 
477
517
  void CancelBalancerChannelConnectivityWatchLocked();
478
518
 
@@ -867,7 +907,7 @@ GrpcLb::BalancerCallState::BalancerCallState(
867
907
  const Timestamp deadline =
868
908
  grpclb_policy()->lb_call_timeout_ == Duration::Zero()
869
909
  ? Timestamp::InfFuture()
870
- : ExecCtx::Get()->Now() + grpclb_policy()->lb_call_timeout_;
910
+ : Timestamp::Now() + grpclb_policy()->lb_call_timeout_;
871
911
  lb_call_ = grpc_channel_create_pollset_set_call(
872
912
  grpclb_policy()->lb_channel_, nullptr, GRPC_PROPAGATE_DEFAULTS,
873
913
  grpclb_policy_->interested_parties(),
@@ -1353,6 +1393,47 @@ ServerAddressList ExtractBalancerAddresses(const ChannelArgs& args) {
1353
1393
  ChannelArgs BuildBalancerChannelArgs(
1354
1394
  FakeResolverResponseGenerator* response_generator,
1355
1395
  const ChannelArgs& args) {
1396
+ ChannelArgs grpclb_channel_args;
1397
+ const grpc_channel_args* lb_channel_specific_args =
1398
+ args.GetPointer<grpc_channel_args>(
1399
+ GRPC_ARG_EXPERIMENTAL_GRPCLB_CHANNEL_ARGS);
1400
+ if (lb_channel_specific_args != nullptr) {
1401
+ grpclb_channel_args = ChannelArgs::FromC(lb_channel_specific_args);
1402
+ } else {
1403
+ // Set grpclb_channel_args based on the parent channel's channel args.
1404
+ grpclb_channel_args =
1405
+ args
1406
+ // LB policy name, since we want to use the default (pick_first) in
1407
+ // the LB channel.
1408
+ .Remove(GRPC_ARG_LB_POLICY_NAME)
1409
+ // Strip out the service config, since we don't want the LB policy
1410
+ // config specified for the parent channel to affect the LB channel.
1411
+ .Remove(GRPC_ARG_SERVICE_CONFIG)
1412
+ // The channel arg for the server URI, since that will be different
1413
+ // for the LB channel than for the parent channel. The client
1414
+ // channel factory will re-add this arg with the right value.
1415
+ .Remove(GRPC_ARG_SERVER_URI)
1416
+ // The fake resolver response generator, because we are replacing it
1417
+ // with the one from the grpclb policy, used to propagate updates to
1418
+ // the LB channel.
1419
+ .Remove(GRPC_ARG_FAKE_RESOLVER_RESPONSE_GENERATOR)
1420
+ // The LB channel should use the authority indicated by the target
1421
+ // authority table (see \a ModifyGrpclbBalancerChannelArgs),
1422
+ // as opposed to the authority from the parent channel.
1423
+ .Remove(GRPC_ARG_DEFAULT_AUTHORITY)
1424
+ // Just as for \a GRPC_ARG_DEFAULT_AUTHORITY, the LB channel should
1425
+ // be treated as a stand-alone channel and not inherit this argument
1426
+ // from the args of the parent channel.
1427
+ .Remove(GRPC_SSL_TARGET_NAME_OVERRIDE_ARG)
1428
+ // Don't want to pass down channelz node from parent; the balancer
1429
+ // channel will get its own.
1430
+ .Remove(GRPC_ARG_CHANNELZ_CHANNEL_NODE)
1431
+ // Remove the channel args for channel credentials and replace it
1432
+ // with a version that does not contain call credentials. The
1433
+ // loadbalancer is not necessarily trusted to handle bearer token
1434
+ // credentials.
1435
+ .Remove(GRPC_ARG_CHANNEL_CREDENTIALS);
1436
+ }
1356
1437
  // Create channel args for channel credentials that does not contain bearer
1357
1438
  // token credentials.
1358
1439
  auto* channel_credentials = args.GetObject<grpc_channel_credentials>();
@@ -1360,36 +1441,7 @@ ChannelArgs BuildBalancerChannelArgs(
1360
1441
  RefCountedPtr<grpc_channel_credentials> creds_sans_call_creds =
1361
1442
  channel_credentials->duplicate_without_call_credentials();
1362
1443
  GPR_ASSERT(creds_sans_call_creds != nullptr);
1363
- return args
1364
- // LB policy name, since we want to use the default (pick_first) in
1365
- // the LB channel.
1366
- .Remove(GRPC_ARG_LB_POLICY_NAME)
1367
- // Strip out the service config, since we don't want the LB policy
1368
- // config specified for the parent channel to affect the LB channel.
1369
- .Remove(GRPC_ARG_SERVICE_CONFIG)
1370
- // The channel arg for the server URI, since that will be different for
1371
- // the LB channel than for the parent channel. The client channel
1372
- // factory will re-add this arg with the right value.
1373
- .Remove(GRPC_ARG_SERVER_URI)
1374
- // The fake resolver response generator, because we are replacing it
1375
- // with the one from the grpclb policy, used to propagate updates to
1376
- // the LB channel.
1377
- .Remove(GRPC_ARG_FAKE_RESOLVER_RESPONSE_GENERATOR)
1378
- // The LB channel should use the authority indicated by the target
1379
- // authority table (see \a ModifyGrpclbBalancerChannelArgs),
1380
- // as opposed to the authority from the parent channel.
1381
- .Remove(GRPC_ARG_DEFAULT_AUTHORITY)
1382
- // Just as for \a GRPC_ARG_DEFAULT_AUTHORITY, the LB channel should be
1383
- // treated as a stand-alone channel and not inherit this argument from the
1384
- // args of the parent channel.
1385
- .Remove(GRPC_SSL_TARGET_NAME_OVERRIDE_ARG)
1386
- // Don't want to pass down channelz node from parent; the balancer
1387
- // channel will get its own.
1388
- .Remove(GRPC_ARG_CHANNELZ_CHANNEL_NODE)
1389
- // Remove the channel args for channel credentials and replace it
1390
- // with a version that does not contain call credentials. The loadbalancer
1391
- // is not necessarily trusted to handle bearer token credentials.
1392
- .Remove(GRPC_ARG_CHANNEL_CREDENTIALS)
1444
+ return grpclb_channel_args
1393
1445
  // A channel arg indicating the target is a grpclb load balancer.
1394
1446
  .Set(GRPC_ARG_ADDRESS_IS_GRPCLB_LOAD_BALANCER, 1)
1395
1447
  // Tells channelz that this is an internal channel.
@@ -1507,7 +1559,7 @@ void GrpcLb::ResetBackoffLocked() {
1507
1559
  }
1508
1560
  }
1509
1561
 
1510
- void GrpcLb::UpdateLocked(UpdateArgs args) {
1562
+ absl::Status GrpcLb::UpdateLocked(UpdateArgs args) {
1511
1563
  const bool is_initial_update = lb_channel_ == nullptr;
1512
1564
  config_ = args.config;
1513
1565
  GPR_ASSERT(config_ != nullptr);
@@ -1523,7 +1575,7 @@ void GrpcLb::UpdateLocked(UpdateArgs args) {
1523
1575
  }
1524
1576
  resolution_note_ = std::move(args.resolution_note);
1525
1577
  // Update balancer channel.
1526
- UpdateBalancerChannelLocked(args.args);
1578
+ absl::Status status = UpdateBalancerChannelLocked(args.args);
1527
1579
  // Update the existing child policy, if any.
1528
1580
  if (child_policy_ != nullptr) CreateOrUpdateChildPolicyLocked();
1529
1581
  // If this is the initial update, start the fallback-at-startup checks
@@ -1531,7 +1583,7 @@ void GrpcLb::UpdateLocked(UpdateArgs args) {
1531
1583
  if (is_initial_update) {
1532
1584
  fallback_at_startup_checks_pending_ = true;
1533
1585
  // Start timer.
1534
- Timestamp deadline = ExecCtx::Get()->Now() + fallback_at_startup_timeout_;
1586
+ Timestamp deadline = Timestamp::Now() + fallback_at_startup_timeout_;
1535
1587
  Ref(DEBUG_LOCATION, "on_fallback_timer").release(); // Ref for callback
1536
1588
  grpc_timer_init(&lb_fallback_timer_, deadline, &lb_on_fallback_);
1537
1589
  // Start watching the channel's connectivity state. If the channel
@@ -1548,18 +1600,24 @@ void GrpcLb::UpdateLocked(UpdateArgs args) {
1548
1600
  // Start balancer call.
1549
1601
  StartBalancerCallLocked();
1550
1602
  }
1603
+ return status;
1551
1604
  }
1552
1605
 
1553
1606
  //
1554
1607
  // helpers for UpdateLocked()
1555
1608
  //
1556
1609
 
1557
- void GrpcLb::UpdateBalancerChannelLocked(const ChannelArgs& args) {
1610
+ absl::Status GrpcLb::UpdateBalancerChannelLocked(const ChannelArgs& args) {
1558
1611
  // Make sure that GRPC_ARG_LB_POLICY_NAME is set in channel args,
1559
1612
  // since we use this to trigger the client_load_reporting filter.
1560
1613
  args_ = args.Set(GRPC_ARG_LB_POLICY_NAME, "grpclb");
1561
- // Construct args for balancer channel.
1614
+ // Get balancer addresses.
1562
1615
  ServerAddressList balancer_addresses = ExtractBalancerAddresses(args);
1616
+ absl::Status status;
1617
+ if (balancer_addresses.empty()) {
1618
+ status = absl::UnavailableError("balancer address list must be non-empty");
1619
+ }
1620
+ // Construct args for balancer channel.
1563
1621
  ChannelArgs lb_channel_args =
1564
1622
  BuildBalancerChannelArgs(response_generator_.get(), args);
1565
1623
  // Create balancer channel if needed.
@@ -1587,6 +1645,8 @@ void GrpcLb::UpdateBalancerChannelLocked(const ChannelArgs& args) {
1587
1645
  result.addresses = std::move(balancer_addresses);
1588
1646
  result.args = lb_channel_args;
1589
1647
  response_generator_->SetResponse(std::move(result));
1648
+ // Return status.
1649
+ return status;
1590
1650
  }
1591
1651
 
1592
1652
  void GrpcLb::CancelBalancerChannelConnectivityWatchLocked() {
@@ -1618,7 +1678,7 @@ void GrpcLb::StartBalancerCallRetryTimerLocked() {
1618
1678
  Timestamp next_try = lb_call_backoff_.NextAttemptTime();
1619
1679
  if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_glb_trace)) {
1620
1680
  gpr_log(GPR_INFO, "[grpclb %p] Connection to LB server lost...", this);
1621
- Duration timeout = next_try - ExecCtx::Get()->Now();
1681
+ Duration timeout = next_try - Timestamp::Now();
1622
1682
  if (timeout > Duration::Zero()) {
1623
1683
  gpr_log(GPR_INFO, "[grpclb %p] ... retry_timer_active in %" PRId64 "ms.",
1624
1684
  this, timeout.millis());
@@ -1777,7 +1837,9 @@ void GrpcLb::CreateOrUpdateChildPolicyLocked() {
1777
1837
  gpr_log(GPR_INFO, "[grpclb %p] Updating child policy handler %p", this,
1778
1838
  child_policy_.get());
1779
1839
  }
1780
- child_policy_->UpdateLocked(std::move(update_args));
1840
+ // TODO(roth): If we're in fallback mode and the child policy rejects the
1841
+ // update, we should propagate that failure back to the resolver somehow.
1842
+ (void)child_policy_->UpdateLocked(std::move(update_args));
1781
1843
  }
1782
1844
 
1783
1845
  //
@@ -1786,7 +1848,7 @@ void GrpcLb::CreateOrUpdateChildPolicyLocked() {
1786
1848
 
1787
1849
  void GrpcLb::CacheDeletedSubchannelLocked(
1788
1850
  RefCountedPtr<SubchannelInterface> subchannel) {
1789
- Timestamp deletion_time = ExecCtx::Get()->Now() + subchannel_cache_interval_;
1851
+ Timestamp deletion_time = Timestamp::Now() + subchannel_cache_interval_;
1790
1852
  cached_subchannels_[deletion_time].push_back(std::move(subchannel));
1791
1853
  if (!subchannel_cache_timer_pending_) {
1792
1854
  Ref(DEBUG_LOCATION, "OnSubchannelCacheTimer").release();
@@ -1845,48 +1907,8 @@ class GrpcLbFactory : public LoadBalancingPolicyFactory {
1845
1907
 
1846
1908
  absl::StatusOr<RefCountedPtr<LoadBalancingPolicy::Config>>
1847
1909
  ParseLoadBalancingConfig(const Json& json) const override {
1848
- if (json.type() == Json::Type::JSON_NULL) {
1849
- return MakeRefCounted<GrpcLbConfig>(nullptr, "");
1850
- }
1851
- std::vector<std::string> error_list;
1852
- std::string service_name;
1853
- auto it = json.object_value().find("serviceName");
1854
- if (it != json.object_value().end()) {
1855
- const Json& service_name_json = it->second;
1856
- if (service_name_json.type() != Json::Type::STRING) {
1857
- error_list.emplace_back(
1858
- "field:serviceName error:type should be string");
1859
- } else {
1860
- service_name = service_name_json.string_value();
1861
- }
1862
- }
1863
- Json child_policy_config_json_tmp;
1864
- const Json* child_policy_config_json;
1865
- it = json.object_value().find("childPolicy");
1866
- if (it == json.object_value().end()) {
1867
- child_policy_config_json_tmp = Json::Array{Json::Object{
1868
- {"round_robin", Json::Object()},
1869
- }};
1870
- child_policy_config_json = &child_policy_config_json_tmp;
1871
- } else {
1872
- child_policy_config_json = &it->second;
1873
- }
1874
- auto child_policy_config =
1875
- LoadBalancingPolicyRegistry::ParseLoadBalancingConfig(
1876
- *child_policy_config_json);
1877
- if (!child_policy_config.ok()) {
1878
- error_list.emplace_back(
1879
- absl::StrCat("error parsing childPolicy field: ",
1880
- child_policy_config.status().message()));
1881
- }
1882
- if (error_list.empty()) {
1883
- return MakeRefCounted<GrpcLbConfig>(std::move(*child_policy_config),
1884
- std::move(service_name));
1885
- } else {
1886
- return absl::InvalidArgumentError(
1887
- absl::StrCat("errors parsing grpclb LB policy config: [",
1888
- absl::StrJoin(error_list, "; "), "]"));
1889
- }
1910
+ return LoadRefCountedFromJson<GrpcLbConfig>(
1911
+ json, JsonArgs(), "errors validating grpclb LB policy config");
1890
1912
  }
1891
1913
  };
1892
1914
 
@@ -1898,16 +1920,10 @@ class GrpcLbFactory : public LoadBalancingPolicyFactory {
1898
1920
  // Plugin registration
1899
1921
  //
1900
1922
 
1901
- void grpc_lb_policy_grpclb_init() {
1902
- grpc_core::LoadBalancingPolicyRegistry::Builder::
1903
- RegisterLoadBalancingPolicyFactory(
1904
- absl::make_unique<grpc_core::GrpcLbFactory>());
1905
- }
1906
-
1907
- void grpc_lb_policy_grpclb_shutdown() {}
1908
-
1909
1923
  namespace grpc_core {
1910
- void RegisterGrpcLbLoadReportingFilter(CoreConfiguration::Builder* builder) {
1924
+ void RegisterGrpcLbPolicy(CoreConfiguration::Builder* builder) {
1925
+ builder->lb_policy_registry()->RegisterLoadBalancingPolicyFactory(
1926
+ absl::make_unique<GrpcLbFactory>());
1911
1927
  builder->channel_init()->RegisterStage(
1912
1928
  GRPC_CLIENT_SUBCHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
1913
1929
  [](ChannelStackBuilder* builder) {
@@ -76,7 +76,7 @@ class OrcaWatcher;
76
76
  // registered watchers.
77
77
  class OrcaProducer : public Subchannel::DataProducerInterface {
78
78
  public:
79
- explicit OrcaProducer(RefCountedPtr<Subchannel> subchannel);
79
+ void Start(RefCountedPtr<Subchannel> subchannel);
80
80
 
81
81
  void Orphan() override;
82
82
 
@@ -288,9 +288,8 @@ class OrcaProducer::OrcaStreamEventHandler
288
288
  // OrcaProducer
289
289
  //
290
290
 
291
- OrcaProducer::OrcaProducer(RefCountedPtr<Subchannel> subchannel)
292
- : subchannel_(std::move(subchannel)) {
293
- subchannel_->AddDataProducer(this);
291
+ void OrcaProducer::Start(RefCountedPtr<Subchannel> subchannel) {
292
+ subchannel_ = std::move(subchannel);
294
293
  connected_subchannel_ = subchannel_->connected_subchannel();
295
294
  auto connectivity_watcher = MakeRefCounted<ConnectivityWatcher>(WeakRef());
296
295
  connectivity_watcher_ = connectivity_watcher.get();
@@ -304,6 +303,7 @@ void OrcaProducer::Orphan() {
304
303
  MutexLock lock(&mu_);
305
304
  stream_client_.reset();
306
305
  }
306
+ GPR_ASSERT(subchannel_ != nullptr); // Should not be called before Start().
307
307
  subchannel_->CancelConnectivityStateWatch(
308
308
  /*health_check_service_name=*/absl::nullopt, connectivity_watcher_);
309
309
  subchannel_->RemoveDataProducer(this);
@@ -384,14 +384,23 @@ OrcaWatcher::~OrcaWatcher() {
384
384
  }
385
385
 
386
386
  void OrcaWatcher::SetSubchannel(Subchannel* subchannel) {
387
+ bool created = false;
387
388
  // Check if our producer is already registered with the subchannel.
388
- // If not, create a new one, which will register itself with the subchannel.
389
- auto* p = static_cast<OrcaProducer*>(
390
- subchannel->GetDataProducer(OrcaProducer::Type()));
391
- if (p != nullptr) producer_ = p->RefIfNonZero();
392
- if (producer_ == nullptr) {
393
- producer_ = MakeRefCounted<OrcaProducer>(subchannel->Ref());
394
- }
389
+ // If not, create a new one.
390
+ subchannel->GetOrAddDataProducer(
391
+ OrcaProducer::Type(), [&](Subchannel::DataProducerInterface** producer) {
392
+ if (*producer != nullptr) producer_ = (*producer)->RefIfNonZero();
393
+ if (producer_ == nullptr) {
394
+ producer_ = MakeRefCounted<OrcaProducer>();
395
+ *producer = producer_.get();
396
+ created = true;
397
+ }
398
+ });
399
+ // If we just created the producer, start it.
400
+ // This needs to be done outside of the lambda passed to
401
+ // GetOrAddDataProducer() to avoid deadlocking by re-acquiring the
402
+ // subchannel lock while already holding it.
403
+ if (created) producer_->Start(subchannel->Ref());
395
404
  // Register ourself with the producer.
396
405
  producer_->AddWatcher(this);
397
406
  }