grpc 1.25.0 → 1.26.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.
- checksums.yaml +4 -4
- data/Makefile +782 -291
- data/include/grpc/impl/codegen/grpc_types.h +4 -0
- data/include/grpc/impl/codegen/port_platform.h +7 -0
- data/include/grpc/support/alloc.h +0 -16
- data/src/core/ext/filters/client_channel/backend_metric.cc +2 -2
- data/src/core/ext/filters/client_channel/backup_poller.cc +1 -1
- data/src/core/ext/filters/client_channel/channel_connectivity.cc +2 -2
- data/src/core/ext/filters/client_channel/client_channel.cc +95 -88
- data/src/core/ext/filters/client_channel/client_channel_channelz.cc +7 -7
- data/src/core/ext/filters/client_channel/client_channel_channelz.h +4 -2
- data/src/core/ext/filters/client_channel/client_channel_factory.cc +1 -1
- data/src/core/ext/filters/client_channel/client_channel_plugin.cc +3 -3
- data/src/core/ext/filters/client_channel/connector.h +40 -45
- data/src/core/ext/filters/client_channel/global_subchannel_pool.cc +10 -10
- data/src/core/ext/filters/client_channel/health/health_check_client.cc +16 -13
- data/src/core/ext/filters/client_channel/http_connect_handshaker.cc +66 -37
- data/src/core/ext/filters/client_channel/http_proxy.cc +107 -116
- data/src/core/ext/filters/client_channel/http_proxy.h +5 -1
- data/src/core/ext/filters/client_channel/lb_policy.cc +3 -3
- data/src/core/ext/filters/client_channel/lb_policy.h +9 -5
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.cc +10 -8
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +18 -19
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.cc +4 -3
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.h +4 -4
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.cc +1 -1
- data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc +3 -3
- data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc +3 -3
- data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +6 -9
- data/src/core/ext/filters/client_channel/lb_policy/xds/cds.cc +368 -0
- data/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc +157 -77
- data/src/core/ext/filters/client_channel/lb_policy_registry.cc +5 -5
- data/src/core/ext/filters/client_channel/lb_policy_registry.h +1 -1
- data/src/core/ext/filters/client_channel/local_subchannel_pool.cc +8 -8
- data/src/core/ext/filters/client_channel/proxy_mapper.h +14 -34
- data/src/core/ext/filters/client_channel/proxy_mapper_registry.cc +46 -79
- data/src/core/ext/filters/client_channel/proxy_mapper_registry.h +23 -17
- data/src/core/ext/filters/client_channel/resolver.cc +2 -1
- data/src/core/ext/filters/client_channel/resolver.h +2 -2
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +1 -1
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.cc +4 -4
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.h +1 -1
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_libuv.cc +13 -10
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_posix.cc +3 -2
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_windows.cc +9 -8
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc +17 -16
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h +2 -2
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_fallback.cc +4 -4
- data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc +9 -9
- data/src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.cc +5 -3
- data/src/core/ext/filters/client_channel/resolver/xds/xds_resolver.cc +1 -1
- data/src/core/ext/filters/client_channel/resolver_factory.h +3 -3
- data/src/core/ext/filters/client_channel/resolver_registry.cc +14 -12
- data/src/core/ext/filters/client_channel/resolver_registry.h +6 -4
- data/src/core/ext/filters/client_channel/resolver_result_parsing.cc +6 -6
- data/src/core/ext/filters/client_channel/resolver_result_parsing.h +6 -6
- data/src/core/ext/filters/client_channel/resolving_lb_policy.cc +5 -5
- data/src/core/ext/filters/client_channel/resolving_lb_policy.h +3 -3
- data/src/core/ext/filters/client_channel/service_config.cc +15 -14
- data/src/core/ext/filters/client_channel/service_config.h +14 -19
- data/src/core/ext/filters/client_channel/subchannel.cc +38 -36
- data/src/core/ext/filters/client_channel/subchannel.h +11 -12
- data/src/core/ext/filters/client_channel/subchannel_interface.h +1 -1
- data/src/core/ext/filters/client_channel/xds/xds_api.cc +19 -9
- data/src/core/ext/filters/client_channel/xds/xds_api.h +19 -9
- data/src/core/ext/filters/client_channel/xds/xds_bootstrap.cc +3 -3
- data/src/core/ext/filters/client_channel/xds/xds_bootstrap.h +6 -5
- data/src/core/ext/filters/client_channel/xds/xds_client.cc +58 -31
- data/src/core/ext/filters/client_channel/xds/xds_client.h +20 -15
- data/src/core/ext/filters/client_channel/xds/xds_client_stats.cc +5 -3
- data/src/core/ext/filters/client_channel/xds/xds_client_stats.h +18 -15
- data/src/core/ext/filters/client_idle/client_idle_filter.cc +10 -10
- data/src/core/ext/filters/deadline/deadline_filter.cc +15 -13
- data/src/core/ext/filters/http/client/http_client_filter.cc +12 -12
- data/src/core/ext/filters/http/client_authority_filter.cc +3 -3
- data/src/core/ext/filters/http/message_compress/message_compress_filter.cc +13 -7
- data/src/core/ext/filters/http/server/http_server_filter.cc +14 -13
- data/src/core/ext/filters/max_age/max_age_filter.cc +16 -14
- data/src/core/ext/filters/message_size/message_size_filter.cc +10 -8
- data/src/core/ext/filters/message_size/message_size_filter.h +1 -1
- data/src/core/ext/filters/workarounds/workaround_cronet_compression_filter.cc +9 -8
- data/src/core/ext/transport/chttp2/client/chttp2_connector.cc +141 -174
- data/src/core/ext/transport/chttp2/client/chttp2_connector.h +31 -1
- data/src/core/ext/transport/chttp2/client/insecure/channel_create.cc +7 -6
- data/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc +14 -12
- data/src/core/ext/transport/chttp2/server/chttp2_server.cc +8 -5
- data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +46 -38
- data/src/core/ext/transport/chttp2/transport/context_list.cc +2 -2
- data/src/core/ext/transport/chttp2/transport/flow_control.h +0 -5
- data/src/core/ext/transport/chttp2/transport/frame_data.cc +6 -7
- data/src/core/ext/transport/chttp2/transport/frame_goaway.cc +2 -2
- data/src/core/ext/transport/chttp2/transport/frame_ping.cc +1 -1
- data/src/core/ext/transport/chttp2/transport/frame_settings.cc +4 -3
- data/src/core/ext/transport/chttp2/transport/hpack_encoder.cc +5 -5
- data/src/core/ext/transport/chttp2/transport/hpack_parser.cc +11 -8
- data/src/core/ext/transport/chttp2/transport/internal.h +3 -3
- data/src/core/ext/transport/chttp2/transport/parsing.cc +4 -4
- data/src/core/ext/transport/chttp2/transport/writing.cc +3 -2
- data/src/core/ext/transport/inproc/inproc_transport.cc +65 -41
- data/src/core/ext/upb-generated/envoy/api/v2/auth/cert.upb.c +0 -1
- data/src/core/ext/upb-generated/envoy/api/v2/cds.upb.c +141 -70
- data/src/core/ext/upb-generated/envoy/api/v2/cds.upb.h +352 -118
- data/src/core/ext/upb-generated/envoy/api/v2/cluster/circuit_breaker.upb.c +0 -1
- data/src/core/ext/upb-generated/envoy/api/v2/cluster/filter.upb.c +0 -1
- data/src/core/ext/upb-generated/envoy/api/v2/cluster/outlier_detection.upb.c +8 -4
- data/src/core/ext/upb-generated/envoy/api/v2/cluster/outlier_detection.upb.h +65 -0
- data/src/core/ext/upb-generated/envoy/api/v2/core/address.upb.c +0 -1
- data/src/core/ext/upb-generated/envoy/api/v2/core/base.upb.c +16 -2
- data/src/core/ext/upb-generated/envoy/api/v2/core/base.upb.h +36 -0
- data/src/core/ext/upb-generated/envoy/api/v2/core/config_source.upb.c +12 -5
- data/src/core/ext/upb-generated/envoy/api/v2/core/config_source.upb.h +34 -0
- data/src/core/ext/upb-generated/envoy/api/v2/core/grpc_service.upb.c +1 -2
- data/src/core/ext/upb-generated/envoy/api/v2/core/health_check.upb.c +13 -12
- data/src/core/ext/upb-generated/envoy/api/v2/core/health_check.upb.h +28 -24
- data/src/core/ext/upb-generated/envoy/api/v2/core/http_uri.upb.c +0 -1
- data/src/core/ext/upb-generated/envoy/api/v2/core/protocol.upb.c +5 -4
- data/src/core/ext/upb-generated/envoy/api/v2/core/protocol.upb.h +13 -0
- data/src/core/ext/upb-generated/envoy/api/v2/discovery.upb.c +0 -1
- data/src/core/ext/upb-generated/envoy/api/v2/eds.upb.c +23 -23
- data/src/core/ext/upb-generated/envoy/api/v2/eds.upb.h +48 -44
- data/src/core/ext/upb-generated/envoy/api/v2/endpoint/endpoint.upb.c +0 -1
- data/src/core/ext/upb-generated/envoy/api/v2/endpoint/load_report.upb.c +0 -1
- data/src/core/ext/upb-generated/envoy/type/http.upb.c +16 -0
- data/src/core/ext/upb-generated/envoy/type/http.upb.h +36 -0
- data/src/core/ext/upb-generated/envoy/type/percent.upb.c +0 -1
- data/src/core/ext/upb-generated/envoy/type/range.upb.c +0 -1
- data/src/core/lib/avl/avl.cc +1 -1
- data/src/core/lib/channel/channel_stack.cc +1 -1
- data/src/core/lib/channel/channel_stack.h +16 -4
- data/src/core/lib/channel/channel_trace.cc +4 -4
- data/src/core/lib/channel/channelz.cc +46 -46
- data/src/core/lib/channel/channelz.h +37 -35
- data/src/core/lib/channel/channelz_registry.cc +2 -2
- data/src/core/lib/channel/channelz_registry.h +1 -1
- data/src/core/lib/channel/connected_channel.cc +3 -2
- data/src/core/lib/channel/handshaker.cc +1 -1
- data/src/core/lib/channel/handshaker_registry.cc +5 -5
- data/src/core/lib/channel/handshaker_registry.h +3 -3
- data/src/core/lib/compression/message_compress.cc +3 -2
- data/src/core/lib/compression/stream_compression_identity.cc +5 -7
- data/src/core/lib/gpr/alloc.cc +4 -29
- data/src/core/lib/gpr/cpu_linux.cc +1 -1
- data/src/core/lib/gprpp/fork.cc +4 -4
- data/src/core/lib/gprpp/global_config_env.cc +7 -7
- data/src/core/lib/gprpp/global_config_env.h +2 -2
- data/src/core/lib/gprpp/host_port.cc +8 -8
- data/src/core/lib/gprpp/host_port.h +3 -3
- data/src/core/lib/gprpp/inlined_vector.h +13 -0
- data/src/core/lib/gprpp/map.h +2 -9
- data/src/core/lib/gprpp/memory.h +12 -98
- data/src/core/lib/gprpp/orphanable.h +3 -3
- data/src/core/lib/gprpp/ref_counted.h +3 -3
- data/src/core/lib/gprpp/ref_counted_ptr.h +1 -1
- data/src/core/lib/gprpp/string_view.h +45 -23
- data/src/core/lib/gprpp/thd.h +1 -1
- data/src/core/lib/gprpp/thd_posix.cc +6 -5
- data/src/core/lib/gprpp/thd_windows.cc +3 -3
- data/src/core/lib/http/httpcli.cc +1 -1
- data/src/core/lib/http/httpcli_security_connector.cc +3 -3
- data/src/core/lib/iomgr/buffer_list.cc +10 -5
- data/src/core/lib/iomgr/call_combiner.cc +7 -6
- data/src/core/lib/iomgr/call_combiner.h +4 -3
- data/src/core/lib/iomgr/cfstream_handle.cc +2 -2
- data/src/core/lib/iomgr/closure.h +33 -135
- data/src/core/lib/iomgr/combiner.cc +10 -17
- data/src/core/lib/iomgr/combiner.h +0 -2
- data/src/core/lib/iomgr/endpoint_cfstream.cc +2 -2
- data/src/core/lib/iomgr/endpoint_pair_posix.cc +1 -1
- data/src/core/lib/iomgr/ev_epoll1_linux.cc +3 -2
- data/src/core/lib/iomgr/ev_epollex_linux.cc +23 -13
- data/src/core/lib/iomgr/ev_poll_posix.cc +30 -17
- data/src/core/lib/iomgr/exec_ctx.cc +52 -5
- data/src/core/lib/iomgr/exec_ctx.h +6 -2
- data/src/core/lib/iomgr/executor.cc +16 -37
- data/src/core/lib/iomgr/executor.h +4 -7
- data/src/core/lib/iomgr/executor/threadpool.cc +4 -4
- data/src/core/lib/iomgr/iomgr_custom.cc +1 -1
- data/src/core/lib/iomgr/lockfree_event.cc +9 -8
- data/src/core/lib/iomgr/logical_thread.cc +103 -0
- data/src/core/lib/iomgr/logical_thread.h +52 -0
- data/src/core/lib/iomgr/pollset_custom.cc +5 -5
- data/src/core/lib/iomgr/pollset_set_custom.cc +9 -9
- data/src/core/lib/iomgr/pollset_windows.cc +16 -2
- data/src/core/lib/iomgr/port.h +3 -0
- data/src/core/lib/iomgr/resolve_address_custom.cc +4 -4
- data/src/core/lib/iomgr/resolve_address_posix.cc +8 -9
- data/src/core/lib/iomgr/resolve_address_windows.cc +4 -6
- data/src/core/lib/iomgr/resource_quota.cc +26 -21
- data/src/core/lib/iomgr/socket_utils_common_posix.cc +11 -0
- data/src/core/lib/iomgr/socket_windows.cc +2 -2
- data/src/core/lib/iomgr/tcp_client_cfstream.cc +2 -2
- data/src/core/lib/iomgr/tcp_client_custom.cc +2 -2
- data/src/core/lib/iomgr/tcp_client_posix.cc +5 -4
- data/src/core/lib/iomgr/tcp_client_windows.cc +2 -2
- data/src/core/lib/iomgr/tcp_custom.cc +10 -9
- data/src/core/lib/iomgr/tcp_posix.cc +19 -15
- data/src/core/lib/iomgr/tcp_server_custom.cc +3 -2
- data/src/core/lib/iomgr/tcp_server_posix.cc +5 -4
- data/src/core/lib/iomgr/tcp_server_windows.cc +5 -3
- data/src/core/lib/iomgr/tcp_windows.cc +16 -13
- data/src/core/lib/iomgr/timer_custom.cc +4 -3
- data/src/core/lib/iomgr/timer_generic.cc +11 -9
- data/src/core/lib/iomgr/udp_server.cc +16 -13
- data/src/core/lib/security/credentials/alts/alts_credentials.cc +8 -5
- data/src/core/lib/security/credentials/alts/check_gcp_environment_windows.cc +45 -57
- data/src/core/lib/security/credentials/composite/composite_credentials.cc +7 -6
- data/src/core/lib/security/credentials/credentials.cc +8 -8
- data/src/core/lib/security/credentials/credentials.h +5 -5
- data/src/core/lib/security/credentials/fake/fake_credentials.cc +5 -5
- data/src/core/lib/security/credentials/google_default/google_default_credentials.cc +1 -1
- data/src/core/lib/security/credentials/iam/iam_credentials.cc +4 -4
- data/src/core/lib/security/credentials/jwt/jwt_credentials.cc +4 -4
- data/src/core/lib/security/credentials/jwt/jwt_verifier.cc +2 -2
- data/src/core/lib/security/credentials/local/local_credentials.cc +3 -3
- data/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc +13 -11
- data/src/core/lib/security/credentials/plugin/plugin_credentials.cc +6 -5
- data/src/core/lib/security/credentials/ssl/ssl_credentials.cc +4 -4
- data/src/core/lib/security/credentials/tls/grpc_tls_credentials_options.cc +5 -5
- data/src/core/lib/security/credentials/tls/spiffe_credentials.cc +2 -2
- data/src/core/lib/security/security_connector/alts/alts_security_connector.cc +28 -22
- data/src/core/lib/security/security_connector/alts/alts_security_connector.h +5 -0
- data/src/core/lib/security/security_connector/fake/fake_security_connector.cc +10 -10
- data/src/core/lib/security/security_connector/load_system_roots_linux.cc +2 -1
- data/src/core/lib/security/security_connector/local/local_security_connector.cc +8 -8
- data/src/core/lib/security/security_connector/security_connector.h +1 -1
- data/src/core/lib/security/security_connector/ssl/ssl_security_connector.cc +9 -9
- data/src/core/lib/security/security_connector/ssl_utils.cc +5 -4
- data/src/core/lib/security/security_connector/tls/spiffe_security_connector.cc +14 -15
- data/src/core/lib/security/transport/client_auth_filter.cc +4 -3
- data/src/core/lib/security/transport/secure_endpoint.cc +9 -8
- data/src/core/lib/security/transport/security_handshaker.cc +67 -23
- data/src/core/lib/security/transport/server_auth_filter.cc +6 -5
- data/src/core/lib/security/transport/target_authority_table.h +1 -1
- data/src/core/lib/slice/b64.cc +3 -4
- data/src/core/lib/slice/b64.h +1 -2
- data/src/core/lib/slice/slice.cc +8 -13
- data/src/core/lib/surface/call.cc +19 -19
- data/src/core/lib/surface/call.h +6 -7
- data/src/core/lib/surface/call_log_batch.cc +1 -2
- data/src/core/lib/surface/channel.cc +17 -18
- data/src/core/lib/surface/channel.h +4 -19
- data/src/core/lib/surface/channel_ping.cc +1 -1
- data/src/core/lib/surface/completion_queue.cc +21 -22
- data/src/core/lib/surface/completion_queue_factory.cc +1 -1
- data/src/core/lib/surface/init.cc +1 -1
- data/src/core/lib/surface/init_secure.cc +2 -2
- data/src/core/lib/surface/lame_client.cc +10 -12
- data/src/core/lib/surface/server.cc +24 -18
- data/src/core/lib/surface/version.cc +2 -2
- data/src/core/lib/transport/byte_stream.cc +2 -2
- data/src/core/lib/transport/byte_stream.h +2 -1
- data/src/core/lib/transport/connectivity_state.cc +4 -4
- data/src/core/lib/transport/connectivity_state.h +2 -2
- data/src/core/lib/transport/metadata.cc +8 -10
- data/src/core/lib/transport/metadata.h +5 -8
- data/src/core/lib/transport/metadata_batch.cc +6 -0
- data/src/core/lib/transport/static_metadata.cc +2 -4
- data/src/core/lib/transport/status_metadata.cc +7 -0
- data/src/core/lib/transport/status_metadata.h +18 -0
- data/src/core/lib/transport/transport.cc +9 -7
- data/src/core/plugin_registry/grpc_plugin_registry.cc +4 -0
- data/src/core/tsi/alts/handshaker/alts_handshaker_client.cc +292 -43
- data/src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc +197 -46
- data/src/core/tsi/alts/handshaker/alts_tsi_handshaker.h +4 -2
- data/src/core/tsi/alts/handshaker/alts_tsi_handshaker_private.h +5 -0
- data/src/core/tsi/ssl/session_cache/ssl_session.h +1 -1
- data/src/core/tsi/ssl/session_cache/ssl_session_boringssl.cc +1 -1
- data/src/core/tsi/ssl/session_cache/ssl_session_cache.cc +4 -4
- data/src/core/tsi/ssl/session_cache/ssl_session_openssl.cc +1 -1
- data/src/core/tsi/ssl_transport_security.cc +2 -1
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +0 -4
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +0 -6
- data/src/ruby/lib/grpc/version.rb +1 -1
- data/third_party/upb/upb/decode.c +1 -0
- metadata +34 -32
- data/src/core/ext/filters/client_channel/connector.cc +0 -41
- data/src/core/ext/filters/client_channel/proxy_mapper.cc +0 -48
- data/src/core/lib/gprpp/set.h +0 -33
@@ -52,7 +52,7 @@ void GrpcLbClientStats::AddCallDropped(const char* token) {
|
|
52
52
|
// Record the drop.
|
53
53
|
MutexLock lock(&drop_count_mu_);
|
54
54
|
if (drop_token_counts_ == nullptr) {
|
55
|
-
drop_token_counts_.reset(
|
55
|
+
drop_token_counts_.reset(new DroppedCallCounts());
|
56
56
|
}
|
57
57
|
for (size_t i = 0; i < drop_token_counts_->size(); ++i) {
|
58
58
|
if (strcmp((*drop_token_counts_)[i].token.get(), token) == 0) {
|
@@ -61,7 +61,8 @@ void GrpcLbClientStats::AddCallDropped(const char* token) {
|
|
61
61
|
}
|
62
62
|
}
|
63
63
|
// Not found, so add a new entry.
|
64
|
-
drop_token_counts_->emplace_back(
|
64
|
+
drop_token_counts_->emplace_back(
|
65
|
+
grpc_core::UniquePtr<char>(gpr_strdup(token)), 1);
|
65
66
|
}
|
66
67
|
|
67
68
|
namespace {
|
@@ -76,7 +77,7 @@ void GrpcLbClientStats::Get(
|
|
76
77
|
int64_t* num_calls_started, int64_t* num_calls_finished,
|
77
78
|
int64_t* num_calls_finished_with_client_failed_to_send,
|
78
79
|
int64_t* num_calls_finished_known_received,
|
79
|
-
|
80
|
+
std::unique_ptr<DroppedCallCounts>* drop_token_counts) {
|
80
81
|
AtomicGetAndResetCounter(num_calls_started, &num_calls_started_);
|
81
82
|
AtomicGetAndResetCounter(num_calls_finished, &num_calls_finished_);
|
82
83
|
AtomicGetAndResetCounter(num_calls_finished_with_client_failed_to_send,
|
@@ -33,10 +33,10 @@ namespace grpc_core {
|
|
33
33
|
class GrpcLbClientStats : public RefCounted<GrpcLbClientStats> {
|
34
34
|
public:
|
35
35
|
struct DropTokenCount {
|
36
|
-
UniquePtr<char> token;
|
36
|
+
grpc_core::UniquePtr<char> token;
|
37
37
|
int64_t count;
|
38
38
|
|
39
|
-
DropTokenCount(UniquePtr<char> token, int64_t count)
|
39
|
+
DropTokenCount(grpc_core::UniquePtr<char> token, int64_t count)
|
40
40
|
: token(std::move(token)), count(count) {}
|
41
41
|
};
|
42
42
|
|
@@ -51,7 +51,7 @@ class GrpcLbClientStats : public RefCounted<GrpcLbClientStats> {
|
|
51
51
|
void Get(int64_t* num_calls_started, int64_t* num_calls_finished,
|
52
52
|
int64_t* num_calls_finished_with_client_failed_to_send,
|
53
53
|
int64_t* num_calls_finished_known_received,
|
54
|
-
|
54
|
+
std::unique_ptr<DroppedCallCounts>* drop_token_counts);
|
55
55
|
|
56
56
|
// A destruction function to use as the user_data key when attaching
|
57
57
|
// client stats to a grpc_mdelem.
|
@@ -65,7 +65,7 @@ class GrpcLbClientStats : public RefCounted<GrpcLbClientStats> {
|
|
65
65
|
gpr_atm num_calls_finished_with_client_failed_to_send_ = 0;
|
66
66
|
gpr_atm num_calls_finished_known_received_ = 0;
|
67
67
|
Mutex drop_count_mu_; // Guards drop_token_counts_.
|
68
|
-
|
68
|
+
std::unique_ptr<DroppedCallCounts> drop_token_counts_;
|
69
69
|
};
|
70
70
|
|
71
71
|
} // namespace grpc_core
|
@@ -63,7 +63,7 @@ grpc_grpclb_request* grpc_grpclb_load_report_request_create(
|
|
63
63
|
int64_t num_calls_finished;
|
64
64
|
int64_t num_calls_finished_with_client_failed_to_send;
|
65
65
|
int64_t num_calls_finished_known_received;
|
66
|
-
|
66
|
+
std::unique_ptr<GrpcLbClientStats::DroppedCallCounts> drop_token_counts;
|
67
67
|
client_stats->Get(&num_calls_started, &num_calls_finished,
|
68
68
|
&num_calls_finished_with_client_failed_to_send,
|
69
69
|
&num_calls_finished_known_received, &drop_token_counts);
|
@@ -112,7 +112,7 @@ class PickFirst : public LoadBalancingPolicy {
|
|
112
112
|
explicit Picker(RefCountedPtr<SubchannelInterface> subchannel)
|
113
113
|
: subchannel_(std::move(subchannel)) {}
|
114
114
|
|
115
|
-
PickResult Pick(PickArgs args) override {
|
115
|
+
PickResult Pick(PickArgs /*args*/) override {
|
116
116
|
PickResult result;
|
117
117
|
result.type = PickResult::PICK_COMPLETE;
|
118
118
|
result.subchannel = subchannel_;
|
@@ -490,12 +490,12 @@ class PickFirstFactory : public LoadBalancingPolicyFactory {
|
|
490
490
|
const char* name() const override { return kPickFirst; }
|
491
491
|
|
492
492
|
RefCountedPtr<LoadBalancingPolicy::Config> ParseLoadBalancingConfig(
|
493
|
-
const grpc_json* json, grpc_error** error) const override {
|
493
|
+
const grpc_json* json, grpc_error** /*error*/) const override {
|
494
494
|
if (json != nullptr) {
|
495
495
|
GPR_DEBUG_ASSERT(strcmp(json->key, name()) == 0);
|
496
496
|
}
|
497
497
|
return RefCountedPtr<LoadBalancingPolicy::Config>(
|
498
|
-
|
498
|
+
new ParsedPickFirstConfig());
|
499
499
|
}
|
500
500
|
};
|
501
501
|
|
@@ -204,7 +204,7 @@ RoundRobin::Picker::Picker(RoundRobin* parent,
|
|
204
204
|
}
|
205
205
|
}
|
206
206
|
|
207
|
-
RoundRobin::PickResult RoundRobin::Picker::Pick(PickArgs args) {
|
207
|
+
RoundRobin::PickResult RoundRobin::Picker::Pick(PickArgs /*args*/) {
|
208
208
|
last_picked_index_ = (last_picked_index_ + 1) % subchannels_.size();
|
209
209
|
if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_round_robin_trace)) {
|
210
210
|
gpr_log(GPR_INFO,
|
@@ -486,12 +486,12 @@ class RoundRobinFactory : public LoadBalancingPolicyFactory {
|
|
486
486
|
const char* name() const override { return kRoundRobin; }
|
487
487
|
|
488
488
|
RefCountedPtr<LoadBalancingPolicy::Config> ParseLoadBalancingConfig(
|
489
|
-
const grpc_json* json, grpc_error** error) const override {
|
489
|
+
const grpc_json* json, grpc_error** /*error*/) const override {
|
490
490
|
if (json != nullptr) {
|
491
491
|
GPR_DEBUG_ASSERT(strcmp(json->key, name()) == 0);
|
492
492
|
}
|
493
493
|
return RefCountedPtr<LoadBalancingPolicy::Config>(
|
494
|
-
|
494
|
+
new ParsedRoundRobinConfig());
|
495
495
|
}
|
496
496
|
};
|
497
497
|
|
@@ -206,10 +206,6 @@ class SubchannelList : public InternallyRefCounted<SubchannelListType> {
|
|
206
206
|
virtual ~SubchannelList();
|
207
207
|
|
208
208
|
private:
|
209
|
-
// So New() can call our private ctor.
|
210
|
-
template <typename T, typename... Args>
|
211
|
-
friend T* New(Args&&... args);
|
212
|
-
|
213
209
|
// For accessing Ref() and Unref().
|
214
210
|
friend class SubchannelData<SubchannelListType, SubchannelDataType>;
|
215
211
|
|
@@ -267,7 +263,8 @@ void SubchannelData<SubchannelListType, SubchannelDataType>::Watcher::
|
|
267
263
|
template <typename SubchannelListType, typename SubchannelDataType>
|
268
264
|
SubchannelData<SubchannelListType, SubchannelDataType>::SubchannelData(
|
269
265
|
SubchannelList<SubchannelListType, SubchannelDataType>* subchannel_list,
|
270
|
-
const ServerAddress& address
|
266
|
+
const ServerAddress& /*address*/,
|
267
|
+
RefCountedPtr<SubchannelInterface> subchannel)
|
271
268
|
: subchannel_list_(subchannel_list),
|
272
269
|
subchannel_(std::move(subchannel)),
|
273
270
|
// We assume that the current state is IDLE. If not, we'll get a
|
@@ -286,10 +283,10 @@ void SubchannelData<SubchannelListType, SubchannelDataType>::
|
|
286
283
|
if (GRPC_TRACE_FLAG_ENABLED(*subchannel_list_->tracer())) {
|
287
284
|
gpr_log(GPR_INFO,
|
288
285
|
"[%s %p] subchannel list %p index %" PRIuPTR " of %" PRIuPTR
|
289
|
-
" (subchannel %p): unreffing subchannel",
|
286
|
+
" (subchannel %p): unreffing subchannel (%s)",
|
290
287
|
subchannel_list_->tracer()->name(), subchannel_list_->policy(),
|
291
288
|
subchannel_list_, Index(), subchannel_list_->num_subchannels(),
|
292
|
-
subchannel_.get());
|
289
|
+
subchannel_.get(), reason);
|
293
290
|
}
|
294
291
|
subchannel_.reset();
|
295
292
|
}
|
@@ -316,10 +313,10 @@ void SubchannelData<SubchannelListType,
|
|
316
313
|
}
|
317
314
|
GPR_ASSERT(pending_watcher_ == nullptr);
|
318
315
|
pending_watcher_ =
|
319
|
-
|
316
|
+
new Watcher(this, subchannel_list()->Ref(DEBUG_LOCATION, "Watcher"));
|
320
317
|
subchannel_->WatchConnectivityState(
|
321
318
|
connectivity_state_,
|
322
|
-
|
319
|
+
std::unique_ptr<SubchannelInterface::ConnectivityStateWatcherInterface>(
|
323
320
|
pending_watcher_));
|
324
321
|
}
|
325
322
|
|
@@ -0,0 +1,368 @@
|
|
1
|
+
//
|
2
|
+
// Copyright 2019 gRPC authors.
|
3
|
+
//
|
4
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
// you may not use this file except in compliance with the License.
|
6
|
+
// You may obtain a copy of the License at
|
7
|
+
//
|
8
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
//
|
10
|
+
// Unless required by applicable law or agreed to in writing, software
|
11
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
// See the License for the specific language governing permissions and
|
14
|
+
// limitations under the License.
|
15
|
+
//
|
16
|
+
|
17
|
+
#include <grpc/support/port_platform.h>
|
18
|
+
|
19
|
+
#include <string.h>
|
20
|
+
|
21
|
+
#include "src/core/ext/filters/client_channel/lb_policy.h"
|
22
|
+
#include "src/core/ext/filters/client_channel/lb_policy_factory.h"
|
23
|
+
#include "src/core/ext/filters/client_channel/lb_policy_registry.h"
|
24
|
+
#include "src/core/ext/filters/client_channel/service_config.h"
|
25
|
+
#include "src/core/ext/filters/client_channel/xds/xds_client.h"
|
26
|
+
#include "src/core/lib/channel/channel_args.h"
|
27
|
+
#include "src/core/lib/gprpp/memory.h"
|
28
|
+
#include "src/core/lib/gprpp/orphanable.h"
|
29
|
+
#include "src/core/lib/gprpp/ref_counted_ptr.h"
|
30
|
+
|
31
|
+
namespace grpc_core {
|
32
|
+
|
33
|
+
TraceFlag grpc_cds_lb_trace(false, "cds_lb");
|
34
|
+
|
35
|
+
namespace {
|
36
|
+
|
37
|
+
constexpr char kCds[] = "cds_experimental";
|
38
|
+
|
39
|
+
// Parsed config for this LB policy.
|
40
|
+
class ParsedCdsConfig : public LoadBalancingPolicy::Config {
|
41
|
+
public:
|
42
|
+
explicit ParsedCdsConfig(grpc_core::UniquePtr<char> cluster)
|
43
|
+
: cluster_(std::move(cluster)) {}
|
44
|
+
const char* cluster() const { return cluster_.get(); }
|
45
|
+
const char* name() const override { return kCds; }
|
46
|
+
|
47
|
+
private:
|
48
|
+
grpc_core::UniquePtr<char> cluster_;
|
49
|
+
};
|
50
|
+
|
51
|
+
// CDS LB policy.
|
52
|
+
class CdsLb : public LoadBalancingPolicy {
|
53
|
+
public:
|
54
|
+
explicit CdsLb(Args args);
|
55
|
+
|
56
|
+
const char* name() const override { return kCds; }
|
57
|
+
|
58
|
+
void UpdateLocked(UpdateArgs args) override;
|
59
|
+
void ResetBackoffLocked() override;
|
60
|
+
|
61
|
+
private:
|
62
|
+
// Watcher for getting cluster data from XdsClient.
|
63
|
+
class ClusterWatcher : public XdsClient::ClusterWatcherInterface {
|
64
|
+
public:
|
65
|
+
explicit ClusterWatcher(RefCountedPtr<CdsLb> parent)
|
66
|
+
: parent_(std::move(parent)) {}
|
67
|
+
void OnClusterChanged(CdsUpdate cluster_data) override;
|
68
|
+
void OnError(grpc_error* error) override;
|
69
|
+
|
70
|
+
private:
|
71
|
+
RefCountedPtr<CdsLb> parent_;
|
72
|
+
};
|
73
|
+
|
74
|
+
// Delegating helper to be passed to child policy.
|
75
|
+
class Helper : public ChannelControlHelper {
|
76
|
+
public:
|
77
|
+
explicit Helper(RefCountedPtr<CdsLb> parent) : parent_(std::move(parent)) {}
|
78
|
+
RefCountedPtr<SubchannelInterface> CreateSubchannel(
|
79
|
+
const grpc_channel_args& args) override;
|
80
|
+
void UpdateState(grpc_connectivity_state state,
|
81
|
+
std::unique_ptr<SubchannelPicker> picker) override;
|
82
|
+
void RequestReresolution() override;
|
83
|
+
void AddTraceEvent(TraceSeverity severity, StringView message) override;
|
84
|
+
|
85
|
+
private:
|
86
|
+
RefCountedPtr<CdsLb> parent_;
|
87
|
+
};
|
88
|
+
|
89
|
+
~CdsLb();
|
90
|
+
|
91
|
+
void ShutdownLocked() override;
|
92
|
+
|
93
|
+
RefCountedPtr<ParsedCdsConfig> config_;
|
94
|
+
|
95
|
+
// Current channel args from the resolver.
|
96
|
+
const grpc_channel_args* args_ = nullptr;
|
97
|
+
|
98
|
+
// The xds client.
|
99
|
+
RefCountedPtr<XdsClient> xds_client_;
|
100
|
+
// A pointer to the cluster watcher, to be used when cancelling the watch.
|
101
|
+
// Note that this is not owned, so this pointer must never be derefernced.
|
102
|
+
ClusterWatcher* cluster_watcher_ = nullptr;
|
103
|
+
|
104
|
+
// Child LB policy.
|
105
|
+
OrphanablePtr<LoadBalancingPolicy> child_policy_;
|
106
|
+
|
107
|
+
// Internal state.
|
108
|
+
bool shutting_down_ = false;
|
109
|
+
};
|
110
|
+
|
111
|
+
//
|
112
|
+
// CdsLb::ClusterWatcher
|
113
|
+
//
|
114
|
+
|
115
|
+
void CdsLb::ClusterWatcher::OnClusterChanged(CdsUpdate cluster_data) {
|
116
|
+
if (GRPC_TRACE_FLAG_ENABLED(grpc_cds_lb_trace)) {
|
117
|
+
gpr_log(GPR_INFO, "[cdslb %p] received CDS update from xds client",
|
118
|
+
parent_.get());
|
119
|
+
}
|
120
|
+
// Construct config for child policy.
|
121
|
+
char* lrs_str = nullptr;
|
122
|
+
if (cluster_data.lrs_load_reporting_server_name != nullptr) {
|
123
|
+
gpr_asprintf(&lrs_str, " \"lrsLoadReportingServerName\": \"%s\",\n",
|
124
|
+
cluster_data.lrs_load_reporting_server_name.get());
|
125
|
+
}
|
126
|
+
char* json_str;
|
127
|
+
gpr_asprintf(&json_str,
|
128
|
+
"[{\n"
|
129
|
+
" \"xds_experimental\": {\n"
|
130
|
+
"%s"
|
131
|
+
" \"edsServiceName\": \"%s\"\n"
|
132
|
+
" }\n"
|
133
|
+
"}]",
|
134
|
+
(lrs_str == nullptr ? "" : lrs_str),
|
135
|
+
(cluster_data.eds_service_name == nullptr
|
136
|
+
? parent_->config_->cluster()
|
137
|
+
: cluster_data.eds_service_name.get()));
|
138
|
+
gpr_free(lrs_str);
|
139
|
+
grpc_core::UniquePtr<char> json_str_deleter(json_str);
|
140
|
+
if (GRPC_TRACE_FLAG_ENABLED(grpc_cds_lb_trace)) {
|
141
|
+
gpr_log(GPR_INFO, "[cdslb %p] generated config for child policy: %s",
|
142
|
+
parent_.get(), json_str);
|
143
|
+
}
|
144
|
+
grpc_json* json = grpc_json_parse_string(json_str);
|
145
|
+
if (json == nullptr) {
|
146
|
+
char* msg;
|
147
|
+
gpr_asprintf(&msg, "Could not parse LB config: %s", json_str);
|
148
|
+
OnError(GRPC_ERROR_CREATE_FROM_COPIED_STRING(msg));
|
149
|
+
gpr_free(msg);
|
150
|
+
return;
|
151
|
+
}
|
152
|
+
grpc_error* error = GRPC_ERROR_NONE;
|
153
|
+
RefCountedPtr<LoadBalancingPolicy::Config> config =
|
154
|
+
LoadBalancingPolicyRegistry::ParseLoadBalancingConfig(json, &error);
|
155
|
+
grpc_json_destroy(json);
|
156
|
+
if (error != GRPC_ERROR_NONE) {
|
157
|
+
OnError(error);
|
158
|
+
return;
|
159
|
+
}
|
160
|
+
// Create child policy if not already present.
|
161
|
+
if (parent_->child_policy_ == nullptr) {
|
162
|
+
LoadBalancingPolicy::Args args;
|
163
|
+
args.combiner = parent_->combiner();
|
164
|
+
args.args = parent_->args_;
|
165
|
+
args.channel_control_helper = MakeUnique<Helper>(parent_->Ref());
|
166
|
+
parent_->child_policy_ =
|
167
|
+
LoadBalancingPolicyRegistry::CreateLoadBalancingPolicy(
|
168
|
+
"xds_experimental", std::move(args));
|
169
|
+
grpc_pollset_set_add_pollset_set(
|
170
|
+
parent_->child_policy_->interested_parties(),
|
171
|
+
parent_->interested_parties());
|
172
|
+
}
|
173
|
+
// Update child policy.
|
174
|
+
UpdateArgs args;
|
175
|
+
args.config = std::move(config);
|
176
|
+
args.args = grpc_channel_args_copy(parent_->args_);
|
177
|
+
parent_->child_policy_->UpdateLocked(std::move(args));
|
178
|
+
}
|
179
|
+
|
180
|
+
void CdsLb::ClusterWatcher::OnError(grpc_error* error) {
|
181
|
+
gpr_log(GPR_ERROR, "[cdslb %p] xds error obtaining data for cluster %s: %s",
|
182
|
+
parent_.get(), parent_->config_->cluster(), grpc_error_string(error));
|
183
|
+
// Go into TRANSIENT_FAILURE if we have not yet created the child
|
184
|
+
// policy (i.e., we have not yet received data from xds). Otherwise,
|
185
|
+
// we keep running with the data we had previously.
|
186
|
+
if (parent_->child_policy_ == nullptr) {
|
187
|
+
parent_->channel_control_helper()->UpdateState(
|
188
|
+
GRPC_CHANNEL_TRANSIENT_FAILURE,
|
189
|
+
MakeUnique<TransientFailurePicker>(error));
|
190
|
+
} else {
|
191
|
+
GRPC_ERROR_UNREF(error);
|
192
|
+
}
|
193
|
+
}
|
194
|
+
|
195
|
+
//
|
196
|
+
// CdsLb::Helper
|
197
|
+
//
|
198
|
+
|
199
|
+
RefCountedPtr<SubchannelInterface> CdsLb::Helper::CreateSubchannel(
|
200
|
+
const grpc_channel_args& args) {
|
201
|
+
if (parent_->shutting_down_) return nullptr;
|
202
|
+
return parent_->channel_control_helper()->CreateSubchannel(args);
|
203
|
+
}
|
204
|
+
|
205
|
+
void CdsLb::Helper::UpdateState(grpc_connectivity_state state,
|
206
|
+
std::unique_ptr<SubchannelPicker> picker) {
|
207
|
+
if (parent_->shutting_down_) return;
|
208
|
+
if (GRPC_TRACE_FLAG_ENABLED(grpc_cds_lb_trace)) {
|
209
|
+
gpr_log(GPR_INFO, "[cdslb %p] state updated by child: %s", this,
|
210
|
+
ConnectivityStateName(state));
|
211
|
+
}
|
212
|
+
parent_->channel_control_helper()->UpdateState(state, std::move(picker));
|
213
|
+
}
|
214
|
+
|
215
|
+
void CdsLb::Helper::RequestReresolution() {
|
216
|
+
if (parent_->shutting_down_) return;
|
217
|
+
if (GRPC_TRACE_FLAG_ENABLED(grpc_cds_lb_trace)) {
|
218
|
+
gpr_log(GPR_INFO, "[cdslb %p] Re-resolution requested from child policy.",
|
219
|
+
parent_.get());
|
220
|
+
}
|
221
|
+
parent_->channel_control_helper()->RequestReresolution();
|
222
|
+
}
|
223
|
+
|
224
|
+
void CdsLb::Helper::AddTraceEvent(TraceSeverity severity, StringView message) {
|
225
|
+
if (parent_->shutting_down_) return;
|
226
|
+
parent_->channel_control_helper()->AddTraceEvent(severity, message);
|
227
|
+
}
|
228
|
+
|
229
|
+
//
|
230
|
+
// CdsLb
|
231
|
+
//
|
232
|
+
|
233
|
+
CdsLb::CdsLb(Args args)
|
234
|
+
: LoadBalancingPolicy(std::move(args)),
|
235
|
+
xds_client_(XdsClient::GetFromChannelArgs(*args.args)) {
|
236
|
+
if (xds_client_ != nullptr && GRPC_TRACE_FLAG_ENABLED(grpc_cds_lb_trace)) {
|
237
|
+
gpr_log(GPR_INFO, "[cdslb %p] Using xds client %p from channel", this,
|
238
|
+
xds_client_.get());
|
239
|
+
}
|
240
|
+
}
|
241
|
+
|
242
|
+
CdsLb::~CdsLb() {
|
243
|
+
if (GRPC_TRACE_FLAG_ENABLED(grpc_cds_lb_trace)) {
|
244
|
+
gpr_log(GPR_INFO, "[cdslb %p] destroying cds LB policy", this);
|
245
|
+
}
|
246
|
+
grpc_channel_args_destroy(args_);
|
247
|
+
}
|
248
|
+
|
249
|
+
void CdsLb::ShutdownLocked() {
|
250
|
+
if (GRPC_TRACE_FLAG_ENABLED(grpc_cds_lb_trace)) {
|
251
|
+
gpr_log(GPR_INFO, "[cdslb %p] shutting down", this);
|
252
|
+
}
|
253
|
+
shutting_down_ = true;
|
254
|
+
if (child_policy_ != nullptr) {
|
255
|
+
grpc_pollset_set_del_pollset_set(child_policy_->interested_parties(),
|
256
|
+
interested_parties());
|
257
|
+
child_policy_.reset();
|
258
|
+
}
|
259
|
+
if (xds_client_ != nullptr) {
|
260
|
+
if (cluster_watcher_ != nullptr) {
|
261
|
+
xds_client_->CancelClusterDataWatch(StringView(config_->cluster()),
|
262
|
+
cluster_watcher_);
|
263
|
+
}
|
264
|
+
xds_client_.reset();
|
265
|
+
}
|
266
|
+
}
|
267
|
+
|
268
|
+
void CdsLb::ResetBackoffLocked() {
|
269
|
+
if (child_policy_ != nullptr) child_policy_->ResetBackoffLocked();
|
270
|
+
}
|
271
|
+
|
272
|
+
void CdsLb::UpdateLocked(UpdateArgs args) {
|
273
|
+
if (GRPC_TRACE_FLAG_ENABLED(grpc_cds_lb_trace)) {
|
274
|
+
gpr_log(GPR_INFO, "[cdslb %p] received update", this);
|
275
|
+
}
|
276
|
+
// Update config.
|
277
|
+
auto old_config = std::move(config_);
|
278
|
+
config_ = std::move(args.config);
|
279
|
+
// Update args.
|
280
|
+
grpc_channel_args_destroy(args_);
|
281
|
+
args_ = args.args;
|
282
|
+
args.args = nullptr;
|
283
|
+
// If cluster name changed, cancel watcher and restart.
|
284
|
+
if (old_config == nullptr ||
|
285
|
+
strcmp(old_config->cluster(), config_->cluster()) != 0) {
|
286
|
+
if (old_config != nullptr) {
|
287
|
+
xds_client_->CancelClusterDataWatch(StringView(old_config->cluster()),
|
288
|
+
cluster_watcher_);
|
289
|
+
}
|
290
|
+
auto watcher = MakeUnique<ClusterWatcher>(Ref());
|
291
|
+
cluster_watcher_ = watcher.get();
|
292
|
+
xds_client_->WatchClusterData(StringView(config_->cluster()),
|
293
|
+
std::move(watcher));
|
294
|
+
}
|
295
|
+
}
|
296
|
+
|
297
|
+
//
|
298
|
+
// factory
|
299
|
+
//
|
300
|
+
|
301
|
+
class CdsFactory : public LoadBalancingPolicyFactory {
|
302
|
+
public:
|
303
|
+
OrphanablePtr<LoadBalancingPolicy> CreateLoadBalancingPolicy(
|
304
|
+
LoadBalancingPolicy::Args args) const override {
|
305
|
+
return MakeOrphanable<CdsLb>(std::move(args));
|
306
|
+
}
|
307
|
+
|
308
|
+
const char* name() const override { return kCds; }
|
309
|
+
|
310
|
+
RefCountedPtr<LoadBalancingPolicy::Config> ParseLoadBalancingConfig(
|
311
|
+
const grpc_json* json, grpc_error** error) const override {
|
312
|
+
GPR_DEBUG_ASSERT(error != nullptr && *error == GRPC_ERROR_NONE);
|
313
|
+
if (json == nullptr) {
|
314
|
+
// xds was mentioned as a policy in the deprecated loadBalancingPolicy
|
315
|
+
// field or in the client API.
|
316
|
+
*error = GRPC_ERROR_CREATE_FROM_STATIC_STRING(
|
317
|
+
"field:loadBalancingPolicy error:cds policy requires configuration. "
|
318
|
+
"Please use loadBalancingConfig field of service config instead.");
|
319
|
+
return nullptr;
|
320
|
+
}
|
321
|
+
GPR_DEBUG_ASSERT(strcmp(json->key, name()) == 0);
|
322
|
+
InlinedVector<grpc_error*, 3> error_list;
|
323
|
+
const char* cluster = nullptr;
|
324
|
+
for (const grpc_json* field = json->child; field != nullptr;
|
325
|
+
field = field->next) {
|
326
|
+
if (field->key == nullptr) continue;
|
327
|
+
if (strcmp(field->key, "cluster") == 0) {
|
328
|
+
if (cluster != nullptr) {
|
329
|
+
error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
|
330
|
+
"field:cluster error:Duplicate entry"));
|
331
|
+
}
|
332
|
+
if (field->type != GRPC_JSON_STRING) {
|
333
|
+
error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
|
334
|
+
"field:cluster error:type should be string"));
|
335
|
+
continue;
|
336
|
+
}
|
337
|
+
cluster = field->value;
|
338
|
+
}
|
339
|
+
}
|
340
|
+
if (cluster == nullptr) {
|
341
|
+
error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
|
342
|
+
"required field 'cluster' not present"));
|
343
|
+
}
|
344
|
+
if (error_list.empty()) {
|
345
|
+
return MakeRefCounted<ParsedCdsConfig>(
|
346
|
+
grpc_core::UniquePtr<char>(gpr_strdup(cluster)));
|
347
|
+
} else {
|
348
|
+
*error = GRPC_ERROR_CREATE_FROM_VECTOR("Cds Parser", &error_list);
|
349
|
+
return nullptr;
|
350
|
+
}
|
351
|
+
}
|
352
|
+
};
|
353
|
+
|
354
|
+
} // namespace
|
355
|
+
|
356
|
+
} // namespace grpc_core
|
357
|
+
|
358
|
+
//
|
359
|
+
// Plugin registration
|
360
|
+
//
|
361
|
+
|
362
|
+
void grpc_lb_policy_cds_init() {
|
363
|
+
grpc_core::LoadBalancingPolicyRegistry::Builder::
|
364
|
+
RegisterLoadBalancingPolicyFactory(
|
365
|
+
grpc_core::MakeUnique<grpc_core::CdsFactory>());
|
366
|
+
}
|
367
|
+
|
368
|
+
void grpc_lb_policy_cds_shutdown() {}
|