grpc 1.28.0 → 1.30.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 +7694 -11190
- data/include/grpc/grpc.h +2 -2
- data/include/grpc/grpc_security.h +22 -9
- data/include/grpc/grpc_security_constants.h +1 -0
- data/include/grpc/impl/codegen/grpc_types.h +19 -21
- data/include/grpc/impl/codegen/port_platform.h +6 -2
- data/include/grpc/module.modulemap +24 -39
- data/src/core/ext/filters/client_channel/backend_metric.cc +7 -4
- data/src/core/ext/filters/client_channel/client_channel.cc +203 -236
- data/src/core/ext/filters/client_channel/client_channel_plugin.cc +3 -2
- data/src/core/ext/filters/client_channel/health/health_check_client.cc +7 -22
- data/src/core/ext/filters/client_channel/health/health_check_client.h +3 -3
- data/src/core/ext/filters/client_channel/http_proxy.cc +17 -10
- data/src/core/ext/filters/client_channel/lb_policy.cc +19 -18
- data/src/core/ext/filters/client_channel/lb_policy.h +42 -33
- data/src/core/ext/filters/client_channel/lb_policy/address_filtering.cc +83 -0
- data/src/core/ext/filters/client_channel/lb_policy/address_filtering.h +99 -0
- data/src/core/ext/filters/client_channel/lb_policy/child_policy_handler.cc +10 -4
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +240 -301
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_balancer_addresses.cc +89 -0
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_balancer_addresses.h +40 -0
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel_secure.cc +11 -9
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.h +3 -2
- data/src/core/ext/filters/client_channel/lb_policy/priority/priority.cc +871 -0
- data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc +1 -1
- data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +5 -11
- data/src/core/ext/filters/client_channel/lb_policy/weighted_target/weighted_target.cc +734 -0
- data/src/core/ext/filters/client_channel/lb_policy/xds/cds.cc +84 -37
- data/src/core/ext/filters/client_channel/lb_policy/xds/eds.cc +938 -0
- data/src/core/ext/filters/client_channel/lb_policy/xds/lrs.cc +528 -0
- data/src/core/ext/filters/client_channel/lb_policy/xds/xds.h +1 -2
- data/src/core/ext/filters/client_channel/lb_policy/xds/xds_routing.cc +834 -0
- data/src/core/ext/filters/client_channel/lb_policy_registry.cc +6 -2
- data/src/core/ext/filters/client_channel/local_subchannel_pool.h +2 -1
- data/src/core/ext/filters/client_channel/parse_address.cc +22 -21
- data/src/core/ext/filters/client_channel/resolver.cc +5 -8
- data/src/core/ext/filters/client_channel/resolver.h +12 -14
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +73 -59
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.cc +35 -35
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.h +8 -7
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_libuv.cc +16 -20
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_posix.cc +4 -4
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_windows.cc +72 -117
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc +184 -133
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h +5 -3
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_fallback.cc +7 -4
- data/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc +40 -43
- data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc +93 -102
- data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.h +0 -4
- data/src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.cc +2 -2
- data/src/core/ext/filters/client_channel/resolver/xds/xds_resolver.cc +32 -5
- data/src/core/ext/filters/client_channel/resolver_factory.h +2 -2
- data/src/core/ext/filters/client_channel/resolver_registry.cc +6 -3
- data/src/core/ext/filters/client_channel/resolver_registry.h +8 -8
- data/src/core/ext/filters/client_channel/resolver_result_parsing.cc +16 -16
- data/src/core/ext/filters/client_channel/resolver_result_parsing.h +19 -16
- data/src/core/ext/filters/client_channel/resolving_lb_policy.cc +20 -31
- data/src/core/ext/filters/client_channel/resolving_lb_policy.h +4 -3
- data/src/core/ext/filters/client_channel/server_address.cc +6 -9
- data/src/core/ext/filters/client_channel/server_address.h +6 -12
- data/src/core/ext/filters/client_channel/service_config.cc +104 -144
- data/src/core/ext/filters/client_channel/service_config.h +28 -98
- data/src/core/ext/filters/client_channel/service_config_call_data.h +68 -0
- data/src/core/ext/filters/client_channel/service_config_parser.cc +87 -0
- data/src/core/ext/filters/client_channel/service_config_parser.h +89 -0
- data/src/core/ext/filters/client_channel/subchannel.cc +54 -24
- data/src/core/ext/filters/client_channel/subchannel.h +35 -11
- data/src/core/ext/filters/client_channel/xds/xds_api.cc +348 -221
- data/src/core/ext/filters/client_channel/xds/xds_api.h +37 -37
- data/src/core/ext/filters/client_channel/xds/xds_bootstrap.cc +44 -49
- data/src/core/ext/filters/client_channel/xds/xds_bootstrap.h +4 -3
- data/src/core/ext/filters/client_channel/xds/xds_channel_secure.cc +4 -2
- data/src/core/ext/filters/client_channel/xds/xds_client.cc +532 -339
- data/src/core/ext/filters/client_channel/xds/xds_client.h +57 -22
- data/src/core/ext/filters/client_channel/xds/xds_client_stats.cc +11 -12
- data/src/core/ext/filters/client_channel/xds/xds_client_stats.h +31 -19
- data/src/core/ext/filters/http/client/http_client_filter.cc +23 -28
- data/src/core/ext/filters/http/client_authority_filter.cc +4 -4
- data/src/core/ext/filters/http/http_filters_plugin.cc +27 -12
- data/src/core/ext/filters/http/message_compress/message_compress_filter.cc +258 -221
- data/src/core/ext/filters/http/message_compress/message_decompress_filter.cc +358 -0
- data/src/core/ext/filters/http/message_compress/message_decompress_filter.h +29 -0
- data/src/core/ext/filters/message_size/message_size_filter.cc +7 -10
- data/src/core/ext/filters/message_size/message_size_filter.h +4 -4
- data/src/core/ext/transport/chttp2/server/chttp2_server.cc +4 -4
- data/src/core/ext/transport/chttp2/transport/bin_encoder.cc +4 -6
- data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +23 -22
- data/src/core/ext/transport/chttp2/transport/chttp2_transport.h +1 -0
- data/src/core/ext/transport/chttp2/transport/flow_control.cc +3 -3
- data/src/core/ext/transport/chttp2/transport/frame_goaway.h +2 -3
- data/src/core/ext/transport/chttp2/transport/frame_ping.h +2 -3
- data/src/core/ext/transport/chttp2/transport/frame_rst_stream.h +2 -3
- data/src/core/ext/transport/chttp2/transport/frame_settings.h +2 -3
- data/src/core/ext/transport/chttp2/transport/frame_window_update.h +2 -3
- data/src/core/ext/transport/chttp2/transport/hpack_encoder.cc +29 -16
- data/src/core/ext/transport/chttp2/transport/hpack_encoder.h +2 -3
- data/src/core/ext/transport/chttp2/transport/hpack_parser.h +2 -3
- data/src/core/ext/transport/chttp2/transport/hpack_table.h +2 -2
- data/src/core/ext/transport/chttp2/transport/http2_settings.h +4 -5
- data/src/core/ext/transport/chttp2/transport/huffsyms.h +2 -3
- data/src/core/ext/transport/chttp2/transport/internal.h +14 -21
- data/src/core/ext/transport/chttp2/transport/stream_map.h +2 -3
- data/src/core/ext/transport/chttp2/transport/writing.cc +15 -8
- data/src/core/ext/transport/inproc/inproc_transport.cc +19 -0
- data/src/core/ext/upb-generated/envoy/api/v2/auth/cert.upb.c +4 -229
- data/src/core/ext/upb-generated/envoy/api/v2/auth/cert.upb.h +5 -875
- data/src/core/ext/upb-generated/envoy/api/v2/auth/common.upb.c +114 -0
- data/src/core/ext/upb-generated/envoy/api/v2/auth/common.upb.h +418 -0
- data/src/core/ext/upb-generated/envoy/api/v2/auth/secret.upb.c +72 -0
- data/src/core/ext/upb-generated/envoy/api/v2/auth/secret.upb.h +197 -0
- data/src/core/ext/upb-generated/envoy/api/v2/auth/tls.upb.c +105 -0
- data/src/core/ext/upb-generated/envoy/api/v2/auth/tls.upb.h +378 -0
- data/src/core/ext/upb-generated/envoy/api/v2/cds.upb.c +1 -0
- data/src/core/ext/upb-generated/envoy/api/v2/cluster.upb.c +21 -8
- data/src/core/ext/upb-generated/envoy/api/v2/cluster.upb.h +43 -7
- data/src/core/ext/upb-generated/envoy/api/v2/cluster/circuit_breaker.upb.c +1 -0
- data/src/core/ext/upb-generated/envoy/api/v2/cluster/filter.upb.c +1 -0
- data/src/core/ext/upb-generated/envoy/api/v2/cluster/outlier_detection.upb.c +1 -0
- data/src/core/ext/upb-generated/envoy/api/v2/core/address.upb.c +2 -1
- data/src/core/ext/upb-generated/envoy/api/v2/core/backoff.upb.c +35 -0
- data/src/core/ext/upb-generated/envoy/api/v2/core/backoff.upb.h +78 -0
- data/src/core/ext/upb-generated/envoy/api/v2/core/base.upb.c +47 -26
- data/src/core/ext/upb-generated/envoy/api/v2/core/base.upb.h +115 -65
- data/src/core/ext/upb-generated/envoy/api/v2/core/config_source.upb.c +1 -0
- data/src/core/ext/upb-generated/envoy/api/v2/core/event_service_config.upb.c +34 -0
- data/src/core/ext/upb-generated/envoy/api/v2/core/event_service_config.upb.h +72 -0
- data/src/core/ext/upb-generated/envoy/api/v2/core/grpc_service.upb.c +2 -1
- data/src/core/ext/upb-generated/envoy/api/v2/core/health_check.upb.c +24 -20
- data/src/core/ext/upb-generated/envoy/api/v2/core/health_check.upb.h +28 -13
- data/src/core/ext/upb-generated/envoy/api/v2/core/http_uri.upb.c +1 -0
- data/src/core/ext/upb-generated/envoy/api/v2/core/protocol.upb.c +38 -18
- data/src/core/ext/upb-generated/envoy/api/v2/core/protocol.upb.h +88 -6
- data/src/core/ext/upb-generated/envoy/api/v2/core/socket_option.upb.c +34 -0
- data/src/core/ext/upb-generated/envoy/api/v2/core/socket_option.upb.h +89 -0
- data/src/core/ext/upb-generated/envoy/api/v2/discovery.upb.c +1 -0
- data/src/core/ext/upb-generated/envoy/api/v2/eds.upb.c +1 -0
- data/src/core/ext/upb-generated/envoy/api/v2/endpoint.upb.c +1 -0
- data/src/core/ext/upb-generated/envoy/api/v2/endpoint/endpoint.upb.c +1 -0
- data/src/core/ext/upb-generated/envoy/api/v2/endpoint/endpoint_components.upb.c +9 -6
- data/src/core/ext/upb-generated/envoy/api/v2/endpoint/endpoint_components.upb.h +12 -4
- data/src/core/ext/upb-generated/envoy/api/v2/endpoint/load_report.upb.c +1 -0
- data/src/core/ext/upb-generated/envoy/api/v2/lds.upb.c +1 -0
- data/src/core/ext/upb-generated/envoy/api/v2/listener.upb.c +15 -10
- data/src/core/ext/upb-generated/envoy/api/v2/listener.upb.h +16 -0
- data/src/core/ext/upb-generated/envoy/api/v2/listener/listener.upb.c +1 -0
- data/src/core/ext/upb-generated/envoy/api/v2/listener/listener_components.upb.c +2 -1
- data/src/core/ext/upb-generated/envoy/api/v2/listener/udp_listener_config.upb.c +1 -0
- data/src/core/ext/upb-generated/envoy/api/v2/rds.upb.c +1 -0
- data/src/core/ext/upb-generated/envoy/api/v2/route.upb.c +1 -0
- data/src/core/ext/upb-generated/envoy/api/v2/route/route.upb.c +1 -0
- data/src/core/ext/upb-generated/envoy/api/v2/route/route_components.upb.c +63 -41
- data/src/core/ext/upb-generated/envoy/api/v2/route/route_components.upb.h +173 -77
- data/src/core/ext/upb-generated/envoy/api/v2/scoped_route.upb.c +1 -0
- data/src/core/ext/upb-generated/envoy/api/v2/srds.upb.c +1 -0
- data/src/core/ext/upb-generated/envoy/config/filter/accesslog/v2/accesslog.upb.c +1 -0
- data/src/core/ext/upb-generated/envoy/config/filter/network/http_connection_manager/v2/http_connection_manager.upb.c +48 -28
- data/src/core/ext/upb-generated/envoy/config/filter/network/http_connection_manager/v2/http_connection_manager.upb.h +90 -30
- data/src/core/ext/upb-generated/envoy/config/listener/v2/api_listener.upb.c +1 -0
- data/src/core/ext/upb-generated/envoy/config/trace/v2/http_tracer.upb.c +51 -0
- data/src/core/ext/upb-generated/envoy/config/trace/v2/http_tracer.upb.h +125 -0
- data/src/core/ext/upb-generated/envoy/service/discovery/v2/ads.upb.c +1 -0
- data/src/core/ext/upb-generated/envoy/service/load_stats/v2/lrs.upb.c +4 -2
- data/src/core/ext/upb-generated/envoy/service/load_stats/v2/lrs.upb.h +4 -0
- data/src/core/ext/upb-generated/envoy/type/http.upb.c +1 -0
- data/src/core/ext/upb-generated/envoy/type/matcher/regex.upb.c +16 -0
- data/src/core/ext/upb-generated/envoy/type/matcher/regex.upb.h +36 -0
- data/src/core/ext/upb-generated/envoy/type/matcher/string.upb.c +1 -0
- data/src/core/ext/upb-generated/envoy/type/metadata/v2/metadata.upb.c +1 -0
- data/src/core/ext/upb-generated/envoy/type/percent.upb.c +1 -0
- data/src/core/ext/upb-generated/envoy/type/range.upb.c +1 -0
- data/src/core/ext/upb-generated/envoy/type/semantic_version.upb.c +1 -0
- data/src/core/ext/upb-generated/envoy/type/tracing/v2/custom_tag.upb.c +1 -0
- data/src/core/ext/upb-generated/google/protobuf/descriptor.upb.c +9 -8
- data/src/core/ext/upb-generated/google/protobuf/descriptor.upb.h +30 -24
- data/src/core/ext/upb-generated/udpa/annotations/status.upb.c +28 -0
- data/src/core/ext/upb-generated/udpa/annotations/status.upb.h +65 -0
- data/src/core/ext/upb-generated/validate/validate.upb.c +21 -20
- data/src/core/ext/upb-generated/validate/validate.upb.h +69 -63
- data/src/core/lib/channel/channel_args.cc +15 -14
- data/src/core/lib/channel/channel_args.h +3 -1
- data/src/core/lib/channel/channel_stack.h +20 -13
- data/src/core/lib/channel/channelz.cc +5 -6
- data/src/core/lib/channel/channelz.h +3 -2
- data/src/core/lib/channel/channelz_registry.cc +5 -3
- data/src/core/lib/channel/connected_channel.cc +7 -5
- data/src/core/lib/channel/context.h +1 -1
- data/src/core/lib/channel/handshaker.cc +11 -13
- data/src/core/lib/channel/handshaker.h +4 -2
- data/src/core/lib/channel/handshaker_registry.cc +5 -17
- data/src/core/lib/channel/status_util.cc +2 -3
- data/src/core/lib/compression/message_compress.cc +5 -1
- data/src/core/lib/debug/stats.cc +21 -27
- data/src/core/lib/debug/stats.h +3 -1
- data/src/core/lib/gpr/spinlock.h +2 -3
- data/src/core/lib/gpr/string.cc +2 -26
- data/src/core/lib/gpr/string.h +0 -16
- data/src/core/lib/gpr/sync_abseil.cc +2 -0
- data/src/core/lib/gpr/time.cc +4 -0
- data/src/core/lib/gpr/time_posix.cc +1 -1
- data/src/core/lib/gprpp/atomic.h +6 -6
- data/src/core/lib/gprpp/fork.cc +1 -1
- data/src/core/lib/gprpp/host_port.cc +29 -35
- data/src/core/lib/gprpp/host_port.h +14 -17
- data/src/core/lib/gprpp/map.h +5 -11
- data/src/core/lib/gprpp/ref_counted_ptr.h +5 -0
- data/src/core/lib/http/format_request.cc +46 -65
- data/src/core/lib/http/httpcli.cc +2 -3
- data/src/core/lib/http/httpcli.h +2 -3
- data/src/core/lib/http/httpcli_security_connector.cc +5 -5
- data/src/core/lib/http/parser.h +2 -3
- data/src/core/lib/iomgr/buffer_list.h +22 -21
- data/src/core/lib/iomgr/call_combiner.h +3 -2
- data/src/core/lib/iomgr/cfstream_handle.cc +3 -2
- data/src/core/lib/iomgr/closure.h +2 -3
- data/src/core/lib/iomgr/dualstack_socket_posix.cc +47 -0
- data/src/core/lib/iomgr/endpoint_cfstream.cc +2 -3
- data/src/core/lib/iomgr/endpoint_pair.h +2 -3
- data/src/core/lib/iomgr/error.cc +6 -9
- data/src/core/lib/iomgr/error.h +0 -1
- data/src/core/lib/iomgr/ev_apple.cc +356 -0
- data/src/core/lib/iomgr/ev_apple.h +43 -0
- data/src/core/lib/iomgr/ev_epoll1_linux.cc +20 -23
- data/src/core/lib/iomgr/ev_epollex_linux.cc +2 -3
- data/src/core/lib/iomgr/ev_poll_posix.cc +3 -3
- data/src/core/lib/iomgr/ev_posix.cc +2 -3
- data/src/core/lib/iomgr/exec_ctx.h +14 -2
- data/src/core/lib/iomgr/iomgr_posix_cfstream.cc +84 -20
- data/src/core/lib/iomgr/pollset_set_custom.cc +10 -10
- data/src/core/lib/{gprpp/optional.h → iomgr/pollset_uv.h} +11 -12
- data/src/core/lib/iomgr/port.h +1 -0
- data/src/core/lib/iomgr/python_util.h +46 -0
- data/src/core/lib/iomgr/resolve_address.h +4 -6
- data/src/core/lib/iomgr/resolve_address_custom.cc +29 -39
- data/src/core/lib/iomgr/resolve_address_custom.h +4 -2
- data/src/core/lib/iomgr/resolve_address_posix.cc +10 -11
- data/src/core/lib/iomgr/resolve_address_windows.cc +8 -17
- data/src/core/lib/iomgr/resource_quota.cc +4 -6
- data/src/core/lib/iomgr/sockaddr_utils.cc +23 -29
- data/src/core/lib/iomgr/sockaddr_utils.h +9 -14
- data/src/core/lib/iomgr/socket_factory_posix.h +2 -3
- data/src/core/lib/iomgr/socket_mutator.h +2 -3
- data/src/core/lib/iomgr/socket_utils_common_posix.cc +7 -26
- data/src/core/lib/iomgr/socket_utils_posix.h +3 -0
- data/src/core/lib/iomgr/tcp_client_cfstream.cc +5 -7
- data/src/core/lib/iomgr/tcp_client_posix.cc +8 -5
- data/src/core/lib/iomgr/tcp_client_windows.cc +2 -3
- data/src/core/lib/iomgr/tcp_custom.cc +2 -3
- data/src/core/lib/iomgr/tcp_server_custom.cc +5 -9
- data/src/core/lib/iomgr/tcp_server_posix.cc +5 -4
- data/src/core/lib/iomgr/tcp_server_utils_posix_common.cc +5 -4
- data/src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc +8 -11
- data/src/core/lib/iomgr/tcp_uv.cc +3 -2
- data/src/core/lib/iomgr/time_averaged_stats.h +2 -3
- data/src/core/lib/iomgr/timer_generic.cc +2 -3
- data/src/core/lib/{gprpp/inlined_vector.h → iomgr/timer_generic.h} +19 -17
- data/src/core/lib/iomgr/timer_heap.h +2 -3
- data/src/core/lib/iomgr/udp_server.cc +9 -14
- data/src/core/lib/json/json.h +3 -2
- data/src/core/lib/json/json_reader.cc +5 -5
- data/src/core/lib/json/json_writer.cc +13 -12
- data/src/core/lib/security/credentials/composite/composite_credentials.cc +12 -0
- data/src/core/lib/security/credentials/composite/composite_credentials.h +6 -3
- data/src/core/lib/security/credentials/credentials.cc +0 -84
- data/src/core/lib/security/credentials/credentials.h +8 -59
- data/src/core/lib/security/credentials/fake/fake_credentials.h +4 -0
- data/src/core/lib/security/credentials/google_default/google_default_credentials.cc +3 -8
- data/src/core/lib/security/credentials/iam/iam_credentials.cc +8 -6
- data/src/core/lib/security/credentials/iam/iam_credentials.h +4 -0
- data/src/core/lib/security/credentials/jwt/json_token.cc +1 -1
- data/src/core/lib/security/credentials/jwt/json_token.h +2 -5
- data/src/core/lib/security/credentials/jwt/jwt_credentials.h +12 -0
- data/src/core/lib/security/credentials/jwt/jwt_verifier.cc +8 -15
- data/src/core/lib/security/credentials/jwt/jwt_verifier.h +2 -3
- data/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc +55 -27
- data/src/core/lib/security/credentials/oauth2/oauth2_credentials.h +9 -3
- data/src/core/lib/security/credentials/plugin/plugin_credentials.cc +13 -0
- data/src/core/lib/security/credentials/plugin/plugin_credentials.h +2 -0
- data/src/core/lib/security/credentials/tls/grpc_tls_credentials_options.cc +23 -13
- data/src/core/lib/security/credentials/tls/grpc_tls_credentials_options.h +38 -11
- data/src/core/lib/security/security_connector/alts/alts_security_connector.cc +21 -6
- data/src/core/lib/security/security_connector/fake/fake_security_connector.cc +7 -7
- data/src/core/lib/security/security_connector/load_system_roots_linux.cc +3 -2
- data/src/core/lib/security/security_connector/local/local_security_connector.cc +1 -1
- data/src/core/lib/security/security_connector/security_connector.h +1 -1
- data/src/core/lib/security/security_connector/ssl/ssl_security_connector.cc +20 -25
- data/src/core/lib/security/security_connector/ssl/ssl_security_connector.h +4 -6
- data/src/core/lib/security/security_connector/ssl_utils.cc +59 -12
- data/src/core/lib/security/security_connector/ssl_utils.h +12 -10
- data/src/core/lib/security/security_connector/tls/tls_security_connector.cc +77 -51
- data/src/core/lib/security/security_connector/tls/tls_security_connector.h +27 -5
- data/src/core/lib/security/transport/client_auth_filter.cc +1 -2
- data/src/core/lib/slice/slice_intern.cc +2 -3
- data/src/core/lib/slice/slice_internal.h +14 -0
- data/src/core/lib/slice/slice_utils.h +9 -0
- data/src/core/lib/surface/byte_buffer_reader.cc +2 -47
- data/src/core/lib/surface/call.cc +2 -3
- data/src/core/lib/surface/call_log_batch.cc +50 -58
- data/src/core/lib/surface/channel.cc +53 -31
- data/src/core/lib/surface/channel.h +35 -4
- data/src/core/lib/surface/channel_ping.cc +2 -3
- data/src/core/lib/surface/completion_queue.cc +33 -33
- data/src/core/lib/surface/event_string.cc +18 -25
- data/src/core/lib/surface/event_string.h +3 -1
- data/src/core/lib/surface/init_secure.cc +1 -4
- data/src/core/lib/surface/server.cc +570 -369
- data/src/core/lib/surface/server.h +32 -0
- data/src/core/lib/surface/version.cc +2 -2
- data/src/core/lib/transport/byte_stream.h +7 -2
- data/src/core/lib/transport/connectivity_state.cc +7 -6
- data/src/core/lib/transport/connectivity_state.h +5 -3
- data/src/core/lib/transport/metadata.cc +3 -3
- data/src/core/lib/transport/metadata_batch.h +2 -3
- data/src/core/lib/transport/static_metadata.h +1 -1
- data/src/core/lib/transport/status_conversion.cc +6 -14
- data/src/core/lib/transport/transport.cc +2 -3
- data/src/core/lib/transport/transport.h +3 -2
- data/src/core/lib/transport/transport_op_string.cc +61 -102
- data/src/core/lib/uri/uri_parser.h +2 -3
- data/src/core/plugin_registry/grpc_plugin_registry.cc +20 -4
- data/src/core/tsi/alts/crypt/aes_gcm.cc +0 -2
- data/src/core/tsi/alts/handshaker/alts_handshaker_client.cc +8 -1
- data/src/core/tsi/alts/handshaker/alts_handshaker_client.h +8 -4
- data/src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc +32 -2
- data/src/core/tsi/alts/handshaker/alts_tsi_handshaker.h +9 -1
- data/src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol_common.h +2 -3
- data/src/core/tsi/fake_transport_security.cc +10 -15
- data/src/core/tsi/ssl/session_cache/ssl_session.h +0 -2
- data/src/core/tsi/ssl/session_cache/ssl_session_cache.h +0 -2
- data/src/core/tsi/ssl_transport_security.cc +52 -39
- data/src/core/tsi/ssl_transport_security.h +8 -8
- data/src/core/tsi/ssl_types.h +0 -2
- data/src/core/tsi/transport_security.h +6 -9
- data/src/core/tsi/transport_security_grpc.h +2 -3
- data/src/core/tsi/transport_security_interface.h +3 -3
- data/src/ruby/ext/grpc/rb_call.c +9 -1
- data/src/ruby/lib/grpc/errors.rb +103 -42
- data/src/ruby/lib/grpc/generic/active_call.rb +2 -3
- data/src/ruby/lib/grpc/generic/interceptors.rb +4 -4
- data/src/ruby/lib/grpc/generic/rpc_server.rb +9 -10
- data/src/ruby/lib/grpc/generic/service.rb +5 -4
- data/src/ruby/lib/grpc/structs.rb +1 -1
- data/src/ruby/lib/grpc/version.rb +1 -1
- data/src/ruby/pb/generate_proto_ruby.sh +5 -3
- data/src/ruby/pb/src/proto/grpc/testing/messages_pb.rb +11 -0
- data/src/ruby/pb/src/proto/grpc/testing/test_services_pb.rb +16 -0
- data/src/ruby/spec/debug_message_spec.rb +134 -0
- data/src/ruby/spec/generic/service_spec.rb +2 -0
- data/src/ruby/spec/pb/codegen/grpc/testing/package_options_ruby_style.proto +5 -0
- data/src/ruby/spec/pb/codegen/package_option_spec.rb +2 -0
- data/src/ruby/spec/testdata/ca.pem +18 -13
- data/src/ruby/spec/testdata/client.key +26 -14
- data/src/ruby/spec/testdata/client.pem +18 -12
- data/src/ruby/spec/testdata/server1.key +26 -14
- data/src/ruby/spec/testdata/server1.pem +20 -14
- data/third_party/abseil-cpp/absl/time/civil_time.cc +175 -0
- data/third_party/abseil-cpp/absl/time/civil_time.h +538 -0
- data/third_party/abseil-cpp/absl/time/clock.cc +569 -0
- data/third_party/abseil-cpp/absl/time/clock.h +74 -0
- data/third_party/abseil-cpp/absl/time/duration.cc +922 -0
- data/third_party/abseil-cpp/absl/time/format.cc +153 -0
- data/third_party/abseil-cpp/absl/time/internal/cctz/include/cctz/civil_time.h +332 -0
- data/third_party/abseil-cpp/absl/time/internal/cctz/include/cctz/civil_time_detail.h +622 -0
- data/third_party/abseil-cpp/absl/time/internal/cctz/include/cctz/time_zone.h +384 -0
- data/third_party/abseil-cpp/absl/time/internal/cctz/include/cctz/zone_info_source.h +102 -0
- data/third_party/abseil-cpp/absl/time/internal/cctz/src/civil_time_detail.cc +94 -0
- data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_fixed.cc +140 -0
- data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_fixed.h +52 -0
- data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_format.cc +922 -0
- data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_if.cc +45 -0
- data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_if.h +76 -0
- data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_impl.cc +121 -0
- data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_impl.h +93 -0
- data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_info.cc +958 -0
- data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_info.h +138 -0
- data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_libc.cc +308 -0
- data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_libc.h +55 -0
- data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_lookup.cc +187 -0
- data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_posix.cc +159 -0
- data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_posix.h +132 -0
- data/third_party/abseil-cpp/absl/time/internal/cctz/src/tzfile.h +122 -0
- data/third_party/abseil-cpp/absl/time/internal/cctz/src/zone_info_source.cc +115 -0
- data/third_party/abseil-cpp/absl/time/internal/get_current_time_chrono.inc +31 -0
- data/third_party/abseil-cpp/absl/time/internal/get_current_time_posix.inc +24 -0
- data/third_party/abseil-cpp/absl/time/time.cc +499 -0
- data/third_party/abseil-cpp/absl/time/time.h +1584 -0
- data/third_party/boringssl-with-bazel/err_data.c +329 -297
- data/third_party/boringssl-with-bazel/src/crypto/cipher_extra/derive_key.c +1 -1
- data/third_party/boringssl-with-bazel/src/crypto/cpu-arm-linux.c +7 -5
- data/third_party/boringssl-with-bazel/src/crypto/cpu-intel.c +13 -4
- data/third_party/boringssl-with-bazel/src/crypto/crypto.c +11 -0
- data/third_party/boringssl-with-bazel/src/{third_party/fiat → crypto/curve25519}/curve25519.c +18 -26
- data/third_party/boringssl-with-bazel/src/{third_party/fiat → crypto/curve25519}/curve25519_tables.h +13 -21
- data/third_party/boringssl-with-bazel/src/{third_party/fiat → crypto/curve25519}/internal.h +14 -22
- data/third_party/boringssl-with-bazel/src/crypto/curve25519/spake25519.c +1 -1
- data/third_party/boringssl-with-bazel/src/crypto/dh/dh.c +15 -0
- data/third_party/boringssl-with-bazel/src/crypto/dsa/dsa.c +10 -0
- data/third_party/boringssl-with-bazel/src/crypto/ec_extra/hash_to_curve.c +425 -0
- data/third_party/boringssl-with-bazel/src/crypto/ec_extra/internal.h +78 -0
- data/third_party/boringssl-with-bazel/src/crypto/ecdh_extra/ecdh_extra.c +2 -2
- data/third_party/boringssl-with-bazel/src/crypto/err/err.c +33 -32
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/aes/aes_nohw.c +1 -1
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/bcm.c +2 -1
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/bn/exponentiation.c +3 -3
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/bn/internal.h +14 -11
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/bn/montgomery.c +8 -8
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/bn/mul.c +30 -154
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/digest/digests.c +16 -0
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/ec.c +289 -117
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/ec_key.c +13 -27
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/ec_montgomery.c +96 -55
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/felem.c +25 -7
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/internal.h +432 -160
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/oct.c +63 -71
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/p224-64.c +5 -14
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/p256-x86_64-table.h +9481 -9485
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/p256-x86_64.c +80 -99
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/p256.c +736 -0
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/p256_table.h +297 -0
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/scalar.c +90 -11
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/simple.c +125 -148
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/simple_mul.c +189 -3
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/wnaf.c +61 -18
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ecdh/ecdh.c +2 -2
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ecdsa/ecdsa.c +20 -5
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rand/fork_detect.c +137 -0
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rand/fork_detect.h +49 -0
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rand/getrandom_fillin.h +64 -0
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rand/internal.h +41 -5
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rand/rand.c +32 -17
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rand/urandom.c +24 -114
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rsa/blinding.c +4 -0
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rsa/internal.h +1 -0
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rsa/rsa.c +51 -38
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rsa/rsa_impl.c +15 -1
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/sha/sha512.c +44 -35
- data/third_party/boringssl-with-bazel/src/crypto/mem.c +29 -12
- data/third_party/boringssl-with-bazel/src/crypto/obj/obj_dat.h +15 -1
- data/third_party/boringssl-with-bazel/src/crypto/rand_extra/deterministic.c +6 -10
- data/third_party/boringssl-with-bazel/src/crypto/rand_extra/windows.c +16 -0
- data/third_party/boringssl-with-bazel/src/crypto/thread_pthread.c +4 -0
- data/third_party/boringssl-with-bazel/src/crypto/thread_win.c +4 -0
- data/third_party/boringssl-with-bazel/src/crypto/trust_token/internal.h +278 -0
- data/third_party/boringssl-with-bazel/src/crypto/trust_token/pmbtoken.c +1474 -0
- data/third_party/boringssl-with-bazel/src/crypto/trust_token/trust_token.c +720 -0
- data/third_party/boringssl-with-bazel/src/crypto/x509/x509_set.c +16 -0
- data/third_party/boringssl-with-bazel/src/crypto/x509/x509_vfy.c +5 -0
- data/third_party/boringssl-with-bazel/src/crypto/x509/x509name.c +4 -3
- data/third_party/boringssl-with-bazel/src/include/openssl/base.h +5 -1
- data/third_party/boringssl-with-bazel/src/include/openssl/crypto.h +9 -4
- data/third_party/boringssl-with-bazel/src/include/openssl/dh.h +20 -0
- data/third_party/boringssl-with-bazel/src/include/openssl/digest.h +1 -0
- data/third_party/boringssl-with-bazel/src/include/openssl/dsa.h +16 -0
- data/third_party/boringssl-with-bazel/src/include/openssl/ecdsa.h +6 -0
- data/third_party/boringssl-with-bazel/src/include/openssl/err.h +2 -0
- data/third_party/boringssl-with-bazel/src/include/openssl/nid.h +5 -0
- data/third_party/boringssl-with-bazel/src/include/openssl/rand.h +3 -17
- data/third_party/boringssl-with-bazel/src/include/openssl/rsa.h +31 -0
- data/third_party/boringssl-with-bazel/src/include/openssl/sha.h +26 -0
- data/third_party/boringssl-with-bazel/src/include/openssl/ssl.h +172 -77
- data/third_party/boringssl-with-bazel/src/include/openssl/tls1.h +1 -0
- data/third_party/boringssl-with-bazel/src/include/openssl/trust_token.h +291 -0
- data/third_party/boringssl-with-bazel/src/include/openssl/x509.h +5 -3
- data/third_party/boringssl-with-bazel/src/include/openssl/x509_vfy.h +1 -0
- data/third_party/boringssl-with-bazel/src/ssl/d1_both.cc +0 -4
- data/third_party/boringssl-with-bazel/src/ssl/d1_lib.cc +3 -3
- data/third_party/boringssl-with-bazel/src/ssl/dtls_method.cc +13 -4
- data/third_party/boringssl-with-bazel/src/ssl/handoff.cc +146 -57
- data/third_party/boringssl-with-bazel/src/ssl/handshake.cc +14 -3
- data/third_party/boringssl-with-bazel/src/ssl/handshake_client.cc +28 -20
- data/third_party/boringssl-with-bazel/src/ssl/handshake_server.cc +12 -4
- data/third_party/boringssl-with-bazel/src/ssl/internal.h +64 -47
- data/third_party/boringssl-with-bazel/src/ssl/s3_both.cc +10 -10
- data/third_party/boringssl-with-bazel/src/ssl/s3_lib.cc +2 -2
- data/third_party/boringssl-with-bazel/src/ssl/s3_pkt.cc +21 -21
- data/third_party/boringssl-with-bazel/src/ssl/ssl_asn1.cc +29 -0
- data/third_party/boringssl-with-bazel/src/ssl/ssl_cert.cc +4 -0
- data/third_party/boringssl-with-bazel/src/ssl/ssl_lib.cc +6 -1
- data/third_party/boringssl-with-bazel/src/ssl/ssl_privkey.cc +13 -2
- data/third_party/boringssl-with-bazel/src/ssl/ssl_session.cc +64 -5
- data/third_party/boringssl-with-bazel/src/ssl/ssl_stat.cc +6 -0
- data/third_party/boringssl-with-bazel/src/ssl/t1_enc.cc +6 -2
- data/third_party/boringssl-with-bazel/src/ssl/t1_lib.cc +47 -53
- data/third_party/boringssl-with-bazel/src/ssl/tls13_both.cc +1 -1
- data/third_party/boringssl-with-bazel/src/ssl/tls13_client.cc +98 -27
- data/third_party/boringssl-with-bazel/src/ssl/tls13_enc.cc +23 -75
- data/third_party/boringssl-with-bazel/src/ssl/tls13_server.cc +50 -20
- data/third_party/boringssl-with-bazel/src/ssl/tls_method.cc +63 -25
- data/third_party/boringssl-with-bazel/src/third_party/fiat/curve25519_32.h +245 -175
- data/third_party/boringssl-with-bazel/src/third_party/fiat/curve25519_64.h +135 -75
- data/third_party/boringssl-with-bazel/src/third_party/fiat/p256_32.h +1593 -1672
- data/third_party/boringssl-with-bazel/src/third_party/fiat/p256_64.h +512 -503
- metadata +111 -37
- data/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc +0 -1754
- data/src/core/lib/gprpp/string_view.h +0 -60
- data/src/core/tsi/grpc_shadow_boringssl.h +0 -3311
- data/third_party/boringssl-with-bazel/src/third_party/fiat/p256.c +0 -1063
@@ -0,0 +1,83 @@
|
|
1
|
+
//
|
2
|
+
// Copyright 2020 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 "src/core/ext/filters/client_channel/lb_policy/address_filtering.h"
|
20
|
+
|
21
|
+
#include "src/core/lib/channel/channel_args.h"
|
22
|
+
|
23
|
+
#define GRPC_ARG_HIERARCHICAL_PATH "grpc.internal.address.hierarchical_path"
|
24
|
+
|
25
|
+
namespace grpc_core {
|
26
|
+
|
27
|
+
namespace {
|
28
|
+
|
29
|
+
void* HierarchicalPathCopy(void* p) {
|
30
|
+
std::vector<std::string>* path = static_cast<std::vector<std::string>*>(p);
|
31
|
+
return static_cast<void*>(new std::vector<std::string>(*path));
|
32
|
+
}
|
33
|
+
|
34
|
+
void HierarchicalPathDestroy(void* p) {
|
35
|
+
std::vector<std::string>* path = static_cast<std::vector<std::string>*>(p);
|
36
|
+
delete path;
|
37
|
+
}
|
38
|
+
|
39
|
+
int HierarchicalPathCompare(void* p1, void* p2) {
|
40
|
+
std::vector<std::string>* path1 = static_cast<std::vector<std::string>*>(p1);
|
41
|
+
std::vector<std::string>* path2 = static_cast<std::vector<std::string>*>(p2);
|
42
|
+
for (size_t i = 0; i < path1->size(); ++i) {
|
43
|
+
if (path2->size() == i) return 1;
|
44
|
+
int r = (*path1)[i].compare((*path2)[i]);
|
45
|
+
if (r != 0) return r;
|
46
|
+
}
|
47
|
+
if (path2->size() > path1->size()) return -1;
|
48
|
+
return 0;
|
49
|
+
}
|
50
|
+
|
51
|
+
const grpc_arg_pointer_vtable hierarchical_path_arg_vtable = {
|
52
|
+
HierarchicalPathCopy, HierarchicalPathDestroy, HierarchicalPathCompare};
|
53
|
+
|
54
|
+
} // namespace
|
55
|
+
|
56
|
+
grpc_arg MakeHierarchicalPathArg(const std::vector<std::string>& path) {
|
57
|
+
return grpc_channel_arg_pointer_create(
|
58
|
+
const_cast<char*>(GRPC_ARG_HIERARCHICAL_PATH),
|
59
|
+
const_cast<std::vector<std::string>*>(&path),
|
60
|
+
&hierarchical_path_arg_vtable);
|
61
|
+
}
|
62
|
+
|
63
|
+
HierarchicalAddressMap MakeHierarchicalAddressMap(
|
64
|
+
const ServerAddressList& addresses) {
|
65
|
+
HierarchicalAddressMap result;
|
66
|
+
for (const ServerAddress& address : addresses) {
|
67
|
+
auto* path = grpc_channel_args_find_pointer<std::vector<std::string>>(
|
68
|
+
address.args(), GRPC_ARG_HIERARCHICAL_PATH);
|
69
|
+
if (path == nullptr || path->empty()) continue;
|
70
|
+
auto it = path->begin();
|
71
|
+
ServerAddressList& target_list = result[*it];
|
72
|
+
++it;
|
73
|
+
std::vector<std::string> remaining_path(it, path->end());
|
74
|
+
const char* name_to_remove = GRPC_ARG_HIERARCHICAL_PATH;
|
75
|
+
grpc_arg new_arg = MakeHierarchicalPathArg(remaining_path);
|
76
|
+
grpc_channel_args* new_args = grpc_channel_args_copy_and_add_and_remove(
|
77
|
+
address.args(), &name_to_remove, 1, &new_arg, 1);
|
78
|
+
target_list.emplace_back(address.address(), new_args);
|
79
|
+
}
|
80
|
+
return result;
|
81
|
+
}
|
82
|
+
|
83
|
+
} // namespace grpc_core
|
@@ -0,0 +1,99 @@
|
|
1
|
+
//
|
2
|
+
// Copyright 2020 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
|
+
#ifndef GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_LB_POLICY_ADDRESS_FILTERING_H
|
18
|
+
#define GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_LB_POLICY_ADDRESS_FILTERING_H
|
19
|
+
|
20
|
+
#include <grpc/support/port_platform.h>
|
21
|
+
|
22
|
+
#include <map>
|
23
|
+
#include <string>
|
24
|
+
#include <vector>
|
25
|
+
|
26
|
+
#include "absl/strings/string_view.h"
|
27
|
+
|
28
|
+
#include "src/core/ext/filters/client_channel/server_address.h"
|
29
|
+
|
30
|
+
// The resolver returns a flat list of addresses. When a hierarchy of
|
31
|
+
// LB policies is in use, each leaf of the hierarchy will need a
|
32
|
+
// different subset of those addresses. This library provides a
|
33
|
+
// mechanism for determining which address is passed to which leaf
|
34
|
+
// policy.
|
35
|
+
//
|
36
|
+
// Each address will have an associated path that indicates which child
|
37
|
+
// it should be sent to at each level of the hierarchy to wind up at the
|
38
|
+
// right leaf policy. Each LB policy will look at the first element of
|
39
|
+
// the path of each address to determine which child to send the address
|
40
|
+
// to. It will then remove that first element when passing the address
|
41
|
+
// down to its child.
|
42
|
+
//
|
43
|
+
// For example, consider the following LB policy hierarchy:
|
44
|
+
//
|
45
|
+
// - priority
|
46
|
+
// - child0 (weighted_target)
|
47
|
+
// - localityA (round_robin)
|
48
|
+
// - localityB (round_robin)
|
49
|
+
// - child1 (weighted_target)
|
50
|
+
// - localityC (round_robin)
|
51
|
+
// - localityD (round_robin)
|
52
|
+
//
|
53
|
+
// Now consider the following addresses:
|
54
|
+
// - 10.0.0.1:80 path=["child0", "localityA"]
|
55
|
+
// - 10.0.0.2:80 path=["child0", "localityB"]
|
56
|
+
// - 10.0.0.3:80 path=["child1", "localityC"]
|
57
|
+
// - 10.0.0.4:80 path=["child1", "localityD"]
|
58
|
+
//
|
59
|
+
// The priority policy will split this up into two lists, one for each
|
60
|
+
// of its children:
|
61
|
+
// - child0:
|
62
|
+
// - 10.0.0.1:80 path=["localityA"]
|
63
|
+
// - 10.0.0.2:80 path=["localityB"]
|
64
|
+
// - child1:
|
65
|
+
// - 10.0.0.3:80 path=["localityC"]
|
66
|
+
// - 10.0.0.4:80 path=["localityD"]
|
67
|
+
//
|
68
|
+
// The weighted_target policy for child0 will split its list up into two
|
69
|
+
// lists, one for each of its children:
|
70
|
+
// - localityA:
|
71
|
+
// - 10.0.0.1:80 path=[]
|
72
|
+
// - localityB:
|
73
|
+
// - 10.0.0.2:80 path=[]
|
74
|
+
//
|
75
|
+
// Similarly, the weighted_target policy for child1 will split its list
|
76
|
+
// up into two lists, one for each of its children:
|
77
|
+
// - localityC:
|
78
|
+
// - 10.0.0.3:80 path=[]
|
79
|
+
// - localityD:
|
80
|
+
// - 10.0.0.4:80 path=[]
|
81
|
+
|
82
|
+
namespace grpc_core {
|
83
|
+
|
84
|
+
// Constructs a channel arg containing the hierarchical path
|
85
|
+
// to be associated with an address.
|
86
|
+
grpc_arg MakeHierarchicalPathArg(const std::vector<std::string>& path);
|
87
|
+
|
88
|
+
// A map from the next path element to the addresses that fall under
|
89
|
+
// that path element.
|
90
|
+
using HierarchicalAddressMap = std::map<std::string, ServerAddressList>;
|
91
|
+
|
92
|
+
// Splits up the addresses into a separate list for each child.
|
93
|
+
HierarchicalAddressMap MakeHierarchicalAddressMap(
|
94
|
+
const ServerAddressList& addresses);
|
95
|
+
|
96
|
+
} // namespace grpc_core
|
97
|
+
|
98
|
+
#endif /* GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_LB_POLICY_ADDRESS_FILTERING_H \
|
99
|
+
*/
|
@@ -49,7 +49,8 @@ class ChildPolicyHandler::Helper
|
|
49
49
|
std::unique_ptr<SubchannelPicker> picker) override {
|
50
50
|
if (parent_->shutting_down_) return;
|
51
51
|
// If this request is from the pending child policy, ignore it until
|
52
|
-
// it reports
|
52
|
+
// it reports something other than CONNECTING, at which point we swap it
|
53
|
+
// into place.
|
53
54
|
if (CalledByPendingChild()) {
|
54
55
|
if (GRPC_TRACE_FLAG_ENABLED(*(parent_->tracer_))) {
|
55
56
|
gpr_log(GPR_INFO,
|
@@ -57,7 +58,7 @@ class ChildPolicyHandler::Helper
|
|
57
58
|
"reports state=%s",
|
58
59
|
parent_.get(), this, child_, ConnectivityStateName(state));
|
59
60
|
}
|
60
|
-
if (state
|
61
|
+
if (state == GRPC_CHANNEL_CONNECTING) return;
|
61
62
|
grpc_pollset_set_del_pollset_set(
|
62
63
|
parent_->child_policy_->interested_parties(),
|
63
64
|
parent_->interested_parties());
|
@@ -86,7 +87,8 @@ class ChildPolicyHandler::Helper
|
|
86
87
|
parent_->channel_control_helper()->RequestReresolution();
|
87
88
|
}
|
88
89
|
|
89
|
-
void AddTraceEvent(TraceSeverity severity,
|
90
|
+
void AddTraceEvent(TraceSeverity severity,
|
91
|
+
absl::string_view message) override {
|
90
92
|
if (parent_->shutting_down_) return;
|
91
93
|
if (!CalledByPendingChild() && !CalledByCurrentChild()) return;
|
92
94
|
parent_->channel_control_helper()->AddTraceEvent(severity, message);
|
@@ -201,6 +203,10 @@ void ChildPolicyHandler::UpdateLocked(UpdateArgs args) {
|
|
201
203
|
// Cases 1, 2b, and 3b: create a new child policy.
|
202
204
|
// If child_policy_ is null, we set it (case 1), else we set
|
203
205
|
// pending_child_policy_ (cases 2b and 3b).
|
206
|
+
// TODO(roth): In cases 2b and 3b, we should start a timer here, so
|
207
|
+
// that there's an upper bound on the amount of time it takes us to
|
208
|
+
// switch to the new policy, even if the new policy stays in
|
209
|
+
// CONNECTING for a very long period of time.
|
204
210
|
if (GRPC_TRACE_FLAG_ENABLED(*tracer_)) {
|
205
211
|
gpr_log(GPR_INFO,
|
206
212
|
"[child_policy_handler %p] creating new %schild policy %s", this,
|
@@ -251,7 +257,7 @@ OrphanablePtr
|
|
251
257
|
const char* child_policy_name, const grpc_channel_args& args) {
|
252
258
|
Helper* helper = new Helper(Ref(DEBUG_LOCATION, "Helper"));
|
253
259
|
LoadBalancingPolicy::Args lb_policy_args;
|
254
|
-
lb_policy_args.
|
260
|
+
lb_policy_args.work_serializer = work_serializer();
|
255
261
|
lb_policy_args.channel_control_helper =
|
256
262
|
std::unique_ptr<ChannelControlHelper>(helper);
|
257
263
|
lb_policy_args.args = &args;
|
@@ -64,6 +64,10 @@
|
|
64
64
|
#include <limits.h>
|
65
65
|
#include <string.h>
|
66
66
|
|
67
|
+
#include "absl/container/inlined_vector.h"
|
68
|
+
#include "absl/strings/str_format.h"
|
69
|
+
#include "absl/strings/str_join.h"
|
70
|
+
|
67
71
|
#include <grpc/byte_buffer_reader.h>
|
68
72
|
#include <grpc/grpc.h>
|
69
73
|
#include <grpc/support/alloc.h>
|
@@ -74,6 +78,7 @@
|
|
74
78
|
#include "src/core/ext/filters/client_channel/lb_policy/child_policy_handler.h"
|
75
79
|
#include "src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.h"
|
76
80
|
#include "src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.h"
|
81
|
+
#include "src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_balancer_addresses.h"
|
77
82
|
#include "src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel.h"
|
78
83
|
#include "src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.h"
|
79
84
|
#include "src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.h"
|
@@ -90,7 +95,6 @@
|
|
90
95
|
#include "src/core/lib/gprpp/memory.h"
|
91
96
|
#include "src/core/lib/gprpp/orphanable.h"
|
92
97
|
#include "src/core/lib/gprpp/ref_counted_ptr.h"
|
93
|
-
#include "src/core/lib/iomgr/combiner.h"
|
94
98
|
#include "src/core/lib/iomgr/sockaddr.h"
|
95
99
|
#include "src/core/lib/iomgr/sockaddr_utils.h"
|
96
100
|
#include "src/core/lib/iomgr/timer.h"
|
@@ -178,11 +182,11 @@ class GrpcLb : public LoadBalancingPolicy {
|
|
178
182
|
static void OnBalancerMessageReceived(void* arg, grpc_error* error);
|
179
183
|
static void OnBalancerStatusReceived(void* arg, grpc_error* error);
|
180
184
|
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
185
|
+
void MaybeSendClientLoadReportLocked(grpc_error* error);
|
186
|
+
void ClientLoadReportDoneLocked(grpc_error* error);
|
187
|
+
void OnInitialRequestSentLocked();
|
188
|
+
void OnBalancerMessageReceivedLocked();
|
189
|
+
void OnBalancerStatusReceivedLocked(grpc_error* error);
|
186
190
|
|
187
191
|
// The owning LB policy.
|
188
192
|
RefCountedPtr<LoadBalancingPolicy> grpclb_policy_;
|
@@ -233,7 +237,7 @@ class GrpcLb : public LoadBalancingPolicy {
|
|
233
237
|
const std::vector<GrpcLbServer>& serverlist() const { return serverlist_; }
|
234
238
|
|
235
239
|
// Returns a text representation suitable for logging.
|
236
|
-
|
240
|
+
std::string AsText() const;
|
237
241
|
|
238
242
|
// Extracts all non-drop entries into a ServerAddressList.
|
239
243
|
ServerAddressList GetServerAddressList(
|
@@ -247,16 +251,16 @@ class GrpcLb : public LoadBalancingPolicy {
|
|
247
251
|
// should not be dropped.
|
248
252
|
//
|
249
253
|
// Note: This is called from the picker, so it will be invoked in
|
250
|
-
// the channel's data plane
|
251
|
-
//
|
254
|
+
// the channel's data plane mutex, NOT the control plane
|
255
|
+
// work_serializer. It should not be accessed by any other part of the LB
|
252
256
|
// policy.
|
253
257
|
const char* ShouldDrop();
|
254
258
|
|
255
259
|
private:
|
256
260
|
std::vector<GrpcLbServer> serverlist_;
|
257
261
|
|
258
|
-
// Guarded by the channel's data plane
|
259
|
-
// plane
|
262
|
+
// Guarded by the channel's data plane mutex, NOT the control
|
263
|
+
// plane work_serializer. It should not be accessed by anything but the
|
260
264
|
// picker via the ShouldDrop() method.
|
261
265
|
size_t drop_index_ = 0;
|
262
266
|
};
|
@@ -295,12 +299,44 @@ class GrpcLb : public LoadBalancingPolicy {
|
|
295
299
|
void UpdateState(grpc_connectivity_state state,
|
296
300
|
std::unique_ptr<SubchannelPicker> picker) override;
|
297
301
|
void RequestReresolution() override;
|
298
|
-
void AddTraceEvent(TraceSeverity severity,
|
302
|
+
void AddTraceEvent(TraceSeverity severity,
|
303
|
+
absl::string_view message) override;
|
299
304
|
|
300
305
|
private:
|
301
306
|
RefCountedPtr<GrpcLb> parent_;
|
302
307
|
};
|
303
308
|
|
309
|
+
class StateWatcher : public AsyncConnectivityStateWatcherInterface {
|
310
|
+
public:
|
311
|
+
explicit StateWatcher(RefCountedPtr<GrpcLb> parent)
|
312
|
+
: AsyncConnectivityStateWatcherInterface(parent->work_serializer()),
|
313
|
+
parent_(std::move(parent)) {}
|
314
|
+
|
315
|
+
~StateWatcher() { parent_.reset(DEBUG_LOCATION, "StateWatcher"); }
|
316
|
+
|
317
|
+
private:
|
318
|
+
void OnConnectivityStateChange(grpc_connectivity_state new_state) override {
|
319
|
+
if (parent_->fallback_at_startup_checks_pending_ &&
|
320
|
+
new_state == GRPC_CHANNEL_TRANSIENT_FAILURE) {
|
321
|
+
// In TRANSIENT_FAILURE. Cancel the fallback timer and go into
|
322
|
+
// fallback mode immediately.
|
323
|
+
gpr_log(GPR_INFO,
|
324
|
+
"[grpclb %p] balancer channel in state TRANSIENT_FAILURE; "
|
325
|
+
"entering fallback mode",
|
326
|
+
parent_.get());
|
327
|
+
parent_->fallback_at_startup_checks_pending_ = false;
|
328
|
+
grpc_timer_cancel(&parent_->lb_fallback_timer_);
|
329
|
+
parent_->fallback_mode_ = true;
|
330
|
+
parent_->CreateOrUpdateChildPolicyLocked();
|
331
|
+
// Cancel the watch, since we don't care about the channel state once we
|
332
|
+
// go into fallback mode.
|
333
|
+
parent_->CancelBalancerChannelConnectivityWatchLocked();
|
334
|
+
}
|
335
|
+
}
|
336
|
+
|
337
|
+
RefCountedPtr<GrpcLb> parent_;
|
338
|
+
};
|
339
|
+
|
304
340
|
~GrpcLb();
|
305
341
|
|
306
342
|
void ShutdownLocked() override;
|
@@ -308,22 +344,19 @@ class GrpcLb : public LoadBalancingPolicy {
|
|
308
344
|
// Helper functions used in UpdateLocked().
|
309
345
|
void ProcessAddressesAndChannelArgsLocked(const ServerAddressList& addresses,
|
310
346
|
const grpc_channel_args& args);
|
311
|
-
|
312
|
-
grpc_error* error);
|
313
|
-
static void OnBalancerChannelConnectivityChangedLocked(void* arg,
|
314
|
-
grpc_error* error);
|
347
|
+
|
315
348
|
void CancelBalancerChannelConnectivityWatchLocked();
|
316
349
|
|
317
350
|
// Methods for dealing with fallback state.
|
318
351
|
void MaybeEnterFallbackModeAfterStartup();
|
319
352
|
static void OnFallbackTimer(void* arg, grpc_error* error);
|
320
|
-
|
353
|
+
void OnFallbackTimerLocked(grpc_error* error);
|
321
354
|
|
322
355
|
// Methods for dealing with the balancer call.
|
323
356
|
void StartBalancerCallLocked();
|
324
357
|
void StartBalancerCallRetryTimerLocked();
|
325
358
|
static void OnBalancerCallRetryTimer(void* arg, grpc_error* error);
|
326
|
-
|
359
|
+
void OnBalancerCallRetryTimerLocked(grpc_error* error);
|
327
360
|
|
328
361
|
// Methods for dealing with the child policy.
|
329
362
|
grpc_channel_args* CreateChildPolicyArgsLocked(
|
@@ -343,6 +376,7 @@ class GrpcLb : public LoadBalancingPolicy {
|
|
343
376
|
|
344
377
|
// The channel for communicating with the LB server.
|
345
378
|
grpc_channel* lb_channel_ = nullptr;
|
379
|
+
StateWatcher* watcher_ = nullptr;
|
346
380
|
// Response generator to inject address updates into lb_channel_.
|
347
381
|
RefCountedPtr<FakeResolverResponseGenerator> response_generator_;
|
348
382
|
|
@@ -375,8 +409,6 @@ class GrpcLb : public LoadBalancingPolicy {
|
|
375
409
|
bool fallback_at_startup_checks_pending_ = false;
|
376
410
|
grpc_timer lb_fallback_timer_;
|
377
411
|
grpc_closure lb_on_fallback_;
|
378
|
-
grpc_connectivity_state lb_channel_connectivity_ = GRPC_CHANNEL_IDLE;
|
379
|
-
grpc_closure lb_channel_on_connectivity_changed_;
|
380
412
|
|
381
413
|
// The child policy to use for the backends.
|
382
414
|
OrphanablePtr<LoadBalancingPolicy> child_policy_;
|
@@ -415,28 +447,22 @@ void ParseServer(const GrpcLbServer& server, grpc_resolved_address* addr) {
|
|
415
447
|
}
|
416
448
|
}
|
417
449
|
|
418
|
-
|
419
|
-
|
420
|
-
gpr_strvec_init(&entries);
|
450
|
+
std::string GrpcLb::Serverlist::AsText() const {
|
451
|
+
std::vector<std::string> entries;
|
421
452
|
for (size_t i = 0; i < serverlist_.size(); ++i) {
|
422
453
|
const GrpcLbServer& server = serverlist_[i];
|
423
|
-
|
454
|
+
std::string ipport;
|
424
455
|
if (server.drop) {
|
425
|
-
ipport =
|
456
|
+
ipport = "(drop)";
|
426
457
|
} else {
|
427
458
|
grpc_resolved_address addr;
|
428
459
|
ParseServer(server, &addr);
|
429
|
-
grpc_sockaddr_to_string(&
|
460
|
+
ipport = grpc_sockaddr_to_string(&addr, false);
|
430
461
|
}
|
431
|
-
|
432
|
-
|
433
|
-
server.load_balance_token);
|
434
|
-
gpr_free(ipport);
|
435
|
-
gpr_strvec_add(&entries, entry);
|
462
|
+
entries.push_back(absl::StrFormat(" %" PRIuPTR ": %s token=%s\n", i,
|
463
|
+
ipport, server.load_balance_token));
|
436
464
|
}
|
437
|
-
|
438
|
-
gpr_strvec_destroy(&entries);
|
439
|
-
return result;
|
465
|
+
return absl::StrJoin(entries, "");
|
440
466
|
}
|
441
467
|
|
442
468
|
// vtables for channel args for LB token and client stats.
|
@@ -528,7 +554,7 @@ ServerAddressList GrpcLb::Serverlist::GetServerAddressList(
|
|
528
554
|
lb_token[0] = '\0';
|
529
555
|
}
|
530
556
|
// Add address.
|
531
|
-
InlinedVector<grpc_arg, 2> args_to_add;
|
557
|
+
absl::InlinedVector<grpc_arg, 2> args_to_add;
|
532
558
|
args_to_add.emplace_back(grpc_channel_arg_pointer_create(
|
533
559
|
const_cast<char*>(GRPC_ARG_GRPCLB_ADDRESS_LB_TOKEN), lb_token,
|
534
560
|
&lb_token_arg_vtable));
|
@@ -599,7 +625,7 @@ GrpcLb::PickResult GrpcLb::Picker::Pick(PickArgs args) {
|
|
599
625
|
// how to interpret it.
|
600
626
|
args.initial_metadata->Add(
|
601
627
|
kGrpcLbClientStatsMetadataKey,
|
602
|
-
|
628
|
+
absl::string_view(reinterpret_cast<const char*>(client_stats), 0));
|
603
629
|
// Update calls-started.
|
604
630
|
client_stats->AddCallStarted();
|
605
631
|
}
|
@@ -692,7 +718,8 @@ void GrpcLb::Helper::RequestReresolution() {
|
|
692
718
|
}
|
693
719
|
}
|
694
720
|
|
695
|
-
void GrpcLb::Helper::AddTraceEvent(TraceSeverity severity,
|
721
|
+
void GrpcLb::Helper::AddTraceEvent(TraceSeverity severity,
|
722
|
+
absl::string_view message) {
|
696
723
|
if (parent_->shutting_down_) return;
|
697
724
|
parent_->channel_control_helper()->AddTraceEvent(severity, message);
|
698
725
|
}
|
@@ -712,6 +739,15 @@ GrpcLb::BalancerCallState::BalancerCallState(
|
|
712
739
|
// the polling entities from client_channel.
|
713
740
|
GPR_ASSERT(grpclb_policy()->server_name_ != nullptr);
|
714
741
|
GPR_ASSERT(grpclb_policy()->server_name_[0] != '\0');
|
742
|
+
// Closure Initialization
|
743
|
+
GRPC_CLOSURE_INIT(&lb_on_initial_request_sent_, OnInitialRequestSent, this,
|
744
|
+
grpc_schedule_on_exec_ctx);
|
745
|
+
GRPC_CLOSURE_INIT(&lb_on_balancer_message_received_,
|
746
|
+
OnBalancerMessageReceived, this, grpc_schedule_on_exec_ctx);
|
747
|
+
GRPC_CLOSURE_INIT(&lb_on_balancer_status_received_, OnBalancerStatusReceived,
|
748
|
+
this, grpc_schedule_on_exec_ctx);
|
749
|
+
GRPC_CLOSURE_INIT(&client_load_report_closure_, MaybeSendClientLoadReport,
|
750
|
+
this, grpc_schedule_on_exec_ctx);
|
715
751
|
const grpc_millis deadline =
|
716
752
|
grpclb_policy()->lb_call_timeout_ms_ == 0
|
717
753
|
? GRPC_MILLIS_INF_FUTURE
|
@@ -788,8 +824,6 @@ void GrpcLb::BalancerCallState::StartQuery() {
|
|
788
824
|
// with the callback.
|
789
825
|
auto self = Ref(DEBUG_LOCATION, "on_initial_request_sent");
|
790
826
|
self.release();
|
791
|
-
GRPC_CLOSURE_INIT(&lb_on_initial_request_sent_, OnInitialRequestSent, this,
|
792
|
-
grpc_schedule_on_exec_ctx);
|
793
827
|
call_error = grpc_call_start_batch_and_execute(
|
794
828
|
lb_call_, ops, (size_t)(op - ops), &lb_on_initial_request_sent_);
|
795
829
|
GPR_ASSERT(GRPC_CALL_OK == call_error);
|
@@ -812,8 +846,6 @@ void GrpcLb::BalancerCallState::StartQuery() {
|
|
812
846
|
// with the callback.
|
813
847
|
self = Ref(DEBUG_LOCATION, "on_message_received");
|
814
848
|
self.release();
|
815
|
-
GRPC_CLOSURE_INIT(&lb_on_balancer_message_received_,
|
816
|
-
OnBalancerMessageReceived, this, grpc_schedule_on_exec_ctx);
|
817
849
|
call_error = grpc_call_start_batch_and_execute(
|
818
850
|
lb_call_, ops, (size_t)(op - ops), &lb_on_balancer_message_received_);
|
819
851
|
GPR_ASSERT(GRPC_CALL_OK == call_error);
|
@@ -830,8 +862,6 @@ void GrpcLb::BalancerCallState::StartQuery() {
|
|
830
862
|
// This callback signals the end of the LB call, so it relies on the initial
|
831
863
|
// ref instead of a new ref. When it's invoked, it's the initial ref that is
|
832
864
|
// unreffed.
|
833
|
-
GRPC_CLOSURE_INIT(&lb_on_balancer_status_received_, OnBalancerStatusReceived,
|
834
|
-
this, grpc_schedule_on_exec_ctx);
|
835
865
|
call_error = grpc_call_start_batch_and_execute(
|
836
866
|
lb_call_, ops, (size_t)(op - ops), &lb_on_balancer_status_received_);
|
837
867
|
GPR_ASSERT(GRPC_CALL_OK == call_error);
|
@@ -850,28 +880,27 @@ void GrpcLb::BalancerCallState::ScheduleNextClientLoadReportLocked() {
|
|
850
880
|
void GrpcLb::BalancerCallState::MaybeSendClientLoadReport(void* arg,
|
851
881
|
grpc_error* error) {
|
852
882
|
BalancerCallState* lb_calld = static_cast<BalancerCallState*>(arg);
|
853
|
-
|
854
|
-
|
855
|
-
|
856
|
-
|
883
|
+
GRPC_ERROR_REF(error); // ref owned by lambda
|
884
|
+
lb_calld->grpclb_policy()->work_serializer()->Run(
|
885
|
+
[lb_calld, error]() { lb_calld->MaybeSendClientLoadReportLocked(error); },
|
886
|
+
DEBUG_LOCATION);
|
857
887
|
}
|
858
888
|
|
859
889
|
void GrpcLb::BalancerCallState::MaybeSendClientLoadReportLocked(
|
860
|
-
|
861
|
-
|
862
|
-
|
863
|
-
|
864
|
-
|
865
|
-
lb_calld->Unref(DEBUG_LOCATION, "client_load_report");
|
890
|
+
grpc_error* error) {
|
891
|
+
client_load_report_timer_callback_pending_ = false;
|
892
|
+
if (error != GRPC_ERROR_NONE || this != grpclb_policy()->lb_calld_.get()) {
|
893
|
+
Unref(DEBUG_LOCATION, "client_load_report");
|
894
|
+
GRPC_ERROR_UNREF(error);
|
866
895
|
return;
|
867
896
|
}
|
868
897
|
// If we've already sent the initial request, then we can go ahead and send
|
869
898
|
// the load report. Otherwise, we need to wait until the initial request has
|
870
899
|
// been sent to send this (see OnInitialRequestSentLocked()).
|
871
|
-
if (
|
872
|
-
|
900
|
+
if (send_message_payload_ == nullptr) {
|
901
|
+
SendClientLoadReportLocked();
|
873
902
|
} else {
|
874
|
-
|
903
|
+
client_load_report_is_due_ = true;
|
875
904
|
}
|
876
905
|
}
|
877
906
|
|
@@ -930,140 +959,125 @@ void GrpcLb::BalancerCallState::SendClientLoadReportLocked() {
|
|
930
959
|
void GrpcLb::BalancerCallState::ClientLoadReportDone(void* arg,
|
931
960
|
grpc_error* error) {
|
932
961
|
BalancerCallState* lb_calld = static_cast<BalancerCallState*>(arg);
|
933
|
-
|
934
|
-
|
935
|
-
|
936
|
-
|
962
|
+
GRPC_ERROR_REF(error); // ref owned by lambda
|
963
|
+
lb_calld->grpclb_policy()->work_serializer()->Run(
|
964
|
+
[lb_calld, error]() { lb_calld->ClientLoadReportDoneLocked(error); },
|
965
|
+
DEBUG_LOCATION);
|
937
966
|
}
|
938
967
|
|
939
|
-
void GrpcLb::BalancerCallState::ClientLoadReportDoneLocked(
|
940
|
-
|
941
|
-
|
942
|
-
|
943
|
-
|
944
|
-
|
945
|
-
if (error != GRPC_ERROR_NONE || lb_calld != grpclb_policy->lb_calld_.get()) {
|
946
|
-
lb_calld->Unref(DEBUG_LOCATION, "client_load_report");
|
968
|
+
void GrpcLb::BalancerCallState::ClientLoadReportDoneLocked(grpc_error* error) {
|
969
|
+
grpc_byte_buffer_destroy(send_message_payload_);
|
970
|
+
send_message_payload_ = nullptr;
|
971
|
+
if (error != GRPC_ERROR_NONE || this != grpclb_policy()->lb_calld_.get()) {
|
972
|
+
Unref(DEBUG_LOCATION, "client_load_report");
|
973
|
+
GRPC_ERROR_UNREF(error);
|
947
974
|
return;
|
948
975
|
}
|
949
|
-
|
976
|
+
ScheduleNextClientLoadReportLocked();
|
950
977
|
}
|
951
978
|
|
952
979
|
void GrpcLb::BalancerCallState::OnInitialRequestSent(void* arg,
|
953
|
-
grpc_error* error) {
|
980
|
+
grpc_error* /*error*/) {
|
954
981
|
BalancerCallState* lb_calld = static_cast<BalancerCallState*>(arg);
|
955
|
-
lb_calld->grpclb_policy()->
|
956
|
-
|
957
|
-
OnInitialRequestSentLocked, lb_calld, nullptr),
|
958
|
-
GRPC_ERROR_REF(error));
|
982
|
+
lb_calld->grpclb_policy()->work_serializer()->Run(
|
983
|
+
[lb_calld]() { lb_calld->OnInitialRequestSentLocked(); }, DEBUG_LOCATION);
|
959
984
|
}
|
960
985
|
|
961
|
-
void GrpcLb::BalancerCallState::OnInitialRequestSentLocked(
|
962
|
-
|
963
|
-
|
964
|
-
grpc_byte_buffer_destroy(lb_calld->send_message_payload_);
|
965
|
-
lb_calld->send_message_payload_ = nullptr;
|
986
|
+
void GrpcLb::BalancerCallState::OnInitialRequestSentLocked() {
|
987
|
+
grpc_byte_buffer_destroy(send_message_payload_);
|
988
|
+
send_message_payload_ = nullptr;
|
966
989
|
// If we attempted to send a client load report before the initial request was
|
967
990
|
// sent (and this lb_calld is still in use), send the load report now.
|
968
|
-
if (
|
969
|
-
|
970
|
-
|
971
|
-
lb_calld->client_load_report_is_due_ = false;
|
991
|
+
if (client_load_report_is_due_ && this == grpclb_policy()->lb_calld_.get()) {
|
992
|
+
SendClientLoadReportLocked();
|
993
|
+
client_load_report_is_due_ = false;
|
972
994
|
}
|
973
|
-
|
995
|
+
Unref(DEBUG_LOCATION, "on_initial_request_sent");
|
974
996
|
}
|
975
997
|
|
976
|
-
void GrpcLb::BalancerCallState::OnBalancerMessageReceived(
|
977
|
-
|
998
|
+
void GrpcLb::BalancerCallState::OnBalancerMessageReceived(
|
999
|
+
void* arg, grpc_error* /*error*/) {
|
978
1000
|
BalancerCallState* lb_calld = static_cast<BalancerCallState*>(arg);
|
979
|
-
lb_calld->grpclb_policy()->
|
980
|
-
|
981
|
-
|
982
|
-
GRPC_ERROR_REF(error));
|
1001
|
+
lb_calld->grpclb_policy()->work_serializer()->Run(
|
1002
|
+
[lb_calld]() { lb_calld->OnBalancerMessageReceivedLocked(); },
|
1003
|
+
DEBUG_LOCATION);
|
983
1004
|
}
|
984
1005
|
|
985
|
-
void GrpcLb::BalancerCallState::OnBalancerMessageReceivedLocked(
|
986
|
-
void* arg, grpc_error* /*error*/) {
|
987
|
-
BalancerCallState* lb_calld = static_cast<BalancerCallState*>(arg);
|
988
|
-
GrpcLb* grpclb_policy = lb_calld->grpclb_policy();
|
1006
|
+
void GrpcLb::BalancerCallState::OnBalancerMessageReceivedLocked() {
|
989
1007
|
// Null payload means the LB call was cancelled.
|
990
|
-
if (
|
991
|
-
|
992
|
-
|
1008
|
+
if (this != grpclb_policy()->lb_calld_.get() ||
|
1009
|
+
recv_message_payload_ == nullptr) {
|
1010
|
+
Unref(DEBUG_LOCATION, "on_message_received");
|
993
1011
|
return;
|
994
1012
|
}
|
995
1013
|
grpc_byte_buffer_reader bbr;
|
996
|
-
grpc_byte_buffer_reader_init(&bbr,
|
1014
|
+
grpc_byte_buffer_reader_init(&bbr, recv_message_payload_);
|
997
1015
|
grpc_slice response_slice = grpc_byte_buffer_reader_readall(&bbr);
|
998
1016
|
grpc_byte_buffer_reader_destroy(&bbr);
|
999
|
-
grpc_byte_buffer_destroy(
|
1000
|
-
|
1017
|
+
grpc_byte_buffer_destroy(recv_message_payload_);
|
1018
|
+
recv_message_payload_ = nullptr;
|
1001
1019
|
GrpcLbResponse response;
|
1002
1020
|
upb::Arena arena;
|
1003
1021
|
if (!GrpcLbResponseParse(response_slice, arena.ptr(), &response) ||
|
1004
|
-
(response.type == response.INITIAL &&
|
1022
|
+
(response.type == response.INITIAL && seen_initial_response_)) {
|
1005
1023
|
char* response_slice_str =
|
1006
1024
|
grpc_dump_slice(response_slice, GPR_DUMP_ASCII | GPR_DUMP_HEX);
|
1007
1025
|
gpr_log(GPR_ERROR,
|
1008
1026
|
"[grpclb %p] lb_calld=%p: Invalid LB response received: '%s'. "
|
1009
1027
|
"Ignoring.",
|
1010
|
-
grpclb_policy,
|
1028
|
+
grpclb_policy(), this, response_slice_str);
|
1011
1029
|
gpr_free(response_slice_str);
|
1012
1030
|
} else {
|
1013
1031
|
switch (response.type) {
|
1014
1032
|
case response.INITIAL: {
|
1015
1033
|
if (response.client_stats_report_interval != 0) {
|
1016
|
-
|
1034
|
+
client_stats_report_interval_ =
|
1017
1035
|
GPR_MAX(GPR_MS_PER_SEC, response.client_stats_report_interval);
|
1018
1036
|
if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_glb_trace)) {
|
1019
1037
|
gpr_log(GPR_INFO,
|
1020
1038
|
"[grpclb %p] lb_calld=%p: Received initial LB response "
|
1021
1039
|
"message; client load reporting interval = %" PRId64
|
1022
1040
|
" milliseconds",
|
1023
|
-
grpclb_policy,
|
1024
|
-
lb_calld->client_stats_report_interval_);
|
1041
|
+
grpclb_policy(), this, client_stats_report_interval_);
|
1025
1042
|
}
|
1026
1043
|
} else if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_glb_trace)) {
|
1027
1044
|
gpr_log(GPR_INFO,
|
1028
1045
|
"[grpclb %p] lb_calld=%p: Received initial LB response "
|
1029
1046
|
"message; client load reporting NOT enabled",
|
1030
|
-
grpclb_policy,
|
1047
|
+
grpclb_policy(), this);
|
1031
1048
|
}
|
1032
|
-
|
1049
|
+
seen_initial_response_ = true;
|
1033
1050
|
break;
|
1034
1051
|
}
|
1035
1052
|
case response.SERVERLIST: {
|
1036
|
-
GPR_ASSERT(
|
1053
|
+
GPR_ASSERT(lb_call_ != nullptr);
|
1037
1054
|
auto serverlist_wrapper =
|
1038
1055
|
MakeRefCounted<Serverlist>(std::move(response.serverlist));
|
1039
1056
|
if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_glb_trace)) {
|
1040
|
-
grpc_core::UniquePtr<char> serverlist_text =
|
1041
|
-
serverlist_wrapper->AsText();
|
1042
1057
|
gpr_log(GPR_INFO,
|
1043
1058
|
"[grpclb %p] lb_calld=%p: Serverlist with %" PRIuPTR
|
1044
1059
|
" servers received:\n%s",
|
1045
|
-
grpclb_policy,
|
1060
|
+
grpclb_policy(), this,
|
1046
1061
|
serverlist_wrapper->serverlist().size(),
|
1047
|
-
|
1062
|
+
serverlist_wrapper->AsText().c_str());
|
1048
1063
|
}
|
1049
|
-
|
1064
|
+
seen_serverlist_ = true;
|
1050
1065
|
// Start sending client load report only after we start using the
|
1051
1066
|
// serverlist returned from the current LB call.
|
1052
|
-
if (
|
1053
|
-
|
1054
|
-
lb_calld->client_stats_ = MakeRefCounted<GrpcLbClientStats>();
|
1067
|
+
if (client_stats_report_interval_ > 0 && client_stats_ == nullptr) {
|
1068
|
+
client_stats_ = MakeRefCounted<GrpcLbClientStats>();
|
1055
1069
|
// Ref held by callback.
|
1056
|
-
|
1057
|
-
|
1070
|
+
Ref(DEBUG_LOCATION, "client_load_report").release();
|
1071
|
+
ScheduleNextClientLoadReportLocked();
|
1058
1072
|
}
|
1059
1073
|
// Check if the serverlist differs from the previous one.
|
1060
|
-
if (grpclb_policy->serverlist_ != nullptr &&
|
1061
|
-
*grpclb_policy->serverlist_ == *serverlist_wrapper) {
|
1074
|
+
if (grpclb_policy()->serverlist_ != nullptr &&
|
1075
|
+
*grpclb_policy()->serverlist_ == *serverlist_wrapper) {
|
1062
1076
|
if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_glb_trace)) {
|
1063
1077
|
gpr_log(GPR_INFO,
|
1064
1078
|
"[grpclb %p] lb_calld=%p: Incoming server list identical "
|
1065
1079
|
"to current, ignoring.",
|
1066
|
-
grpclb_policy,
|
1080
|
+
grpclb_policy(), this);
|
1067
1081
|
}
|
1068
1082
|
} else { // New serverlist.
|
1069
1083
|
// Dispose of the fallback.
|
@@ -1085,155 +1099,135 @@ void GrpcLb::BalancerCallState::OnBalancerMessageReceivedLocked(
|
|
1085
1099
|
// the grpclb implementation at this point, since we're deprecating
|
1086
1100
|
// it in favor of the xds policy. We will implement this the
|
1087
1101
|
// right way in the xds policy instead.
|
1088
|
-
if (grpclb_policy->fallback_mode_) {
|
1102
|
+
if (grpclb_policy()->fallback_mode_) {
|
1089
1103
|
gpr_log(GPR_INFO,
|
1090
1104
|
"[grpclb %p] Received response from balancer; exiting "
|
1091
1105
|
"fallback mode",
|
1092
|
-
grpclb_policy);
|
1093
|
-
grpclb_policy->fallback_mode_ = false;
|
1106
|
+
grpclb_policy());
|
1107
|
+
grpclb_policy()->fallback_mode_ = false;
|
1094
1108
|
}
|
1095
|
-
if (grpclb_policy->fallback_at_startup_checks_pending_) {
|
1096
|
-
grpclb_policy->fallback_at_startup_checks_pending_ = false;
|
1097
|
-
grpc_timer_cancel(&grpclb_policy->lb_fallback_timer_);
|
1098
|
-
grpclb_policy->CancelBalancerChannelConnectivityWatchLocked();
|
1109
|
+
if (grpclb_policy()->fallback_at_startup_checks_pending_) {
|
1110
|
+
grpclb_policy()->fallback_at_startup_checks_pending_ = false;
|
1111
|
+
grpc_timer_cancel(&grpclb_policy()->lb_fallback_timer_);
|
1112
|
+
grpclb_policy()->CancelBalancerChannelConnectivityWatchLocked();
|
1099
1113
|
}
|
1100
1114
|
// Update the serverlist in the GrpcLb instance. This serverlist
|
1101
1115
|
// instance will be destroyed either upon the next update or when the
|
1102
1116
|
// GrpcLb instance is destroyed.
|
1103
|
-
grpclb_policy->serverlist_ = std::move(serverlist_wrapper);
|
1104
|
-
grpclb_policy->CreateOrUpdateChildPolicyLocked();
|
1117
|
+
grpclb_policy()->serverlist_ = std::move(serverlist_wrapper);
|
1118
|
+
grpclb_policy()->CreateOrUpdateChildPolicyLocked();
|
1105
1119
|
}
|
1106
1120
|
break;
|
1107
1121
|
}
|
1108
1122
|
case response.FALLBACK: {
|
1109
|
-
if (!grpclb_policy->fallback_mode_) {
|
1123
|
+
if (!grpclb_policy()->fallback_mode_) {
|
1110
1124
|
gpr_log(GPR_INFO,
|
1111
1125
|
"[grpclb %p] Entering fallback mode as requested by balancer",
|
1112
|
-
grpclb_policy);
|
1113
|
-
if (grpclb_policy->fallback_at_startup_checks_pending_) {
|
1114
|
-
grpclb_policy->fallback_at_startup_checks_pending_ = false;
|
1115
|
-
grpc_timer_cancel(&grpclb_policy->lb_fallback_timer_);
|
1116
|
-
grpclb_policy->CancelBalancerChannelConnectivityWatchLocked();
|
1126
|
+
grpclb_policy());
|
1127
|
+
if (grpclb_policy()->fallback_at_startup_checks_pending_) {
|
1128
|
+
grpclb_policy()->fallback_at_startup_checks_pending_ = false;
|
1129
|
+
grpc_timer_cancel(&grpclb_policy()->lb_fallback_timer_);
|
1130
|
+
grpclb_policy()->CancelBalancerChannelConnectivityWatchLocked();
|
1117
1131
|
}
|
1118
|
-
grpclb_policy->fallback_mode_ = true;
|
1119
|
-
grpclb_policy->CreateOrUpdateChildPolicyLocked();
|
1132
|
+
grpclb_policy()->fallback_mode_ = true;
|
1133
|
+
grpclb_policy()->CreateOrUpdateChildPolicyLocked();
|
1120
1134
|
// Reset serverlist, so that if the balancer exits fallback
|
1121
1135
|
// mode by sending the same serverlist we were previously
|
1122
1136
|
// using, we don't incorrectly ignore it as a duplicate.
|
1123
|
-
grpclb_policy->serverlist_.reset();
|
1137
|
+
grpclb_policy()->serverlist_.reset();
|
1124
1138
|
}
|
1125
1139
|
break;
|
1126
1140
|
}
|
1127
1141
|
}
|
1128
1142
|
}
|
1129
1143
|
grpc_slice_unref_internal(response_slice);
|
1130
|
-
if (!grpclb_policy->shutting_down_) {
|
1144
|
+
if (!grpclb_policy()->shutting_down_) {
|
1131
1145
|
// Keep listening for serverlist updates.
|
1132
1146
|
grpc_op op;
|
1133
1147
|
memset(&op, 0, sizeof(op));
|
1134
1148
|
op.op = GRPC_OP_RECV_MESSAGE;
|
1135
|
-
op.data.recv_message.recv_message = &
|
1149
|
+
op.data.recv_message.recv_message = &recv_message_payload_;
|
1136
1150
|
op.flags = 0;
|
1137
1151
|
op.reserved = nullptr;
|
1138
1152
|
// Reuse the "OnBalancerMessageReceivedLocked" ref taken in StartQuery().
|
1139
|
-
GRPC_CLOSURE_INIT(&lb_calld->lb_on_balancer_message_received_,
|
1140
|
-
GrpcLb::BalancerCallState::OnBalancerMessageReceived,
|
1141
|
-
lb_calld, grpc_schedule_on_exec_ctx);
|
1142
1153
|
const grpc_call_error call_error = grpc_call_start_batch_and_execute(
|
1143
|
-
|
1144
|
-
&lb_calld->lb_on_balancer_message_received_);
|
1154
|
+
lb_call_, &op, 1, &lb_on_balancer_message_received_);
|
1145
1155
|
GPR_ASSERT(GRPC_CALL_OK == call_error);
|
1146
1156
|
} else {
|
1147
|
-
|
1157
|
+
Unref(DEBUG_LOCATION, "on_message_received+grpclb_shutdown");
|
1148
1158
|
}
|
1149
1159
|
}
|
1150
1160
|
|
1151
1161
|
void GrpcLb::BalancerCallState::OnBalancerStatusReceived(void* arg,
|
1152
1162
|
grpc_error* error) {
|
1153
1163
|
BalancerCallState* lb_calld = static_cast<BalancerCallState*>(arg);
|
1154
|
-
|
1155
|
-
|
1156
|
-
|
1157
|
-
|
1164
|
+
GRPC_ERROR_REF(error); // owned by lambda
|
1165
|
+
lb_calld->grpclb_policy()->work_serializer()->Run(
|
1166
|
+
[lb_calld, error]() { lb_calld->OnBalancerStatusReceivedLocked(error); },
|
1167
|
+
DEBUG_LOCATION);
|
1158
1168
|
}
|
1159
1169
|
|
1160
1170
|
void GrpcLb::BalancerCallState::OnBalancerStatusReceivedLocked(
|
1161
|
-
|
1162
|
-
|
1163
|
-
GrpcLb* grpclb_policy = lb_calld->grpclb_policy();
|
1164
|
-
GPR_ASSERT(lb_calld->lb_call_ != nullptr);
|
1171
|
+
grpc_error* error) {
|
1172
|
+
GPR_ASSERT(lb_call_ != nullptr);
|
1165
1173
|
if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_glb_trace)) {
|
1166
|
-
char* status_details =
|
1167
|
-
grpc_slice_to_c_string(lb_calld->lb_call_status_details_);
|
1174
|
+
char* status_details = grpc_slice_to_c_string(lb_call_status_details_);
|
1168
1175
|
gpr_log(GPR_INFO,
|
1169
1176
|
"[grpclb %p] lb_calld=%p: Status from LB server received. "
|
1170
1177
|
"Status = %d, details = '%s', (lb_call: %p), error '%s'",
|
1171
|
-
grpclb_policy,
|
1172
|
-
|
1178
|
+
grpclb_policy(), this, lb_call_status_, status_details, lb_call_,
|
1179
|
+
grpc_error_string(error));
|
1173
1180
|
gpr_free(status_details);
|
1174
1181
|
}
|
1182
|
+
GRPC_ERROR_UNREF(error);
|
1175
1183
|
// If this lb_calld is still in use, this call ended because of a failure so
|
1176
1184
|
// we want to retry connecting. Otherwise, we have deliberately ended this
|
1177
1185
|
// call and no further action is required.
|
1178
|
-
if (
|
1186
|
+
if (this == grpclb_policy()->lb_calld_.get()) {
|
1179
1187
|
// If the fallback-at-startup checks are pending, go into fallback mode
|
1180
1188
|
// immediately. This short-circuits the timeout for the fallback-at-startup
|
1181
1189
|
// case.
|
1182
|
-
if (grpclb_policy->fallback_at_startup_checks_pending_) {
|
1183
|
-
GPR_ASSERT(!
|
1190
|
+
if (grpclb_policy()->fallback_at_startup_checks_pending_) {
|
1191
|
+
GPR_ASSERT(!seen_serverlist_);
|
1184
1192
|
gpr_log(GPR_INFO,
|
1185
1193
|
"[grpclb %p] Balancer call finished without receiving "
|
1186
1194
|
"serverlist; entering fallback mode",
|
1187
|
-
grpclb_policy);
|
1188
|
-
grpclb_policy->fallback_at_startup_checks_pending_ = false;
|
1189
|
-
grpc_timer_cancel(&grpclb_policy->lb_fallback_timer_);
|
1190
|
-
grpclb_policy->CancelBalancerChannelConnectivityWatchLocked();
|
1191
|
-
grpclb_policy->fallback_mode_ = true;
|
1192
|
-
grpclb_policy->CreateOrUpdateChildPolicyLocked();
|
1195
|
+
grpclb_policy());
|
1196
|
+
grpclb_policy()->fallback_at_startup_checks_pending_ = false;
|
1197
|
+
grpc_timer_cancel(&grpclb_policy()->lb_fallback_timer_);
|
1198
|
+
grpclb_policy()->CancelBalancerChannelConnectivityWatchLocked();
|
1199
|
+
grpclb_policy()->fallback_mode_ = true;
|
1200
|
+
grpclb_policy()->CreateOrUpdateChildPolicyLocked();
|
1193
1201
|
} else {
|
1194
1202
|
// This handles the fallback-after-startup case.
|
1195
|
-
grpclb_policy->MaybeEnterFallbackModeAfterStartup();
|
1203
|
+
grpclb_policy()->MaybeEnterFallbackModeAfterStartup();
|
1196
1204
|
}
|
1197
|
-
grpclb_policy->lb_calld_.reset();
|
1198
|
-
GPR_ASSERT(!grpclb_policy->shutting_down_);
|
1199
|
-
grpclb_policy->channel_control_helper()->RequestReresolution();
|
1200
|
-
if (
|
1205
|
+
grpclb_policy()->lb_calld_.reset();
|
1206
|
+
GPR_ASSERT(!grpclb_policy()->shutting_down_);
|
1207
|
+
grpclb_policy()->channel_control_helper()->RequestReresolution();
|
1208
|
+
if (seen_initial_response_) {
|
1201
1209
|
// If we lose connection to the LB server, reset the backoff and restart
|
1202
1210
|
// the LB call immediately.
|
1203
|
-
grpclb_policy->lb_call_backoff_.Reset();
|
1204
|
-
grpclb_policy->StartBalancerCallLocked();
|
1211
|
+
grpclb_policy()->lb_call_backoff_.Reset();
|
1212
|
+
grpclb_policy()->StartBalancerCallLocked();
|
1205
1213
|
} else {
|
1206
1214
|
// If this LB call fails establishing any connection to the LB server,
|
1207
1215
|
// retry later.
|
1208
|
-
grpclb_policy->StartBalancerCallRetryTimerLocked();
|
1216
|
+
grpclb_policy()->StartBalancerCallRetryTimerLocked();
|
1209
1217
|
}
|
1210
1218
|
}
|
1211
|
-
|
1219
|
+
Unref(DEBUG_LOCATION, "lb_call_ended");
|
1212
1220
|
}
|
1213
1221
|
|
1214
1222
|
//
|
1215
1223
|
// helper code for creating balancer channel
|
1216
1224
|
//
|
1217
1225
|
|
1218
|
-
ServerAddressList ExtractBalancerAddresses(const
|
1219
|
-
ServerAddressList
|
1220
|
-
|
1221
|
-
|
1222
|
-
|
1223
|
-
// recursively use the grpclb policy in the channel used to talk to
|
1224
|
-
// the balancers. Note that we do NOT strip out the balancer_name
|
1225
|
-
// channel arg, since we need that to set the authority correctly
|
1226
|
-
// to talk to the balancers.
|
1227
|
-
static const char* args_to_remove[] = {
|
1228
|
-
GRPC_ARG_ADDRESS_IS_BALANCER,
|
1229
|
-
};
|
1230
|
-
balancer_addresses.emplace_back(
|
1231
|
-
addresses[i].address(),
|
1232
|
-
grpc_channel_args_copy_and_remove(addresses[i].args(), args_to_remove,
|
1233
|
-
GPR_ARRAY_SIZE(args_to_remove)));
|
1234
|
-
}
|
1235
|
-
}
|
1236
|
-
return balancer_addresses;
|
1226
|
+
ServerAddressList ExtractBalancerAddresses(const grpc_channel_args& args) {
|
1227
|
+
const ServerAddressList* addresses =
|
1228
|
+
FindGrpclbBalancerAddressesInChannelArgs(args);
|
1229
|
+
if (addresses != nullptr) return *addresses;
|
1230
|
+
return ServerAddressList();
|
1237
1231
|
}
|
1238
1232
|
|
1239
1233
|
/* Returns the channel args for the LB channel, used to create a bidirectional
|
@@ -1277,7 +1271,7 @@ grpc_channel_args* BuildBalancerChannelArgs(
|
|
1277
1271
|
GRPC_ARG_CHANNELZ_CHANNEL_NODE,
|
1278
1272
|
};
|
1279
1273
|
// Channel args to add.
|
1280
|
-
InlinedVector<grpc_arg, 3> args_to_add;
|
1274
|
+
absl::InlinedVector<grpc_arg, 3> args_to_add;
|
1281
1275
|
// The fake resolver response generator, which we use to inject
|
1282
1276
|
// address updates into the LB channel.
|
1283
1277
|
args_to_add.emplace_back(
|
@@ -1319,6 +1313,11 @@ GrpcLb::GrpcLb(Args args)
|
|
1319
1313
|
.set_jitter(GRPC_GRPCLB_RECONNECT_JITTER)
|
1320
1314
|
.set_max_backoff(GRPC_GRPCLB_RECONNECT_MAX_BACKOFF_SECONDS *
|
1321
1315
|
1000)) {
|
1316
|
+
// Closure Initialization
|
1317
|
+
GRPC_CLOSURE_INIT(&lb_on_fallback_, &GrpcLb::OnFallbackTimer, this,
|
1318
|
+
grpc_schedule_on_exec_ctx);
|
1319
|
+
GRPC_CLOSURE_INIT(&lb_on_call_retry_, &GrpcLb::OnBalancerCallRetryTimer, this,
|
1320
|
+
grpc_schedule_on_exec_ctx);
|
1322
1321
|
// Record server name.
|
1323
1322
|
const grpc_arg* arg = grpc_channel_args_find(args.args, GRPC_ARG_SERVER_URI);
|
1324
1323
|
const char* server_uri = grpc_channel_arg_get_string(arg);
|
@@ -1353,6 +1352,7 @@ void GrpcLb::ShutdownLocked() {
|
|
1353
1352
|
grpc_timer_cancel(&lb_call_retry_timer_);
|
1354
1353
|
}
|
1355
1354
|
if (fallback_at_startup_checks_pending_) {
|
1355
|
+
fallback_at_startup_checks_pending_ = false;
|
1356
1356
|
grpc_timer_cancel(&lb_fallback_timer_);
|
1357
1357
|
CancelBalancerChannelConnectivityWatchLocked();
|
1358
1358
|
}
|
@@ -1402,8 +1402,6 @@ void GrpcLb::UpdateLocked(UpdateArgs args) {
|
|
1402
1402
|
// Start timer.
|
1403
1403
|
grpc_millis deadline = ExecCtx::Get()->Now() + fallback_at_startup_timeout_;
|
1404
1404
|
Ref(DEBUG_LOCATION, "on_fallback_timer").release(); // Ref for callback
|
1405
|
-
GRPC_CLOSURE_INIT(&lb_on_fallback_, &GrpcLb::OnFallbackTimer, this,
|
1406
|
-
grpc_schedule_on_exec_ctx);
|
1407
1405
|
grpc_timer_init(&lb_fallback_timer_, deadline, &lb_on_fallback_);
|
1408
1406
|
// Start watching the channel's connectivity state. If the channel
|
1409
1407
|
// goes into state TRANSIENT_FAILURE before the timer fires, we go into
|
@@ -1412,15 +1410,10 @@ void GrpcLb::UpdateLocked(UpdateArgs args) {
|
|
1412
1410
|
grpc_channel_get_channel_stack(lb_channel_));
|
1413
1411
|
GPR_ASSERT(client_channel_elem->filter == &grpc_client_channel_filter);
|
1414
1412
|
// Ref held by callback.
|
1415
|
-
Ref(DEBUG_LOCATION, "
|
1416
|
-
|
1417
|
-
|
1418
|
-
|
1419
|
-
grpc_client_channel_watch_connectivity_state(
|
1420
|
-
client_channel_elem,
|
1421
|
-
grpc_polling_entity_create_from_pollset_set(interested_parties()),
|
1422
|
-
&lb_channel_connectivity_, &lb_channel_on_connectivity_changed_,
|
1423
|
-
nullptr);
|
1413
|
+
watcher_ = new StateWatcher(Ref(DEBUG_LOCATION, "StateWatcher"));
|
1414
|
+
grpc_client_channel_start_connectivity_watch(
|
1415
|
+
client_channel_elem, GRPC_CHANNEL_IDLE,
|
1416
|
+
OrphanablePtr<AsyncConnectivityStateWatcherInterface>(watcher_));
|
1424
1417
|
// Start balancer call.
|
1425
1418
|
StartBalancerCallLocked();
|
1426
1419
|
}
|
@@ -1430,27 +1423,25 @@ void GrpcLb::UpdateLocked(UpdateArgs args) {
|
|
1430
1423
|
// helpers for UpdateLocked()
|
1431
1424
|
//
|
1432
1425
|
|
1433
|
-
|
1434
|
-
|
1426
|
+
ServerAddressList AddNullLbTokenToAddresses(
|
1427
|
+
const ServerAddressList& addresses) {
|
1435
1428
|
static const char* lb_token = "";
|
1436
1429
|
grpc_arg arg = grpc_channel_arg_pointer_create(
|
1437
1430
|
const_cast<char*>(GRPC_ARG_GRPCLB_ADDRESS_LB_TOKEN),
|
1438
1431
|
const_cast<char*>(lb_token), &lb_token_arg_vtable);
|
1439
|
-
ServerAddressList
|
1432
|
+
ServerAddressList addresses_out;
|
1440
1433
|
for (size_t i = 0; i < addresses.size(); ++i) {
|
1441
|
-
|
1442
|
-
|
1443
|
-
|
1444
|
-
grpc_channel_args_copy_and_add(addresses[i].args(), &arg, 1));
|
1445
|
-
}
|
1434
|
+
addresses_out.emplace_back(
|
1435
|
+
addresses[i].address(),
|
1436
|
+
grpc_channel_args_copy_and_add(addresses[i].args(), &arg, 1));
|
1446
1437
|
}
|
1447
|
-
return
|
1438
|
+
return addresses_out;
|
1448
1439
|
}
|
1449
1440
|
|
1450
1441
|
void GrpcLb::ProcessAddressesAndChannelArgsLocked(
|
1451
1442
|
const ServerAddressList& addresses, const grpc_channel_args& args) {
|
1452
1443
|
// Update fallback address list.
|
1453
|
-
fallback_backend_addresses_ =
|
1444
|
+
fallback_backend_addresses_ = AddNullLbTokenToAddresses(addresses);
|
1454
1445
|
// Make sure that GRPC_ARG_LB_POLICY_NAME is set in channel args,
|
1455
1446
|
// since we use this to trigger the client_load_reporting filter.
|
1456
1447
|
static const char* args_to_remove[] = {GRPC_ARG_LB_POLICY_NAME};
|
@@ -1460,7 +1451,7 @@ void GrpcLb::ProcessAddressesAndChannelArgsLocked(
|
|
1460
1451
|
args_ = grpc_channel_args_copy_and_add_and_remove(
|
1461
1452
|
&args, args_to_remove, GPR_ARRAY_SIZE(args_to_remove), &new_arg, 1);
|
1462
1453
|
// Construct args for balancer channel.
|
1463
|
-
ServerAddressList balancer_addresses = ExtractBalancerAddresses(
|
1454
|
+
ServerAddressList balancer_addresses = ExtractBalancerAddresses(args);
|
1464
1455
|
grpc_channel_args* lb_channel_args = BuildBalancerChannelArgs(
|
1465
1456
|
balancer_addresses, response_generator_.get(), &args);
|
1466
1457
|
// Create balancer channel if needed.
|
@@ -1479,60 +1470,11 @@ void GrpcLb::ProcessAddressesAndChannelArgsLocked(
|
|
1479
1470
|
response_generator_->SetResponse(std::move(result));
|
1480
1471
|
}
|
1481
1472
|
|
1482
|
-
void GrpcLb::OnBalancerChannelConnectivityChanged(void* arg,
|
1483
|
-
grpc_error* error) {
|
1484
|
-
GrpcLb* self = static_cast<GrpcLb*>(arg);
|
1485
|
-
self->combiner()->Run(
|
1486
|
-
GRPC_CLOSURE_INIT(&self->lb_channel_on_connectivity_changed_,
|
1487
|
-
&GrpcLb::OnBalancerChannelConnectivityChangedLocked,
|
1488
|
-
self, nullptr),
|
1489
|
-
GRPC_ERROR_REF(error));
|
1490
|
-
}
|
1491
|
-
|
1492
|
-
void GrpcLb::OnBalancerChannelConnectivityChangedLocked(void* arg,
|
1493
|
-
grpc_error* /*error*/) {
|
1494
|
-
GrpcLb* self = static_cast<GrpcLb*>(arg);
|
1495
|
-
if (!self->shutting_down_ && self->fallback_at_startup_checks_pending_) {
|
1496
|
-
if (self->lb_channel_connectivity_ != GRPC_CHANNEL_TRANSIENT_FAILURE) {
|
1497
|
-
// Not in TRANSIENT_FAILURE. Renew connectivity watch.
|
1498
|
-
grpc_channel_element* client_channel_elem =
|
1499
|
-
grpc_channel_stack_last_element(
|
1500
|
-
grpc_channel_get_channel_stack(self->lb_channel_));
|
1501
|
-
GPR_ASSERT(client_channel_elem->filter == &grpc_client_channel_filter);
|
1502
|
-
GRPC_CLOSURE_INIT(&self->lb_channel_on_connectivity_changed_,
|
1503
|
-
&GrpcLb::OnBalancerChannelConnectivityChanged, self,
|
1504
|
-
grpc_schedule_on_exec_ctx);
|
1505
|
-
grpc_client_channel_watch_connectivity_state(
|
1506
|
-
client_channel_elem,
|
1507
|
-
grpc_polling_entity_create_from_pollset_set(
|
1508
|
-
self->interested_parties()),
|
1509
|
-
&self->lb_channel_connectivity_,
|
1510
|
-
&self->lb_channel_on_connectivity_changed_, nullptr);
|
1511
|
-
return; // Early out so we don't drop the ref below.
|
1512
|
-
}
|
1513
|
-
// In TRANSIENT_FAILURE. Cancel the fallback timer and go into
|
1514
|
-
// fallback mode immediately.
|
1515
|
-
gpr_log(GPR_INFO,
|
1516
|
-
"[grpclb %p] balancer channel in state TRANSIENT_FAILURE; "
|
1517
|
-
"entering fallback mode",
|
1518
|
-
self);
|
1519
|
-
self->fallback_at_startup_checks_pending_ = false;
|
1520
|
-
grpc_timer_cancel(&self->lb_fallback_timer_);
|
1521
|
-
self->fallback_mode_ = true;
|
1522
|
-
self->CreateOrUpdateChildPolicyLocked();
|
1523
|
-
}
|
1524
|
-
// Done watching connectivity state, so drop ref.
|
1525
|
-
self->Unref(DEBUG_LOCATION, "watch_lb_channel_connectivity");
|
1526
|
-
}
|
1527
|
-
|
1528
1473
|
void GrpcLb::CancelBalancerChannelConnectivityWatchLocked() {
|
1529
1474
|
grpc_channel_element* client_channel_elem = grpc_channel_stack_last_element(
|
1530
1475
|
grpc_channel_get_channel_stack(lb_channel_));
|
1531
1476
|
GPR_ASSERT(client_channel_elem->filter == &grpc_client_channel_filter);
|
1532
|
-
|
1533
|
-
client_channel_elem,
|
1534
|
-
grpc_polling_entity_create_from_pollset_set(interested_parties()),
|
1535
|
-
nullptr, &lb_channel_on_connectivity_changed_, nullptr);
|
1477
|
+
grpc_client_channel_stop_connectivity_watch(client_channel_elem, watcher_);
|
1536
1478
|
}
|
1537
1479
|
|
1538
1480
|
//
|
@@ -1571,33 +1513,30 @@ void GrpcLb::StartBalancerCallRetryTimerLocked() {
|
|
1571
1513
|
// with the callback.
|
1572
1514
|
auto self = Ref(DEBUG_LOCATION, "on_balancer_call_retry_timer");
|
1573
1515
|
self.release();
|
1574
|
-
GRPC_CLOSURE_INIT(&lb_on_call_retry_, &GrpcLb::OnBalancerCallRetryTimer, this,
|
1575
|
-
grpc_schedule_on_exec_ctx);
|
1576
1516
|
retry_timer_callback_pending_ = true;
|
1577
1517
|
grpc_timer_init(&lb_call_retry_timer_, next_try, &lb_on_call_retry_);
|
1578
1518
|
}
|
1579
1519
|
|
1580
1520
|
void GrpcLb::OnBalancerCallRetryTimer(void* arg, grpc_error* error) {
|
1581
1521
|
GrpcLb* grpclb_policy = static_cast<GrpcLb*>(arg);
|
1582
|
-
|
1583
|
-
|
1584
|
-
|
1585
|
-
|
1586
|
-
|
1522
|
+
GRPC_ERROR_REF(error); // ref owned by lambda
|
1523
|
+
grpclb_policy->work_serializer()->Run(
|
1524
|
+
[grpclb_policy, error]() {
|
1525
|
+
grpclb_policy->OnBalancerCallRetryTimerLocked(error);
|
1526
|
+
},
|
1527
|
+
DEBUG_LOCATION);
|
1587
1528
|
}
|
1588
1529
|
|
1589
|
-
void GrpcLb::OnBalancerCallRetryTimerLocked(
|
1590
|
-
|
1591
|
-
|
1592
|
-
if (!grpclb_policy->shutting_down_ && error == GRPC_ERROR_NONE &&
|
1593
|
-
grpclb_policy->lb_calld_ == nullptr) {
|
1530
|
+
void GrpcLb::OnBalancerCallRetryTimerLocked(grpc_error* error) {
|
1531
|
+
retry_timer_callback_pending_ = false;
|
1532
|
+
if (!shutting_down_ && error == GRPC_ERROR_NONE && lb_calld_ == nullptr) {
|
1594
1533
|
if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_glb_trace)) {
|
1595
|
-
gpr_log(GPR_INFO, "[grpclb %p] Restarting call to LB server",
|
1596
|
-
grpclb_policy);
|
1534
|
+
gpr_log(GPR_INFO, "[grpclb %p] Restarting call to LB server", this);
|
1597
1535
|
}
|
1598
|
-
|
1536
|
+
StartBalancerCallLocked();
|
1599
1537
|
}
|
1600
|
-
|
1538
|
+
Unref(DEBUG_LOCATION, "on_balancer_call_retry_timer");
|
1539
|
+
GRPC_ERROR_UNREF(error);
|
1601
1540
|
}
|
1602
1541
|
|
1603
1542
|
//
|
@@ -1624,28 +1563,28 @@ void GrpcLb::MaybeEnterFallbackModeAfterStartup() {
|
|
1624
1563
|
|
1625
1564
|
void GrpcLb::OnFallbackTimer(void* arg, grpc_error* error) {
|
1626
1565
|
GrpcLb* grpclb_policy = static_cast<GrpcLb*>(arg);
|
1627
|
-
|
1628
|
-
|
1629
|
-
|
1630
|
-
|
1566
|
+
GRPC_ERROR_REF(error); // ref owned by lambda
|
1567
|
+
grpclb_policy->work_serializer()->Run(
|
1568
|
+
[grpclb_policy, error]() { grpclb_policy->OnFallbackTimerLocked(error); },
|
1569
|
+
DEBUG_LOCATION);
|
1631
1570
|
}
|
1632
1571
|
|
1633
|
-
void GrpcLb::OnFallbackTimerLocked(
|
1634
|
-
GrpcLb* grpclb_policy = static_cast<GrpcLb*>(arg);
|
1572
|
+
void GrpcLb::OnFallbackTimerLocked(grpc_error* error) {
|
1635
1573
|
// If we receive a serverlist after the timer fires but before this callback
|
1636
1574
|
// actually runs, don't fall back.
|
1637
|
-
if (
|
1638
|
-
|
1575
|
+
if (fallback_at_startup_checks_pending_ && !shutting_down_ &&
|
1576
|
+
error == GRPC_ERROR_NONE) {
|
1639
1577
|
gpr_log(GPR_INFO,
|
1640
1578
|
"[grpclb %p] No response from balancer after fallback timeout; "
|
1641
1579
|
"entering fallback mode",
|
1642
|
-
|
1643
|
-
|
1644
|
-
|
1645
|
-
|
1646
|
-
|
1580
|
+
this);
|
1581
|
+
fallback_at_startup_checks_pending_ = false;
|
1582
|
+
CancelBalancerChannelConnectivityWatchLocked();
|
1583
|
+
fallback_mode_ = true;
|
1584
|
+
CreateOrUpdateChildPolicyLocked();
|
1647
1585
|
}
|
1648
|
-
|
1586
|
+
Unref(DEBUG_LOCATION, "on_fallback_timer");
|
1587
|
+
GRPC_ERROR_UNREF(error);
|
1649
1588
|
}
|
1650
1589
|
|
1651
1590
|
//
|
@@ -1654,7 +1593,7 @@ void GrpcLb::OnFallbackTimerLocked(void* arg, grpc_error* error) {
|
|
1654
1593
|
|
1655
1594
|
grpc_channel_args* GrpcLb::CreateChildPolicyArgsLocked(
|
1656
1595
|
bool is_backend_from_grpclb_load_balancer) {
|
1657
|
-
InlinedVector<grpc_arg, 2> args_to_add;
|
1596
|
+
absl::InlinedVector<grpc_arg, 2> args_to_add;
|
1658
1597
|
args_to_add.emplace_back(grpc_channel_arg_integer_create(
|
1659
1598
|
const_cast<char*>(GRPC_ARG_ADDRESS_IS_BACKEND_FROM_GRPCLB_LOAD_BALANCER),
|
1660
1599
|
is_backend_from_grpclb_load_balancer));
|
@@ -1669,7 +1608,7 @@ grpc_channel_args* GrpcLb::CreateChildPolicyArgsLocked(
|
|
1669
1608
|
OrphanablePtr<LoadBalancingPolicy> GrpcLb::CreateChildPolicyLocked(
|
1670
1609
|
const grpc_channel_args* args) {
|
1671
1610
|
LoadBalancingPolicy::Args lb_policy_args;
|
1672
|
-
lb_policy_args.
|
1611
|
+
lb_policy_args.work_serializer = work_serializer();
|
1673
1612
|
lb_policy_args.args = args;
|
1674
1613
|
lb_policy_args.channel_control_helper = absl::make_unique<Helper>(Ref());
|
1675
1614
|
OrphanablePtr<LoadBalancingPolicy> lb_policy =
|