grpc 1.20.0 → 1.21.0

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

Potentially problematic release.


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

Files changed (209) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +500 -29
  3. data/etc/roots.pem +146 -0
  4. data/include/grpc/grpc_security.h +1 -1
  5. data/include/grpc/impl/codegen/grpc_types.h +10 -7
  6. data/include/grpc/impl/codegen/port_platform.h +11 -1
  7. data/include/grpc/impl/codegen/slice.h +1 -21
  8. data/include/grpc/impl/codegen/status.h +2 -1
  9. data/include/grpc/slice.h +1 -1
  10. data/src/core/ext/filters/client_channel/backup_poller.cc +19 -13
  11. data/src/core/ext/filters/client_channel/backup_poller.h +3 -0
  12. data/src/core/ext/filters/client_channel/channel_connectivity.cc +1 -1
  13. data/src/core/ext/filters/client_channel/client_channel.cc +2084 -1673
  14. data/src/core/ext/filters/client_channel/client_channel_channelz.cc +2 -3
  15. data/src/core/ext/filters/client_channel/client_channel_plugin.cc +4 -0
  16. data/src/core/ext/filters/client_channel/health/health_check_client.cc +54 -49
  17. data/src/core/ext/filters/client_channel/health/health_check_client.h +20 -9
  18. data/src/core/ext/filters/client_channel/http_connect_handshaker.cc +1 -2
  19. data/src/core/ext/filters/client_channel/http_connect_handshaker.h +1 -1
  20. data/src/core/ext/filters/client_channel/lb_policy.cc +3 -30
  21. data/src/core/ext/filters/client_channel/lb_policy.h +16 -25
  22. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +106 -81
  23. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.cc +6 -2
  24. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.h +8 -12
  25. data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.cc +2 -2
  26. data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.h +1 -1
  27. data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc +57 -49
  28. data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc +47 -41
  29. data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +24 -20
  30. data/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc +989 -284
  31. data/src/core/ext/filters/client_channel/lb_policy_factory.h +4 -1
  32. data/src/core/ext/filters/client_channel/lb_policy_registry.cc +105 -2
  33. data/src/core/ext/filters/client_channel/lb_policy_registry.h +9 -2
  34. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +79 -36
  35. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.cc +84 -2
  36. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.h +3 -0
  37. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_libuv.cc +179 -0
  38. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_windows.cc +15 -3
  39. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc +80 -4
  40. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h +7 -13
  41. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_fallback.cc +2 -2
  42. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_libuv.cc +39 -0
  43. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_posix.cc +0 -6
  44. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_windows.cc +2 -64
  45. data/src/core/ext/filters/client_channel/resolver/dns/dns_resolver_selection.cc +28 -0
  46. data/src/core/ext/filters/client_channel/resolver/dns/dns_resolver_selection.h +29 -0
  47. data/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc +4 -4
  48. data/src/core/ext/filters/client_channel/resolver_result_parsing.cc +367 -232
  49. data/src/core/ext/filters/client_channel/resolver_result_parsing.h +55 -76
  50. data/src/core/ext/filters/client_channel/resolving_lb_policy.cc +50 -39
  51. data/src/core/ext/filters/client_channel/resolving_lb_policy.h +18 -12
  52. data/src/core/ext/filters/client_channel/service_config.cc +247 -27
  53. data/src/core/ext/filters/client_channel/service_config.h +119 -166
  54. data/src/core/ext/filters/client_channel/subchannel.cc +46 -84
  55. data/src/core/ext/filters/client_channel/subchannel.h +7 -7
  56. data/src/core/ext/filters/deadline/deadline_filter.cc +3 -4
  57. data/src/core/ext/filters/deadline/deadline_filter.h +3 -2
  58. data/src/core/ext/filters/http/client/http_client_filter.cc +7 -5
  59. data/src/core/ext/filters/http/client/http_client_filter.h +1 -1
  60. data/src/core/ext/filters/http/client_authority_filter.cc +1 -1
  61. data/src/core/ext/filters/http/message_compress/message_compress_filter.cc +4 -3
  62. data/src/core/ext/filters/http/server/http_server_filter.cc +18 -12
  63. data/src/core/ext/filters/message_size/message_size_filter.cc +118 -76
  64. data/src/core/ext/filters/message_size/message_size_filter.h +33 -0
  65. data/src/core/ext/transport/chttp2/alpn/alpn.h +1 -1
  66. data/src/core/ext/transport/chttp2/transport/chttp2_plugin.cc +9 -7
  67. data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +93 -60
  68. data/src/core/ext/transport/chttp2/transport/flow_control.h +1 -1
  69. data/src/core/ext/transport/chttp2/transport/frame_settings.cc +4 -3
  70. data/src/core/ext/transport/chttp2/transport/hpack_encoder.cc +3 -3
  71. data/src/core/ext/transport/chttp2/transport/hpack_parser.cc +8 -2
  72. data/src/core/ext/transport/chttp2/transport/hpack_table.cc +2 -2
  73. data/src/core/ext/transport/chttp2/transport/incoming_metadata.cc +1 -1
  74. data/src/core/ext/transport/chttp2/transport/incoming_metadata.h +3 -2
  75. data/src/core/ext/transport/chttp2/transport/internal.h +35 -23
  76. data/src/core/ext/transport/chttp2/transport/parsing.cc +4 -4
  77. data/src/core/ext/transport/chttp2/transport/stream_lists.cc +3 -3
  78. data/src/core/ext/transport/chttp2/transport/writing.cc +61 -27
  79. data/src/core/ext/transport/inproc/inproc_transport.cc +18 -18
  80. data/src/core/lib/channel/channel_args.cc +0 -101
  81. data/src/core/lib/channel/channel_args.h +0 -37
  82. data/src/core/lib/channel/channel_stack.h +9 -5
  83. data/src/core/lib/channel/channelz_registry.cc +1 -1
  84. data/src/core/lib/channel/connected_channel.cc +2 -2
  85. data/src/core/lib/channel/context.h +3 -0
  86. data/src/core/lib/channel/handshaker.cc +4 -4
  87. data/src/core/lib/channel/handshaker.h +1 -1
  88. data/src/core/lib/compression/compression_args.cc +127 -0
  89. data/src/core/lib/compression/compression_args.h +55 -0
  90. data/src/core/lib/debug/trace.cc +13 -7
  91. data/src/core/lib/debug/trace.h +12 -0
  92. data/src/core/lib/gpr/arena.h +13 -9
  93. data/src/core/lib/gpr/env.h +2 -5
  94. data/src/core/lib/gpr/env_linux.cc +6 -1
  95. data/src/core/lib/gpr/env_posix.cc +5 -0
  96. data/src/core/lib/gpr/env_windows.cc +7 -5
  97. data/src/core/lib/gpr/log.cc +9 -13
  98. data/src/core/lib/gpr/string.cc +12 -6
  99. data/src/core/lib/gpr/string.h +4 -2
  100. data/src/core/lib/gpr/time_posix.cc +13 -0
  101. data/src/core/lib/gprpp/arena.cc +103 -0
  102. data/src/core/lib/gprpp/arena.h +121 -0
  103. data/src/core/lib/gprpp/fork.cc +12 -29
  104. data/src/core/lib/gprpp/global_config.h +87 -0
  105. data/src/core/lib/gprpp/global_config_custom.h +29 -0
  106. data/src/core/lib/gprpp/global_config_env.cc +135 -0
  107. data/src/core/lib/gprpp/global_config_env.h +131 -0
  108. data/src/core/lib/gprpp/global_config_generic.h +44 -0
  109. data/src/core/lib/gprpp/map.h +419 -0
  110. data/src/core/lib/gprpp/optional.h +1 -0
  111. data/src/core/lib/gprpp/orphanable.h +2 -2
  112. data/src/core/lib/gprpp/{mutex_lock.h → pair.h} +15 -19
  113. data/src/core/lib/gprpp/ref_counted.h +18 -2
  114. data/src/core/lib/gprpp/sync.h +126 -0
  115. data/src/core/lib/http/parser.cc +1 -1
  116. data/src/core/lib/iomgr/call_combiner.cc +84 -90
  117. data/src/core/lib/iomgr/call_combiner.h +75 -82
  118. data/src/core/lib/iomgr/cfstream_handle.cc +202 -0
  119. data/src/core/lib/iomgr/cfstream_handle.h +82 -0
  120. data/src/core/lib/iomgr/combiner.h +1 -1
  121. data/src/core/lib/iomgr/endpoint_cfstream.cc +375 -0
  122. data/src/core/lib/iomgr/endpoint_cfstream.h +49 -0
  123. data/src/core/lib/iomgr/endpoint_pair_windows.cc +2 -2
  124. data/src/core/lib/iomgr/error.h +23 -0
  125. data/src/core/lib/iomgr/error_cfstream.cc +52 -0
  126. data/src/core/lib/iomgr/error_cfstream.h +31 -0
  127. data/src/core/lib/iomgr/ev_epoll1_linux.cc +34 -27
  128. data/src/core/lib/iomgr/ev_epollex_linux.cc +33 -33
  129. data/src/core/lib/iomgr/ev_poll_posix.cc +7 -7
  130. data/src/core/lib/iomgr/ev_posix.cc +15 -13
  131. data/src/core/lib/iomgr/ev_posix.h +4 -1
  132. data/src/core/lib/iomgr/executor.cc +13 -9
  133. data/src/core/lib/iomgr/fork_posix.cc +0 -1
  134. data/src/core/lib/iomgr/internal_errqueue.cc +1 -1
  135. data/src/core/lib/iomgr/iomgr.cc +6 -5
  136. data/src/core/lib/iomgr/iomgr_custom.cc +3 -0
  137. data/src/core/lib/iomgr/iomgr_custom.h +2 -0
  138. data/src/core/lib/iomgr/iomgr_posix_cfstream.cc +93 -0
  139. data/src/core/lib/iomgr/iomgr_windows.cc +1 -0
  140. data/src/core/lib/iomgr/lockfree_event.cc +3 -3
  141. data/src/core/lib/iomgr/port.h +11 -0
  142. data/src/core/lib/iomgr/resource_quota.cc +40 -37
  143. data/src/core/lib/iomgr/socket_utils_common_posix.cc +6 -2
  144. data/src/core/lib/iomgr/socket_windows.cc +19 -0
  145. data/src/core/lib/iomgr/socket_windows.h +8 -0
  146. data/src/core/lib/iomgr/tcp_client_cfstream.cc +216 -0
  147. data/src/core/lib/iomgr/tcp_client_custom.cc +2 -2
  148. data/src/core/lib/iomgr/tcp_client_posix.cc +3 -3
  149. data/src/core/lib/iomgr/tcp_client_windows.cc +1 -1
  150. data/src/core/lib/iomgr/tcp_custom.cc +9 -9
  151. data/src/core/lib/iomgr/tcp_posix.cc +41 -41
  152. data/src/core/lib/iomgr/tcp_server_custom.cc +3 -3
  153. data/src/core/lib/iomgr/tcp_server_posix.cc +14 -1
  154. data/src/core/lib/iomgr/tcp_server_windows.cc +2 -2
  155. data/src/core/lib/iomgr/tcp_windows.cc +7 -9
  156. data/src/core/lib/iomgr/timer_generic.cc +16 -16
  157. data/src/core/lib/iomgr/timer_manager.cc +12 -11
  158. data/src/core/lib/profiling/basic_timers.cc +10 -4
  159. data/src/core/lib/security/context/security_context.cc +6 -7
  160. data/src/core/lib/security/context/security_context.h +3 -4
  161. data/src/core/lib/security/credentials/jwt/jwt_credentials.cc +1 -1
  162. data/src/core/lib/security/credentials/jwt/jwt_verifier.cc +2 -3
  163. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc +1 -1
  164. data/src/core/lib/security/credentials/plugin/plugin_credentials.cc +7 -7
  165. data/src/core/lib/security/security_connector/load_system_roots_linux.cc +7 -5
  166. data/src/core/lib/security/security_connector/security_connector.cc +0 -1
  167. data/src/core/lib/security/security_connector/ssl/ssl_security_connector.cc +3 -2
  168. data/src/core/lib/security/security_connector/ssl_utils.cc +30 -26
  169. data/src/core/lib/security/security_connector/ssl_utils.h +5 -1
  170. data/src/core/lib/security/transport/client_auth_filter.cc +7 -11
  171. data/src/core/lib/security/transport/secure_endpoint.cc +4 -4
  172. data/src/core/lib/security/transport/server_auth_filter.cc +2 -3
  173. data/src/core/lib/slice/slice.cc +99 -116
  174. data/src/core/lib/slice/slice_buffer.cc +5 -0
  175. data/src/core/lib/slice/slice_intern.cc +38 -95
  176. data/src/core/lib/slice/slice_internal.h +200 -2
  177. data/src/core/lib/surface/api_trace.h +1 -1
  178. data/src/core/lib/surface/call.cc +41 -35
  179. data/src/core/lib/surface/call.h +7 -2
  180. data/src/core/lib/surface/call_details.cc +0 -1
  181. data/src/core/lib/surface/completion_queue.cc +36 -27
  182. data/src/core/lib/surface/init.cc +3 -4
  183. data/src/core/lib/surface/lame_client.cc +1 -1
  184. data/src/core/lib/surface/server.cc +18 -25
  185. data/src/core/lib/surface/version.cc +1 -1
  186. data/src/core/lib/transport/bdp_estimator.cc +3 -3
  187. data/src/core/lib/transport/bdp_estimator.h +2 -2
  188. data/src/core/lib/transport/connectivity_state.cc +10 -40
  189. data/src/core/lib/transport/connectivity_state.h +0 -8
  190. data/src/core/lib/transport/error_utils.cc +12 -0
  191. data/src/core/lib/transport/metadata.cc +206 -278
  192. data/src/core/lib/transport/metadata.h +205 -10
  193. data/src/core/lib/transport/static_metadata.cc +108 -116
  194. data/src/core/lib/transport/static_metadata.h +1 -2
  195. data/src/core/lib/transport/status_metadata.cc +3 -3
  196. data/src/core/lib/transport/transport.cc +29 -66
  197. data/src/core/lib/transport/transport.h +36 -8
  198. data/src/core/lib/transport/transport_impl.h +1 -1
  199. data/src/core/tsi/fake_transport_security.cc +4 -4
  200. data/src/core/tsi/ssl/session_cache/ssl_session_cache.cc +1 -1
  201. data/src/core/tsi/ssl_transport_security.cc +1 -1
  202. data/src/ruby/ext/grpc/rb_grpc.c +1 -1
  203. data/src/ruby/lib/grpc/errors.rb +22 -3
  204. data/src/ruby/lib/grpc/generic/bidi_call.rb +1 -1
  205. data/src/ruby/lib/grpc/generic/rpc_server.rb +1 -1
  206. data/src/ruby/lib/grpc/version.rb +1 -1
  207. data/src/ruby/spec/errors_spec.rb +141 -0
  208. metadata +57 -33
  209. data/src/core/lib/gpr/arena.cc +0 -192
@@ -22,10 +22,12 @@
22
22
  #include <grpc/support/port_platform.h>
23
23
 
24
24
  #include "src/core/ext/filters/client_channel/lb_policy.h"
25
+ #include "src/core/ext/filters/client_channel/lb_policy_factory.h"
25
26
  #include "src/core/ext/filters/client_channel/resolver.h"
26
27
  #include "src/core/ext/filters/client_channel/retry_throttle.h"
27
28
  #include "src/core/ext/filters/client_channel/service_config.h"
28
29
  #include "src/core/lib/channel/status_util.h"
30
+ #include "src/core/lib/gprpp/optional.h"
29
31
  #include "src/core/lib/gprpp/ref_counted.h"
30
32
  #include "src/core/lib/gprpp/ref_counted_ptr.h"
31
33
  #include "src/core/lib/iomgr/exec_ctx.h" // for grpc_millis
@@ -35,76 +37,48 @@
35
37
  namespace grpc_core {
36
38
  namespace internal {
37
39
 
38
- class ClientChannelMethodParams;
39
-
40
- // A table mapping from a method name to its method parameters.
41
- typedef SliceHashTable<RefCountedPtr<ClientChannelMethodParams>>
42
- ClientChannelMethodParamsTable;
43
-
44
- // A container of processed fields from the resolver result. Simplifies the
45
- // usage of resolver result.
46
- class ProcessedResolverResult {
40
+ class ClientChannelGlobalParsedObject : public ServiceConfig::ParsedConfig {
47
41
  public:
48
- // Processes the resolver result and populates the relative members
49
- // for later consumption. Tries to parse retry parameters only if parse_retry
50
- // is true.
51
- ProcessedResolverResult(Resolver::Result* resolver_result, bool parse_retry);
52
-
53
- // Getters. Any managed object's ownership is transferred.
54
- UniquePtr<char> service_config_json() {
55
- return std::move(service_config_json_);
42
+ struct RetryThrottling {
43
+ intptr_t max_milli_tokens = 0;
44
+ intptr_t milli_token_ratio = 0;
45
+ };
46
+
47
+ ClientChannelGlobalParsedObject(
48
+ RefCountedPtr<ParsedLoadBalancingConfig> parsed_lb_config,
49
+ UniquePtr<char> parsed_deprecated_lb_policy,
50
+ const Optional<RetryThrottling>& retry_throttling,
51
+ const char* health_check_service_name)
52
+ : parsed_lb_config_(std::move(parsed_lb_config)),
53
+ parsed_deprecated_lb_policy_(std::move(parsed_deprecated_lb_policy)),
54
+ retry_throttling_(retry_throttling),
55
+ health_check_service_name_(health_check_service_name) {}
56
+
57
+ Optional<RetryThrottling> retry_throttling() const {
58
+ return retry_throttling_;
56
59
  }
57
- RefCountedPtr<ServerRetryThrottleData> retry_throttle_data() {
58
- return std::move(retry_throttle_data_);
60
+
61
+ RefCountedPtr<ParsedLoadBalancingConfig> parsed_lb_config() const {
62
+ return parsed_lb_config_;
59
63
  }
60
- RefCountedPtr<ClientChannelMethodParamsTable> method_params_table() {
61
- return std::move(method_params_table_);
64
+
65
+ const char* parsed_deprecated_lb_policy() const {
66
+ return parsed_deprecated_lb_policy_.get();
62
67
  }
63
- UniquePtr<char> lb_policy_name() { return std::move(lb_policy_name_); }
64
- RefCountedPtr<LoadBalancingPolicy::Config> lb_policy_config() {
65
- return std::move(lb_policy_config_);
68
+
69
+ const char* health_check_service_name() const {
70
+ return health_check_service_name_;
66
71
  }
67
72
 
68
73
  private:
69
- // Finds the service config; extracts LB config and (maybe) retry throttle
70
- // params from it.
71
- void ProcessServiceConfig(const Resolver::Result& resolver_result,
72
- bool parse_retry);
73
-
74
- // Finds the LB policy name (when no LB config was found).
75
- void ProcessLbPolicyName(const Resolver::Result& resolver_result);
76
-
77
- // Parses the service config. Intended to be used by
78
- // ServiceConfig::ParseGlobalParams.
79
- static void ParseServiceConfig(const grpc_json* field,
80
- ProcessedResolverResult* parsing_state);
81
- // Parses the LB config from service config.
82
- void ParseLbConfigFromServiceConfig(const grpc_json* field);
83
- // Parses the retry throttle parameters from service config.
84
- void ParseRetryThrottleParamsFromServiceConfig(const grpc_json* field);
85
-
86
- // Service config.
87
- UniquePtr<char> service_config_json_;
88
- RefCountedPtr<ServiceConfig> service_config_;
89
- // LB policy.
90
- UniquePtr<char> lb_policy_name_;
91
- RefCountedPtr<LoadBalancingPolicy::Config> lb_policy_config_;
92
- // Retry throttle data.
93
- char* server_name_ = nullptr;
94
- RefCountedPtr<ServerRetryThrottleData> retry_throttle_data_;
95
- // Method params table.
96
- RefCountedPtr<ClientChannelMethodParamsTable> method_params_table_;
74
+ RefCountedPtr<ParsedLoadBalancingConfig> parsed_lb_config_;
75
+ UniquePtr<char> parsed_deprecated_lb_policy_;
76
+ Optional<RetryThrottling> retry_throttling_;
77
+ const char* health_check_service_name_;
97
78
  };
98
79
 
99
- // The parameters of a method.
100
- class ClientChannelMethodParams : public RefCounted<ClientChannelMethodParams> {
80
+ class ClientChannelMethodParsedObject : public ServiceConfig::ParsedConfig {
101
81
  public:
102
- enum WaitForReady {
103
- WAIT_FOR_READY_UNSET = 0,
104
- WAIT_FOR_READY_FALSE,
105
- WAIT_FOR_READY_TRUE
106
- };
107
-
108
82
  struct RetryPolicy {
109
83
  int max_attempts = 0;
110
84
  grpc_millis initial_backoff = 0;
@@ -113,30 +87,35 @@ class ClientChannelMethodParams : public RefCounted<ClientChannelMethodParams> {
113
87
  StatusCodeSet retryable_status_codes;
114
88
  };
115
89
 
116
- /// Creates a method_parameters object from \a json.
117
- /// Intended for use with ServiceConfig::CreateMethodConfigTable().
118
- static RefCountedPtr<ClientChannelMethodParams> CreateFromJson(
119
- const grpc_json* json);
90
+ ClientChannelMethodParsedObject(grpc_millis timeout,
91
+ const Optional<bool>& wait_for_ready,
92
+ UniquePtr<RetryPolicy> retry_policy)
93
+ : timeout_(timeout),
94
+ wait_for_ready_(wait_for_ready),
95
+ retry_policy_(std::move(retry_policy)) {}
120
96
 
121
97
  grpc_millis timeout() const { return timeout_; }
122
- WaitForReady wait_for_ready() const { return wait_for_ready_; }
98
+
99
+ Optional<bool> wait_for_ready() const { return wait_for_ready_; }
100
+
123
101
  const RetryPolicy* retry_policy() const { return retry_policy_.get(); }
124
102
 
125
103
  private:
126
- // So New() can call our private ctor.
127
- template <typename T, typename... Args>
128
- friend T* grpc_core::New(Args&&... args);
104
+ grpc_millis timeout_ = 0;
105
+ Optional<bool> wait_for_ready_;
106
+ UniquePtr<RetryPolicy> retry_policy_;
107
+ };
129
108
 
130
- // So Delete() can call our private dtor.
131
- template <typename T>
132
- friend void grpc_core::Delete(T*);
109
+ class ClientChannelServiceConfigParser : public ServiceConfig::Parser {
110
+ public:
111
+ UniquePtr<ServiceConfig::ParsedConfig> ParseGlobalParams(
112
+ const grpc_json* json, grpc_error** error) override;
133
113
 
134
- ClientChannelMethodParams() {}
135
- virtual ~ClientChannelMethodParams() {}
114
+ UniquePtr<ServiceConfig::ParsedConfig> ParsePerMethodParams(
115
+ const grpc_json* json, grpc_error** error) override;
136
116
 
137
- grpc_millis timeout_ = 0;
138
- WaitForReady wait_for_ready_ = WAIT_FOR_READY_UNSET;
139
- UniquePtr<RetryPolicy> retry_policy_;
117
+ static size_t ParserIndex();
118
+ static void Register();
140
119
  };
141
120
 
142
121
  } // namespace internal
@@ -48,7 +48,7 @@
48
48
  #include "src/core/lib/gpr/string.h"
49
49
  #include "src/core/lib/gprpp/inlined_vector.h"
50
50
  #include "src/core/lib/gprpp/manual_constructor.h"
51
- #include "src/core/lib/gprpp/mutex_lock.h"
51
+ #include "src/core/lib/gprpp/sync.h"
52
52
  #include "src/core/lib/iomgr/combiner.h"
53
53
  #include "src/core/lib/iomgr/iomgr.h"
54
54
  #include "src/core/lib/iomgr/polling_entity.h"
@@ -77,7 +77,7 @@ class ResolvingLoadBalancingPolicy::ResolverResultHandler
77
77
  : parent_(std::move(parent)) {}
78
78
 
79
79
  ~ResolverResultHandler() {
80
- if (parent_->tracer_->enabled()) {
80
+ if (GRPC_TRACE_FLAG_ENABLED(*(parent_->tracer_))) {
81
81
  gpr_log(GPR_INFO, "resolving_lb=%p: resolver shutdown complete",
82
82
  parent_.get());
83
83
  }
@@ -119,27 +119,20 @@ class ResolvingLoadBalancingPolicy::ResolvingControlHelper
119
119
  return parent_->channel_control_helper()->CreateChannel(target, args);
120
120
  }
121
121
 
122
- void UpdateState(grpc_connectivity_state state, grpc_error* state_error,
122
+ void UpdateState(grpc_connectivity_state state,
123
123
  UniquePtr<SubchannelPicker> picker) override {
124
- if (parent_->resolver_ == nullptr) {
125
- // shutting down.
126
- GRPC_ERROR_UNREF(state_error);
127
- return;
128
- }
124
+ if (parent_->resolver_ == nullptr) return; // Shutting down.
129
125
  // If this request is from the pending child policy, ignore it until
130
126
  // it reports READY, at which point we swap it into place.
131
127
  if (CalledByPendingChild()) {
132
- if (parent_->tracer_->enabled()) {
128
+ if (GRPC_TRACE_FLAG_ENABLED(*(parent_->tracer_))) {
133
129
  gpr_log(GPR_INFO,
134
130
  "resolving_lb=%p helper=%p: pending child policy %p reports "
135
131
  "state=%s",
136
132
  parent_.get(), this, child_,
137
133
  grpc_connectivity_state_name(state));
138
134
  }
139
- if (state != GRPC_CHANNEL_READY) {
140
- GRPC_ERROR_UNREF(state_error);
141
- return;
142
- }
135
+ if (state != GRPC_CHANNEL_READY) return;
143
136
  grpc_pollset_set_del_pollset_set(
144
137
  parent_->lb_policy_->interested_parties(),
145
138
  parent_->interested_parties());
@@ -147,11 +140,9 @@ class ResolvingLoadBalancingPolicy::ResolvingControlHelper
147
140
  parent_->lb_policy_ = std::move(parent_->pending_lb_policy_);
148
141
  } else if (!CalledByCurrentChild()) {
149
142
  // This request is from an outdated child, so ignore it.
150
- GRPC_ERROR_UNREF(state_error);
151
143
  return;
152
144
  }
153
- parent_->channel_control_helper()->UpdateState(state, state_error,
154
- std::move(picker));
145
+ parent_->channel_control_helper()->UpdateState(state, std::move(picker));
155
146
  }
156
147
 
157
148
  void RequestReresolution() override {
@@ -160,7 +151,7 @@ class ResolvingLoadBalancingPolicy::ResolvingControlHelper
160
151
  if (parent_->pending_lb_policy_ != nullptr && !CalledByPendingChild()) {
161
152
  return;
162
153
  }
163
- if (parent_->tracer_->enabled()) {
154
+ if (GRPC_TRACE_FLAG_ENABLED(*(parent_->tracer_))) {
164
155
  gpr_log(GPR_INFO, "resolving_lb=%p: started name re-resolving",
165
156
  parent_.get());
166
157
  }
@@ -192,7 +183,8 @@ class ResolvingLoadBalancingPolicy::ResolvingControlHelper
192
183
 
193
184
  ResolvingLoadBalancingPolicy::ResolvingLoadBalancingPolicy(
194
185
  Args args, TraceFlag* tracer, UniquePtr<char> target_uri,
195
- UniquePtr<char> child_policy_name, RefCountedPtr<Config> child_lb_config,
186
+ UniquePtr<char> child_policy_name,
187
+ RefCountedPtr<ParsedLoadBalancingConfig> child_lb_config,
196
188
  grpc_error** error)
197
189
  : LoadBalancingPolicy(std::move(args)),
198
190
  tracer_(tracer),
@@ -234,8 +226,7 @@ grpc_error* ResolvingLoadBalancingPolicy::Init(const grpc_channel_args& args) {
234
226
  }
235
227
  // Return our picker to the channel.
236
228
  channel_control_helper()->UpdateState(
237
- GRPC_CHANNEL_IDLE, GRPC_ERROR_NONE,
238
- UniquePtr<SubchannelPicker>(New<QueuePicker>(Ref())));
229
+ GRPC_CHANNEL_IDLE, UniquePtr<SubchannelPicker>(New<QueuePicker>(Ref())));
239
230
  return GRPC_ERROR_NONE;
240
231
  }
241
232
 
@@ -250,7 +241,7 @@ void ResolvingLoadBalancingPolicy::ShutdownLocked() {
250
241
  resolver_.reset();
251
242
  MutexLock lock(&lb_policy_mu_);
252
243
  if (lb_policy_ != nullptr) {
253
- if (tracer_->enabled()) {
244
+ if (GRPC_TRACE_FLAG_ENABLED(*tracer_)) {
254
245
  gpr_log(GPR_INFO, "resolving_lb=%p: shutting down lb_policy=%p", this,
255
246
  lb_policy_.get());
256
247
  }
@@ -259,7 +250,7 @@ void ResolvingLoadBalancingPolicy::ShutdownLocked() {
259
250
  lb_policy_.reset();
260
251
  }
261
252
  if (pending_lb_policy_ != nullptr) {
262
- if (tracer_->enabled()) {
253
+ if (GRPC_TRACE_FLAG_ENABLED(*tracer_)) {
263
254
  gpr_log(GPR_INFO, "resolving_lb=%p: shutting down pending lb_policy=%p",
264
255
  this, pending_lb_policy_.get());
265
256
  }
@@ -307,13 +298,13 @@ void ResolvingLoadBalancingPolicy::FillChildRefsForChannelz(
307
298
  }
308
299
 
309
300
  void ResolvingLoadBalancingPolicy::StartResolvingLocked() {
310
- if (tracer_->enabled()) {
301
+ if (GRPC_TRACE_FLAG_ENABLED(*tracer_)) {
311
302
  gpr_log(GPR_INFO, "resolving_lb=%p: starting name resolution", this);
312
303
  }
313
304
  GPR_ASSERT(!started_resolving_);
314
305
  started_resolving_ = true;
315
306
  channel_control_helper()->UpdateState(
316
- GRPC_CHANNEL_CONNECTING, GRPC_ERROR_NONE,
307
+ GRPC_CHANNEL_CONNECTING,
317
308
  UniquePtr<SubchannelPicker>(New<QueuePicker>(Ref())));
318
309
  resolver_->StartLocked();
319
310
  }
@@ -323,7 +314,7 @@ void ResolvingLoadBalancingPolicy::OnResolverError(grpc_error* error) {
323
314
  GRPC_ERROR_UNREF(error);
324
315
  return;
325
316
  }
326
- if (tracer_->enabled()) {
317
+ if (GRPC_TRACE_FLAG_ENABLED(*tracer_)) {
327
318
  gpr_log(GPR_INFO, "resolving_lb=%p: resolver transient failure: %s", this,
328
319
  grpc_error_string(error));
329
320
  }
@@ -334,14 +325,15 @@ void ResolvingLoadBalancingPolicy::OnResolverError(grpc_error* error) {
334
325
  grpc_error* state_error = GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING(
335
326
  "Resolver transient failure", &error, 1);
336
327
  channel_control_helper()->UpdateState(
337
- GRPC_CHANNEL_TRANSIENT_FAILURE, GRPC_ERROR_REF(state_error),
328
+ GRPC_CHANNEL_TRANSIENT_FAILURE,
338
329
  UniquePtr<SubchannelPicker>(New<TransientFailurePicker>(state_error)));
339
330
  }
340
331
  GRPC_ERROR_UNREF(error);
341
332
  }
342
333
 
343
334
  void ResolvingLoadBalancingPolicy::CreateOrUpdateLbPolicyLocked(
344
- const char* lb_policy_name, RefCountedPtr<Config> lb_policy_config,
335
+ const char* lb_policy_name,
336
+ RefCountedPtr<ParsedLoadBalancingConfig> lb_policy_config,
345
337
  Resolver::Result result, TraceStringVector* trace_strings) {
346
338
  // If the child policy name changes, we need to create a new child
347
339
  // policy. When this happens, we leave child_policy_ as-is and store
@@ -406,7 +398,7 @@ void ResolvingLoadBalancingPolicy::CreateOrUpdateLbPolicyLocked(
406
398
  // Cases 1, 2b, and 3b: create a new child policy.
407
399
  // If lb_policy_ is null, we set it (case 1), else we set
408
400
  // pending_lb_policy_ (cases 2b and 3b).
409
- if (tracer_->enabled()) {
401
+ if (GRPC_TRACE_FLAG_ENABLED(*tracer_)) {
410
402
  gpr_log(GPR_INFO, "resolving_lb=%p: Creating new %schild policy %s", this,
411
403
  lb_policy_ == nullptr ? "" : "pending ", lb_policy_name);
412
404
  }
@@ -427,7 +419,7 @@ void ResolvingLoadBalancingPolicy::CreateOrUpdateLbPolicyLocked(
427
419
  }
428
420
  GPR_ASSERT(policy_to_update != nullptr);
429
421
  // Update the policy.
430
- if (tracer_->enabled()) {
422
+ if (GRPC_TRACE_FLAG_ENABLED(*tracer_)) {
431
423
  gpr_log(GPR_INFO, "resolving_lb=%p: Updating %schild policy %p", this,
432
424
  policy_to_update == pending_lb_policy_.get() ? "pending " : "",
433
425
  policy_to_update);
@@ -466,7 +458,7 @@ ResolvingLoadBalancingPolicy::CreateLbPolicyLocked(
466
458
  return nullptr;
467
459
  }
468
460
  helper->set_child(lb_policy.get());
469
- if (tracer_->enabled()) {
461
+ if (GRPC_TRACE_FLAG_ENABLED(*tracer_)) {
470
462
  gpr_log(GPR_INFO, "resolving_lb=%p: created new LB policy \"%s\" (%p)",
471
463
  this, lb_policy_name, lb_policy.get());
472
464
  }
@@ -522,7 +514,7 @@ void ResolvingLoadBalancingPolicy::OnResolverResultChangedLocked(
522
514
  Resolver::Result result) {
523
515
  // Handle race conditions.
524
516
  if (resolver_ == nullptr) return;
525
- if (tracer_->enabled()) {
517
+ if (GRPC_TRACE_FLAG_ENABLED(*tracer_)) {
526
518
  gpr_log(GPR_INFO, "resolving_lb=%p: got resolver result", this);
527
519
  }
528
520
  // We only want to trace the address resolution in the follow cases:
@@ -538,20 +530,34 @@ void ResolvingLoadBalancingPolicy::OnResolverResultChangedLocked(
538
530
  const bool resolution_contains_addresses = result.addresses.size() > 0;
539
531
  // Process the resolver result.
540
532
  const char* lb_policy_name = nullptr;
541
- RefCountedPtr<Config> lb_policy_config;
533
+ RefCountedPtr<ParsedLoadBalancingConfig> lb_policy_config;
542
534
  bool service_config_changed = false;
535
+ char* service_config_error_string = nullptr;
543
536
  if (process_resolver_result_ != nullptr) {
544
- service_config_changed =
545
- process_resolver_result_(process_resolver_result_user_data_, &result,
546
- &lb_policy_name, &lb_policy_config);
537
+ grpc_error* service_config_error = GRPC_ERROR_NONE;
538
+ service_config_changed = process_resolver_result_(
539
+ process_resolver_result_user_data_, result, &lb_policy_name,
540
+ &lb_policy_config, &service_config_error);
541
+ if (service_config_error != GRPC_ERROR_NONE) {
542
+ service_config_error_string =
543
+ gpr_strdup(grpc_error_string(service_config_error));
544
+ if (lb_policy_name == nullptr) {
545
+ // Use an empty lb_policy_name as an indicator that we received an
546
+ // invalid service config and we don't have a fallback service config.
547
+ OnResolverError(service_config_error);
548
+ } else {
549
+ GRPC_ERROR_UNREF(service_config_error);
550
+ }
551
+ }
547
552
  } else {
548
553
  lb_policy_name = child_policy_name_.get();
549
554
  lb_policy_config = child_lb_config_;
550
555
  }
551
- GPR_ASSERT(lb_policy_name != nullptr);
552
- // Create or update LB policy, as needed.
553
- CreateOrUpdateLbPolicyLocked(lb_policy_name, std::move(lb_policy_config),
554
- std::move(result), &trace_strings);
556
+ if (lb_policy_name != nullptr) {
557
+ // Create or update LB policy, as needed.
558
+ CreateOrUpdateLbPolicyLocked(lb_policy_name, lb_policy_config,
559
+ std::move(result), &trace_strings);
560
+ }
555
561
  // Add channel trace event.
556
562
  if (channelz_node() != nullptr) {
557
563
  if (service_config_changed) {
@@ -559,10 +565,15 @@ void ResolvingLoadBalancingPolicy::OnResolverResultChangedLocked(
559
565
  // config in the trace, at the risk of bloating the trace logs.
560
566
  trace_strings.push_back(gpr_strdup("Service config changed"));
561
567
  }
568
+ if (service_config_error_string != nullptr) {
569
+ trace_strings.push_back(service_config_error_string);
570
+ service_config_error_string = nullptr;
571
+ }
562
572
  MaybeAddTraceMessagesForAddressChangesLocked(resolution_contains_addresses,
563
573
  &trace_strings);
564
574
  ConcatenateAndAddChannelTraceLocked(&trace_strings);
565
575
  }
576
+ gpr_free(service_config_error_string);
566
577
  }
567
578
 
568
579
  } // namespace grpc_core
@@ -23,6 +23,7 @@
23
23
 
24
24
  #include "src/core/ext/filters/client_channel/client_channel_channelz.h"
25
25
  #include "src/core/ext/filters/client_channel/lb_policy.h"
26
+ #include "src/core/ext/filters/client_channel/lb_policy_factory.h"
26
27
  #include "src/core/ext/filters/client_channel/resolver.h"
27
28
  #include "src/core/lib/channel/channel_args.h"
28
29
  #include "src/core/lib/channel/channel_stack.h"
@@ -53,20 +54,25 @@ class ResolvingLoadBalancingPolicy : public LoadBalancingPolicy {
53
54
  public:
54
55
  // If error is set when this returns, then construction failed, and
55
56
  // the caller may not use the new object.
56
- ResolvingLoadBalancingPolicy(Args args, TraceFlag* tracer,
57
- UniquePtr<char> target_uri,
58
- UniquePtr<char> child_policy_name,
59
- RefCountedPtr<Config> child_lb_config,
60
- grpc_error** error);
57
+ ResolvingLoadBalancingPolicy(
58
+ Args args, TraceFlag* tracer, UniquePtr<char> target_uri,
59
+ UniquePtr<char> child_policy_name,
60
+ RefCountedPtr<ParsedLoadBalancingConfig> child_lb_config,
61
+ grpc_error** error);
61
62
 
62
63
  // Private ctor, to be used by client_channel only!
63
64
  //
64
65
  // Synchronous callback that takes the resolver result and sets
65
66
  // lb_policy_name and lb_policy_config to point to the right data.
66
67
  // Returns true if the service config has changed since the last result.
68
+ // If the returned service_config_error is not none and lb_policy_name is
69
+ // empty, it means that we don't have a valid service config to use, and we
70
+ // should set the channel to be in TRANSIENT_FAILURE.
67
71
  typedef bool (*ProcessResolverResultCallback)(
68
- void* user_data, Resolver::Result* result, const char** lb_policy_name,
69
- RefCountedPtr<Config>* lb_policy_config);
72
+ void* user_data, const Resolver::Result& result,
73
+ const char** lb_policy_name,
74
+ RefCountedPtr<ParsedLoadBalancingConfig>* lb_policy_config,
75
+ grpc_error** service_config_error);
70
76
  // If error is set when this returns, then construction failed, and
71
77
  // the caller may not use the new object.
72
78
  ResolvingLoadBalancingPolicy(
@@ -102,10 +108,10 @@ class ResolvingLoadBalancingPolicy : public LoadBalancingPolicy {
102
108
 
103
109
  void StartResolvingLocked();
104
110
  void OnResolverError(grpc_error* error);
105
- void CreateOrUpdateLbPolicyLocked(const char* lb_policy_name,
106
- RefCountedPtr<Config> lb_policy_config,
107
- Resolver::Result result,
108
- TraceStringVector* trace_strings);
111
+ void CreateOrUpdateLbPolicyLocked(
112
+ const char* lb_policy_name,
113
+ RefCountedPtr<ParsedLoadBalancingConfig> lb_policy_config,
114
+ Resolver::Result result, TraceStringVector* trace_strings);
109
115
  OrphanablePtr<LoadBalancingPolicy> CreateLbPolicyLocked(
110
116
  const char* lb_policy_name, const grpc_channel_args& args,
111
117
  TraceStringVector* trace_strings);
@@ -121,7 +127,7 @@ class ResolvingLoadBalancingPolicy : public LoadBalancingPolicy {
121
127
  ProcessResolverResultCallback process_resolver_result_ = nullptr;
122
128
  void* process_resolver_result_user_data_ = nullptr;
123
129
  UniquePtr<char> child_policy_name_;
124
- RefCountedPtr<Config> child_lb_config_;
130
+ RefCountedPtr<ParsedLoadBalancingConfig> child_lb_config_;
125
131
 
126
132
  // Resolver and associated state.
127
133
  OrphanablePtr<Resolver> resolver_;