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.
- checksums.yaml +4 -4
- data/Makefile +500 -29
- data/etc/roots.pem +146 -0
- data/include/grpc/grpc_security.h +1 -1
- data/include/grpc/impl/codegen/grpc_types.h +10 -7
- data/include/grpc/impl/codegen/port_platform.h +11 -1
- data/include/grpc/impl/codegen/slice.h +1 -21
- data/include/grpc/impl/codegen/status.h +2 -1
- data/include/grpc/slice.h +1 -1
- data/src/core/ext/filters/client_channel/backup_poller.cc +19 -13
- data/src/core/ext/filters/client_channel/backup_poller.h +3 -0
- data/src/core/ext/filters/client_channel/channel_connectivity.cc +1 -1
- data/src/core/ext/filters/client_channel/client_channel.cc +2084 -1673
- data/src/core/ext/filters/client_channel/client_channel_channelz.cc +2 -3
- data/src/core/ext/filters/client_channel/client_channel_plugin.cc +4 -0
- data/src/core/ext/filters/client_channel/health/health_check_client.cc +54 -49
- data/src/core/ext/filters/client_channel/health/health_check_client.h +20 -9
- data/src/core/ext/filters/client_channel/http_connect_handshaker.cc +1 -2
- data/src/core/ext/filters/client_channel/http_connect_handshaker.h +1 -1
- data/src/core/ext/filters/client_channel/lb_policy.cc +3 -30
- data/src/core/ext/filters/client_channel/lb_policy.h +16 -25
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +106 -81
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.cc +6 -2
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.h +8 -12
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.cc +2 -2
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.h +1 -1
- data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc +57 -49
- data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc +47 -41
- data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +24 -20
- data/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc +989 -284
- data/src/core/ext/filters/client_channel/lb_policy_factory.h +4 -1
- data/src/core/ext/filters/client_channel/lb_policy_registry.cc +105 -2
- data/src/core/ext/filters/client_channel/lb_policy_registry.h +9 -2
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +79 -36
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.cc +84 -2
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.h +3 -0
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_libuv.cc +179 -0
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_windows.cc +15 -3
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc +80 -4
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h +7 -13
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_fallback.cc +2 -2
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_libuv.cc +39 -0
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_posix.cc +0 -6
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_windows.cc +2 -64
- data/src/core/ext/filters/client_channel/resolver/dns/dns_resolver_selection.cc +28 -0
- data/src/core/ext/filters/client_channel/resolver/dns/dns_resolver_selection.h +29 -0
- data/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc +4 -4
- data/src/core/ext/filters/client_channel/resolver_result_parsing.cc +367 -232
- data/src/core/ext/filters/client_channel/resolver_result_parsing.h +55 -76
- data/src/core/ext/filters/client_channel/resolving_lb_policy.cc +50 -39
- data/src/core/ext/filters/client_channel/resolving_lb_policy.h +18 -12
- data/src/core/ext/filters/client_channel/service_config.cc +247 -27
- data/src/core/ext/filters/client_channel/service_config.h +119 -166
- data/src/core/ext/filters/client_channel/subchannel.cc +46 -84
- data/src/core/ext/filters/client_channel/subchannel.h +7 -7
- data/src/core/ext/filters/deadline/deadline_filter.cc +3 -4
- data/src/core/ext/filters/deadline/deadline_filter.h +3 -2
- data/src/core/ext/filters/http/client/http_client_filter.cc +7 -5
- data/src/core/ext/filters/http/client/http_client_filter.h +1 -1
- data/src/core/ext/filters/http/client_authority_filter.cc +1 -1
- data/src/core/ext/filters/http/message_compress/message_compress_filter.cc +4 -3
- data/src/core/ext/filters/http/server/http_server_filter.cc +18 -12
- data/src/core/ext/filters/message_size/message_size_filter.cc +118 -76
- data/src/core/ext/filters/message_size/message_size_filter.h +33 -0
- data/src/core/ext/transport/chttp2/alpn/alpn.h +1 -1
- data/src/core/ext/transport/chttp2/transport/chttp2_plugin.cc +9 -7
- data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +93 -60
- data/src/core/ext/transport/chttp2/transport/flow_control.h +1 -1
- data/src/core/ext/transport/chttp2/transport/frame_settings.cc +4 -3
- data/src/core/ext/transport/chttp2/transport/hpack_encoder.cc +3 -3
- data/src/core/ext/transport/chttp2/transport/hpack_parser.cc +8 -2
- data/src/core/ext/transport/chttp2/transport/hpack_table.cc +2 -2
- data/src/core/ext/transport/chttp2/transport/incoming_metadata.cc +1 -1
- data/src/core/ext/transport/chttp2/transport/incoming_metadata.h +3 -2
- data/src/core/ext/transport/chttp2/transport/internal.h +35 -23
- data/src/core/ext/transport/chttp2/transport/parsing.cc +4 -4
- data/src/core/ext/transport/chttp2/transport/stream_lists.cc +3 -3
- data/src/core/ext/transport/chttp2/transport/writing.cc +61 -27
- data/src/core/ext/transport/inproc/inproc_transport.cc +18 -18
- data/src/core/lib/channel/channel_args.cc +0 -101
- data/src/core/lib/channel/channel_args.h +0 -37
- data/src/core/lib/channel/channel_stack.h +9 -5
- data/src/core/lib/channel/channelz_registry.cc +1 -1
- data/src/core/lib/channel/connected_channel.cc +2 -2
- data/src/core/lib/channel/context.h +3 -0
- data/src/core/lib/channel/handshaker.cc +4 -4
- data/src/core/lib/channel/handshaker.h +1 -1
- data/src/core/lib/compression/compression_args.cc +127 -0
- data/src/core/lib/compression/compression_args.h +55 -0
- data/src/core/lib/debug/trace.cc +13 -7
- data/src/core/lib/debug/trace.h +12 -0
- data/src/core/lib/gpr/arena.h +13 -9
- data/src/core/lib/gpr/env.h +2 -5
- data/src/core/lib/gpr/env_linux.cc +6 -1
- data/src/core/lib/gpr/env_posix.cc +5 -0
- data/src/core/lib/gpr/env_windows.cc +7 -5
- data/src/core/lib/gpr/log.cc +9 -13
- data/src/core/lib/gpr/string.cc +12 -6
- data/src/core/lib/gpr/string.h +4 -2
- data/src/core/lib/gpr/time_posix.cc +13 -0
- data/src/core/lib/gprpp/arena.cc +103 -0
- data/src/core/lib/gprpp/arena.h +121 -0
- data/src/core/lib/gprpp/fork.cc +12 -29
- data/src/core/lib/gprpp/global_config.h +87 -0
- data/src/core/lib/gprpp/global_config_custom.h +29 -0
- data/src/core/lib/gprpp/global_config_env.cc +135 -0
- data/src/core/lib/gprpp/global_config_env.h +131 -0
- data/src/core/lib/gprpp/global_config_generic.h +44 -0
- data/src/core/lib/gprpp/map.h +419 -0
- data/src/core/lib/gprpp/optional.h +1 -0
- data/src/core/lib/gprpp/orphanable.h +2 -2
- data/src/core/lib/gprpp/{mutex_lock.h → pair.h} +15 -19
- data/src/core/lib/gprpp/ref_counted.h +18 -2
- data/src/core/lib/gprpp/sync.h +126 -0
- data/src/core/lib/http/parser.cc +1 -1
- data/src/core/lib/iomgr/call_combiner.cc +84 -90
- data/src/core/lib/iomgr/call_combiner.h +75 -82
- data/src/core/lib/iomgr/cfstream_handle.cc +202 -0
- data/src/core/lib/iomgr/cfstream_handle.h +82 -0
- data/src/core/lib/iomgr/combiner.h +1 -1
- data/src/core/lib/iomgr/endpoint_cfstream.cc +375 -0
- data/src/core/lib/iomgr/endpoint_cfstream.h +49 -0
- data/src/core/lib/iomgr/endpoint_pair_windows.cc +2 -2
- data/src/core/lib/iomgr/error.h +23 -0
- data/src/core/lib/iomgr/error_cfstream.cc +52 -0
- data/src/core/lib/iomgr/error_cfstream.h +31 -0
- data/src/core/lib/iomgr/ev_epoll1_linux.cc +34 -27
- data/src/core/lib/iomgr/ev_epollex_linux.cc +33 -33
- data/src/core/lib/iomgr/ev_poll_posix.cc +7 -7
- data/src/core/lib/iomgr/ev_posix.cc +15 -13
- data/src/core/lib/iomgr/ev_posix.h +4 -1
- data/src/core/lib/iomgr/executor.cc +13 -9
- data/src/core/lib/iomgr/fork_posix.cc +0 -1
- data/src/core/lib/iomgr/internal_errqueue.cc +1 -1
- data/src/core/lib/iomgr/iomgr.cc +6 -5
- data/src/core/lib/iomgr/iomgr_custom.cc +3 -0
- data/src/core/lib/iomgr/iomgr_custom.h +2 -0
- data/src/core/lib/iomgr/iomgr_posix_cfstream.cc +93 -0
- data/src/core/lib/iomgr/iomgr_windows.cc +1 -0
- data/src/core/lib/iomgr/lockfree_event.cc +3 -3
- data/src/core/lib/iomgr/port.h +11 -0
- data/src/core/lib/iomgr/resource_quota.cc +40 -37
- data/src/core/lib/iomgr/socket_utils_common_posix.cc +6 -2
- data/src/core/lib/iomgr/socket_windows.cc +19 -0
- data/src/core/lib/iomgr/socket_windows.h +8 -0
- data/src/core/lib/iomgr/tcp_client_cfstream.cc +216 -0
- data/src/core/lib/iomgr/tcp_client_custom.cc +2 -2
- data/src/core/lib/iomgr/tcp_client_posix.cc +3 -3
- data/src/core/lib/iomgr/tcp_client_windows.cc +1 -1
- data/src/core/lib/iomgr/tcp_custom.cc +9 -9
- data/src/core/lib/iomgr/tcp_posix.cc +41 -41
- data/src/core/lib/iomgr/tcp_server_custom.cc +3 -3
- data/src/core/lib/iomgr/tcp_server_posix.cc +14 -1
- data/src/core/lib/iomgr/tcp_server_windows.cc +2 -2
- data/src/core/lib/iomgr/tcp_windows.cc +7 -9
- data/src/core/lib/iomgr/timer_generic.cc +16 -16
- data/src/core/lib/iomgr/timer_manager.cc +12 -11
- data/src/core/lib/profiling/basic_timers.cc +10 -4
- data/src/core/lib/security/context/security_context.cc +6 -7
- data/src/core/lib/security/context/security_context.h +3 -4
- data/src/core/lib/security/credentials/jwt/jwt_credentials.cc +1 -1
- data/src/core/lib/security/credentials/jwt/jwt_verifier.cc +2 -3
- data/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc +1 -1
- data/src/core/lib/security/credentials/plugin/plugin_credentials.cc +7 -7
- data/src/core/lib/security/security_connector/load_system_roots_linux.cc +7 -5
- data/src/core/lib/security/security_connector/security_connector.cc +0 -1
- data/src/core/lib/security/security_connector/ssl/ssl_security_connector.cc +3 -2
- data/src/core/lib/security/security_connector/ssl_utils.cc +30 -26
- data/src/core/lib/security/security_connector/ssl_utils.h +5 -1
- data/src/core/lib/security/transport/client_auth_filter.cc +7 -11
- data/src/core/lib/security/transport/secure_endpoint.cc +4 -4
- data/src/core/lib/security/transport/server_auth_filter.cc +2 -3
- data/src/core/lib/slice/slice.cc +99 -116
- data/src/core/lib/slice/slice_buffer.cc +5 -0
- data/src/core/lib/slice/slice_intern.cc +38 -95
- data/src/core/lib/slice/slice_internal.h +200 -2
- data/src/core/lib/surface/api_trace.h +1 -1
- data/src/core/lib/surface/call.cc +41 -35
- data/src/core/lib/surface/call.h +7 -2
- data/src/core/lib/surface/call_details.cc +0 -1
- data/src/core/lib/surface/completion_queue.cc +36 -27
- data/src/core/lib/surface/init.cc +3 -4
- data/src/core/lib/surface/lame_client.cc +1 -1
- data/src/core/lib/surface/server.cc +18 -25
- data/src/core/lib/surface/version.cc +1 -1
- data/src/core/lib/transport/bdp_estimator.cc +3 -3
- data/src/core/lib/transport/bdp_estimator.h +2 -2
- data/src/core/lib/transport/connectivity_state.cc +10 -40
- data/src/core/lib/transport/connectivity_state.h +0 -8
- data/src/core/lib/transport/error_utils.cc +12 -0
- data/src/core/lib/transport/metadata.cc +206 -278
- data/src/core/lib/transport/metadata.h +205 -10
- data/src/core/lib/transport/static_metadata.cc +108 -116
- data/src/core/lib/transport/static_metadata.h +1 -2
- data/src/core/lib/transport/status_metadata.cc +3 -3
- data/src/core/lib/transport/transport.cc +29 -66
- data/src/core/lib/transport/transport.h +36 -8
- data/src/core/lib/transport/transport_impl.h +1 -1
- data/src/core/tsi/fake_transport_security.cc +4 -4
- data/src/core/tsi/ssl/session_cache/ssl_session_cache.cc +1 -1
- data/src/core/tsi/ssl_transport_security.cc +1 -1
- data/src/ruby/ext/grpc/rb_grpc.c +1 -1
- data/src/ruby/lib/grpc/errors.rb +22 -3
- data/src/ruby/lib/grpc/generic/bidi_call.rb +1 -1
- data/src/ruby/lib/grpc/generic/rpc_server.rb +1 -1
- data/src/ruby/lib/grpc/version.rb +1 -1
- data/src/ruby/spec/errors_spec.rb +141 -0
- metadata +57 -33
- data/src/core/lib/gpr/arena.cc +0 -192
@@ -62,32 +62,6 @@ void LoadBalancingPolicy::ShutdownAndUnrefLocked(void* arg,
|
|
62
62
|
policy->Unref();
|
63
63
|
}
|
64
64
|
|
65
|
-
grpc_json* LoadBalancingPolicy::ParseLoadBalancingConfig(
|
66
|
-
const grpc_json* lb_config_array) {
|
67
|
-
if (lb_config_array == nullptr || lb_config_array->type != GRPC_JSON_ARRAY) {
|
68
|
-
return nullptr;
|
69
|
-
}
|
70
|
-
// Find the first LB policy that this client supports.
|
71
|
-
for (const grpc_json* lb_config = lb_config_array->child;
|
72
|
-
lb_config != nullptr; lb_config = lb_config->next) {
|
73
|
-
if (lb_config->type != GRPC_JSON_OBJECT) return nullptr;
|
74
|
-
grpc_json* policy = nullptr;
|
75
|
-
for (grpc_json* field = lb_config->child; field != nullptr;
|
76
|
-
field = field->next) {
|
77
|
-
if (field->key == nullptr || field->type != GRPC_JSON_OBJECT)
|
78
|
-
return nullptr;
|
79
|
-
if (policy != nullptr) return nullptr; // Violate "oneof" type.
|
80
|
-
policy = field;
|
81
|
-
}
|
82
|
-
if (policy == nullptr) return nullptr;
|
83
|
-
// If we support this policy, then select it.
|
84
|
-
if (LoadBalancingPolicyRegistry::LoadBalancingPolicyExists(policy->key)) {
|
85
|
-
return policy;
|
86
|
-
}
|
87
|
-
}
|
88
|
-
return nullptr;
|
89
|
-
}
|
90
|
-
|
91
65
|
//
|
92
66
|
// LoadBalancingPolicy::UpdateArgs
|
93
67
|
//
|
@@ -140,10 +114,9 @@ LoadBalancingPolicy::PickResult LoadBalancingPolicy::QueuePicker::Pick(
|
|
140
114
|
// the time this function returns, the pick will already have
|
141
115
|
// been processed, and we'll be trying to re-process the same
|
142
116
|
// pick again, leading to a crash.
|
143
|
-
// 2.
|
144
|
-
//
|
145
|
-
//
|
146
|
-
// the control plane combiner.
|
117
|
+
// 2. We are currently running in the data plane combiner, but we
|
118
|
+
// need to bounce into the control plane combiner to call
|
119
|
+
// ExitIdleLocked().
|
147
120
|
if (!exit_idle_called_) {
|
148
121
|
exit_idle_called_ = true;
|
149
122
|
parent_->Ref().release(); // ref held by closure.
|
@@ -36,6 +36,18 @@ extern grpc_core::DebugOnlyTraceFlag grpc_trace_lb_policy_refcount;
|
|
36
36
|
|
37
37
|
namespace grpc_core {
|
38
38
|
|
39
|
+
/// Interface for parsed forms of load balancing configs found in a service
|
40
|
+
/// config.
|
41
|
+
class ParsedLoadBalancingConfig : public RefCounted<ParsedLoadBalancingConfig> {
|
42
|
+
public:
|
43
|
+
virtual ~ParsedLoadBalancingConfig() = default;
|
44
|
+
|
45
|
+
// Returns the load balancing policy name
|
46
|
+
virtual const char* name() const GRPC_ABSTRACT;
|
47
|
+
|
48
|
+
GRPC_ABSTRACT_BASE_CLASS;
|
49
|
+
};
|
50
|
+
|
39
51
|
/// Interface for load balancing policies.
|
40
52
|
///
|
41
53
|
/// The following concepts are used here:
|
@@ -167,6 +179,9 @@ class LoadBalancingPolicy : public InternallyRefCounted<LoadBalancingPolicy> {
|
|
167
179
|
|
168
180
|
/// A proxy object used by the LB policy to communicate with the client
|
169
181
|
/// channel.
|
182
|
+
// TODO(juanlishen): Consider adding a mid-layer subclass that helps handle
|
183
|
+
// things like swapping in pending policy when it's ready. Currently, we are
|
184
|
+
// duplicating the logic in many subclasses.
|
170
185
|
class ChannelControlHelper {
|
171
186
|
public:
|
172
187
|
ChannelControlHelper() = default;
|
@@ -185,7 +200,6 @@ class LoadBalancingPolicy : public InternallyRefCounted<LoadBalancingPolicy> {
|
|
185
200
|
/// Sets the connectivity state and returns a new picker to be used
|
186
201
|
/// by the client channel.
|
187
202
|
virtual void UpdateState(grpc_connectivity_state state,
|
188
|
-
grpc_error* state_error,
|
189
203
|
UniquePtr<SubchannelPicker>) GRPC_ABSTRACT;
|
190
204
|
|
191
205
|
/// Requests that the resolver re-resolve.
|
@@ -194,30 +208,11 @@ class LoadBalancingPolicy : public InternallyRefCounted<LoadBalancingPolicy> {
|
|
194
208
|
GRPC_ABSTRACT_BASE_CLASS
|
195
209
|
};
|
196
210
|
|
197
|
-
/// Configuration for an LB policy instance.
|
198
|
-
// TODO(roth): Find a better JSON representation for this API.
|
199
|
-
class Config : public RefCounted<Config> {
|
200
|
-
public:
|
201
|
-
Config(const grpc_json* lb_config,
|
202
|
-
RefCountedPtr<ServiceConfig> service_config)
|
203
|
-
: json_(lb_config), service_config_(std::move(service_config)) {}
|
204
|
-
|
205
|
-
const char* name() const { return json_->key; }
|
206
|
-
const grpc_json* config() const { return json_->child; }
|
207
|
-
RefCountedPtr<ServiceConfig> service_config() const {
|
208
|
-
return service_config_;
|
209
|
-
}
|
210
|
-
|
211
|
-
private:
|
212
|
-
const grpc_json* json_;
|
213
|
-
RefCountedPtr<ServiceConfig> service_config_;
|
214
|
-
};
|
215
|
-
|
216
211
|
/// Data passed to the UpdateLocked() method when new addresses and
|
217
212
|
/// config are available.
|
218
213
|
struct UpdateArgs {
|
219
214
|
ServerAddressList addresses;
|
220
|
-
RefCountedPtr<
|
215
|
+
RefCountedPtr<ParsedLoadBalancingConfig> config;
|
221
216
|
const grpc_channel_args* args = nullptr;
|
222
217
|
|
223
218
|
// TODO(roth): Remove everything below once channel args is
|
@@ -288,10 +283,6 @@ class LoadBalancingPolicy : public InternallyRefCounted<LoadBalancingPolicy> {
|
|
288
283
|
|
289
284
|
void Orphan() override;
|
290
285
|
|
291
|
-
/// Returns the JSON node of policy (with both policy name and config content)
|
292
|
-
/// given the JSON node of a LoadBalancingConfig array.
|
293
|
-
static grpc_json* ParseLoadBalancingConfig(const grpc_json* lb_config_array);
|
294
|
-
|
295
286
|
// A picker that returns PICK_QUEUE for all picks.
|
296
287
|
// Also calls the parent LB policy's ExitIdleLocked() method when the
|
297
288
|
// first pick is seen.
|
@@ -88,7 +88,6 @@
|
|
88
88
|
#include "src/core/lib/gpr/string.h"
|
89
89
|
#include "src/core/lib/gprpp/manual_constructor.h"
|
90
90
|
#include "src/core/lib/gprpp/memory.h"
|
91
|
-
#include "src/core/lib/gprpp/mutex_lock.h"
|
92
91
|
#include "src/core/lib/gprpp/orphanable.h"
|
93
92
|
#include "src/core/lib/gprpp/ref_counted_ptr.h"
|
94
93
|
#include "src/core/lib/iomgr/combiner.h"
|
@@ -119,6 +118,21 @@ namespace {
|
|
119
118
|
|
120
119
|
constexpr char kGrpclb[] = "grpclb";
|
121
120
|
|
121
|
+
class ParsedGrpcLbConfig : public ParsedLoadBalancingConfig {
|
122
|
+
public:
|
123
|
+
explicit ParsedGrpcLbConfig(
|
124
|
+
RefCountedPtr<ParsedLoadBalancingConfig> child_policy)
|
125
|
+
: child_policy_(std::move(child_policy)) {}
|
126
|
+
const char* name() const override { return kGrpclb; }
|
127
|
+
|
128
|
+
RefCountedPtr<ParsedLoadBalancingConfig> child_policy() const {
|
129
|
+
return child_policy_;
|
130
|
+
}
|
131
|
+
|
132
|
+
private:
|
133
|
+
RefCountedPtr<ParsedLoadBalancingConfig> child_policy_;
|
134
|
+
};
|
135
|
+
|
122
136
|
class GrpcLb : public LoadBalancingPolicy {
|
123
137
|
public:
|
124
138
|
explicit GrpcLb(Args args);
|
@@ -234,12 +248,19 @@ class GrpcLb : public LoadBalancingPolicy {
|
|
234
248
|
|
235
249
|
// Returns the LB token to use for a drop, or null if the call
|
236
250
|
// should not be dropped.
|
237
|
-
//
|
238
|
-
//
|
251
|
+
//
|
252
|
+
// Note: This is called from the picker, so it will be invoked in
|
253
|
+
// the channel's data plane combiner, NOT the control plane
|
254
|
+
// combiner. It should not be accessed by any other part of the LB
|
255
|
+
// policy.
|
239
256
|
const char* ShouldDrop();
|
240
257
|
|
241
258
|
private:
|
242
259
|
grpc_grpclb_serverlist* serverlist_;
|
260
|
+
|
261
|
+
// Guarded by the channel's data plane combiner, NOT the control
|
262
|
+
// plane combiner. It should not be accessed by anything but the
|
263
|
+
// picker via the ShouldDrop() method.
|
243
264
|
size_t drop_index_ = 0;
|
244
265
|
};
|
245
266
|
|
@@ -275,7 +296,7 @@ class GrpcLb : public LoadBalancingPolicy {
|
|
275
296
|
Subchannel* CreateSubchannel(const grpc_channel_args& args) override;
|
276
297
|
grpc_channel* CreateChannel(const char* target,
|
277
298
|
const grpc_channel_args& args) override;
|
278
|
-
void UpdateState(grpc_connectivity_state state,
|
299
|
+
void UpdateState(grpc_connectivity_state state,
|
279
300
|
UniquePtr<SubchannelPicker> picker) override;
|
280
301
|
void RequestReresolution() override;
|
281
302
|
|
@@ -296,7 +317,6 @@ class GrpcLb : public LoadBalancingPolicy {
|
|
296
317
|
// Helper functions used in UpdateLocked().
|
297
318
|
void ProcessAddressesAndChannelArgsLocked(const ServerAddressList& addresses,
|
298
319
|
const grpc_channel_args& args);
|
299
|
-
void ParseLbConfig(Config* grpclb_config);
|
300
320
|
static void OnBalancerChannelConnectivityChangedLocked(void* arg,
|
301
321
|
grpc_error* error);
|
302
322
|
void CancelBalancerChannelConnectivityWatchLocked();
|
@@ -374,7 +394,7 @@ class GrpcLb : public LoadBalancingPolicy {
|
|
374
394
|
// until it reports READY, at which point it will be moved to child_policy_.
|
375
395
|
OrphanablePtr<LoadBalancingPolicy> pending_child_policy_;
|
376
396
|
// The child policy config.
|
377
|
-
RefCountedPtr<
|
397
|
+
RefCountedPtr<ParsedLoadBalancingConfig> child_policy_config_;
|
378
398
|
// Child policy in state READY.
|
379
399
|
bool child_policy_ready_ = false;
|
380
400
|
};
|
@@ -551,7 +571,7 @@ GrpcLb::PickResult GrpcLb::Picker::Pick(PickArgs* pick, grpc_error** error) {
|
|
551
571
|
// subchannel call (and therefore no client_load_reporting filter)
|
552
572
|
// for dropped calls.
|
553
573
|
if (client_stats_ != nullptr) {
|
554
|
-
client_stats_->
|
574
|
+
client_stats_->AddCallDropped(drop_token);
|
555
575
|
}
|
556
576
|
return PICK_COMPLETE;
|
557
577
|
}
|
@@ -615,25 +635,18 @@ grpc_channel* GrpcLb::Helper::CreateChannel(const char* target,
|
|
615
635
|
}
|
616
636
|
|
617
637
|
void GrpcLb::Helper::UpdateState(grpc_connectivity_state state,
|
618
|
-
grpc_error* state_error,
|
619
638
|
UniquePtr<SubchannelPicker> picker) {
|
620
|
-
if (parent_->shutting_down_)
|
621
|
-
GRPC_ERROR_UNREF(state_error);
|
622
|
-
return;
|
623
|
-
}
|
639
|
+
if (parent_->shutting_down_) return;
|
624
640
|
// If this request is from the pending child policy, ignore it until
|
625
641
|
// it reports READY, at which point we swap it into place.
|
626
642
|
if (CalledByPendingChild()) {
|
627
|
-
if (grpc_lb_glb_trace
|
643
|
+
if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_glb_trace)) {
|
628
644
|
gpr_log(GPR_INFO,
|
629
645
|
"[grpclb %p helper %p] pending child policy %p reports state=%s",
|
630
646
|
parent_.get(), this, parent_->pending_child_policy_.get(),
|
631
647
|
grpc_connectivity_state_name(state));
|
632
648
|
}
|
633
|
-
if (state != GRPC_CHANNEL_READY)
|
634
|
-
GRPC_ERROR_UNREF(state_error);
|
635
|
-
return;
|
636
|
-
}
|
649
|
+
if (state != GRPC_CHANNEL_READY) return;
|
637
650
|
grpc_pollset_set_del_pollset_set(
|
638
651
|
parent_->child_policy_->interested_parties(),
|
639
652
|
parent_->interested_parties());
|
@@ -641,7 +654,6 @@ void GrpcLb::Helper::UpdateState(grpc_connectivity_state state,
|
|
641
654
|
parent_->child_policy_ = std::move(parent_->pending_child_policy_);
|
642
655
|
} else if (!CalledByCurrentChild()) {
|
643
656
|
// This request is from an outdated child, so ignore it.
|
644
|
-
GRPC_ERROR_UNREF(state_error);
|
645
657
|
return;
|
646
658
|
}
|
647
659
|
// Record whether child policy reports READY.
|
@@ -670,18 +682,17 @@ void GrpcLb::Helper::UpdateState(grpc_connectivity_state state,
|
|
670
682
|
if (parent_->serverlist_ == nullptr ||
|
671
683
|
(!parent_->serverlist_->ContainsAllDropEntries() &&
|
672
684
|
state != GRPC_CHANNEL_READY)) {
|
673
|
-
if (grpc_lb_glb_trace
|
685
|
+
if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_glb_trace)) {
|
674
686
|
gpr_log(GPR_INFO,
|
675
687
|
"[grpclb %p helper %p] state=%s passing child picker %p as-is",
|
676
688
|
parent_.get(), this, grpc_connectivity_state_name(state),
|
677
689
|
picker.get());
|
678
690
|
}
|
679
|
-
parent_->channel_control_helper()->UpdateState(state,
|
680
|
-
std::move(picker));
|
691
|
+
parent_->channel_control_helper()->UpdateState(state, std::move(picker));
|
681
692
|
return;
|
682
693
|
}
|
683
694
|
// Cases 2 and 3a: wrap picker from the child in our own picker.
|
684
|
-
if (grpc_lb_glb_trace
|
695
|
+
if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_glb_trace)) {
|
685
696
|
gpr_log(GPR_INFO, "[grpclb %p helper %p] state=%s wrapping child picker %p",
|
686
697
|
parent_.get(), this, grpc_connectivity_state_name(state),
|
687
698
|
picker.get());
|
@@ -692,10 +703,9 @@ void GrpcLb::Helper::UpdateState(grpc_connectivity_state state,
|
|
692
703
|
client_stats = parent_->lb_calld_->client_stats()->Ref();
|
693
704
|
}
|
694
705
|
parent_->channel_control_helper()->UpdateState(
|
695
|
-
state,
|
696
|
-
|
697
|
-
|
698
|
-
std::move(client_stats))));
|
706
|
+
state, UniquePtr<SubchannelPicker>(
|
707
|
+
New<Picker>(parent_.get(), parent_->serverlist_,
|
708
|
+
std::move(picker), std::move(client_stats))));
|
699
709
|
}
|
700
710
|
|
701
711
|
void GrpcLb::Helper::RequestReresolution() {
|
@@ -705,7 +715,7 @@ void GrpcLb::Helper::RequestReresolution() {
|
|
705
715
|
? parent_->pending_child_policy_.get()
|
706
716
|
: parent_->child_policy_.get();
|
707
717
|
if (child_ != latest_child_policy) return;
|
708
|
-
if (grpc_lb_glb_trace
|
718
|
+
if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_glb_trace)) {
|
709
719
|
gpr_log(GPR_INFO,
|
710
720
|
"[grpclb %p] Re-resolution requested from %schild policy (%p).",
|
711
721
|
parent_.get(), CalledByPendingChild() ? "pending " : "", child_);
|
@@ -792,7 +802,7 @@ void GrpcLb::BalancerCallState::Orphan() {
|
|
792
802
|
|
793
803
|
void GrpcLb::BalancerCallState::StartQuery() {
|
794
804
|
GPR_ASSERT(lb_call_ != nullptr);
|
795
|
-
if (grpc_lb_glb_trace
|
805
|
+
if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_glb_trace)) {
|
796
806
|
gpr_log(GPR_INFO, "[grpclb %p] lb_calld=%p: Starting LB call %p",
|
797
807
|
grpclb_policy_.get(), this, lb_call_);
|
798
808
|
}
|
@@ -910,7 +920,7 @@ void GrpcLb::BalancerCallState::SendClientLoadReportLocked() {
|
|
910
920
|
// Construct message payload.
|
911
921
|
GPR_ASSERT(send_message_payload_ == nullptr);
|
912
922
|
grpc_grpclb_request* request =
|
913
|
-
|
923
|
+
grpc_grpclb_load_report_request_create(client_stats_.get());
|
914
924
|
// Skip client load report if the counters were all zero in the last
|
915
925
|
// report and they are still zero in this one.
|
916
926
|
if (LoadReportCountersAreZero(request)) {
|
@@ -999,7 +1009,7 @@ void GrpcLb::BalancerCallState::OnBalancerMessageReceivedLocked(
|
|
999
1009
|
lb_calld->client_stats_report_interval_ = GPR_MAX(
|
1000
1010
|
GPR_MS_PER_SEC, grpc_grpclb_duration_to_millis(
|
1001
1011
|
&initial_response->client_stats_report_interval));
|
1002
|
-
if (grpc_lb_glb_trace
|
1012
|
+
if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_glb_trace)) {
|
1003
1013
|
gpr_log(GPR_INFO,
|
1004
1014
|
"[grpclb %p] lb_calld=%p: Received initial LB response "
|
1005
1015
|
"message; client load reporting interval = %" PRId64
|
@@ -1007,7 +1017,7 @@ void GrpcLb::BalancerCallState::OnBalancerMessageReceivedLocked(
|
|
1007
1017
|
grpclb_policy, lb_calld,
|
1008
1018
|
lb_calld->client_stats_report_interval_);
|
1009
1019
|
}
|
1010
|
-
} else if (grpc_lb_glb_trace
|
1020
|
+
} else if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_glb_trace)) {
|
1011
1021
|
gpr_log(GPR_INFO,
|
1012
1022
|
"[grpclb %p] lb_calld=%p: Received initial LB response message; "
|
1013
1023
|
"client load reporting NOT enabled",
|
@@ -1020,7 +1030,7 @@ void GrpcLb::BalancerCallState::OnBalancerMessageReceivedLocked(
|
|
1020
1030
|
// Have seen initial response, look for serverlist.
|
1021
1031
|
GPR_ASSERT(lb_calld->lb_call_ != nullptr);
|
1022
1032
|
auto serverlist_wrapper = MakeRefCounted<Serverlist>(serverlist);
|
1023
|
-
if (grpc_lb_glb_trace
|
1033
|
+
if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_glb_trace)) {
|
1024
1034
|
UniquePtr<char> serverlist_text = serverlist_wrapper->AsText();
|
1025
1035
|
gpr_log(GPR_INFO,
|
1026
1036
|
"[grpclb %p] lb_calld=%p: Serverlist with %" PRIuPTR
|
@@ -1041,7 +1051,7 @@ void GrpcLb::BalancerCallState::OnBalancerMessageReceivedLocked(
|
|
1041
1051
|
// Check if the serverlist differs from the previous one.
|
1042
1052
|
if (grpclb_policy->serverlist_ != nullptr &&
|
1043
1053
|
*grpclb_policy->serverlist_ == *serverlist_wrapper) {
|
1044
|
-
if (grpc_lb_glb_trace
|
1054
|
+
if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_glb_trace)) {
|
1045
1055
|
gpr_log(GPR_INFO,
|
1046
1056
|
"[grpclb %p] lb_calld=%p: Incoming server list identical to "
|
1047
1057
|
"current, ignoring.",
|
@@ -1119,7 +1129,7 @@ void GrpcLb::BalancerCallState::OnBalancerStatusReceivedLocked(
|
|
1119
1129
|
BalancerCallState* lb_calld = static_cast<BalancerCallState*>(arg);
|
1120
1130
|
GrpcLb* grpclb_policy = lb_calld->grpclb_policy();
|
1121
1131
|
GPR_ASSERT(lb_calld->lb_call_ != nullptr);
|
1122
|
-
if (grpc_lb_glb_trace
|
1132
|
+
if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_glb_trace)) {
|
1123
1133
|
char* status_details =
|
1124
1134
|
grpc_slice_to_c_string(lb_calld->lb_call_status_details_);
|
1125
1135
|
gpr_log(GPR_INFO,
|
@@ -1133,13 +1143,13 @@ void GrpcLb::BalancerCallState::OnBalancerStatusReceivedLocked(
|
|
1133
1143
|
// we want to retry connecting. Otherwise, we have deliberately ended this
|
1134
1144
|
// call and no further action is required.
|
1135
1145
|
if (lb_calld == grpclb_policy->lb_calld_.get()) {
|
1136
|
-
// If
|
1137
|
-
//
|
1138
|
-
//
|
1139
|
-
if (
|
1140
|
-
|
1146
|
+
// If the fallback-at-startup checks are pending, go into fallback mode
|
1147
|
+
// immediately. This short-circuits the timeout for the fallback-at-startup
|
1148
|
+
// case.
|
1149
|
+
if (grpclb_policy->fallback_at_startup_checks_pending_) {
|
1150
|
+
GPR_ASSERT(!lb_calld->seen_serverlist_);
|
1141
1151
|
gpr_log(GPR_INFO,
|
1142
|
-
"[grpclb %p]
|
1152
|
+
"[grpclb %p] Balancer call finished without receiving "
|
1143
1153
|
"serverlist; entering fallback mode",
|
1144
1154
|
grpclb_policy);
|
1145
1155
|
grpclb_policy->fallback_at_startup_checks_pending_ = false;
|
@@ -1281,7 +1291,7 @@ GrpcLb::GrpcLb(Args args)
|
|
1281
1291
|
grpc_uri* uri = grpc_uri_parse(server_uri, true);
|
1282
1292
|
GPR_ASSERT(uri->path[0] != '\0');
|
1283
1293
|
server_name_ = gpr_strdup(uri->path[0] == '/' ? uri->path + 1 : uri->path);
|
1284
|
-
if (grpc_lb_glb_trace
|
1294
|
+
if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_glb_trace)) {
|
1285
1295
|
gpr_log(GPR_INFO,
|
1286
1296
|
"[grpclb %p] Will use '%s' as the server name for LB request.",
|
1287
1297
|
this, server_name_);
|
@@ -1377,7 +1387,13 @@ void GrpcLb::FillChildRefsForChannelz(
|
|
1377
1387
|
|
1378
1388
|
void GrpcLb::UpdateLocked(UpdateArgs args) {
|
1379
1389
|
const bool is_initial_update = lb_channel_ == nullptr;
|
1380
|
-
|
1390
|
+
auto* grpclb_config =
|
1391
|
+
static_cast<const ParsedGrpcLbConfig*>(args.config.get());
|
1392
|
+
if (grpclb_config != nullptr) {
|
1393
|
+
child_policy_config_ = grpclb_config->child_policy();
|
1394
|
+
} else {
|
1395
|
+
child_policy_config_ = nullptr;
|
1396
|
+
}
|
1381
1397
|
ProcessAddressesAndChannelArgsLocked(args.addresses, *args.args);
|
1382
1398
|
// Update the existing child policy.
|
1383
1399
|
if (child_policy_ != nullptr) CreateOrUpdateChildPolicyLocked();
|
@@ -1466,27 +1482,6 @@ void GrpcLb::ProcessAddressesAndChannelArgsLocked(
|
|
1466
1482
|
response_generator_->SetResponse(std::move(result));
|
1467
1483
|
}
|
1468
1484
|
|
1469
|
-
void GrpcLb::ParseLbConfig(Config* grpclb_config) {
|
1470
|
-
const grpc_json* child_policy = nullptr;
|
1471
|
-
if (grpclb_config != nullptr) {
|
1472
|
-
const grpc_json* grpclb_config_json = grpclb_config->config();
|
1473
|
-
for (const grpc_json* field = grpclb_config_json; field != nullptr;
|
1474
|
-
field = field->next) {
|
1475
|
-
if (field->key == nullptr) return;
|
1476
|
-
if (strcmp(field->key, "childPolicy") == 0) {
|
1477
|
-
if (child_policy != nullptr) return; // Duplicate.
|
1478
|
-
child_policy = ParseLoadBalancingConfig(field);
|
1479
|
-
}
|
1480
|
-
}
|
1481
|
-
}
|
1482
|
-
if (child_policy != nullptr) {
|
1483
|
-
child_policy_config_ =
|
1484
|
-
MakeRefCounted<Config>(child_policy, grpclb_config->service_config());
|
1485
|
-
} else {
|
1486
|
-
child_policy_config_.reset();
|
1487
|
-
}
|
1488
|
-
}
|
1489
|
-
|
1490
1485
|
void GrpcLb::OnBalancerChannelConnectivityChangedLocked(void* arg,
|
1491
1486
|
grpc_error* error) {
|
1492
1487
|
GrpcLb* self = static_cast<GrpcLb*>(arg);
|
@@ -1540,7 +1535,7 @@ void GrpcLb::StartBalancerCallLocked() {
|
|
1540
1535
|
// Init the LB call data.
|
1541
1536
|
GPR_ASSERT(lb_calld_ == nullptr);
|
1542
1537
|
lb_calld_ = MakeOrphanable<BalancerCallState>(Ref());
|
1543
|
-
if (grpc_lb_glb_trace
|
1538
|
+
if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_glb_trace)) {
|
1544
1539
|
gpr_log(GPR_INFO,
|
1545
1540
|
"[grpclb %p] Query for backends (lb_channel: %p, lb_calld: %p)",
|
1546
1541
|
this, lb_channel_, lb_calld_.get());
|
@@ -1550,7 +1545,7 @@ void GrpcLb::StartBalancerCallLocked() {
|
|
1550
1545
|
|
1551
1546
|
void GrpcLb::StartBalancerCallRetryTimerLocked() {
|
1552
1547
|
grpc_millis next_try = lb_call_backoff_.NextAttemptTime();
|
1553
|
-
if (grpc_lb_glb_trace
|
1548
|
+
if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_glb_trace)) {
|
1554
1549
|
gpr_log(GPR_INFO, "[grpclb %p] Connection to LB server lost...", this);
|
1555
1550
|
grpc_millis timeout = next_try - ExecCtx::Get()->Now();
|
1556
1551
|
if (timeout > 0) {
|
@@ -1577,7 +1572,7 @@ void GrpcLb::OnBalancerCallRetryTimerLocked(void* arg, grpc_error* error) {
|
|
1577
1572
|
grpclb_policy->retry_timer_callback_pending_ = false;
|
1578
1573
|
if (!grpclb_policy->shutting_down_ && error == GRPC_ERROR_NONE &&
|
1579
1574
|
grpclb_policy->lb_calld_ == nullptr) {
|
1580
|
-
if (grpc_lb_glb_trace
|
1575
|
+
if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_glb_trace)) {
|
1581
1576
|
gpr_log(GPR_INFO, "[grpclb %p] Restarting call to LB server",
|
1582
1577
|
grpclb_policy);
|
1583
1578
|
}
|
@@ -1632,20 +1627,16 @@ void GrpcLb::OnFallbackTimerLocked(void* arg, grpc_error* error) {
|
|
1632
1627
|
|
1633
1628
|
grpc_channel_args* GrpcLb::CreateChildPolicyArgsLocked(
|
1634
1629
|
bool is_backend_from_grpclb_load_balancer) {
|
1635
|
-
grpc_arg
|
1636
|
-
|
1637
|
-
|
1638
|
-
|
1639
|
-
const_cast<char*>(
|
1640
|
-
GRPC_ARG_ADDRESS_IS_BACKEND_FROM_GRPCLB_LOAD_BALANCER),
|
1641
|
-
is_backend_from_grpclb_load_balancer),
|
1642
|
-
};
|
1643
|
-
size_t num_args_to_add = 1;
|
1630
|
+
InlinedVector<grpc_arg, 2> args_to_add;
|
1631
|
+
args_to_add.emplace_back(grpc_channel_arg_integer_create(
|
1632
|
+
const_cast<char*>(GRPC_ARG_ADDRESS_IS_BACKEND_FROM_GRPCLB_LOAD_BALANCER),
|
1633
|
+
is_backend_from_grpclb_load_balancer));
|
1644
1634
|
if (is_backend_from_grpclb_load_balancer) {
|
1645
|
-
args_to_add
|
1646
|
-
const_cast<char*>(GRPC_ARG_INHIBIT_HEALTH_CHECKING), 1);
|
1635
|
+
args_to_add.emplace_back(grpc_channel_arg_integer_create(
|
1636
|
+
const_cast<char*>(GRPC_ARG_INHIBIT_HEALTH_CHECKING), 1));
|
1647
1637
|
}
|
1648
|
-
return grpc_channel_args_copy_and_add(args_, args_to_add,
|
1638
|
+
return grpc_channel_args_copy_and_add(args_, args_to_add.data(),
|
1639
|
+
args_to_add.size());
|
1649
1640
|
}
|
1650
1641
|
|
1651
1642
|
OrphanablePtr<LoadBalancingPolicy> GrpcLb::CreateChildPolicyLocked(
|
@@ -1665,7 +1656,7 @@ OrphanablePtr<LoadBalancingPolicy> GrpcLb::CreateChildPolicyLocked(
|
|
1665
1656
|
return nullptr;
|
1666
1657
|
}
|
1667
1658
|
helper->set_child(lb_policy.get());
|
1668
|
-
if (grpc_lb_glb_trace
|
1659
|
+
if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_glb_trace)) {
|
1669
1660
|
gpr_log(GPR_INFO, "[grpclb %p] Created new child policy %s (%p)", this,
|
1670
1661
|
name, lb_policy.get());
|
1671
1662
|
}
|
@@ -1764,7 +1755,7 @@ void GrpcLb::CreateOrUpdateChildPolicyLocked() {
|
|
1764
1755
|
// Cases 1, 2b, and 3b: create a new child policy.
|
1765
1756
|
// If child_policy_ is null, we set it (case 1), else we set
|
1766
1757
|
// pending_child_policy_ (cases 2b and 3b).
|
1767
|
-
if (grpc_lb_glb_trace
|
1758
|
+
if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_glb_trace)) {
|
1768
1759
|
gpr_log(GPR_INFO, "[grpclb %p] Creating new %schild policy %s", this,
|
1769
1760
|
child_policy_ == nullptr ? "" : "pending ", child_policy_name);
|
1770
1761
|
}
|
@@ -1788,7 +1779,7 @@ void GrpcLb::CreateOrUpdateChildPolicyLocked() {
|
|
1788
1779
|
}
|
1789
1780
|
GPR_ASSERT(policy_to_update != nullptr);
|
1790
1781
|
// Update the policy.
|
1791
|
-
if (grpc_lb_glb_trace
|
1782
|
+
if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_glb_trace)) {
|
1792
1783
|
gpr_log(GPR_INFO, "[grpclb %p] Updating %schild policy %p", this,
|
1793
1784
|
policy_to_update == pending_child_policy_.get() ? "pending " : "",
|
1794
1785
|
policy_to_update);
|
@@ -1808,6 +1799,40 @@ class GrpcLbFactory : public LoadBalancingPolicyFactory {
|
|
1808
1799
|
}
|
1809
1800
|
|
1810
1801
|
const char* name() const override { return kGrpclb; }
|
1802
|
+
|
1803
|
+
RefCountedPtr<ParsedLoadBalancingConfig> ParseLoadBalancingConfig(
|
1804
|
+
const grpc_json* json, grpc_error** error) const override {
|
1805
|
+
GPR_DEBUG_ASSERT(error != nullptr && *error == GRPC_ERROR_NONE);
|
1806
|
+
if (json == nullptr) {
|
1807
|
+
return RefCountedPtr<ParsedLoadBalancingConfig>(
|
1808
|
+
New<ParsedGrpcLbConfig>(nullptr));
|
1809
|
+
}
|
1810
|
+
InlinedVector<grpc_error*, 2> error_list;
|
1811
|
+
RefCountedPtr<ParsedLoadBalancingConfig> child_policy;
|
1812
|
+
for (const grpc_json* field = json->child; field != nullptr;
|
1813
|
+
field = field->next) {
|
1814
|
+
if (field->key == nullptr) continue;
|
1815
|
+
if (strcmp(field->key, "childPolicy") == 0) {
|
1816
|
+
if (child_policy != nullptr) {
|
1817
|
+
error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
|
1818
|
+
"field:childPolicy error:Duplicate entry"));
|
1819
|
+
}
|
1820
|
+
grpc_error* parse_error = GRPC_ERROR_NONE;
|
1821
|
+
child_policy = LoadBalancingPolicyRegistry::ParseLoadBalancingConfig(
|
1822
|
+
field, &parse_error);
|
1823
|
+
if (parse_error != GRPC_ERROR_NONE) {
|
1824
|
+
error_list.push_back(parse_error);
|
1825
|
+
}
|
1826
|
+
}
|
1827
|
+
}
|
1828
|
+
if (error_list.empty()) {
|
1829
|
+
return RefCountedPtr<ParsedLoadBalancingConfig>(
|
1830
|
+
New<ParsedGrpcLbConfig>(std::move(child_policy)));
|
1831
|
+
} else {
|
1832
|
+
*error = GRPC_ERROR_CREATE_FROM_VECTOR("GrpcLb Parser", &error_list);
|
1833
|
+
return nullptr;
|
1834
|
+
}
|
1835
|
+
}
|
1811
1836
|
};
|
1812
1837
|
|
1813
1838
|
} // namespace
|