From 5e9848e7b078ac35c0b6899d27c780e3836b3905 Mon Sep 17 00:00:00 2001 From: "Mark D. Roth" Date: Fri, 6 Oct 2017 13:59:32 -0700 Subject: Refactor subchannel_list code out of RR and use it in PF. --- tools/doxygen/Doxyfile.core.internal | 2 ++ tools/run_tests/generated/sources_and_headers.json | 25 ++++++++++++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) (limited to 'tools') diff --git a/tools/doxygen/Doxyfile.core.internal b/tools/doxygen/Doxyfile.core.internal index ee593e3ea0..dc6df1decd 100644 --- a/tools/doxygen/Doxyfile.core.internal +++ b/tools/doxygen/Doxyfile.core.internal @@ -934,6 +934,8 @@ src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/load_balan src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.h \ src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc \ src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc \ +src/core/ext/filters/client_channel/lb_policy/subchannel_list.cc \ +src/core/ext/filters/client_channel/lb_policy/subchannel_list.h \ src/core/ext/filters/client_channel/lb_policy_factory.cc \ src/core/ext/filters/client_channel/lb_policy_factory.h \ src/core/ext/filters/client_channel/lb_policy_registry.cc \ diff --git a/tools/run_tests/generated/sources_and_headers.json b/tools/run_tests/generated/sources_and_headers.json index 95556b2e6f..6c2a0cf416 100644 --- a/tools/run_tests/generated/sources_and_headers.json +++ b/tools/run_tests/generated/sources_and_headers.json @@ -8628,7 +8628,8 @@ "deps": [ "gpr", "grpc_base", - "grpc_client_channel" + "grpc_client_channel", + "grpc_lb_subchannel_list" ], "headers": [], "is_filegroup": true, @@ -8644,7 +8645,8 @@ "deps": [ "gpr", "grpc_base", - "grpc_client_channel" + "grpc_client_channel", + "grpc_lb_subchannel_list" ], "headers": [], "is_filegroup": true, @@ -8656,6 +8658,25 @@ "third_party": false, "type": "filegroup" }, + { + "deps": [ + "gpr", + "grpc_base", + "grpc_client_channel" + ], + "headers": [ + "src/core/ext/filters/client_channel/lb_policy/subchannel_list.h" + ], + "is_filegroup": true, + "language": "c", + "name": "grpc_lb_subchannel_list", + "src": [ + "src/core/ext/filters/client_channel/lb_policy/subchannel_list.cc", + "src/core/ext/filters/client_channel/lb_policy/subchannel_list.h" + ], + "third_party": false, + "type": "filegroup" + }, { "deps": [ "gpr", -- cgit v1.2.3 From a5113563df94e35fd1d7318e48c8f260646cc685 Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Thu, 26 Oct 2017 15:35:43 +0200 Subject: limit concurrent jobs for build_only on linux --- tools/internal_ci/linux/grpc_build_submodule_at_head.sh | 2 +- tools/internal_ci/linux/grpc_portability_build_only.cfg | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'tools') diff --git a/tools/internal_ci/linux/grpc_build_submodule_at_head.sh b/tools/internal_ci/linux/grpc_build_submodule_at_head.sh index b67b030361..e203a62b08 100755 --- a/tools/internal_ci/linux/grpc_build_submodule_at_head.sh +++ b/tools/internal_ci/linux/grpc_build_submodule_at_head.sh @@ -27,5 +27,5 @@ source tools/internal_ci/helper_scripts/prepare_build_linux_rc tools/buildgen/generate_projects.sh git -c user.name='foo' -c user.email='foo@google.com' commit -a -m 'Update submodule' -tools/run_tests/run_tests_matrix.py -f linux --internal_ci --build_only +tools/run_tests/run_tests_matrix.py -f linux --inner_jobs 4 -j 4 --internal_ci --build_only diff --git a/tools/internal_ci/linux/grpc_portability_build_only.cfg b/tools/internal_ci/linux/grpc_portability_build_only.cfg index 501223c0c7..4acd9353fb 100644 --- a/tools/internal_ci/linux/grpc_portability_build_only.cfg +++ b/tools/internal_ci/linux/grpc_portability_build_only.cfg @@ -26,5 +26,5 @@ action { env_vars { key: "RUN_TESTS_FLAGS" - value: "-f portability linux --internal_ci --build_only" + value: "-f portability linux --inner_jobs 4 -j 4 --internal_ci --build_only" } -- cgit v1.2.3 From 69bd8f2d5d981dd646733f2fd030c93c4b23c58b Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Thu, 26 Oct 2017 16:48:09 +0200 Subject: print timing for docker pull --- tools/run_tests/dockerize/build_and_run_docker.sh | 4 ++-- tools/run_tests/dockerize/build_docker_and_run_tests.sh | 2 +- tools/run_tests/dockerize/build_interop_image.sh | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) (limited to 'tools') diff --git a/tools/run_tests/dockerize/build_and_run_docker.sh b/tools/run_tests/dockerize/build_and_run_docker.sh index 80aec82c3d..323c2f78af 100755 --- a/tools/run_tests/dockerize/build_and_run_docker.sh +++ b/tools/run_tests/dockerize/build_and_run_docker.sh @@ -36,13 +36,13 @@ DOCKER_IMAGE_NAME=$(basename $DOCKERFILE_DIR)_$(sha1sum $DOCKERFILE_DIR/Dockerfi # Pull the base image to force an update if [ "$DOCKER_BASE_IMAGE" != "" ] then - docker pull $DOCKER_BASE_IMAGE + time docker pull $DOCKER_BASE_IMAGE fi if [ "$DOCKERHUB_ORGANIZATION" != "" ] then DOCKER_IMAGE_NAME=$DOCKERHUB_ORGANIZATION/$DOCKER_IMAGE_NAME - docker pull $DOCKER_IMAGE_NAME + time docker pull $DOCKER_IMAGE_NAME else # Make sure docker image has been built. Should be instantaneous if so. docker build -t $DOCKER_IMAGE_NAME $DOCKERFILE_DIR diff --git a/tools/run_tests/dockerize/build_docker_and_run_tests.sh b/tools/run_tests/dockerize/build_docker_and_run_tests.sh index eea00da821..06a5dae6a5 100755 --- a/tools/run_tests/dockerize/build_docker_and_run_tests.sh +++ b/tools/run_tests/dockerize/build_docker_and_run_tests.sh @@ -40,7 +40,7 @@ DOCKER_IMAGE_NAME=$(basename $DOCKERFILE_DIR)_$(sha1sum $DOCKERFILE_DIR/Dockerfi if [ "$DOCKERHUB_ORGANIZATION" != "" ] then DOCKER_IMAGE_NAME=$DOCKERHUB_ORGANIZATION/$DOCKER_IMAGE_NAME - docker pull $DOCKER_IMAGE_NAME + time docker pull $DOCKER_IMAGE_NAME else # Make sure docker image has been built. Should be instantaneous if so. docker build -t $DOCKER_IMAGE_NAME $DOCKERFILE_DIR diff --git a/tools/run_tests/dockerize/build_interop_image.sh b/tools/run_tests/dockerize/build_interop_image.sh index 09e062980d..dbc6bdeea5 100755 --- a/tools/run_tests/dockerize/build_interop_image.sh +++ b/tools/run_tests/dockerize/build_interop_image.sh @@ -78,7 +78,7 @@ fi if [ "$DOCKERHUB_ORGANIZATION" != "" ] then BASE_IMAGE=$DOCKERHUB_ORGANIZATION/$BASE_IMAGE - docker pull $BASE_IMAGE + time docker pull $BASE_IMAGE else # Make sure docker image has been built. Should be instantaneous if so. docker build -t $BASE_IMAGE --force-rm=true tools/dockerfile/interoptest/$BASE_NAME || exit $? -- cgit v1.2.3 From f568c0a07e965a34db3205a77e6a17826266261e Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Thu, 26 Oct 2017 17:25:29 +0200 Subject: use GCR mirror for pulling images --- tools/internal_ci/helper_scripts/prepare_build_linux_rc | 3 +++ 1 file changed, 3 insertions(+) (limited to 'tools') diff --git a/tools/internal_ci/helper_scripts/prepare_build_linux_rc b/tools/internal_ci/helper_scripts/prepare_build_linux_rc index ea2a17f2bc..8715d6c8e0 100644 --- a/tools/internal_ci/helper_scripts/prepare_build_linux_rc +++ b/tools/internal_ci/helper_scripts/prepare_build_linux_rc @@ -22,6 +22,9 @@ ulimit -n 32768 # Move docker's storage location to scratch disk so we don't run out of space. echo 'DOCKER_OPTS="${DOCKER_OPTS} --graph=/tmpfs/docker"' | sudo tee --append /etc/default/docker +# Use container registry mirror for pulling docker images (should make downloads faster) +# See https://cloud.google.com/container-registry/docs/using-dockerhub-mirroring +echo 'DOCKER_OPTS="${DOCKER_OPTS} --registry-mirror=https://mirror.gcr.io"' | sudo tee --append /etc/default/docker sudo service docker restart # Populate xdg-cache-home to workaround https://github.com/grpc/grpc/issues/11968 -- cgit v1.2.3 From 667aa2b9906aa4eb8bdb3f049444ad68adde5aa8 Mon Sep 17 00:00:00 2001 From: Ken Payson Date: Fri, 27 Oct 2017 14:33:17 -0700 Subject: Add call size bm_diff --- Makefile | 1 + grpc.gyp | 1 + test/cpp/microbenchmarks/helpers.cc | 14 ++++++++++---- third_party/benchmark | 2 +- tools/profiling/microbenchmarks/bm_diff/bm_constants.py | 2 +- tools/run_tests/generated/sources_and_headers.json | 2 +- tools/run_tests/sanity/check_submodules.sh | 2 +- 7 files changed, 16 insertions(+), 8 deletions(-) (limited to 'tools') diff --git a/Makefile b/Makefile index 325c9123d9..236dc74779 100644 --- a/Makefile +++ b/Makefile @@ -8298,6 +8298,7 @@ LIBBENCHMARK_SRC = \ third_party/benchmark/src/commandlineflags.cc \ third_party/benchmark/src/complexity.cc \ third_party/benchmark/src/console_reporter.cc \ + third_party/benchmark/src/counter.cc \ third_party/benchmark/src/csv_reporter.cc \ third_party/benchmark/src/json_reporter.cc \ third_party/benchmark/src/reporter.cc \ diff --git a/grpc.gyp b/grpc.gyp index 487d529316..e61166e769 100644 --- a/grpc.gyp +++ b/grpc.gyp @@ -2316,6 +2316,7 @@ 'third_party/benchmark/src/commandlineflags.cc', 'third_party/benchmark/src/complexity.cc', 'third_party/benchmark/src/console_reporter.cc', + 'third_party/benchmark/src/counter.cc', 'third_party/benchmark/src/csv_reporter.cc', 'third_party/benchmark/src/json_reporter.cc', 'third_party/benchmark/src/reporter.cc', diff --git a/test/cpp/microbenchmarks/helpers.cc b/test/cpp/microbenchmarks/helpers.cc index 6802a0aa99..782f12e99a 100644 --- a/test/cpp/microbenchmarks/helpers.cc +++ b/test/cpp/microbenchmarks/helpers.cc @@ -16,6 +16,8 @@ * */ +#include + #include "test/cpp/microbenchmarks/helpers.h" void TrackCounters::Finish(benchmark::State &state) { @@ -45,10 +47,14 @@ void TrackCounters::AddToLabel(std::ostream &out, benchmark::State &state) { << "/iter:" << ((double)stats.counters[i] / (double)state.iterations()); } for (int i = 0; i < GRPC_STATS_HISTOGRAM_COUNT; i++) { - out << " " << grpc_stats_histogram_name[i] << "-median:" - << grpc_stats_histo_percentile(&stats, (grpc_stats_histograms)i, 50.0) - << " " << grpc_stats_histogram_name[i] << "-99p:" - << grpc_stats_histo_percentile(&stats, (grpc_stats_histograms)i, 99.0); + std::ostringstream median_ss; + median_ss << grpc_stats_histogram_name[i] << "-median"; + state.counters[median_ss.str()] = benchmark::Counter( + grpc_stats_histo_percentile(&stats, (grpc_stats_histograms)i, 50.0)); + std::ostringstream tail_ss; + tail_ss << grpc_stats_histogram_name[i] << "-99p"; + state.counters[tail_ss.str()] = benchmark::Counter( + grpc_stats_histo_percentile(&stats, (grpc_stats_histograms)i, 99.0)); } #ifdef GPR_LOW_LEVEL_COUNTERS grpc_memory_counters counters_at_end = grpc_memory_counters_snapshot(); diff --git a/third_party/benchmark b/third_party/benchmark index 44c25c892a..5b7683f49e 160000 --- a/third_party/benchmark +++ b/third_party/benchmark @@ -1 +1 @@ -Subproject commit 44c25c892a6229b20db7cd9dc05584ea865896de +Subproject commit 5b7683f49e1e9223cf9927b24f6fd3d6bd82e3f8 diff --git a/tools/profiling/microbenchmarks/bm_diff/bm_constants.py b/tools/profiling/microbenchmarks/bm_diff/bm_constants.py index f8989b17fc..0ec17fa17e 100644 --- a/tools/profiling/microbenchmarks/bm_diff/bm_constants.py +++ b/tools/profiling/microbenchmarks/bm_diff/bm_constants.py @@ -23,7 +23,7 @@ _AVAILABLE_BENCHMARK_TESTS = [ 'bm_metadata', 'bm_fullstack_trickle' ] -_INTERESTING = ('cpu_time', 'real_time', 'locks_per_iteration', +_INTERESTING = ('cpu_time', 'real_time', 'call_initial_size-median', 'locks_per_iteration', 'allocs_per_iteration', 'writes_per_iteration', 'atm_cas_per_iteration', 'atm_add_per_iteration', 'nows_per_iteration', 'cli_transport_stalls_per_iteration', diff --git a/tools/run_tests/generated/sources_and_headers.json b/tools/run_tests/generated/sources_and_headers.json index 46f4cb6532..08ab2a5d93 100644 --- a/tools/run_tests/generated/sources_and_headers.json +++ b/tools/run_tests/generated/sources_and_headers.json @@ -7453,7 +7453,6 @@ "headers": [ "third_party/benchmark/include/benchmark/benchmark.h", "third_party/benchmark/include/benchmark/benchmark_api.h", - "third_party/benchmark/include/benchmark/macros.h", "third_party/benchmark/include/benchmark/reporter.h", "third_party/benchmark/src/arraysize.h", "third_party/benchmark/src/benchmark_api_internal.h", @@ -7461,6 +7460,7 @@ "third_party/benchmark/src/colorprint.h", "third_party/benchmark/src/commandlineflags.h", "third_party/benchmark/src/complexity.h", + "third_party/benchmark/src/counter.h", "third_party/benchmark/src/cycleclock.h", "third_party/benchmark/src/internal_macros.h", "third_party/benchmark/src/log.h", diff --git a/tools/run_tests/sanity/check_submodules.sh b/tools/run_tests/sanity/check_submodules.sh index 2aee0001a3..1f7b078ff7 100755 --- a/tools/run_tests/sanity/check_submodules.sh +++ b/tools/run_tests/sanity/check_submodules.sh @@ -26,7 +26,7 @@ want_submodules=`mktemp /tmp/submXXXXXX` git submodule | awk '{ print $1 }' | sort > $submodules cat << EOF | awk '{ print $1 }' | sort > $want_submodules - 44c25c892a6229b20db7cd9dc05584ea865896de third_party/benchmark (v0.1.0-343-g44c25c8) + 5b7683f49e1e9223cf9927b24f6fd3d6bd82e3f8 third_party/benchmark (v1.2.0) be2ee342d3781ddb954f91f8a7e660c6f59e87e5 third_party/boringssl (heads/chromium-stable) 886e7d75368e3f4fab3f4d0d3584e4abfc557755 third_party/boringssl-with-bazel (version_for_cocoapods_7.0-857-g886e7d7) 30dbc81fb5ffdc98ea9b14b1918bfe4e8779b26e third_party/gflags (v2.2.0) -- cgit v1.2.3 From 7269667f9e091445faa62f8ed96885dca4686487 Mon Sep 17 00:00:00 2001 From: Yuchen Zeng Date: Tue, 26 Sep 2017 19:37:49 -0700 Subject: Add client channel connectivity watcher --- BUILD | 3 + CMakeLists.txt | 6 + Makefile | 6 + binding.gyp | 1 + config.m4 | 1 + config.w32 | 1 + gRPC-Core.podspec | 5 + grpc.gemspec | 3 + grpc.gyp | 4 + package.xml | 3 + .../filters/client_channel/channel_connectivity.cc | 165 +---------------- .../channel_connectivity_internal.cc | 195 +++++++++++++++++++++ .../client_channel/channel_connectivity_internal.h | 33 ++++ .../ext/filters/client_channel/client_channel.cc | 3 + .../filters/client_channel/connectivity_watcher.c | 179 +++++++++++++++++++ .../filters/client_channel/connectivity_watcher.h | 30 ++++ src/python/grpcio/grpc_core_dependencies.py | 1 + tools/doxygen/Doxyfile.core.internal | 3 + tools/run_tests/generated/sources_and_headers.json | 5 + 19 files changed, 491 insertions(+), 156 deletions(-) create mode 100644 src/core/ext/filters/client_channel/channel_connectivity_internal.cc create mode 100644 src/core/ext/filters/client_channel/channel_connectivity_internal.h create mode 100644 src/core/ext/filters/client_channel/connectivity_watcher.c create mode 100644 src/core/ext/filters/client_channel/connectivity_watcher.h (limited to 'tools') diff --git a/BUILD b/BUILD index 99411f955e..4e1f61ee10 100644 --- a/BUILD +++ b/BUILD @@ -876,6 +876,7 @@ grpc_cc_library( "src/core/ext/filters/client_channel/client_channel.cc", "src/core/ext/filters/client_channel/client_channel_factory.cc", "src/core/ext/filters/client_channel/client_channel_plugin.cc", + "src/core/ext/filters/client_channel/connectivity_watcher.cc", "src/core/ext/filters/client_channel/connector.cc", "src/core/ext/filters/client_channel/http_connect_handshaker.cc", "src/core/ext/filters/client_channel/http_proxy.cc", @@ -894,8 +895,10 @@ grpc_cc_library( "src/core/ext/filters/client_channel/uri_parser.cc", ], hdrs = [ + "src/core/ext/filters/client_channel/channel_connectivity_internal.h", "src/core/ext/filters/client_channel/client_channel.h", "src/core/ext/filters/client_channel/client_channel_factory.h", + "src/core/ext/filters/client_channel/connectivity_watcher.h", "src/core/ext/filters/client_channel/connector.h", "src/core/ext/filters/client_channel/http_connect_handshaker.h", "src/core/ext/filters/client_channel/http_proxy.h", diff --git a/CMakeLists.txt b/CMakeLists.txt index 3ac6c9b63d..8122d4b025 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1157,6 +1157,7 @@ add_library(grpc src/core/ext/filters/client_channel/client_channel.cc src/core/ext/filters/client_channel/client_channel_factory.cc src/core/ext/filters/client_channel/client_channel_plugin.cc + src/core/ext/filters/client_channel/connectivity_watcher.c src/core/ext/filters/client_channel/connector.cc src/core/ext/filters/client_channel/http_connect_handshaker.cc src/core/ext/filters/client_channel/http_proxy.cc @@ -1481,6 +1482,7 @@ add_library(grpc_cronet src/core/ext/filters/client_channel/client_channel.cc src/core/ext/filters/client_channel/client_channel_factory.cc src/core/ext/filters/client_channel/client_channel_plugin.cc + src/core/ext/filters/client_channel/connectivity_watcher.c src/core/ext/filters/client_channel/connector.cc src/core/ext/filters/client_channel/http_connect_handshaker.cc src/core/ext/filters/client_channel/http_proxy.cc @@ -1771,6 +1773,7 @@ add_library(grpc_test_util src/core/ext/filters/client_channel/client_channel.cc src/core/ext/filters/client_channel/client_channel_factory.cc src/core/ext/filters/client_channel/client_channel_plugin.cc + src/core/ext/filters/client_channel/connectivity_watcher.c src/core/ext/filters/client_channel/connector.cc src/core/ext/filters/client_channel/http_connect_handshaker.cc src/core/ext/filters/client_channel/http_proxy.cc @@ -2036,6 +2039,7 @@ add_library(grpc_test_util_unsecure src/core/ext/filters/client_channel/client_channel.cc src/core/ext/filters/client_channel/client_channel_factory.cc src/core/ext/filters/client_channel/client_channel_plugin.cc + src/core/ext/filters/client_channel/connectivity_watcher.c src/core/ext/filters/client_channel/connector.cc src/core/ext/filters/client_channel/http_connect_handshaker.cc src/core/ext/filters/client_channel/http_proxy.cc @@ -2320,6 +2324,7 @@ add_library(grpc_unsecure src/core/ext/filters/client_channel/client_channel.cc src/core/ext/filters/client_channel/client_channel_factory.cc src/core/ext/filters/client_channel/client_channel_plugin.cc + src/core/ext/filters/client_channel/connectivity_watcher.c src/core/ext/filters/client_channel/connector.cc src/core/ext/filters/client_channel/http_connect_handshaker.cc src/core/ext/filters/client_channel/http_proxy.cc @@ -3055,6 +3060,7 @@ add_library(grpc++_cronet src/core/ext/filters/client_channel/client_channel.cc src/core/ext/filters/client_channel/client_channel_factory.cc src/core/ext/filters/client_channel/client_channel_plugin.cc + src/core/ext/filters/client_channel/connectivity_watcher.c src/core/ext/filters/client_channel/connector.cc src/core/ext/filters/client_channel/http_connect_handshaker.cc src/core/ext/filters/client_channel/http_proxy.cc diff --git a/Makefile b/Makefile index 236dc74779..3ff9b39f45 100644 --- a/Makefile +++ b/Makefile @@ -3157,6 +3157,7 @@ LIBGRPC_SRC = \ src/core/ext/filters/client_channel/client_channel.cc \ src/core/ext/filters/client_channel/client_channel_factory.cc \ src/core/ext/filters/client_channel/client_channel_plugin.cc \ + src/core/ext/filters/client_channel/connectivity_watcher.c \ src/core/ext/filters/client_channel/connector.cc \ src/core/ext/filters/client_channel/http_connect_handshaker.cc \ src/core/ext/filters/client_channel/http_proxy.cc \ @@ -3480,6 +3481,7 @@ LIBGRPC_CRONET_SRC = \ src/core/ext/filters/client_channel/client_channel.cc \ src/core/ext/filters/client_channel/client_channel_factory.cc \ src/core/ext/filters/client_channel/client_channel_plugin.cc \ + src/core/ext/filters/client_channel/connectivity_watcher.c \ src/core/ext/filters/client_channel/connector.cc \ src/core/ext/filters/client_channel/http_connect_handshaker.cc \ src/core/ext/filters/client_channel/http_proxy.cc \ @@ -3768,6 +3770,7 @@ LIBGRPC_TEST_UTIL_SRC = \ src/core/ext/filters/client_channel/client_channel.cc \ src/core/ext/filters/client_channel/client_channel_factory.cc \ src/core/ext/filters/client_channel/client_channel_plugin.cc \ + src/core/ext/filters/client_channel/connectivity_watcher.c \ src/core/ext/filters/client_channel/connector.cc \ src/core/ext/filters/client_channel/http_connect_handshaker.cc \ src/core/ext/filters/client_channel/http_proxy.cc \ @@ -4023,6 +4026,7 @@ LIBGRPC_TEST_UTIL_UNSECURE_SRC = \ src/core/ext/filters/client_channel/client_channel.cc \ src/core/ext/filters/client_channel/client_channel_factory.cc \ src/core/ext/filters/client_channel/client_channel_plugin.cc \ + src/core/ext/filters/client_channel/connectivity_watcher.c \ src/core/ext/filters/client_channel/connector.cc \ src/core/ext/filters/client_channel/http_connect_handshaker.cc \ src/core/ext/filters/client_channel/http_proxy.cc \ @@ -4284,6 +4288,7 @@ LIBGRPC_UNSECURE_SRC = \ src/core/ext/filters/client_channel/client_channel.cc \ src/core/ext/filters/client_channel/client_channel_factory.cc \ src/core/ext/filters/client_channel/client_channel_plugin.cc \ + src/core/ext/filters/client_channel/connectivity_watcher.c \ src/core/ext/filters/client_channel/connector.cc \ src/core/ext/filters/client_channel/http_connect_handshaker.cc \ src/core/ext/filters/client_channel/http_proxy.cc \ @@ -4997,6 +5002,7 @@ LIBGRPC++_CRONET_SRC = \ src/core/ext/filters/client_channel/client_channel.cc \ src/core/ext/filters/client_channel/client_channel_factory.cc \ src/core/ext/filters/client_channel/client_channel_plugin.cc \ + src/core/ext/filters/client_channel/connectivity_watcher.c \ src/core/ext/filters/client_channel/connector.cc \ src/core/ext/filters/client_channel/http_connect_handshaker.cc \ src/core/ext/filters/client_channel/http_proxy.cc \ diff --git a/binding.gyp b/binding.gyp index e004b0fa32..707afb476a 100644 --- a/binding.gyp +++ b/binding.gyp @@ -857,6 +857,7 @@ 'src/core/ext/filters/client_channel/client_channel.cc', 'src/core/ext/filters/client_channel/client_channel_factory.cc', 'src/core/ext/filters/client_channel/client_channel_plugin.cc', + 'src/core/ext/filters/client_channel/connectivity_watcher.c', 'src/core/ext/filters/client_channel/connector.cc', 'src/core/ext/filters/client_channel/http_connect_handshaker.cc', 'src/core/ext/filters/client_channel/http_proxy.cc', diff --git a/config.m4 b/config.m4 index 5d92a2ae34..eaa3af978b 100644 --- a/config.m4 +++ b/config.m4 @@ -282,6 +282,7 @@ if test "$PHP_GRPC" != "no"; then src/core/ext/filters/client_channel/client_channel.cc \ src/core/ext/filters/client_channel/client_channel_factory.cc \ src/core/ext/filters/client_channel/client_channel_plugin.cc \ + src/core/ext/filters/client_channel/connectivity_watcher.c \ src/core/ext/filters/client_channel/connector.cc \ src/core/ext/filters/client_channel/http_connect_handshaker.cc \ src/core/ext/filters/client_channel/http_proxy.cc \ diff --git a/config.w32 b/config.w32 index 67b5e2f554..75a83e2414 100644 --- a/config.w32 +++ b/config.w32 @@ -259,6 +259,7 @@ if (PHP_GRPC != "no") { "src\\core\\ext\\filters\\client_channel\\client_channel.cc " + "src\\core\\ext\\filters\\client_channel\\client_channel_factory.cc " + "src\\core\\ext\\filters\\client_channel\\client_channel_plugin.cc " + + "src\\core\\ext\\filters\\client_channel\\connectivity_watcher.c " + "src\\core\\ext\\filters\\client_channel\\connector.cc " + "src\\core\\ext\\filters\\client_channel\\http_connect_handshaker.cc " + "src\\core\\ext\\filters\\client_channel\\http_proxy.cc " + diff --git a/gRPC-Core.podspec b/gRPC-Core.podspec index 0e3b50c4aa..9b4f4ec675 100644 --- a/gRPC-Core.podspec +++ b/gRPC-Core.podspec @@ -299,8 +299,10 @@ Pod::Spec.new do |s| 'src/core/tsi/transport_security_adapter.h', 'src/core/tsi/transport_security_interface.h', 'src/core/ext/transport/chttp2/server/chttp2_server.h', + 'src/core/ext/filters/client_channel/channel_connectivity_internal.h', 'src/core/ext/filters/client_channel/client_channel.h', 'src/core/ext/filters/client_channel/client_channel_factory.h', + 'src/core/ext/filters/client_channel/connectivity_watcher.h', 'src/core/ext/filters/client_channel/connector.h', 'src/core/ext/filters/client_channel/http_connect_handshaker.h', 'src/core/ext/filters/client_channel/http_proxy.h', @@ -672,6 +674,7 @@ Pod::Spec.new do |s| 'src/core/ext/filters/client_channel/client_channel.cc', 'src/core/ext/filters/client_channel/client_channel_factory.cc', 'src/core/ext/filters/client_channel/client_channel_plugin.cc', + 'src/core/ext/filters/client_channel/connectivity_watcher.c', 'src/core/ext/filters/client_channel/connector.cc', 'src/core/ext/filters/client_channel/http_connect_handshaker.cc', 'src/core/ext/filters/client_channel/http_proxy.cc', @@ -802,8 +805,10 @@ Pod::Spec.new do |s| 'src/core/tsi/transport_security_adapter.h', 'src/core/tsi/transport_security_interface.h', 'src/core/ext/transport/chttp2/server/chttp2_server.h', + 'src/core/ext/filters/client_channel/channel_connectivity_internal.h', 'src/core/ext/filters/client_channel/client_channel.h', 'src/core/ext/filters/client_channel/client_channel_factory.h', + 'src/core/ext/filters/client_channel/connectivity_watcher.h', 'src/core/ext/filters/client_channel/connector.h', 'src/core/ext/filters/client_channel/http_connect_handshaker.h', 'src/core/ext/filters/client_channel/http_proxy.h', diff --git a/grpc.gemspec b/grpc.gemspec index 4567058344..9f5f45bb1b 100644 --- a/grpc.gemspec +++ b/grpc.gemspec @@ -230,8 +230,10 @@ Gem::Specification.new do |s| s.files += %w( src/core/tsi/transport_security_adapter.h ) s.files += %w( src/core/tsi/transport_security_interface.h ) s.files += %w( src/core/ext/transport/chttp2/server/chttp2_server.h ) + s.files += %w( src/core/ext/filters/client_channel/channel_connectivity_internal.h ) s.files += %w( src/core/ext/filters/client_channel/client_channel.h ) s.files += %w( src/core/ext/filters/client_channel/client_channel_factory.h ) + s.files += %w( src/core/ext/filters/client_channel/connectivity_watcher.h ) s.files += %w( src/core/ext/filters/client_channel/connector.h ) s.files += %w( src/core/ext/filters/client_channel/http_connect_handshaker.h ) s.files += %w( src/core/ext/filters/client_channel/http_proxy.h ) @@ -607,6 +609,7 @@ Gem::Specification.new do |s| s.files += %w( src/core/ext/filters/client_channel/client_channel.cc ) s.files += %w( src/core/ext/filters/client_channel/client_channel_factory.cc ) s.files += %w( src/core/ext/filters/client_channel/client_channel_plugin.cc ) + s.files += %w( src/core/ext/filters/client_channel/connectivity_watcher.c ) s.files += %w( src/core/ext/filters/client_channel/connector.cc ) s.files += %w( src/core/ext/filters/client_channel/http_connect_handshaker.cc ) s.files += %w( src/core/ext/filters/client_channel/http_proxy.cc ) diff --git a/grpc.gyp b/grpc.gyp index e61166e769..420621fb4c 100644 --- a/grpc.gyp +++ b/grpc.gyp @@ -423,6 +423,7 @@ 'src/core/ext/filters/client_channel/client_channel.cc', 'src/core/ext/filters/client_channel/client_channel_factory.cc', 'src/core/ext/filters/client_channel/client_channel_plugin.cc', + 'src/core/ext/filters/client_channel/connectivity_watcher.c', 'src/core/ext/filters/client_channel/connector.cc', 'src/core/ext/filters/client_channel/http_connect_handshaker.cc', 'src/core/ext/filters/client_channel/http_proxy.cc', @@ -665,6 +666,7 @@ 'src/core/ext/filters/client_channel/client_channel.cc', 'src/core/ext/filters/client_channel/client_channel_factory.cc', 'src/core/ext/filters/client_channel/client_channel_plugin.cc', + 'src/core/ext/filters/client_channel/connectivity_watcher.c', 'src/core/ext/filters/client_channel/connector.cc', 'src/core/ext/filters/client_channel/http_connect_handshaker.cc', 'src/core/ext/filters/client_channel/http_proxy.cc', @@ -872,6 +874,7 @@ 'src/core/ext/filters/client_channel/client_channel.cc', 'src/core/ext/filters/client_channel/client_channel_factory.cc', 'src/core/ext/filters/client_channel/client_channel_plugin.cc', + 'src/core/ext/filters/client_channel/connectivity_watcher.c', 'src/core/ext/filters/client_channel/connector.cc', 'src/core/ext/filters/client_channel/http_connect_handshaker.cc', 'src/core/ext/filters/client_channel/http_proxy.cc', @@ -1097,6 +1100,7 @@ 'src/core/ext/filters/client_channel/client_channel.cc', 'src/core/ext/filters/client_channel/client_channel_factory.cc', 'src/core/ext/filters/client_channel/client_channel_plugin.cc', + 'src/core/ext/filters/client_channel/connectivity_watcher.c', 'src/core/ext/filters/client_channel/connector.cc', 'src/core/ext/filters/client_channel/http_connect_handshaker.cc', 'src/core/ext/filters/client_channel/http_proxy.cc', diff --git a/package.xml b/package.xml index d08b803355..65cb53ad1c 100644 --- a/package.xml +++ b/package.xml @@ -242,8 +242,10 @@ + + @@ -619,6 +621,7 @@ + diff --git a/src/core/ext/filters/client_channel/channel_connectivity.cc b/src/core/ext/filters/client_channel/channel_connectivity.cc index 31a8fc39ce..33e9deaaf6 100644 --- a/src/core/ext/filters/client_channel/channel_connectivity.cc +++ b/src/core/ext/filters/client_channel/channel_connectivity.cc @@ -23,8 +23,8 @@ #include #include +#include "src/core/ext/filters/client_channel/channel_connectivity_internal.h" #include "src/core/ext/filters/client_channel/client_channel.h" -#include "src/core/lib/iomgr/timer.h" #include "src/core/lib/surface/api_trace.h" #include "src/core/lib/surface/completion_queue.h" @@ -52,125 +52,6 @@ grpc_connectivity_state grpc_channel_check_connectivity_state( return GRPC_CHANNEL_SHUTDOWN; } -typedef enum { - WAITING, - READY_TO_CALL_BACK, - CALLING_BACK_AND_FINISHED, -} callback_phase; - -typedef struct { - gpr_mu mu; - callback_phase phase; - grpc_closure on_complete; - grpc_closure on_timeout; - grpc_closure watcher_timer_init; - grpc_timer alarm; - grpc_connectivity_state state; - grpc_completion_queue *cq; - grpc_cq_completion completion_storage; - grpc_channel *channel; - grpc_error *error; - void *tag; -} state_watcher; - -static void delete_state_watcher(grpc_exec_ctx *exec_ctx, state_watcher *w) { - grpc_channel_element *client_channel_elem = grpc_channel_stack_last_element( - grpc_channel_get_channel_stack(w->channel)); - if (client_channel_elem->filter == &grpc_client_channel_filter) { - GRPC_CHANNEL_INTERNAL_UNREF(exec_ctx, w->channel, - "watch_channel_connectivity"); - } else { - abort(); - } - gpr_mu_destroy(&w->mu); - gpr_free(w); -} - -static void finished_completion(grpc_exec_ctx *exec_ctx, void *pw, - grpc_cq_completion *ignored) { - bool should_delete = false; - state_watcher *w = (state_watcher *)pw; - gpr_mu_lock(&w->mu); - switch (w->phase) { - case WAITING: - case READY_TO_CALL_BACK: - GPR_UNREACHABLE_CODE(return ); - case CALLING_BACK_AND_FINISHED: - should_delete = true; - break; - } - gpr_mu_unlock(&w->mu); - - if (should_delete) { - delete_state_watcher(exec_ctx, w); - } -} - -static void partly_done(grpc_exec_ctx *exec_ctx, state_watcher *w, - bool due_to_completion, grpc_error *error) { - if (due_to_completion) { - grpc_timer_cancel(exec_ctx, &w->alarm); - } else { - grpc_channel_element *client_channel_elem = grpc_channel_stack_last_element( - grpc_channel_get_channel_stack(w->channel)); - grpc_client_channel_watch_connectivity_state( - exec_ctx, client_channel_elem, - grpc_polling_entity_create_from_pollset(grpc_cq_pollset(w->cq)), NULL, - &w->on_complete, NULL); - } - - gpr_mu_lock(&w->mu); - - if (due_to_completion) { - if (GRPC_TRACER_ON(grpc_trace_operation_failures)) { - GRPC_LOG_IF_ERROR("watch_completion_error", GRPC_ERROR_REF(error)); - } - GRPC_ERROR_UNREF(error); - error = GRPC_ERROR_NONE; - } else { - if (error == GRPC_ERROR_NONE) { - error = GRPC_ERROR_CREATE_FROM_STATIC_STRING( - "Timed out waiting for connection state change"); - } else if (error == GRPC_ERROR_CANCELLED) { - error = GRPC_ERROR_NONE; - } - } - switch (w->phase) { - case WAITING: - GRPC_ERROR_REF(error); - w->error = error; - w->phase = READY_TO_CALL_BACK; - break; - case READY_TO_CALL_BACK: - if (error != GRPC_ERROR_NONE) { - GPR_ASSERT(!due_to_completion); - GRPC_ERROR_UNREF(w->error); - GRPC_ERROR_REF(error); - w->error = error; - } - w->phase = CALLING_BACK_AND_FINISHED; - grpc_cq_end_op(exec_ctx, w->cq, w->tag, w->error, finished_completion, w, - &w->completion_storage); - break; - case CALLING_BACK_AND_FINISHED: - GPR_UNREACHABLE_CODE(return ); - break; - } - gpr_mu_unlock(&w->mu); - - GRPC_ERROR_UNREF(error); -} - -static void watch_complete(grpc_exec_ctx *exec_ctx, void *pw, - grpc_error *error) { - partly_done(exec_ctx, (state_watcher *)pw, true, GRPC_ERROR_REF(error)); -} - -static void timeout_complete(grpc_exec_ctx *exec_ctx, void *pw, - grpc_error *error) { - partly_done(exec_ctx, (state_watcher *)pw, false, GRPC_ERROR_REF(error)); -} - int grpc_channel_num_external_connectivity_watchers(grpc_channel *channel) { grpc_channel_element *client_channel_elem = grpc_channel_stack_last_element(grpc_channel_get_channel_stack(channel)); @@ -202,10 +83,10 @@ int grpc_channel_support_connectivity_watcher(grpc_channel *channel) { void grpc_channel_watch_connectivity_state( grpc_channel *channel, grpc_connectivity_state last_observed_state, gpr_timespec deadline, grpc_completion_queue *cq, void *tag) { + grpc_channel_stack *channel_stack = grpc_channel_get_channel_stack(channel); grpc_channel_element *client_channel_elem = - grpc_channel_stack_last_element(grpc_channel_get_channel_stack(channel)); + grpc_channel_stack_last_element(channel_stack); grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - state_watcher *w = (state_watcher *)gpr_malloc(sizeof(*w)); GRPC_API_TRACE( "grpc_channel_watch_connectivity_state(" @@ -213,39 +94,11 @@ void grpc_channel_watch_connectivity_state( "deadline=gpr_timespec { tv_sec: %" PRId64 ", tv_nsec: %d, clock_type: %d }, " "cq=%p, tag=%p)", - 7, (channel, (int)last_observed_state, deadline.tv_sec, deadline.tv_nsec, - (int)deadline.clock_type, cq, tag)); - - GPR_ASSERT(grpc_cq_begin_op(cq, tag)); - - gpr_mu_init(&w->mu); - GRPC_CLOSURE_INIT(&w->on_complete, watch_complete, w, - grpc_schedule_on_exec_ctx); - GRPC_CLOSURE_INIT(&w->on_timeout, timeout_complete, w, - grpc_schedule_on_exec_ctx); - w->phase = WAITING; - w->state = last_observed_state; - w->cq = cq; - w->tag = tag; - w->channel = channel; - w->error = NULL; - - watcher_timer_init_arg *wa = - (watcher_timer_init_arg *)gpr_malloc(sizeof(watcher_timer_init_arg)); - wa->w = w; - wa->deadline = deadline; - GRPC_CLOSURE_INIT(&w->watcher_timer_init, watcher_timer_init, wa, - grpc_schedule_on_exec_ctx); - - if (client_channel_elem->filter == &grpc_client_channel_filter) { - GRPC_CHANNEL_INTERNAL_REF(channel, "watch_channel_connectivity"); - grpc_client_channel_watch_connectivity_state( - &exec_ctx, client_channel_elem, - grpc_polling_entity_create_from_pollset(grpc_cq_pollset(cq)), &w->state, - &w->on_complete, &w->watcher_timer_init); - } else { - abort(); - } - + 7, + (channel, (int)last_observed_state, deadline.tv_sec, deadline.tv_nsec, + (int)deadline.clock_type, cq, tag)); + grpc_channel_watch_connectivity_state_internal( + &exec_ctx, client_channel_elem, channel_stack, last_observed_state, + deadline, cq, tag); grpc_exec_ctx_finish(&exec_ctx); } diff --git a/src/core/ext/filters/client_channel/channel_connectivity_internal.cc b/src/core/ext/filters/client_channel/channel_connectivity_internal.cc new file mode 100644 index 0000000000..06bcfe2ffb --- /dev/null +++ b/src/core/ext/filters/client_channel/channel_connectivity_internal.cc @@ -0,0 +1,195 @@ +/* + * + * Copyright 2015 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include "src/core/ext/filters/client_channel/channel_connectivity_internal.h" + +#include +#include + +#include "src/core/ext/filters/client_channel/client_channel.h" +#include "src/core/lib/iomgr/timer.h" +#include "src/core/lib/surface/api_trace.h" +#include "src/core/lib/surface/completion_queue.h" + +typedef enum { + WAITING, + READY_TO_CALL_BACK, + CALLING_BACK_AND_FINISHED, +} callback_phase; + +typedef struct { + gpr_mu mu; + callback_phase phase; + grpc_closure on_complete; + grpc_closure on_timeout; + grpc_closure watcher_timer_init; + grpc_timer alarm; + grpc_connectivity_state state; + grpc_completion_queue *cq; + grpc_cq_completion completion_storage; + grpc_channel_element *client_channel_elem; + grpc_channel_stack *channel_stack; + grpc_error *error; + void *tag; +} state_watcher; + +static void delete_state_watcher(grpc_exec_ctx *exec_ctx, state_watcher *w) { + GRPC_CHANNEL_STACK_UNREF(exec_ctx, w->channel_stack, + "watch_channel_connectivity"); + gpr_mu_destroy(&w->mu); + gpr_free(w); +} + +static void finished_completion(grpc_exec_ctx *exec_ctx, void *pw, + grpc_cq_completion *ignored) { + bool should_delete = false; + state_watcher *w = (state_watcher *)pw; + gpr_mu_lock(&w->mu); + switch (w->phase) { + case WAITING: + case READY_TO_CALL_BACK: + GPR_UNREACHABLE_CODE(return ); + case CALLING_BACK_AND_FINISHED: + should_delete = true; + break; + } + gpr_mu_unlock(&w->mu); + + if (should_delete) { + delete_state_watcher(exec_ctx, w); + } +} + +static void partly_done(grpc_exec_ctx *exec_ctx, state_watcher *w, + bool due_to_completion, grpc_error *error) { + if (due_to_completion) { + grpc_timer_cancel(exec_ctx, &w->alarm); + } else { + grpc_channel_element *client_channel_elem = w->client_channel_elem; + grpc_client_channel_watch_connectivity_state( + exec_ctx, client_channel_elem, + grpc_polling_entity_create_from_pollset(grpc_cq_pollset(w->cq)), NULL, + &w->on_complete, NULL); + } + + gpr_mu_lock(&w->mu); + + if (due_to_completion) { + if (GRPC_TRACER_ON(grpc_trace_operation_failures)) { + GRPC_LOG_IF_ERROR("watch_completion_error", GRPC_ERROR_REF(error)); + } + GRPC_ERROR_UNREF(error); + error = GRPC_ERROR_NONE; + } else { + if (error == GRPC_ERROR_NONE) { + error = GRPC_ERROR_CREATE_FROM_STATIC_STRING( + "Timed out waiting for connection state change"); + } else if (error == GRPC_ERROR_CANCELLED) { + error = GRPC_ERROR_NONE; + } + } + switch (w->phase) { + case WAITING: + GRPC_ERROR_REF(error); + w->error = error; + w->phase = READY_TO_CALL_BACK; + break; + case READY_TO_CALL_BACK: + if (error != GRPC_ERROR_NONE) { + GPR_ASSERT(!due_to_completion); + GRPC_ERROR_UNREF(w->error); + GRPC_ERROR_REF(error); + w->error = error; + } + w->phase = CALLING_BACK_AND_FINISHED; + grpc_cq_end_op(exec_ctx, w->cq, w->tag, w->error, finished_completion, w, + &w->completion_storage); + break; + case CALLING_BACK_AND_FINISHED: + GPR_UNREACHABLE_CODE(return ); + break; + } + gpr_mu_unlock(&w->mu); + + GRPC_ERROR_UNREF(error); +} + +static void watch_complete(grpc_exec_ctx *exec_ctx, void *pw, + grpc_error *error) { + partly_done(exec_ctx, (state_watcher *)pw, true, GRPC_ERROR_REF(error)); +} + +static void timeout_complete(grpc_exec_ctx *exec_ctx, void *pw, + grpc_error *error) { + partly_done(exec_ctx, (state_watcher *)pw, false, GRPC_ERROR_REF(error)); +} + +typedef struct watcher_timer_init_arg { + state_watcher *w; + gpr_timespec deadline; +} watcher_timer_init_arg; + +static void watcher_timer_init(grpc_exec_ctx *exec_ctx, void *arg, + grpc_error *error_ignored) { + watcher_timer_init_arg *wa = (watcher_timer_init_arg *)arg; + + grpc_timer_init(exec_ctx, &wa->w->alarm, + gpr_convert_clock_type(wa->deadline, GPR_CLOCK_MONOTONIC), + &wa->w->on_timeout, gpr_now(GPR_CLOCK_MONOTONIC)); + gpr_free(wa); +} + +void grpc_channel_watch_connectivity_state_internal( + grpc_exec_ctx *exec_ctx, grpc_channel_element *client_channel_elem, + grpc_channel_stack *channel_stack, + grpc_connectivity_state last_observed_state, gpr_timespec deadline, + grpc_completion_queue *cq, void *tag) { + state_watcher *w = (state_watcher *)gpr_malloc(sizeof(*w)); + + GPR_ASSERT(grpc_cq_begin_op(cq, tag)); + + gpr_mu_init(&w->mu); + GRPC_CLOSURE_INIT(&w->on_complete, watch_complete, w, + grpc_schedule_on_exec_ctx); + GRPC_CLOSURE_INIT(&w->on_timeout, timeout_complete, w, + grpc_schedule_on_exec_ctx); + w->phase = WAITING; + w->state = last_observed_state; + w->cq = cq; + w->tag = tag; + w->client_channel_elem = client_channel_elem; + w->channel_stack = channel_stack; + w->error = NULL; + + watcher_timer_init_arg *wa = + (watcher_timer_init_arg *)gpr_malloc(sizeof(watcher_timer_init_arg)); + wa->w = w; + wa->deadline = deadline; + GRPC_CLOSURE_INIT(&w->watcher_timer_init, watcher_timer_init, wa, + grpc_schedule_on_exec_ctx); + + if (client_channel_elem->filter == &grpc_client_channel_filter) { + GRPC_CHANNEL_STACK_REF(channel_stack, "watch_channel_connectivity"); + grpc_client_channel_watch_connectivity_state( + exec_ctx, client_channel_elem, + grpc_polling_entity_create_from_pollset(grpc_cq_pollset(cq)), &w->state, + &w->on_complete, &w->watcher_timer_init); + } else { + abort(); + } +} diff --git a/src/core/ext/filters/client_channel/channel_connectivity_internal.h b/src/core/ext/filters/client_channel/channel_connectivity_internal.h new file mode 100644 index 0000000000..d260a20c07 --- /dev/null +++ b/src/core/ext/filters/client_channel/channel_connectivity_internal.h @@ -0,0 +1,33 @@ +/* + * + * Copyright 2015 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#ifndef GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_CHANNEL_CONNECTIVITY_INTERNAL_H +#define GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_CHANNEL_CONNECTIVITY_INTERNAL_H + +#include +#include "src/core/lib/channel/channel_stack.h" +#include "src/core/lib/iomgr/exec_ctx.h" + +void grpc_channel_watch_connectivity_state_internal( + grpc_exec_ctx *exec_ctx, grpc_channel_element *client_channel_elem, + grpc_channel_stack *channel_stack, + grpc_connectivity_state last_observed_state, gpr_timespec deadline, + grpc_completion_queue *cq, void *tag); + +#endif /* GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_CHANNEL_CONNECTIVITY_INTERNAL_H \ + */ diff --git a/src/core/ext/filters/client_channel/client_channel.cc b/src/core/ext/filters/client_channel/client_channel.cc index ea5e076c3b..be8ea81a02 100644 --- a/src/core/ext/filters/client_channel/client_channel.cc +++ b/src/core/ext/filters/client_channel/client_channel.cc @@ -31,6 +31,7 @@ #include #include +#include "src/core/ext/filters/client_channel/connectivity_watcher.h" #include "src/core/ext/filters/client_channel/http_connect_handshaker.h" #include "src/core/ext/filters/client_channel/lb_policy_registry.h" #include "src/core/ext/filters/client_channel/proxy_mapper_registry.h" @@ -753,6 +754,8 @@ static grpc_error *cc_init_channel_elem(grpc_exec_ctx *exec_ctx, } chand->deadline_checking_enabled = grpc_deadline_checking_enabled(args->channel_args); + grpc_client_channel_start_watching_connectivity(exec_ctx, elem, + chand->owning_stack); return GRPC_ERROR_NONE; } diff --git a/src/core/ext/filters/client_channel/connectivity_watcher.c b/src/core/ext/filters/client_channel/connectivity_watcher.c new file mode 100644 index 0000000000..da45929f26 --- /dev/null +++ b/src/core/ext/filters/client_channel/connectivity_watcher.c @@ -0,0 +1,179 @@ +/* + * + * Copyright 2015 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include "src/core/ext/filters/client_channel/connectivity_watcher.h" + +#include +#include +#include +#include +#include "src/core/ext/filters/client_channel/channel_connectivity_internal.h" +#include "src/core/ext/filters/client_channel/client_channel.h" +#include "src/core/lib/iomgr/timer.h" +#include "src/core/lib/support/env.h" +#include "src/core/lib/support/string.h" +#include "src/core/lib/surface/channel.h" +#include "src/core/lib/surface/completion_queue.h" + +#define DEFAULT_CONNECTIVITY_CHECK_INTERVAL_MS 500 + +typedef struct connectivity_watcher { + grpc_timer watcher_timer; + grpc_closure check_connectivity_closure; + grpc_completion_queue* cq; + gpr_refcount refs; + size_t channel_count; + bool shutting_down; +} connectivity_watcher; + +typedef struct channel_state { + grpc_channel_element* client_channel_elem; + grpc_channel_stack* channel_stack; + grpc_connectivity_state state; +} channel_state; + +static gpr_once g_once = GPR_ONCE_INIT; +static gpr_mu g_watcher_mu; +static connectivity_watcher* g_watcher = NULL; + +static void init_g_watcher_mu() { gpr_mu_init(&g_watcher_mu); } + +static void start_watching_locked(grpc_exec_ctx* exec_ctx, + grpc_channel_element* client_channel_elem, + grpc_channel_stack* channel_stack) { + gpr_ref(&g_watcher->refs); + ++g_watcher->channel_count; + channel_state* s = (channel_state*)gpr_zalloc(sizeof(channel_state)); + s->client_channel_elem = client_channel_elem; + s->channel_stack = channel_stack; + s->state = GRPC_CHANNEL_IDLE; + grpc_channel_watch_connectivity_state_internal( + exec_ctx, client_channel_elem, channel_stack, s->state, + gpr_inf_future(GPR_CLOCK_MONOTONIC), g_watcher->cq, (void*)s); +} + +static bool is_disabled() { + char* env = gpr_getenv("GRPC_DISABLE_CHANNEL_CONNECTIVITY_WATCHER"); + bool disabled = gpr_is_true(env); + gpr_free(env); + return disabled; +} + +static bool connectivity_watcher_unref(grpc_exec_ctx* exec_ctx) { + if (gpr_unref(&g_watcher->refs)) { + gpr_mu_lock(&g_watcher_mu); + grpc_completion_queue_destroy(g_watcher->cq); + gpr_free(g_watcher); + g_watcher = NULL; + gpr_mu_unlock(&g_watcher_mu); + return true; + } + return false; +} + +static void check_connectivity_state(grpc_exec_ctx* exec_ctx, void* ignored, + grpc_error* error) { + grpc_event ev; + while (true) { + gpr_mu_lock(&g_watcher_mu); + if (g_watcher->shutting_down) { + // Drain cq if the watcher is shutting down + ev = grpc_completion_queue_next( + g_watcher->cq, gpr_inf_future(GPR_CLOCK_MONOTONIC), NULL); + } else { + ev = grpc_completion_queue_next(g_watcher->cq, + gpr_inf_past(GPR_CLOCK_MONOTONIC), NULL); + // Make sure we've seen 2 TIMEOUTs before going to sleep + if (ev.type == GRPC_QUEUE_TIMEOUT) { + ev = grpc_completion_queue_next( + g_watcher->cq, gpr_inf_past(GPR_CLOCK_MONOTONIC), NULL); + if (ev.type == GRPC_QUEUE_TIMEOUT) { + gpr_timespec now = gpr_now(GPR_CLOCK_MONOTONIC); + grpc_timer_init( + exec_ctx, &g_watcher->watcher_timer, + gpr_time_add(now, gpr_time_from_millis( + DEFAULT_CONNECTIVITY_CHECK_INTERVAL_MS, + GPR_TIMESPAN)), + &g_watcher->check_connectivity_closure, now); + gpr_mu_unlock(&g_watcher_mu); + break; + } + } + } + gpr_mu_unlock(&g_watcher_mu); + if (ev.type != GRPC_OP_COMPLETE) { + break; + } + channel_state* s = (channel_state*)(ev.tag); + s->state = grpc_client_channel_check_connectivity_state( + exec_ctx, s->client_channel_elem, false /* try_to_connect */); + if (s->state == GRPC_CHANNEL_SHUTDOWN) { + GRPC_CHANNEL_STACK_UNREF(exec_ctx, s->channel_stack, + "connectivity_watcher_stop_watching"); + gpr_free(s); + if (connectivity_watcher_unref(exec_ctx)) { + break; + } + } else { + grpc_channel_watch_connectivity_state_internal( + exec_ctx, s->client_channel_elem, s->channel_stack, s->state, + gpr_inf_future(GPR_CLOCK_MONOTONIC), g_watcher->cq, s); + } + } +} + +void grpc_client_channel_start_watching_connectivity( + grpc_exec_ctx* exec_ctx, grpc_channel_element* client_channel_elem, + grpc_channel_stack* channel_stack) { + if (is_disabled()) return; + GRPC_CHANNEL_STACK_REF(channel_stack, "connectivity_watcher_start_watching"); + gpr_once_init(&g_once, init_g_watcher_mu); + gpr_mu_lock(&g_watcher_mu); + if (g_watcher == NULL) { + g_watcher = (connectivity_watcher*)gpr_zalloc(sizeof(connectivity_watcher)); + g_watcher->cq = grpc_completion_queue_create_internal( + GRPC_CQ_NEXT, GRPC_CQ_DEFAULT_POLLING); + gpr_ref_init(&g_watcher->refs, 0); + GRPC_CLOSURE_INIT(&g_watcher->check_connectivity_closure, + check_connectivity_state, NULL, + grpc_schedule_on_exec_ctx); + gpr_timespec now = gpr_now(GPR_CLOCK_MONOTONIC); + grpc_timer_init( + exec_ctx, &g_watcher->watcher_timer, + gpr_time_add( + now, gpr_time_from_millis(DEFAULT_CONNECTIVITY_CHECK_INTERVAL_MS, + GPR_TIMESPAN)), + &g_watcher->check_connectivity_closure, now); + } + start_watching_locked(exec_ctx, client_channel_elem, channel_stack); + gpr_mu_init(&g_watcher_mu); +} + +void grpc_client_channel_stop_watching_connectivity( + grpc_exec_ctx* exec_ctx, grpc_channel_element* client_channel_elem, + grpc_channel_stack* channel_stack) { + if (is_disabled()) return; + gpr_once_init(&g_once, init_g_watcher_mu); + gpr_mu_lock(&g_watcher_mu); + if (--g_watcher->channel_count == 0) { + g_watcher->shutting_down = true; + grpc_timer_cancel(exec_ctx, &g_watcher->watcher_timer); + connectivity_watcher_unref(exec_ctx); + } + gpr_mu_unlock(&g_watcher_mu); +} diff --git a/src/core/ext/filters/client_channel/connectivity_watcher.h b/src/core/ext/filters/client_channel/connectivity_watcher.h new file mode 100644 index 0000000000..89586dc736 --- /dev/null +++ b/src/core/ext/filters/client_channel/connectivity_watcher.h @@ -0,0 +1,30 @@ +/* + * + * Copyright 2015 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#ifndef GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_CONNECTIVITY_WATCHER_H +#define GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_CONNECTIVITY_WATCHER_H + +#include +#include "src/core/lib/channel/channel_stack.h" +#include "src/core/lib/iomgr/exec_ctx.h" + +void grpc_client_channel_start_watching_connectivity( + grpc_exec_ctx* exec_ctx, grpc_channel_element* client_channel_elem, + grpc_channel_stack* channel_stack); + +#endif /* GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_CONNECTIVITY_WATCHER_H */ diff --git a/src/python/grpcio/grpc_core_dependencies.py b/src/python/grpcio/grpc_core_dependencies.py index 140f4ceee1..467b13f22b 100644 --- a/src/python/grpcio/grpc_core_dependencies.py +++ b/src/python/grpcio/grpc_core_dependencies.py @@ -258,6 +258,7 @@ CORE_SOURCE_FILES = [ 'src/core/ext/filters/client_channel/client_channel.cc', 'src/core/ext/filters/client_channel/client_channel_factory.cc', 'src/core/ext/filters/client_channel/client_channel_plugin.cc', + 'src/core/ext/filters/client_channel/connectivity_watcher.c', 'src/core/ext/filters/client_channel/connector.cc', 'src/core/ext/filters/client_channel/http_connect_handshaker.cc', 'src/core/ext/filters/client_channel/http_proxy.cc', diff --git a/tools/doxygen/Doxyfile.core.internal b/tools/doxygen/Doxyfile.core.internal index e0536423fa..bed3845db2 100644 --- a/tools/doxygen/Doxyfile.core.internal +++ b/tools/doxygen/Doxyfile.core.internal @@ -908,11 +908,14 @@ src/core/ext/census/tracing.cc \ src/core/ext/census/tracing.h \ src/core/ext/filters/client_channel/README.md \ src/core/ext/filters/client_channel/channel_connectivity.cc \ +src/core/ext/filters/client_channel/channel_connectivity_internal.h \ src/core/ext/filters/client_channel/client_channel.cc \ src/core/ext/filters/client_channel/client_channel.h \ src/core/ext/filters/client_channel/client_channel_factory.cc \ src/core/ext/filters/client_channel/client_channel_factory.h \ src/core/ext/filters/client_channel/client_channel_plugin.cc \ +src/core/ext/filters/client_channel/connectivity_watcher.c \ +src/core/ext/filters/client_channel/connectivity_watcher.h \ src/core/ext/filters/client_channel/connector.cc \ src/core/ext/filters/client_channel/connector.h \ src/core/ext/filters/client_channel/http_connect_handshaker.cc \ diff --git a/tools/run_tests/generated/sources_and_headers.json b/tools/run_tests/generated/sources_and_headers.json index 08ab2a5d93..af7b7ee9a0 100644 --- a/tools/run_tests/generated/sources_and_headers.json +++ b/tools/run_tests/generated/sources_and_headers.json @@ -8467,8 +8467,10 @@ "grpc_deadline_filter" ], "headers": [ + "src/core/ext/filters/client_channel/channel_connectivity_internal.h", "src/core/ext/filters/client_channel/client_channel.h", "src/core/ext/filters/client_channel/client_channel_factory.h", + "src/core/ext/filters/client_channel/connectivity_watcher.h", "src/core/ext/filters/client_channel/connector.h", "src/core/ext/filters/client_channel/http_connect_handshaker.h", "src/core/ext/filters/client_channel/http_proxy.h", @@ -8491,11 +8493,14 @@ "name": "grpc_client_channel", "src": [ "src/core/ext/filters/client_channel/channel_connectivity.cc", + "src/core/ext/filters/client_channel/channel_connectivity_internal.h", "src/core/ext/filters/client_channel/client_channel.cc", "src/core/ext/filters/client_channel/client_channel.h", "src/core/ext/filters/client_channel/client_channel_factory.cc", "src/core/ext/filters/client_channel/client_channel_factory.h", "src/core/ext/filters/client_channel/client_channel_plugin.cc", + "src/core/ext/filters/client_channel/connectivity_watcher.c", + "src/core/ext/filters/client_channel/connectivity_watcher.h", "src/core/ext/filters/client_channel/connector.cc", "src/core/ext/filters/client_channel/connector.h", "src/core/ext/filters/client_channel/http_connect_handshaker.cc", -- cgit v1.2.3 From f8ed4fa7f4b516d98daeefb0459ce1b175baa7e3 Mon Sep 17 00:00:00 2001 From: Yuchen Zeng Date: Thu, 5 Oct 2017 13:15:49 -0700 Subject: convert connectivity_watcher to cpp file --- BUILD | 1 + CMakeLists.txt | 18 ++- Makefile | 18 ++- binding.gyp | 3 +- build.yaml | 4 + config.m4 | 3 +- config.w32 | 3 +- gRPC-Core.podspec | 3 +- grpc.gemspec | 3 +- grpc.gyp | 12 +- package.xml | 3 +- .../filters/client_channel/connectivity_watcher.c | 179 --------------------- .../filters/client_channel/connectivity_watcher.cc | 179 +++++++++++++++++++++ src/python/grpcio/grpc_core_dependencies.py | 3 +- tools/doxygen/Doxyfile.core.internal | 3 +- tools/run_tests/generated/sources_and_headers.json | 3 +- 16 files changed, 234 insertions(+), 204 deletions(-) delete mode 100644 src/core/ext/filters/client_channel/connectivity_watcher.c create mode 100644 src/core/ext/filters/client_channel/connectivity_watcher.cc (limited to 'tools') diff --git a/BUILD b/BUILD index 4e1f61ee10..0e59e78db4 100644 --- a/BUILD +++ b/BUILD @@ -872,6 +872,7 @@ grpc_cc_library( grpc_cc_library( name = "grpc_client_channel", srcs = [ + "src/core/ext/filters/client_channel/channel_connectivity_internal.cc", "src/core/ext/filters/client_channel/channel_connectivity.cc", "src/core/ext/filters/client_channel/client_channel.cc", "src/core/ext/filters/client_channel/client_channel_factory.cc", diff --git a/CMakeLists.txt b/CMakeLists.txt index 8122d4b025..c00a9e04a0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1154,10 +1154,11 @@ add_library(grpc src/core/ext/transport/chttp2/server/chttp2_server.cc src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc src/core/ext/filters/client_channel/channel_connectivity.cc + src/core/ext/filters/client_channel/channel_connectivity_internal.cc src/core/ext/filters/client_channel/client_channel.cc src/core/ext/filters/client_channel/client_channel_factory.cc src/core/ext/filters/client_channel/client_channel_plugin.cc - src/core/ext/filters/client_channel/connectivity_watcher.c + src/core/ext/filters/client_channel/connectivity_watcher.cc src/core/ext/filters/client_channel/connector.cc src/core/ext/filters/client_channel/http_connect_handshaker.cc src/core/ext/filters/client_channel/http_proxy.cc @@ -1479,10 +1480,11 @@ add_library(grpc_cronet src/core/ext/filters/http/message_compress/message_compress_filter.cc src/core/ext/filters/http/server/http_server_filter.cc src/core/ext/filters/client_channel/channel_connectivity.cc + src/core/ext/filters/client_channel/channel_connectivity_internal.cc src/core/ext/filters/client_channel/client_channel.cc src/core/ext/filters/client_channel/client_channel_factory.cc src/core/ext/filters/client_channel/client_channel_plugin.cc - src/core/ext/filters/client_channel/connectivity_watcher.c + src/core/ext/filters/client_channel/connectivity_watcher.cc src/core/ext/filters/client_channel/connector.cc src/core/ext/filters/client_channel/http_connect_handshaker.cc src/core/ext/filters/client_channel/http_proxy.cc @@ -1770,10 +1772,11 @@ add_library(grpc_test_util src/core/lib/transport/transport_op_string.cc src/core/lib/debug/trace.cc src/core/ext/filters/client_channel/channel_connectivity.cc + src/core/ext/filters/client_channel/channel_connectivity_internal.cc src/core/ext/filters/client_channel/client_channel.cc src/core/ext/filters/client_channel/client_channel_factory.cc src/core/ext/filters/client_channel/client_channel_plugin.cc - src/core/ext/filters/client_channel/connectivity_watcher.c + src/core/ext/filters/client_channel/connectivity_watcher.cc src/core/ext/filters/client_channel/connector.cc src/core/ext/filters/client_channel/http_connect_handshaker.cc src/core/ext/filters/client_channel/http_proxy.cc @@ -2036,10 +2039,11 @@ add_library(grpc_test_util_unsecure src/core/lib/transport/transport_op_string.cc src/core/lib/debug/trace.cc src/core/ext/filters/client_channel/channel_connectivity.cc + src/core/ext/filters/client_channel/channel_connectivity_internal.cc src/core/ext/filters/client_channel/client_channel.cc src/core/ext/filters/client_channel/client_channel_factory.cc src/core/ext/filters/client_channel/client_channel_plugin.cc - src/core/ext/filters/client_channel/connectivity_watcher.c + src/core/ext/filters/client_channel/connectivity_watcher.cc src/core/ext/filters/client_channel/connector.cc src/core/ext/filters/client_channel/http_connect_handshaker.cc src/core/ext/filters/client_channel/http_proxy.cc @@ -2321,10 +2325,11 @@ add_library(grpc_unsecure src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc src/core/ext/transport/chttp2/client/chttp2_connector.cc src/core/ext/filters/client_channel/channel_connectivity.cc + src/core/ext/filters/client_channel/channel_connectivity_internal.cc src/core/ext/filters/client_channel/client_channel.cc src/core/ext/filters/client_channel/client_channel_factory.cc src/core/ext/filters/client_channel/client_channel_plugin.cc - src/core/ext/filters/client_channel/connectivity_watcher.c + src/core/ext/filters/client_channel/connectivity_watcher.cc src/core/ext/filters/client_channel/connector.cc src/core/ext/filters/client_channel/http_connect_handshaker.cc src/core/ext/filters/client_channel/http_proxy.cc @@ -3057,10 +3062,11 @@ add_library(grpc++_cronet src/core/ext/filters/http/message_compress/message_compress_filter.cc src/core/ext/filters/http/server/http_server_filter.cc src/core/ext/filters/client_channel/channel_connectivity.cc + src/core/ext/filters/client_channel/channel_connectivity_internal.cc src/core/ext/filters/client_channel/client_channel.cc src/core/ext/filters/client_channel/client_channel_factory.cc src/core/ext/filters/client_channel/client_channel_plugin.cc - src/core/ext/filters/client_channel/connectivity_watcher.c + src/core/ext/filters/client_channel/connectivity_watcher.cc src/core/ext/filters/client_channel/connector.cc src/core/ext/filters/client_channel/http_connect_handshaker.cc src/core/ext/filters/client_channel/http_proxy.cc diff --git a/Makefile b/Makefile index 3ff9b39f45..bda3c3fce4 100644 --- a/Makefile +++ b/Makefile @@ -3154,10 +3154,11 @@ LIBGRPC_SRC = \ src/core/ext/transport/chttp2/server/chttp2_server.cc \ src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc \ src/core/ext/filters/client_channel/channel_connectivity.cc \ + src/core/ext/filters/client_channel/channel_connectivity_internal.cc \ src/core/ext/filters/client_channel/client_channel.cc \ src/core/ext/filters/client_channel/client_channel_factory.cc \ src/core/ext/filters/client_channel/client_channel_plugin.cc \ - src/core/ext/filters/client_channel/connectivity_watcher.c \ + src/core/ext/filters/client_channel/connectivity_watcher.cc \ src/core/ext/filters/client_channel/connector.cc \ src/core/ext/filters/client_channel/http_connect_handshaker.cc \ src/core/ext/filters/client_channel/http_proxy.cc \ @@ -3478,10 +3479,11 @@ LIBGRPC_CRONET_SRC = \ src/core/ext/filters/http/message_compress/message_compress_filter.cc \ src/core/ext/filters/http/server/http_server_filter.cc \ src/core/ext/filters/client_channel/channel_connectivity.cc \ + src/core/ext/filters/client_channel/channel_connectivity_internal.cc \ src/core/ext/filters/client_channel/client_channel.cc \ src/core/ext/filters/client_channel/client_channel_factory.cc \ src/core/ext/filters/client_channel/client_channel_plugin.cc \ - src/core/ext/filters/client_channel/connectivity_watcher.c \ + src/core/ext/filters/client_channel/connectivity_watcher.cc \ src/core/ext/filters/client_channel/connector.cc \ src/core/ext/filters/client_channel/http_connect_handshaker.cc \ src/core/ext/filters/client_channel/http_proxy.cc \ @@ -3767,10 +3769,11 @@ LIBGRPC_TEST_UTIL_SRC = \ src/core/lib/transport/transport_op_string.cc \ src/core/lib/debug/trace.cc \ src/core/ext/filters/client_channel/channel_connectivity.cc \ + src/core/ext/filters/client_channel/channel_connectivity_internal.cc \ src/core/ext/filters/client_channel/client_channel.cc \ src/core/ext/filters/client_channel/client_channel_factory.cc \ src/core/ext/filters/client_channel/client_channel_plugin.cc \ - src/core/ext/filters/client_channel/connectivity_watcher.c \ + src/core/ext/filters/client_channel/connectivity_watcher.cc \ src/core/ext/filters/client_channel/connector.cc \ src/core/ext/filters/client_channel/http_connect_handshaker.cc \ src/core/ext/filters/client_channel/http_proxy.cc \ @@ -4023,10 +4026,11 @@ LIBGRPC_TEST_UTIL_UNSECURE_SRC = \ src/core/lib/transport/transport_op_string.cc \ src/core/lib/debug/trace.cc \ src/core/ext/filters/client_channel/channel_connectivity.cc \ + src/core/ext/filters/client_channel/channel_connectivity_internal.cc \ src/core/ext/filters/client_channel/client_channel.cc \ src/core/ext/filters/client_channel/client_channel_factory.cc \ src/core/ext/filters/client_channel/client_channel_plugin.cc \ - src/core/ext/filters/client_channel/connectivity_watcher.c \ + src/core/ext/filters/client_channel/connectivity_watcher.cc \ src/core/ext/filters/client_channel/connector.cc \ src/core/ext/filters/client_channel/http_connect_handshaker.cc \ src/core/ext/filters/client_channel/http_proxy.cc \ @@ -4285,10 +4289,11 @@ LIBGRPC_UNSECURE_SRC = \ src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc \ src/core/ext/transport/chttp2/client/chttp2_connector.cc \ src/core/ext/filters/client_channel/channel_connectivity.cc \ + src/core/ext/filters/client_channel/channel_connectivity_internal.cc \ src/core/ext/filters/client_channel/client_channel.cc \ src/core/ext/filters/client_channel/client_channel_factory.cc \ src/core/ext/filters/client_channel/client_channel_plugin.cc \ - src/core/ext/filters/client_channel/connectivity_watcher.c \ + src/core/ext/filters/client_channel/connectivity_watcher.cc \ src/core/ext/filters/client_channel/connector.cc \ src/core/ext/filters/client_channel/http_connect_handshaker.cc \ src/core/ext/filters/client_channel/http_proxy.cc \ @@ -4999,10 +5004,11 @@ LIBGRPC++_CRONET_SRC = \ src/core/ext/filters/http/message_compress/message_compress_filter.cc \ src/core/ext/filters/http/server/http_server_filter.cc \ src/core/ext/filters/client_channel/channel_connectivity.cc \ + src/core/ext/filters/client_channel/channel_connectivity_internal.cc \ src/core/ext/filters/client_channel/client_channel.cc \ src/core/ext/filters/client_channel/client_channel_factory.cc \ src/core/ext/filters/client_channel/client_channel_plugin.cc \ - src/core/ext/filters/client_channel/connectivity_watcher.c \ + src/core/ext/filters/client_channel/connectivity_watcher.cc \ src/core/ext/filters/client_channel/connector.cc \ src/core/ext/filters/client_channel/http_connect_handshaker.cc \ src/core/ext/filters/client_channel/http_proxy.cc \ diff --git a/binding.gyp b/binding.gyp index 707afb476a..ff7bf8fcda 100644 --- a/binding.gyp +++ b/binding.gyp @@ -854,10 +854,11 @@ 'src/core/ext/transport/chttp2/server/chttp2_server.cc', 'src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc', 'src/core/ext/filters/client_channel/channel_connectivity.cc', + 'src/core/ext/filters/client_channel/channel_connectivity_internal.cc', 'src/core/ext/filters/client_channel/client_channel.cc', 'src/core/ext/filters/client_channel/client_channel_factory.cc', 'src/core/ext/filters/client_channel/client_channel_plugin.cc', - 'src/core/ext/filters/client_channel/connectivity_watcher.c', + 'src/core/ext/filters/client_channel/connectivity_watcher.cc', 'src/core/ext/filters/client_channel/connector.cc', 'src/core/ext/filters/client_channel/http_connect_handshaker.cc', 'src/core/ext/filters/client_channel/http_proxy.cc', diff --git a/build.yaml b/build.yaml index 592cbb9f8c..6308b08040 100644 --- a/build.yaml +++ b/build.yaml @@ -463,8 +463,10 @@ filegroups: - grpc_trace_headers - name: grpc_client_channel headers: + - src/core/ext/filters/client_channel/channel_connectivity_internal.h - src/core/ext/filters/client_channel/client_channel.h - src/core/ext/filters/client_channel/client_channel_factory.h + - src/core/ext/filters/client_channel/connectivity_watcher.h - src/core/ext/filters/client_channel/connector.h - src/core/ext/filters/client_channel/http_connect_handshaker.h - src/core/ext/filters/client_channel/http_proxy.h @@ -483,9 +485,11 @@ filegroups: - src/core/ext/filters/client_channel/uri_parser.h src: - src/core/ext/filters/client_channel/channel_connectivity.cc + - src/core/ext/filters/client_channel/channel_connectivity_internal.cc - src/core/ext/filters/client_channel/client_channel.cc - src/core/ext/filters/client_channel/client_channel_factory.cc - src/core/ext/filters/client_channel/client_channel_plugin.cc + - src/core/ext/filters/client_channel/connectivity_watcher.cc - src/core/ext/filters/client_channel/connector.cc - src/core/ext/filters/client_channel/http_connect_handshaker.cc - src/core/ext/filters/client_channel/http_proxy.cc diff --git a/config.m4 b/config.m4 index eaa3af978b..ca374cec0d 100644 --- a/config.m4 +++ b/config.m4 @@ -279,10 +279,11 @@ if test "$PHP_GRPC" != "no"; then src/core/ext/transport/chttp2/server/chttp2_server.cc \ src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc \ src/core/ext/filters/client_channel/channel_connectivity.cc \ + src/core/ext/filters/client_channel/channel_connectivity_internal.cc \ src/core/ext/filters/client_channel/client_channel.cc \ src/core/ext/filters/client_channel/client_channel_factory.cc \ src/core/ext/filters/client_channel/client_channel_plugin.cc \ - src/core/ext/filters/client_channel/connectivity_watcher.c \ + src/core/ext/filters/client_channel/connectivity_watcher.cc \ src/core/ext/filters/client_channel/connector.cc \ src/core/ext/filters/client_channel/http_connect_handshaker.cc \ src/core/ext/filters/client_channel/http_proxy.cc \ diff --git a/config.w32 b/config.w32 index 75a83e2414..0db7620b30 100644 --- a/config.w32 +++ b/config.w32 @@ -256,10 +256,11 @@ if (PHP_GRPC != "no") { "src\\core\\ext\\transport\\chttp2\\server\\chttp2_server.cc " + "src\\core\\ext\\transport\\chttp2\\client\\secure\\secure_channel_create.cc " + "src\\core\\ext\\filters\\client_channel\\channel_connectivity.cc " + + "src\\core\\ext\\filters\\client_channel\\channel_connectivity_internal.cc " + "src\\core\\ext\\filters\\client_channel\\client_channel.cc " + "src\\core\\ext\\filters\\client_channel\\client_channel_factory.cc " + "src\\core\\ext\\filters\\client_channel\\client_channel_plugin.cc " + - "src\\core\\ext\\filters\\client_channel\\connectivity_watcher.c " + + "src\\core\\ext\\filters\\client_channel\\connectivity_watcher.cc " + "src\\core\\ext\\filters\\client_channel\\connector.cc " + "src\\core\\ext\\filters\\client_channel\\http_connect_handshaker.cc " + "src\\core\\ext\\filters\\client_channel\\http_proxy.cc " + diff --git a/gRPC-Core.podspec b/gRPC-Core.podspec index 9b4f4ec675..b0ac155e54 100644 --- a/gRPC-Core.podspec +++ b/gRPC-Core.podspec @@ -671,10 +671,11 @@ Pod::Spec.new do |s| 'src/core/ext/transport/chttp2/server/chttp2_server.cc', 'src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc', 'src/core/ext/filters/client_channel/channel_connectivity.cc', + 'src/core/ext/filters/client_channel/channel_connectivity_internal.cc', 'src/core/ext/filters/client_channel/client_channel.cc', 'src/core/ext/filters/client_channel/client_channel_factory.cc', 'src/core/ext/filters/client_channel/client_channel_plugin.cc', - 'src/core/ext/filters/client_channel/connectivity_watcher.c', + 'src/core/ext/filters/client_channel/connectivity_watcher.cc', 'src/core/ext/filters/client_channel/connector.cc', 'src/core/ext/filters/client_channel/http_connect_handshaker.cc', 'src/core/ext/filters/client_channel/http_proxy.cc', diff --git a/grpc.gemspec b/grpc.gemspec index 9f5f45bb1b..c791adf74b 100644 --- a/grpc.gemspec +++ b/grpc.gemspec @@ -606,10 +606,11 @@ Gem::Specification.new do |s| s.files += %w( src/core/ext/transport/chttp2/server/chttp2_server.cc ) s.files += %w( src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc ) s.files += %w( src/core/ext/filters/client_channel/channel_connectivity.cc ) + s.files += %w( src/core/ext/filters/client_channel/channel_connectivity_internal.cc ) s.files += %w( src/core/ext/filters/client_channel/client_channel.cc ) s.files += %w( src/core/ext/filters/client_channel/client_channel_factory.cc ) s.files += %w( src/core/ext/filters/client_channel/client_channel_plugin.cc ) - s.files += %w( src/core/ext/filters/client_channel/connectivity_watcher.c ) + s.files += %w( src/core/ext/filters/client_channel/connectivity_watcher.cc ) s.files += %w( src/core/ext/filters/client_channel/connector.cc ) s.files += %w( src/core/ext/filters/client_channel/http_connect_handshaker.cc ) s.files += %w( src/core/ext/filters/client_channel/http_proxy.cc ) diff --git a/grpc.gyp b/grpc.gyp index 420621fb4c..96224ab889 100644 --- a/grpc.gyp +++ b/grpc.gyp @@ -420,10 +420,11 @@ 'src/core/ext/transport/chttp2/server/chttp2_server.cc', 'src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc', 'src/core/ext/filters/client_channel/channel_connectivity.cc', + 'src/core/ext/filters/client_channel/channel_connectivity_internal.cc', 'src/core/ext/filters/client_channel/client_channel.cc', 'src/core/ext/filters/client_channel/client_channel_factory.cc', 'src/core/ext/filters/client_channel/client_channel_plugin.cc', - 'src/core/ext/filters/client_channel/connectivity_watcher.c', + 'src/core/ext/filters/client_channel/connectivity_watcher.cc', 'src/core/ext/filters/client_channel/connector.cc', 'src/core/ext/filters/client_channel/http_connect_handshaker.cc', 'src/core/ext/filters/client_channel/http_proxy.cc', @@ -663,10 +664,11 @@ 'src/core/lib/transport/transport_op_string.cc', 'src/core/lib/debug/trace.cc', 'src/core/ext/filters/client_channel/channel_connectivity.cc', + 'src/core/ext/filters/client_channel/channel_connectivity_internal.cc', 'src/core/ext/filters/client_channel/client_channel.cc', 'src/core/ext/filters/client_channel/client_channel_factory.cc', 'src/core/ext/filters/client_channel/client_channel_plugin.cc', - 'src/core/ext/filters/client_channel/connectivity_watcher.c', + 'src/core/ext/filters/client_channel/connectivity_watcher.cc', 'src/core/ext/filters/client_channel/connector.cc', 'src/core/ext/filters/client_channel/http_connect_handshaker.cc', 'src/core/ext/filters/client_channel/http_proxy.cc', @@ -871,10 +873,11 @@ 'src/core/lib/transport/transport_op_string.cc', 'src/core/lib/debug/trace.cc', 'src/core/ext/filters/client_channel/channel_connectivity.cc', + 'src/core/ext/filters/client_channel/channel_connectivity_internal.cc', 'src/core/ext/filters/client_channel/client_channel.cc', 'src/core/ext/filters/client_channel/client_channel_factory.cc', 'src/core/ext/filters/client_channel/client_channel_plugin.cc', - 'src/core/ext/filters/client_channel/connectivity_watcher.c', + 'src/core/ext/filters/client_channel/connectivity_watcher.cc', 'src/core/ext/filters/client_channel/connector.cc', 'src/core/ext/filters/client_channel/http_connect_handshaker.cc', 'src/core/ext/filters/client_channel/http_proxy.cc', @@ -1097,10 +1100,11 @@ 'src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc', 'src/core/ext/transport/chttp2/client/chttp2_connector.cc', 'src/core/ext/filters/client_channel/channel_connectivity.cc', + 'src/core/ext/filters/client_channel/channel_connectivity_internal.cc', 'src/core/ext/filters/client_channel/client_channel.cc', 'src/core/ext/filters/client_channel/client_channel_factory.cc', 'src/core/ext/filters/client_channel/client_channel_plugin.cc', - 'src/core/ext/filters/client_channel/connectivity_watcher.c', + 'src/core/ext/filters/client_channel/connectivity_watcher.cc', 'src/core/ext/filters/client_channel/connector.cc', 'src/core/ext/filters/client_channel/http_connect_handshaker.cc', 'src/core/ext/filters/client_channel/http_proxy.cc', diff --git a/package.xml b/package.xml index 65cb53ad1c..b78b210069 100644 --- a/package.xml +++ b/package.xml @@ -618,10 +618,11 @@ + - + diff --git a/src/core/ext/filters/client_channel/connectivity_watcher.c b/src/core/ext/filters/client_channel/connectivity_watcher.c deleted file mode 100644 index da45929f26..0000000000 --- a/src/core/ext/filters/client_channel/connectivity_watcher.c +++ /dev/null @@ -1,179 +0,0 @@ -/* - * - * Copyright 2015 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include "src/core/ext/filters/client_channel/connectivity_watcher.h" - -#include -#include -#include -#include -#include "src/core/ext/filters/client_channel/channel_connectivity_internal.h" -#include "src/core/ext/filters/client_channel/client_channel.h" -#include "src/core/lib/iomgr/timer.h" -#include "src/core/lib/support/env.h" -#include "src/core/lib/support/string.h" -#include "src/core/lib/surface/channel.h" -#include "src/core/lib/surface/completion_queue.h" - -#define DEFAULT_CONNECTIVITY_CHECK_INTERVAL_MS 500 - -typedef struct connectivity_watcher { - grpc_timer watcher_timer; - grpc_closure check_connectivity_closure; - grpc_completion_queue* cq; - gpr_refcount refs; - size_t channel_count; - bool shutting_down; -} connectivity_watcher; - -typedef struct channel_state { - grpc_channel_element* client_channel_elem; - grpc_channel_stack* channel_stack; - grpc_connectivity_state state; -} channel_state; - -static gpr_once g_once = GPR_ONCE_INIT; -static gpr_mu g_watcher_mu; -static connectivity_watcher* g_watcher = NULL; - -static void init_g_watcher_mu() { gpr_mu_init(&g_watcher_mu); } - -static void start_watching_locked(grpc_exec_ctx* exec_ctx, - grpc_channel_element* client_channel_elem, - grpc_channel_stack* channel_stack) { - gpr_ref(&g_watcher->refs); - ++g_watcher->channel_count; - channel_state* s = (channel_state*)gpr_zalloc(sizeof(channel_state)); - s->client_channel_elem = client_channel_elem; - s->channel_stack = channel_stack; - s->state = GRPC_CHANNEL_IDLE; - grpc_channel_watch_connectivity_state_internal( - exec_ctx, client_channel_elem, channel_stack, s->state, - gpr_inf_future(GPR_CLOCK_MONOTONIC), g_watcher->cq, (void*)s); -} - -static bool is_disabled() { - char* env = gpr_getenv("GRPC_DISABLE_CHANNEL_CONNECTIVITY_WATCHER"); - bool disabled = gpr_is_true(env); - gpr_free(env); - return disabled; -} - -static bool connectivity_watcher_unref(grpc_exec_ctx* exec_ctx) { - if (gpr_unref(&g_watcher->refs)) { - gpr_mu_lock(&g_watcher_mu); - grpc_completion_queue_destroy(g_watcher->cq); - gpr_free(g_watcher); - g_watcher = NULL; - gpr_mu_unlock(&g_watcher_mu); - return true; - } - return false; -} - -static void check_connectivity_state(grpc_exec_ctx* exec_ctx, void* ignored, - grpc_error* error) { - grpc_event ev; - while (true) { - gpr_mu_lock(&g_watcher_mu); - if (g_watcher->shutting_down) { - // Drain cq if the watcher is shutting down - ev = grpc_completion_queue_next( - g_watcher->cq, gpr_inf_future(GPR_CLOCK_MONOTONIC), NULL); - } else { - ev = grpc_completion_queue_next(g_watcher->cq, - gpr_inf_past(GPR_CLOCK_MONOTONIC), NULL); - // Make sure we've seen 2 TIMEOUTs before going to sleep - if (ev.type == GRPC_QUEUE_TIMEOUT) { - ev = grpc_completion_queue_next( - g_watcher->cq, gpr_inf_past(GPR_CLOCK_MONOTONIC), NULL); - if (ev.type == GRPC_QUEUE_TIMEOUT) { - gpr_timespec now = gpr_now(GPR_CLOCK_MONOTONIC); - grpc_timer_init( - exec_ctx, &g_watcher->watcher_timer, - gpr_time_add(now, gpr_time_from_millis( - DEFAULT_CONNECTIVITY_CHECK_INTERVAL_MS, - GPR_TIMESPAN)), - &g_watcher->check_connectivity_closure, now); - gpr_mu_unlock(&g_watcher_mu); - break; - } - } - } - gpr_mu_unlock(&g_watcher_mu); - if (ev.type != GRPC_OP_COMPLETE) { - break; - } - channel_state* s = (channel_state*)(ev.tag); - s->state = grpc_client_channel_check_connectivity_state( - exec_ctx, s->client_channel_elem, false /* try_to_connect */); - if (s->state == GRPC_CHANNEL_SHUTDOWN) { - GRPC_CHANNEL_STACK_UNREF(exec_ctx, s->channel_stack, - "connectivity_watcher_stop_watching"); - gpr_free(s); - if (connectivity_watcher_unref(exec_ctx)) { - break; - } - } else { - grpc_channel_watch_connectivity_state_internal( - exec_ctx, s->client_channel_elem, s->channel_stack, s->state, - gpr_inf_future(GPR_CLOCK_MONOTONIC), g_watcher->cq, s); - } - } -} - -void grpc_client_channel_start_watching_connectivity( - grpc_exec_ctx* exec_ctx, grpc_channel_element* client_channel_elem, - grpc_channel_stack* channel_stack) { - if (is_disabled()) return; - GRPC_CHANNEL_STACK_REF(channel_stack, "connectivity_watcher_start_watching"); - gpr_once_init(&g_once, init_g_watcher_mu); - gpr_mu_lock(&g_watcher_mu); - if (g_watcher == NULL) { - g_watcher = (connectivity_watcher*)gpr_zalloc(sizeof(connectivity_watcher)); - g_watcher->cq = grpc_completion_queue_create_internal( - GRPC_CQ_NEXT, GRPC_CQ_DEFAULT_POLLING); - gpr_ref_init(&g_watcher->refs, 0); - GRPC_CLOSURE_INIT(&g_watcher->check_connectivity_closure, - check_connectivity_state, NULL, - grpc_schedule_on_exec_ctx); - gpr_timespec now = gpr_now(GPR_CLOCK_MONOTONIC); - grpc_timer_init( - exec_ctx, &g_watcher->watcher_timer, - gpr_time_add( - now, gpr_time_from_millis(DEFAULT_CONNECTIVITY_CHECK_INTERVAL_MS, - GPR_TIMESPAN)), - &g_watcher->check_connectivity_closure, now); - } - start_watching_locked(exec_ctx, client_channel_elem, channel_stack); - gpr_mu_init(&g_watcher_mu); -} - -void grpc_client_channel_stop_watching_connectivity( - grpc_exec_ctx* exec_ctx, grpc_channel_element* client_channel_elem, - grpc_channel_stack* channel_stack) { - if (is_disabled()) return; - gpr_once_init(&g_once, init_g_watcher_mu); - gpr_mu_lock(&g_watcher_mu); - if (--g_watcher->channel_count == 0) { - g_watcher->shutting_down = true; - grpc_timer_cancel(exec_ctx, &g_watcher->watcher_timer); - connectivity_watcher_unref(exec_ctx); - } - gpr_mu_unlock(&g_watcher_mu); -} diff --git a/src/core/ext/filters/client_channel/connectivity_watcher.cc b/src/core/ext/filters/client_channel/connectivity_watcher.cc new file mode 100644 index 0000000000..da45929f26 --- /dev/null +++ b/src/core/ext/filters/client_channel/connectivity_watcher.cc @@ -0,0 +1,179 @@ +/* + * + * Copyright 2015 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include "src/core/ext/filters/client_channel/connectivity_watcher.h" + +#include +#include +#include +#include +#include "src/core/ext/filters/client_channel/channel_connectivity_internal.h" +#include "src/core/ext/filters/client_channel/client_channel.h" +#include "src/core/lib/iomgr/timer.h" +#include "src/core/lib/support/env.h" +#include "src/core/lib/support/string.h" +#include "src/core/lib/surface/channel.h" +#include "src/core/lib/surface/completion_queue.h" + +#define DEFAULT_CONNECTIVITY_CHECK_INTERVAL_MS 500 + +typedef struct connectivity_watcher { + grpc_timer watcher_timer; + grpc_closure check_connectivity_closure; + grpc_completion_queue* cq; + gpr_refcount refs; + size_t channel_count; + bool shutting_down; +} connectivity_watcher; + +typedef struct channel_state { + grpc_channel_element* client_channel_elem; + grpc_channel_stack* channel_stack; + grpc_connectivity_state state; +} channel_state; + +static gpr_once g_once = GPR_ONCE_INIT; +static gpr_mu g_watcher_mu; +static connectivity_watcher* g_watcher = NULL; + +static void init_g_watcher_mu() { gpr_mu_init(&g_watcher_mu); } + +static void start_watching_locked(grpc_exec_ctx* exec_ctx, + grpc_channel_element* client_channel_elem, + grpc_channel_stack* channel_stack) { + gpr_ref(&g_watcher->refs); + ++g_watcher->channel_count; + channel_state* s = (channel_state*)gpr_zalloc(sizeof(channel_state)); + s->client_channel_elem = client_channel_elem; + s->channel_stack = channel_stack; + s->state = GRPC_CHANNEL_IDLE; + grpc_channel_watch_connectivity_state_internal( + exec_ctx, client_channel_elem, channel_stack, s->state, + gpr_inf_future(GPR_CLOCK_MONOTONIC), g_watcher->cq, (void*)s); +} + +static bool is_disabled() { + char* env = gpr_getenv("GRPC_DISABLE_CHANNEL_CONNECTIVITY_WATCHER"); + bool disabled = gpr_is_true(env); + gpr_free(env); + return disabled; +} + +static bool connectivity_watcher_unref(grpc_exec_ctx* exec_ctx) { + if (gpr_unref(&g_watcher->refs)) { + gpr_mu_lock(&g_watcher_mu); + grpc_completion_queue_destroy(g_watcher->cq); + gpr_free(g_watcher); + g_watcher = NULL; + gpr_mu_unlock(&g_watcher_mu); + return true; + } + return false; +} + +static void check_connectivity_state(grpc_exec_ctx* exec_ctx, void* ignored, + grpc_error* error) { + grpc_event ev; + while (true) { + gpr_mu_lock(&g_watcher_mu); + if (g_watcher->shutting_down) { + // Drain cq if the watcher is shutting down + ev = grpc_completion_queue_next( + g_watcher->cq, gpr_inf_future(GPR_CLOCK_MONOTONIC), NULL); + } else { + ev = grpc_completion_queue_next(g_watcher->cq, + gpr_inf_past(GPR_CLOCK_MONOTONIC), NULL); + // Make sure we've seen 2 TIMEOUTs before going to sleep + if (ev.type == GRPC_QUEUE_TIMEOUT) { + ev = grpc_completion_queue_next( + g_watcher->cq, gpr_inf_past(GPR_CLOCK_MONOTONIC), NULL); + if (ev.type == GRPC_QUEUE_TIMEOUT) { + gpr_timespec now = gpr_now(GPR_CLOCK_MONOTONIC); + grpc_timer_init( + exec_ctx, &g_watcher->watcher_timer, + gpr_time_add(now, gpr_time_from_millis( + DEFAULT_CONNECTIVITY_CHECK_INTERVAL_MS, + GPR_TIMESPAN)), + &g_watcher->check_connectivity_closure, now); + gpr_mu_unlock(&g_watcher_mu); + break; + } + } + } + gpr_mu_unlock(&g_watcher_mu); + if (ev.type != GRPC_OP_COMPLETE) { + break; + } + channel_state* s = (channel_state*)(ev.tag); + s->state = grpc_client_channel_check_connectivity_state( + exec_ctx, s->client_channel_elem, false /* try_to_connect */); + if (s->state == GRPC_CHANNEL_SHUTDOWN) { + GRPC_CHANNEL_STACK_UNREF(exec_ctx, s->channel_stack, + "connectivity_watcher_stop_watching"); + gpr_free(s); + if (connectivity_watcher_unref(exec_ctx)) { + break; + } + } else { + grpc_channel_watch_connectivity_state_internal( + exec_ctx, s->client_channel_elem, s->channel_stack, s->state, + gpr_inf_future(GPR_CLOCK_MONOTONIC), g_watcher->cq, s); + } + } +} + +void grpc_client_channel_start_watching_connectivity( + grpc_exec_ctx* exec_ctx, grpc_channel_element* client_channel_elem, + grpc_channel_stack* channel_stack) { + if (is_disabled()) return; + GRPC_CHANNEL_STACK_REF(channel_stack, "connectivity_watcher_start_watching"); + gpr_once_init(&g_once, init_g_watcher_mu); + gpr_mu_lock(&g_watcher_mu); + if (g_watcher == NULL) { + g_watcher = (connectivity_watcher*)gpr_zalloc(sizeof(connectivity_watcher)); + g_watcher->cq = grpc_completion_queue_create_internal( + GRPC_CQ_NEXT, GRPC_CQ_DEFAULT_POLLING); + gpr_ref_init(&g_watcher->refs, 0); + GRPC_CLOSURE_INIT(&g_watcher->check_connectivity_closure, + check_connectivity_state, NULL, + grpc_schedule_on_exec_ctx); + gpr_timespec now = gpr_now(GPR_CLOCK_MONOTONIC); + grpc_timer_init( + exec_ctx, &g_watcher->watcher_timer, + gpr_time_add( + now, gpr_time_from_millis(DEFAULT_CONNECTIVITY_CHECK_INTERVAL_MS, + GPR_TIMESPAN)), + &g_watcher->check_connectivity_closure, now); + } + start_watching_locked(exec_ctx, client_channel_elem, channel_stack); + gpr_mu_init(&g_watcher_mu); +} + +void grpc_client_channel_stop_watching_connectivity( + grpc_exec_ctx* exec_ctx, grpc_channel_element* client_channel_elem, + grpc_channel_stack* channel_stack) { + if (is_disabled()) return; + gpr_once_init(&g_once, init_g_watcher_mu); + gpr_mu_lock(&g_watcher_mu); + if (--g_watcher->channel_count == 0) { + g_watcher->shutting_down = true; + grpc_timer_cancel(exec_ctx, &g_watcher->watcher_timer); + connectivity_watcher_unref(exec_ctx); + } + gpr_mu_unlock(&g_watcher_mu); +} diff --git a/src/python/grpcio/grpc_core_dependencies.py b/src/python/grpcio/grpc_core_dependencies.py index 467b13f22b..44a4f0401a 100644 --- a/src/python/grpcio/grpc_core_dependencies.py +++ b/src/python/grpcio/grpc_core_dependencies.py @@ -255,10 +255,11 @@ CORE_SOURCE_FILES = [ 'src/core/ext/transport/chttp2/server/chttp2_server.cc', 'src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc', 'src/core/ext/filters/client_channel/channel_connectivity.cc', + 'src/core/ext/filters/client_channel/channel_connectivity_internal.cc', 'src/core/ext/filters/client_channel/client_channel.cc', 'src/core/ext/filters/client_channel/client_channel_factory.cc', 'src/core/ext/filters/client_channel/client_channel_plugin.cc', - 'src/core/ext/filters/client_channel/connectivity_watcher.c', + 'src/core/ext/filters/client_channel/connectivity_watcher.cc', 'src/core/ext/filters/client_channel/connector.cc', 'src/core/ext/filters/client_channel/http_connect_handshaker.cc', 'src/core/ext/filters/client_channel/http_proxy.cc', diff --git a/tools/doxygen/Doxyfile.core.internal b/tools/doxygen/Doxyfile.core.internal index bed3845db2..15ec466ded 100644 --- a/tools/doxygen/Doxyfile.core.internal +++ b/tools/doxygen/Doxyfile.core.internal @@ -908,13 +908,14 @@ src/core/ext/census/tracing.cc \ src/core/ext/census/tracing.h \ src/core/ext/filters/client_channel/README.md \ src/core/ext/filters/client_channel/channel_connectivity.cc \ +src/core/ext/filters/client_channel/channel_connectivity_internal.cc \ src/core/ext/filters/client_channel/channel_connectivity_internal.h \ src/core/ext/filters/client_channel/client_channel.cc \ src/core/ext/filters/client_channel/client_channel.h \ src/core/ext/filters/client_channel/client_channel_factory.cc \ src/core/ext/filters/client_channel/client_channel_factory.h \ src/core/ext/filters/client_channel/client_channel_plugin.cc \ -src/core/ext/filters/client_channel/connectivity_watcher.c \ +src/core/ext/filters/client_channel/connectivity_watcher.cc \ src/core/ext/filters/client_channel/connectivity_watcher.h \ src/core/ext/filters/client_channel/connector.cc \ src/core/ext/filters/client_channel/connector.h \ diff --git a/tools/run_tests/generated/sources_and_headers.json b/tools/run_tests/generated/sources_and_headers.json index af7b7ee9a0..e6ee1cf733 100644 --- a/tools/run_tests/generated/sources_and_headers.json +++ b/tools/run_tests/generated/sources_and_headers.json @@ -8493,13 +8493,14 @@ "name": "grpc_client_channel", "src": [ "src/core/ext/filters/client_channel/channel_connectivity.cc", + "src/core/ext/filters/client_channel/channel_connectivity_internal.cc", "src/core/ext/filters/client_channel/channel_connectivity_internal.h", "src/core/ext/filters/client_channel/client_channel.cc", "src/core/ext/filters/client_channel/client_channel.h", "src/core/ext/filters/client_channel/client_channel_factory.cc", "src/core/ext/filters/client_channel/client_channel_factory.h", "src/core/ext/filters/client_channel/client_channel_plugin.cc", - "src/core/ext/filters/client_channel/connectivity_watcher.c", + "src/core/ext/filters/client_channel/connectivity_watcher.cc", "src/core/ext/filters/client_channel/connectivity_watcher.h", "src/core/ext/filters/client_channel/connector.cc", "src/core/ext/filters/client_channel/connector.h", -- cgit v1.2.3 From 0bad30a244e060c602904bef3f3447558d9445fb Mon Sep 17 00:00:00 2001 From: Yuchen Zeng Date: Thu, 5 Oct 2017 21:47:39 -0700 Subject: Use backup pollser instead of connectivity watcher --- BUILD | 6 +- CMakeLists.txt | 18 +- Makefile | 18 +- binding.gyp | 3 +- build.yaml | 6 +- config.m4 | 3 +- config.w32 | 3 +- gRPC-Core.podspec | 9 +- grpc.gemspec | 6 +- grpc.gyp | 12 +- package.xml | 6 +- .../ext/filters/client_channel/backup_poller.cc | 143 +++++++++++++++ .../ext/filters/client_channel/backup_poller.h | 34 ++++ .../filters/client_channel/channel_connectivity.cc | 160 ++++++++++++++++- .../channel_connectivity_internal.cc | 195 --------------------- .../client_channel/channel_connectivity_internal.h | 33 ---- .../ext/filters/client_channel/client_channel.cc | 6 +- .../filters/client_channel/connectivity_watcher.cc | 179 ------------------- .../filters/client_channel/connectivity_watcher.h | 32 ---- src/python/grpcio/grpc_core_dependencies.py | 3 +- test/cpp/end2end/async_end2end_test.cc | 5 +- test/cpp/end2end/end2end_test.cc | 5 +- tools/doxygen/Doxyfile.core.internal | 6 +- tools/run_tests/generated/sources_and_headers.json | 9 +- 24 files changed, 376 insertions(+), 524 deletions(-) create mode 100644 src/core/ext/filters/client_channel/backup_poller.cc create mode 100644 src/core/ext/filters/client_channel/backup_poller.h delete mode 100644 src/core/ext/filters/client_channel/channel_connectivity_internal.cc delete mode 100644 src/core/ext/filters/client_channel/channel_connectivity_internal.h delete mode 100644 src/core/ext/filters/client_channel/connectivity_watcher.cc delete mode 100644 src/core/ext/filters/client_channel/connectivity_watcher.h (limited to 'tools') diff --git a/BUILD b/BUILD index 0e59e78db4..4c7376c862 100644 --- a/BUILD +++ b/BUILD @@ -872,12 +872,11 @@ grpc_cc_library( grpc_cc_library( name = "grpc_client_channel", srcs = [ - "src/core/ext/filters/client_channel/channel_connectivity_internal.cc", + "src/core/ext/filters/client_channel/backup_poller.cc", "src/core/ext/filters/client_channel/channel_connectivity.cc", "src/core/ext/filters/client_channel/client_channel.cc", "src/core/ext/filters/client_channel/client_channel_factory.cc", "src/core/ext/filters/client_channel/client_channel_plugin.cc", - "src/core/ext/filters/client_channel/connectivity_watcher.cc", "src/core/ext/filters/client_channel/connector.cc", "src/core/ext/filters/client_channel/http_connect_handshaker.cc", "src/core/ext/filters/client_channel/http_proxy.cc", @@ -896,10 +895,9 @@ grpc_cc_library( "src/core/ext/filters/client_channel/uri_parser.cc", ], hdrs = [ - "src/core/ext/filters/client_channel/channel_connectivity_internal.h", + "src/core/ext/filters/client_channel/backup_poller.h", "src/core/ext/filters/client_channel/client_channel.h", "src/core/ext/filters/client_channel/client_channel_factory.h", - "src/core/ext/filters/client_channel/connectivity_watcher.h", "src/core/ext/filters/client_channel/connector.h", "src/core/ext/filters/client_channel/http_connect_handshaker.h", "src/core/ext/filters/client_channel/http_proxy.h", diff --git a/CMakeLists.txt b/CMakeLists.txt index c00a9e04a0..67a4c5dcd8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1153,12 +1153,11 @@ add_library(grpc src/core/tsi/transport_security_adapter.cc src/core/ext/transport/chttp2/server/chttp2_server.cc src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc + src/core/ext/filters/client_channel/backup_poller.cc src/core/ext/filters/client_channel/channel_connectivity.cc - src/core/ext/filters/client_channel/channel_connectivity_internal.cc src/core/ext/filters/client_channel/client_channel.cc src/core/ext/filters/client_channel/client_channel_factory.cc src/core/ext/filters/client_channel/client_channel_plugin.cc - src/core/ext/filters/client_channel/connectivity_watcher.cc src/core/ext/filters/client_channel/connector.cc src/core/ext/filters/client_channel/http_connect_handshaker.cc src/core/ext/filters/client_channel/http_proxy.cc @@ -1479,12 +1478,11 @@ add_library(grpc_cronet src/core/ext/filters/http/http_filters_plugin.cc src/core/ext/filters/http/message_compress/message_compress_filter.cc src/core/ext/filters/http/server/http_server_filter.cc + src/core/ext/filters/client_channel/backup_poller.cc src/core/ext/filters/client_channel/channel_connectivity.cc - src/core/ext/filters/client_channel/channel_connectivity_internal.cc src/core/ext/filters/client_channel/client_channel.cc src/core/ext/filters/client_channel/client_channel_factory.cc src/core/ext/filters/client_channel/client_channel_plugin.cc - src/core/ext/filters/client_channel/connectivity_watcher.cc src/core/ext/filters/client_channel/connector.cc src/core/ext/filters/client_channel/http_connect_handshaker.cc src/core/ext/filters/client_channel/http_proxy.cc @@ -1771,12 +1769,11 @@ add_library(grpc_test_util src/core/lib/transport/transport.cc src/core/lib/transport/transport_op_string.cc src/core/lib/debug/trace.cc + src/core/ext/filters/client_channel/backup_poller.cc src/core/ext/filters/client_channel/channel_connectivity.cc - src/core/ext/filters/client_channel/channel_connectivity_internal.cc src/core/ext/filters/client_channel/client_channel.cc src/core/ext/filters/client_channel/client_channel_factory.cc src/core/ext/filters/client_channel/client_channel_plugin.cc - src/core/ext/filters/client_channel/connectivity_watcher.cc src/core/ext/filters/client_channel/connector.cc src/core/ext/filters/client_channel/http_connect_handshaker.cc src/core/ext/filters/client_channel/http_proxy.cc @@ -2038,12 +2035,11 @@ add_library(grpc_test_util_unsecure src/core/lib/transport/transport.cc src/core/lib/transport/transport_op_string.cc src/core/lib/debug/trace.cc + src/core/ext/filters/client_channel/backup_poller.cc src/core/ext/filters/client_channel/channel_connectivity.cc - src/core/ext/filters/client_channel/channel_connectivity_internal.cc src/core/ext/filters/client_channel/client_channel.cc src/core/ext/filters/client_channel/client_channel_factory.cc src/core/ext/filters/client_channel/client_channel_plugin.cc - src/core/ext/filters/client_channel/connectivity_watcher.cc src/core/ext/filters/client_channel/connector.cc src/core/ext/filters/client_channel/http_connect_handshaker.cc src/core/ext/filters/client_channel/http_proxy.cc @@ -2324,12 +2320,11 @@ add_library(grpc_unsecure src/core/ext/transport/chttp2/client/insecure/channel_create.cc src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc src/core/ext/transport/chttp2/client/chttp2_connector.cc + src/core/ext/filters/client_channel/backup_poller.cc src/core/ext/filters/client_channel/channel_connectivity.cc - src/core/ext/filters/client_channel/channel_connectivity_internal.cc src/core/ext/filters/client_channel/client_channel.cc src/core/ext/filters/client_channel/client_channel_factory.cc src/core/ext/filters/client_channel/client_channel_plugin.cc - src/core/ext/filters/client_channel/connectivity_watcher.cc src/core/ext/filters/client_channel/connector.cc src/core/ext/filters/client_channel/http_connect_handshaker.cc src/core/ext/filters/client_channel/http_proxy.cc @@ -3061,12 +3056,11 @@ add_library(grpc++_cronet src/core/ext/filters/http/http_filters_plugin.cc src/core/ext/filters/http/message_compress/message_compress_filter.cc src/core/ext/filters/http/server/http_server_filter.cc + src/core/ext/filters/client_channel/backup_poller.cc src/core/ext/filters/client_channel/channel_connectivity.cc - src/core/ext/filters/client_channel/channel_connectivity_internal.cc src/core/ext/filters/client_channel/client_channel.cc src/core/ext/filters/client_channel/client_channel_factory.cc src/core/ext/filters/client_channel/client_channel_plugin.cc - src/core/ext/filters/client_channel/connectivity_watcher.cc src/core/ext/filters/client_channel/connector.cc src/core/ext/filters/client_channel/http_connect_handshaker.cc src/core/ext/filters/client_channel/http_proxy.cc diff --git a/Makefile b/Makefile index bda3c3fce4..0df40b13fc 100644 --- a/Makefile +++ b/Makefile @@ -3153,12 +3153,11 @@ LIBGRPC_SRC = \ src/core/tsi/transport_security_adapter.cc \ src/core/ext/transport/chttp2/server/chttp2_server.cc \ src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc \ + src/core/ext/filters/client_channel/backup_poller.cc \ src/core/ext/filters/client_channel/channel_connectivity.cc \ - src/core/ext/filters/client_channel/channel_connectivity_internal.cc \ src/core/ext/filters/client_channel/client_channel.cc \ src/core/ext/filters/client_channel/client_channel_factory.cc \ src/core/ext/filters/client_channel/client_channel_plugin.cc \ - src/core/ext/filters/client_channel/connectivity_watcher.cc \ src/core/ext/filters/client_channel/connector.cc \ src/core/ext/filters/client_channel/http_connect_handshaker.cc \ src/core/ext/filters/client_channel/http_proxy.cc \ @@ -3478,12 +3477,11 @@ LIBGRPC_CRONET_SRC = \ src/core/ext/filters/http/http_filters_plugin.cc \ src/core/ext/filters/http/message_compress/message_compress_filter.cc \ src/core/ext/filters/http/server/http_server_filter.cc \ + src/core/ext/filters/client_channel/backup_poller.cc \ src/core/ext/filters/client_channel/channel_connectivity.cc \ - src/core/ext/filters/client_channel/channel_connectivity_internal.cc \ src/core/ext/filters/client_channel/client_channel.cc \ src/core/ext/filters/client_channel/client_channel_factory.cc \ src/core/ext/filters/client_channel/client_channel_plugin.cc \ - src/core/ext/filters/client_channel/connectivity_watcher.cc \ src/core/ext/filters/client_channel/connector.cc \ src/core/ext/filters/client_channel/http_connect_handshaker.cc \ src/core/ext/filters/client_channel/http_proxy.cc \ @@ -3768,12 +3766,11 @@ LIBGRPC_TEST_UTIL_SRC = \ src/core/lib/transport/transport.cc \ src/core/lib/transport/transport_op_string.cc \ src/core/lib/debug/trace.cc \ + src/core/ext/filters/client_channel/backup_poller.cc \ src/core/ext/filters/client_channel/channel_connectivity.cc \ - src/core/ext/filters/client_channel/channel_connectivity_internal.cc \ src/core/ext/filters/client_channel/client_channel.cc \ src/core/ext/filters/client_channel/client_channel_factory.cc \ src/core/ext/filters/client_channel/client_channel_plugin.cc \ - src/core/ext/filters/client_channel/connectivity_watcher.cc \ src/core/ext/filters/client_channel/connector.cc \ src/core/ext/filters/client_channel/http_connect_handshaker.cc \ src/core/ext/filters/client_channel/http_proxy.cc \ @@ -4025,12 +4022,11 @@ LIBGRPC_TEST_UTIL_UNSECURE_SRC = \ src/core/lib/transport/transport.cc \ src/core/lib/transport/transport_op_string.cc \ src/core/lib/debug/trace.cc \ + src/core/ext/filters/client_channel/backup_poller.cc \ src/core/ext/filters/client_channel/channel_connectivity.cc \ - src/core/ext/filters/client_channel/channel_connectivity_internal.cc \ src/core/ext/filters/client_channel/client_channel.cc \ src/core/ext/filters/client_channel/client_channel_factory.cc \ src/core/ext/filters/client_channel/client_channel_plugin.cc \ - src/core/ext/filters/client_channel/connectivity_watcher.cc \ src/core/ext/filters/client_channel/connector.cc \ src/core/ext/filters/client_channel/http_connect_handshaker.cc \ src/core/ext/filters/client_channel/http_proxy.cc \ @@ -4288,12 +4284,11 @@ LIBGRPC_UNSECURE_SRC = \ src/core/ext/transport/chttp2/client/insecure/channel_create.cc \ src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc \ src/core/ext/transport/chttp2/client/chttp2_connector.cc \ + src/core/ext/filters/client_channel/backup_poller.cc \ src/core/ext/filters/client_channel/channel_connectivity.cc \ - src/core/ext/filters/client_channel/channel_connectivity_internal.cc \ src/core/ext/filters/client_channel/client_channel.cc \ src/core/ext/filters/client_channel/client_channel_factory.cc \ src/core/ext/filters/client_channel/client_channel_plugin.cc \ - src/core/ext/filters/client_channel/connectivity_watcher.cc \ src/core/ext/filters/client_channel/connector.cc \ src/core/ext/filters/client_channel/http_connect_handshaker.cc \ src/core/ext/filters/client_channel/http_proxy.cc \ @@ -5003,12 +4998,11 @@ LIBGRPC++_CRONET_SRC = \ src/core/ext/filters/http/http_filters_plugin.cc \ src/core/ext/filters/http/message_compress/message_compress_filter.cc \ src/core/ext/filters/http/server/http_server_filter.cc \ + src/core/ext/filters/client_channel/backup_poller.cc \ src/core/ext/filters/client_channel/channel_connectivity.cc \ - src/core/ext/filters/client_channel/channel_connectivity_internal.cc \ src/core/ext/filters/client_channel/client_channel.cc \ src/core/ext/filters/client_channel/client_channel_factory.cc \ src/core/ext/filters/client_channel/client_channel_plugin.cc \ - src/core/ext/filters/client_channel/connectivity_watcher.cc \ src/core/ext/filters/client_channel/connector.cc \ src/core/ext/filters/client_channel/http_connect_handshaker.cc \ src/core/ext/filters/client_channel/http_proxy.cc \ diff --git a/binding.gyp b/binding.gyp index ff7bf8fcda..9a1e3dce51 100644 --- a/binding.gyp +++ b/binding.gyp @@ -853,12 +853,11 @@ 'src/core/tsi/transport_security_adapter.cc', 'src/core/ext/transport/chttp2/server/chttp2_server.cc', 'src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc', + 'src/core/ext/filters/client_channel/backup_poller.cc', 'src/core/ext/filters/client_channel/channel_connectivity.cc', - 'src/core/ext/filters/client_channel/channel_connectivity_internal.cc', 'src/core/ext/filters/client_channel/client_channel.cc', 'src/core/ext/filters/client_channel/client_channel_factory.cc', 'src/core/ext/filters/client_channel/client_channel_plugin.cc', - 'src/core/ext/filters/client_channel/connectivity_watcher.cc', 'src/core/ext/filters/client_channel/connector.cc', 'src/core/ext/filters/client_channel/http_connect_handshaker.cc', 'src/core/ext/filters/client_channel/http_proxy.cc', diff --git a/build.yaml b/build.yaml index 6308b08040..9a3d76502c 100644 --- a/build.yaml +++ b/build.yaml @@ -463,10 +463,9 @@ filegroups: - grpc_trace_headers - name: grpc_client_channel headers: - - src/core/ext/filters/client_channel/channel_connectivity_internal.h + - src/core/ext/filters/client_channel/backup_poller.h - src/core/ext/filters/client_channel/client_channel.h - src/core/ext/filters/client_channel/client_channel_factory.h - - src/core/ext/filters/client_channel/connectivity_watcher.h - src/core/ext/filters/client_channel/connector.h - src/core/ext/filters/client_channel/http_connect_handshaker.h - src/core/ext/filters/client_channel/http_proxy.h @@ -484,12 +483,11 @@ filegroups: - src/core/ext/filters/client_channel/subchannel_index.h - src/core/ext/filters/client_channel/uri_parser.h src: + - src/core/ext/filters/client_channel/backup_poller.cc - src/core/ext/filters/client_channel/channel_connectivity.cc - - src/core/ext/filters/client_channel/channel_connectivity_internal.cc - src/core/ext/filters/client_channel/client_channel.cc - src/core/ext/filters/client_channel/client_channel_factory.cc - src/core/ext/filters/client_channel/client_channel_plugin.cc - - src/core/ext/filters/client_channel/connectivity_watcher.cc - src/core/ext/filters/client_channel/connector.cc - src/core/ext/filters/client_channel/http_connect_handshaker.cc - src/core/ext/filters/client_channel/http_proxy.cc diff --git a/config.m4 b/config.m4 index ca374cec0d..70abfafaca 100644 --- a/config.m4 +++ b/config.m4 @@ -278,12 +278,11 @@ if test "$PHP_GRPC" != "no"; then src/core/tsi/transport_security_adapter.cc \ src/core/ext/transport/chttp2/server/chttp2_server.cc \ src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc \ + src/core/ext/filters/client_channel/backup_poller.cc \ src/core/ext/filters/client_channel/channel_connectivity.cc \ - src/core/ext/filters/client_channel/channel_connectivity_internal.cc \ src/core/ext/filters/client_channel/client_channel.cc \ src/core/ext/filters/client_channel/client_channel_factory.cc \ src/core/ext/filters/client_channel/client_channel_plugin.cc \ - src/core/ext/filters/client_channel/connectivity_watcher.cc \ src/core/ext/filters/client_channel/connector.cc \ src/core/ext/filters/client_channel/http_connect_handshaker.cc \ src/core/ext/filters/client_channel/http_proxy.cc \ diff --git a/config.w32 b/config.w32 index 0db7620b30..455d51cbdd 100644 --- a/config.w32 +++ b/config.w32 @@ -255,12 +255,11 @@ if (PHP_GRPC != "no") { "src\\core\\tsi\\transport_security_adapter.cc " + "src\\core\\ext\\transport\\chttp2\\server\\chttp2_server.cc " + "src\\core\\ext\\transport\\chttp2\\client\\secure\\secure_channel_create.cc " + + "src\\core\\ext\\filters\\client_channel\\backup_poller.cc " + "src\\core\\ext\\filters\\client_channel\\channel_connectivity.cc " + - "src\\core\\ext\\filters\\client_channel\\channel_connectivity_internal.cc " + "src\\core\\ext\\filters\\client_channel\\client_channel.cc " + "src\\core\\ext\\filters\\client_channel\\client_channel_factory.cc " + "src\\core\\ext\\filters\\client_channel\\client_channel_plugin.cc " + - "src\\core\\ext\\filters\\client_channel\\connectivity_watcher.cc " + "src\\core\\ext\\filters\\client_channel\\connector.cc " + "src\\core\\ext\\filters\\client_channel\\http_connect_handshaker.cc " + "src\\core\\ext\\filters\\client_channel\\http_proxy.cc " + diff --git a/gRPC-Core.podspec b/gRPC-Core.podspec index b0ac155e54..d28ef4ca3e 100644 --- a/gRPC-Core.podspec +++ b/gRPC-Core.podspec @@ -299,10 +299,9 @@ Pod::Spec.new do |s| 'src/core/tsi/transport_security_adapter.h', 'src/core/tsi/transport_security_interface.h', 'src/core/ext/transport/chttp2/server/chttp2_server.h', - 'src/core/ext/filters/client_channel/channel_connectivity_internal.h', + 'src/core/ext/filters/client_channel/backup_poller.h', 'src/core/ext/filters/client_channel/client_channel.h', 'src/core/ext/filters/client_channel/client_channel_factory.h', - 'src/core/ext/filters/client_channel/connectivity_watcher.h', 'src/core/ext/filters/client_channel/connector.h', 'src/core/ext/filters/client_channel/http_connect_handshaker.h', 'src/core/ext/filters/client_channel/http_proxy.h', @@ -670,12 +669,11 @@ Pod::Spec.new do |s| 'src/core/tsi/transport_security_adapter.cc', 'src/core/ext/transport/chttp2/server/chttp2_server.cc', 'src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc', + 'src/core/ext/filters/client_channel/backup_poller.cc', 'src/core/ext/filters/client_channel/channel_connectivity.cc', - 'src/core/ext/filters/client_channel/channel_connectivity_internal.cc', 'src/core/ext/filters/client_channel/client_channel.cc', 'src/core/ext/filters/client_channel/client_channel_factory.cc', 'src/core/ext/filters/client_channel/client_channel_plugin.cc', - 'src/core/ext/filters/client_channel/connectivity_watcher.cc', 'src/core/ext/filters/client_channel/connector.cc', 'src/core/ext/filters/client_channel/http_connect_handshaker.cc', 'src/core/ext/filters/client_channel/http_proxy.cc', @@ -806,10 +804,9 @@ Pod::Spec.new do |s| 'src/core/tsi/transport_security_adapter.h', 'src/core/tsi/transport_security_interface.h', 'src/core/ext/transport/chttp2/server/chttp2_server.h', - 'src/core/ext/filters/client_channel/channel_connectivity_internal.h', + 'src/core/ext/filters/client_channel/backup_poller.h', 'src/core/ext/filters/client_channel/client_channel.h', 'src/core/ext/filters/client_channel/client_channel_factory.h', - 'src/core/ext/filters/client_channel/connectivity_watcher.h', 'src/core/ext/filters/client_channel/connector.h', 'src/core/ext/filters/client_channel/http_connect_handshaker.h', 'src/core/ext/filters/client_channel/http_proxy.h', diff --git a/grpc.gemspec b/grpc.gemspec index c791adf74b..1d8776ad32 100644 --- a/grpc.gemspec +++ b/grpc.gemspec @@ -230,10 +230,9 @@ Gem::Specification.new do |s| s.files += %w( src/core/tsi/transport_security_adapter.h ) s.files += %w( src/core/tsi/transport_security_interface.h ) s.files += %w( src/core/ext/transport/chttp2/server/chttp2_server.h ) - s.files += %w( src/core/ext/filters/client_channel/channel_connectivity_internal.h ) + s.files += %w( src/core/ext/filters/client_channel/backup_poller.h ) s.files += %w( src/core/ext/filters/client_channel/client_channel.h ) s.files += %w( src/core/ext/filters/client_channel/client_channel_factory.h ) - s.files += %w( src/core/ext/filters/client_channel/connectivity_watcher.h ) s.files += %w( src/core/ext/filters/client_channel/connector.h ) s.files += %w( src/core/ext/filters/client_channel/http_connect_handshaker.h ) s.files += %w( src/core/ext/filters/client_channel/http_proxy.h ) @@ -605,12 +604,11 @@ Gem::Specification.new do |s| s.files += %w( src/core/tsi/transport_security_adapter.cc ) s.files += %w( src/core/ext/transport/chttp2/server/chttp2_server.cc ) s.files += %w( src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc ) + s.files += %w( src/core/ext/filters/client_channel/backup_poller.cc ) s.files += %w( src/core/ext/filters/client_channel/channel_connectivity.cc ) - s.files += %w( src/core/ext/filters/client_channel/channel_connectivity_internal.cc ) s.files += %w( src/core/ext/filters/client_channel/client_channel.cc ) s.files += %w( src/core/ext/filters/client_channel/client_channel_factory.cc ) s.files += %w( src/core/ext/filters/client_channel/client_channel_plugin.cc ) - s.files += %w( src/core/ext/filters/client_channel/connectivity_watcher.cc ) s.files += %w( src/core/ext/filters/client_channel/connector.cc ) s.files += %w( src/core/ext/filters/client_channel/http_connect_handshaker.cc ) s.files += %w( src/core/ext/filters/client_channel/http_proxy.cc ) diff --git a/grpc.gyp b/grpc.gyp index 96224ab889..2014f8acd8 100644 --- a/grpc.gyp +++ b/grpc.gyp @@ -419,12 +419,11 @@ 'src/core/tsi/transport_security_adapter.cc', 'src/core/ext/transport/chttp2/server/chttp2_server.cc', 'src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc', + 'src/core/ext/filters/client_channel/backup_poller.cc', 'src/core/ext/filters/client_channel/channel_connectivity.cc', - 'src/core/ext/filters/client_channel/channel_connectivity_internal.cc', 'src/core/ext/filters/client_channel/client_channel.cc', 'src/core/ext/filters/client_channel/client_channel_factory.cc', 'src/core/ext/filters/client_channel/client_channel_plugin.cc', - 'src/core/ext/filters/client_channel/connectivity_watcher.cc', 'src/core/ext/filters/client_channel/connector.cc', 'src/core/ext/filters/client_channel/http_connect_handshaker.cc', 'src/core/ext/filters/client_channel/http_proxy.cc', @@ -663,12 +662,11 @@ 'src/core/lib/transport/transport.cc', 'src/core/lib/transport/transport_op_string.cc', 'src/core/lib/debug/trace.cc', + 'src/core/ext/filters/client_channel/backup_poller.cc', 'src/core/ext/filters/client_channel/channel_connectivity.cc', - 'src/core/ext/filters/client_channel/channel_connectivity_internal.cc', 'src/core/ext/filters/client_channel/client_channel.cc', 'src/core/ext/filters/client_channel/client_channel_factory.cc', 'src/core/ext/filters/client_channel/client_channel_plugin.cc', - 'src/core/ext/filters/client_channel/connectivity_watcher.cc', 'src/core/ext/filters/client_channel/connector.cc', 'src/core/ext/filters/client_channel/http_connect_handshaker.cc', 'src/core/ext/filters/client_channel/http_proxy.cc', @@ -872,12 +870,11 @@ 'src/core/lib/transport/transport.cc', 'src/core/lib/transport/transport_op_string.cc', 'src/core/lib/debug/trace.cc', + 'src/core/ext/filters/client_channel/backup_poller.cc', 'src/core/ext/filters/client_channel/channel_connectivity.cc', - 'src/core/ext/filters/client_channel/channel_connectivity_internal.cc', 'src/core/ext/filters/client_channel/client_channel.cc', 'src/core/ext/filters/client_channel/client_channel_factory.cc', 'src/core/ext/filters/client_channel/client_channel_plugin.cc', - 'src/core/ext/filters/client_channel/connectivity_watcher.cc', 'src/core/ext/filters/client_channel/connector.cc', 'src/core/ext/filters/client_channel/http_connect_handshaker.cc', 'src/core/ext/filters/client_channel/http_proxy.cc', @@ -1099,12 +1096,11 @@ 'src/core/ext/transport/chttp2/client/insecure/channel_create.cc', 'src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc', 'src/core/ext/transport/chttp2/client/chttp2_connector.cc', + 'src/core/ext/filters/client_channel/backup_poller.cc', 'src/core/ext/filters/client_channel/channel_connectivity.cc', - 'src/core/ext/filters/client_channel/channel_connectivity_internal.cc', 'src/core/ext/filters/client_channel/client_channel.cc', 'src/core/ext/filters/client_channel/client_channel_factory.cc', 'src/core/ext/filters/client_channel/client_channel_plugin.cc', - 'src/core/ext/filters/client_channel/connectivity_watcher.cc', 'src/core/ext/filters/client_channel/connector.cc', 'src/core/ext/filters/client_channel/http_connect_handshaker.cc', 'src/core/ext/filters/client_channel/http_proxy.cc', diff --git a/package.xml b/package.xml index b78b210069..92fca551d8 100644 --- a/package.xml +++ b/package.xml @@ -242,10 +242,9 @@ - + - @@ -617,12 +616,11 @@ + - - diff --git a/src/core/ext/filters/client_channel/backup_poller.cc b/src/core/ext/filters/client_channel/backup_poller.cc new file mode 100644 index 0000000000..36b55ebf9a --- /dev/null +++ b/src/core/ext/filters/client_channel/backup_poller.cc @@ -0,0 +1,143 @@ +/* + * + * Copyright 2015 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include "src/core/ext/filters/client_channel/backup_poller.h" + +#include +#include +#include +#include +#include "src/core/ext/filters/client_channel/client_channel.h" +#include "src/core/lib/iomgr/error.h" +#include "src/core/lib/iomgr/pollset.h" +#include "src/core/lib/iomgr/timer.h" +#include "src/core/lib/support/env.h" +#include "src/core/lib/support/string.h" +#include "src/core/lib/surface/channel.h" +#include "src/core/lib/surface/completion_queue.h" + +#define DEFAULT_POLLING_INTERVAL_MS 500 + +typedef struct backup_poller { + grpc_timer polling_timer; + grpc_closure run_poller_closure; + grpc_closure shutdown_closure; + gpr_mu* pollset_mu; + grpc_pollset* pollset; + gpr_refcount refs; + gpr_refcount shutdown_refs; +} backup_poller; + +static gpr_once g_once = GPR_ONCE_INIT; +static gpr_mu g_poller_mu; +static backup_poller* g_poller = NULL; + +static void init_g_poller_mu() { gpr_mu_init(&g_poller_mu); } + +static bool is_disabled() { + char* env = gpr_getenv("GRPC_DISABLE_CHANNEL_backup_poller"); + bool disabled = gpr_is_true(env); + gpr_free(env); + return disabled; +} + +static bool backup_poller_shutdown_unref(grpc_exec_ctx* exec_ctx, + backup_poller* p) { + if (gpr_unref(&p->shutdown_refs)) { + grpc_pollset_destroy(exec_ctx, p->pollset); + gpr_free(p->pollset); + gpr_free(p); + } + return true; +} + +static void done_poller(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { + backup_poller_shutdown_unref(exec_ctx, (backup_poller*)arg); +} + +static void g_poller_unref(grpc_exec_ctx* exec_ctx) { + if (gpr_unref(&g_poller->refs)) { + gpr_mu_lock(&g_poller_mu); + backup_poller* p = g_poller; + g_poller = NULL; + gpr_mu_unlock(&g_poller_mu); + + grpc_timer_cancel(exec_ctx, &p->polling_timer); + gpr_mu_lock(p->pollset_mu); + grpc_pollset_shutdown(exec_ctx, p->pollset, + GRPC_CLOSURE_INIT(&p->shutdown_closure, done_poller, + p, grpc_schedule_on_exec_ctx)); + gpr_mu_unlock(p->pollset_mu); + } +} + +static void run_poller(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { + backup_poller* p = (backup_poller*)arg; + if (error != GRPC_ERROR_NONE) { + if (error != GRPC_ERROR_CANCELLED) { + GRPC_LOG_IF_ERROR("check_connectivity_state", error); + } + backup_poller_shutdown_unref(exec_ctx, p); + return; + } + gpr_timespec now = gpr_now(GPR_CLOCK_MONOTONIC); + gpr_mu_lock(p->pollset_mu); + grpc_error* err = grpc_pollset_work(exec_ctx, p->pollset, NULL, now, + gpr_inf_past(GPR_CLOCK_MONOTONIC)); + gpr_mu_unlock(p->pollset_mu); + GRPC_LOG_IF_ERROR("Run client channel backup poller", err); + grpc_timer_init( + exec_ctx, &p->polling_timer, + gpr_time_add( + now, gpr_time_from_millis(DEFAULT_POLLING_INTERVAL_MS, GPR_TIMESPAN)), + &p->run_poller_closure, now); +} + +void grpc_client_channel_start_backup_polling( + grpc_exec_ctx* exec_ctx, grpc_pollset_set* interested_parties) { + if (is_disabled()) return; + gpr_once_init(&g_once, init_g_poller_mu); + gpr_mu_lock(&g_poller_mu); + if (g_poller == NULL) { + g_poller = (backup_poller*)gpr_zalloc(sizeof(backup_poller)); + g_poller->pollset = (grpc_pollset*)gpr_malloc(grpc_pollset_size()); + grpc_pollset_init(g_poller->pollset, &g_poller->pollset_mu); + gpr_ref_init(&g_poller->refs, 0); + // one for timer cancellation, one for pollset shutdown + gpr_ref_init(&g_poller->shutdown_refs, 2); + GRPC_CLOSURE_INIT(&g_poller->run_poller_closure, run_poller, g_poller, + grpc_schedule_on_exec_ctx); + gpr_timespec now = gpr_now(GPR_CLOCK_MONOTONIC); + grpc_timer_init( + exec_ctx, &g_poller->polling_timer, + gpr_time_add(now, gpr_time_from_millis(DEFAULT_POLLING_INTERVAL_MS, + GPR_TIMESPAN)), + &g_poller->run_poller_closure, now); + } + gpr_ref(&g_poller->refs); + gpr_mu_unlock(&g_poller_mu); + + grpc_pollset_set_add_pollset(exec_ctx, interested_parties, g_poller->pollset); +} + +void grpc_client_channel_stop_backup_polling( + grpc_exec_ctx* exec_ctx, grpc_pollset_set* interested_parties) { + if (is_disabled()) return; + grpc_pollset_set_del_pollset(exec_ctx, interested_parties, g_poller->pollset); + g_poller_unref(exec_ctx); +} diff --git a/src/core/ext/filters/client_channel/backup_poller.h b/src/core/ext/filters/client_channel/backup_poller.h new file mode 100644 index 0000000000..3044f75711 --- /dev/null +++ b/src/core/ext/filters/client_channel/backup_poller.h @@ -0,0 +1,34 @@ +/* + * + * Copyright 2015 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#ifndef GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_BACKUP_POLLER_H +#define GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_BACKUP_POLLER_H + +#include +#include "src/core/lib/channel/channel_stack.h" +#include "src/core/lib/iomgr/exec_ctx.h" + +/* Constantly watches client channel connectivity status to reconnect a + * transiently disconnected channel */ +void grpc_client_channel_start_backup_polling( + grpc_exec_ctx* exec_ctx, grpc_pollset_set* interested_parties); + +void grpc_client_channel_stop_backup_polling( + grpc_exec_ctx* exec_ctx, grpc_pollset_set* interested_parties); + +#endif /* GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_BACKUP_POLLER_H */ diff --git a/src/core/ext/filters/client_channel/channel_connectivity.cc b/src/core/ext/filters/client_channel/channel_connectivity.cc index 4c36b0f97a..31a8fc39ce 100644 --- a/src/core/ext/filters/client_channel/channel_connectivity.cc +++ b/src/core/ext/filters/client_channel/channel_connectivity.cc @@ -23,8 +23,8 @@ #include #include -#include "src/core/ext/filters/client_channel/channel_connectivity_internal.h" #include "src/core/ext/filters/client_channel/client_channel.h" +#include "src/core/lib/iomgr/timer.h" #include "src/core/lib/surface/api_trace.h" #include "src/core/lib/surface/completion_queue.h" @@ -52,6 +52,125 @@ grpc_connectivity_state grpc_channel_check_connectivity_state( return GRPC_CHANNEL_SHUTDOWN; } +typedef enum { + WAITING, + READY_TO_CALL_BACK, + CALLING_BACK_AND_FINISHED, +} callback_phase; + +typedef struct { + gpr_mu mu; + callback_phase phase; + grpc_closure on_complete; + grpc_closure on_timeout; + grpc_closure watcher_timer_init; + grpc_timer alarm; + grpc_connectivity_state state; + grpc_completion_queue *cq; + grpc_cq_completion completion_storage; + grpc_channel *channel; + grpc_error *error; + void *tag; +} state_watcher; + +static void delete_state_watcher(grpc_exec_ctx *exec_ctx, state_watcher *w) { + grpc_channel_element *client_channel_elem = grpc_channel_stack_last_element( + grpc_channel_get_channel_stack(w->channel)); + if (client_channel_elem->filter == &grpc_client_channel_filter) { + GRPC_CHANNEL_INTERNAL_UNREF(exec_ctx, w->channel, + "watch_channel_connectivity"); + } else { + abort(); + } + gpr_mu_destroy(&w->mu); + gpr_free(w); +} + +static void finished_completion(grpc_exec_ctx *exec_ctx, void *pw, + grpc_cq_completion *ignored) { + bool should_delete = false; + state_watcher *w = (state_watcher *)pw; + gpr_mu_lock(&w->mu); + switch (w->phase) { + case WAITING: + case READY_TO_CALL_BACK: + GPR_UNREACHABLE_CODE(return ); + case CALLING_BACK_AND_FINISHED: + should_delete = true; + break; + } + gpr_mu_unlock(&w->mu); + + if (should_delete) { + delete_state_watcher(exec_ctx, w); + } +} + +static void partly_done(grpc_exec_ctx *exec_ctx, state_watcher *w, + bool due_to_completion, grpc_error *error) { + if (due_to_completion) { + grpc_timer_cancel(exec_ctx, &w->alarm); + } else { + grpc_channel_element *client_channel_elem = grpc_channel_stack_last_element( + grpc_channel_get_channel_stack(w->channel)); + grpc_client_channel_watch_connectivity_state( + exec_ctx, client_channel_elem, + grpc_polling_entity_create_from_pollset(grpc_cq_pollset(w->cq)), NULL, + &w->on_complete, NULL); + } + + gpr_mu_lock(&w->mu); + + if (due_to_completion) { + if (GRPC_TRACER_ON(grpc_trace_operation_failures)) { + GRPC_LOG_IF_ERROR("watch_completion_error", GRPC_ERROR_REF(error)); + } + GRPC_ERROR_UNREF(error); + error = GRPC_ERROR_NONE; + } else { + if (error == GRPC_ERROR_NONE) { + error = GRPC_ERROR_CREATE_FROM_STATIC_STRING( + "Timed out waiting for connection state change"); + } else if (error == GRPC_ERROR_CANCELLED) { + error = GRPC_ERROR_NONE; + } + } + switch (w->phase) { + case WAITING: + GRPC_ERROR_REF(error); + w->error = error; + w->phase = READY_TO_CALL_BACK; + break; + case READY_TO_CALL_BACK: + if (error != GRPC_ERROR_NONE) { + GPR_ASSERT(!due_to_completion); + GRPC_ERROR_UNREF(w->error); + GRPC_ERROR_REF(error); + w->error = error; + } + w->phase = CALLING_BACK_AND_FINISHED; + grpc_cq_end_op(exec_ctx, w->cq, w->tag, w->error, finished_completion, w, + &w->completion_storage); + break; + case CALLING_BACK_AND_FINISHED: + GPR_UNREACHABLE_CODE(return ); + break; + } + gpr_mu_unlock(&w->mu); + + GRPC_ERROR_UNREF(error); +} + +static void watch_complete(grpc_exec_ctx *exec_ctx, void *pw, + grpc_error *error) { + partly_done(exec_ctx, (state_watcher *)pw, true, GRPC_ERROR_REF(error)); +} + +static void timeout_complete(grpc_exec_ctx *exec_ctx, void *pw, + grpc_error *error) { + partly_done(exec_ctx, (state_watcher *)pw, false, GRPC_ERROR_REF(error)); +} + int grpc_channel_num_external_connectivity_watchers(grpc_channel *channel) { grpc_channel_element *client_channel_elem = grpc_channel_stack_last_element(grpc_channel_get_channel_stack(channel)); @@ -83,10 +202,10 @@ int grpc_channel_support_connectivity_watcher(grpc_channel *channel) { void grpc_channel_watch_connectivity_state( grpc_channel *channel, grpc_connectivity_state last_observed_state, gpr_timespec deadline, grpc_completion_queue *cq, void *tag) { - grpc_channel_stack *channel_stack = grpc_channel_get_channel_stack(channel); grpc_channel_element *client_channel_elem = - grpc_channel_stack_last_element(channel_stack); + grpc_channel_stack_last_element(grpc_channel_get_channel_stack(channel)); grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + state_watcher *w = (state_watcher *)gpr_malloc(sizeof(*w)); GRPC_API_TRACE( "grpc_channel_watch_connectivity_state(" @@ -96,8 +215,37 @@ void grpc_channel_watch_connectivity_state( "cq=%p, tag=%p)", 7, (channel, (int)last_observed_state, deadline.tv_sec, deadline.tv_nsec, (int)deadline.clock_type, cq, tag)); - grpc_channel_watch_connectivity_state_internal( - &exec_ctx, client_channel_elem, channel_stack, last_observed_state, - deadline, cq, tag); + + GPR_ASSERT(grpc_cq_begin_op(cq, tag)); + + gpr_mu_init(&w->mu); + GRPC_CLOSURE_INIT(&w->on_complete, watch_complete, w, + grpc_schedule_on_exec_ctx); + GRPC_CLOSURE_INIT(&w->on_timeout, timeout_complete, w, + grpc_schedule_on_exec_ctx); + w->phase = WAITING; + w->state = last_observed_state; + w->cq = cq; + w->tag = tag; + w->channel = channel; + w->error = NULL; + + watcher_timer_init_arg *wa = + (watcher_timer_init_arg *)gpr_malloc(sizeof(watcher_timer_init_arg)); + wa->w = w; + wa->deadline = deadline; + GRPC_CLOSURE_INIT(&w->watcher_timer_init, watcher_timer_init, wa, + grpc_schedule_on_exec_ctx); + + if (client_channel_elem->filter == &grpc_client_channel_filter) { + GRPC_CHANNEL_INTERNAL_REF(channel, "watch_channel_connectivity"); + grpc_client_channel_watch_connectivity_state( + &exec_ctx, client_channel_elem, + grpc_polling_entity_create_from_pollset(grpc_cq_pollset(cq)), &w->state, + &w->on_complete, &w->watcher_timer_init); + } else { + abort(); + } + grpc_exec_ctx_finish(&exec_ctx); } diff --git a/src/core/ext/filters/client_channel/channel_connectivity_internal.cc b/src/core/ext/filters/client_channel/channel_connectivity_internal.cc deleted file mode 100644 index 06bcfe2ffb..0000000000 --- a/src/core/ext/filters/client_channel/channel_connectivity_internal.cc +++ /dev/null @@ -1,195 +0,0 @@ -/* - * - * Copyright 2015 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include "src/core/ext/filters/client_channel/channel_connectivity_internal.h" - -#include -#include - -#include "src/core/ext/filters/client_channel/client_channel.h" -#include "src/core/lib/iomgr/timer.h" -#include "src/core/lib/surface/api_trace.h" -#include "src/core/lib/surface/completion_queue.h" - -typedef enum { - WAITING, - READY_TO_CALL_BACK, - CALLING_BACK_AND_FINISHED, -} callback_phase; - -typedef struct { - gpr_mu mu; - callback_phase phase; - grpc_closure on_complete; - grpc_closure on_timeout; - grpc_closure watcher_timer_init; - grpc_timer alarm; - grpc_connectivity_state state; - grpc_completion_queue *cq; - grpc_cq_completion completion_storage; - grpc_channel_element *client_channel_elem; - grpc_channel_stack *channel_stack; - grpc_error *error; - void *tag; -} state_watcher; - -static void delete_state_watcher(grpc_exec_ctx *exec_ctx, state_watcher *w) { - GRPC_CHANNEL_STACK_UNREF(exec_ctx, w->channel_stack, - "watch_channel_connectivity"); - gpr_mu_destroy(&w->mu); - gpr_free(w); -} - -static void finished_completion(grpc_exec_ctx *exec_ctx, void *pw, - grpc_cq_completion *ignored) { - bool should_delete = false; - state_watcher *w = (state_watcher *)pw; - gpr_mu_lock(&w->mu); - switch (w->phase) { - case WAITING: - case READY_TO_CALL_BACK: - GPR_UNREACHABLE_CODE(return ); - case CALLING_BACK_AND_FINISHED: - should_delete = true; - break; - } - gpr_mu_unlock(&w->mu); - - if (should_delete) { - delete_state_watcher(exec_ctx, w); - } -} - -static void partly_done(grpc_exec_ctx *exec_ctx, state_watcher *w, - bool due_to_completion, grpc_error *error) { - if (due_to_completion) { - grpc_timer_cancel(exec_ctx, &w->alarm); - } else { - grpc_channel_element *client_channel_elem = w->client_channel_elem; - grpc_client_channel_watch_connectivity_state( - exec_ctx, client_channel_elem, - grpc_polling_entity_create_from_pollset(grpc_cq_pollset(w->cq)), NULL, - &w->on_complete, NULL); - } - - gpr_mu_lock(&w->mu); - - if (due_to_completion) { - if (GRPC_TRACER_ON(grpc_trace_operation_failures)) { - GRPC_LOG_IF_ERROR("watch_completion_error", GRPC_ERROR_REF(error)); - } - GRPC_ERROR_UNREF(error); - error = GRPC_ERROR_NONE; - } else { - if (error == GRPC_ERROR_NONE) { - error = GRPC_ERROR_CREATE_FROM_STATIC_STRING( - "Timed out waiting for connection state change"); - } else if (error == GRPC_ERROR_CANCELLED) { - error = GRPC_ERROR_NONE; - } - } - switch (w->phase) { - case WAITING: - GRPC_ERROR_REF(error); - w->error = error; - w->phase = READY_TO_CALL_BACK; - break; - case READY_TO_CALL_BACK: - if (error != GRPC_ERROR_NONE) { - GPR_ASSERT(!due_to_completion); - GRPC_ERROR_UNREF(w->error); - GRPC_ERROR_REF(error); - w->error = error; - } - w->phase = CALLING_BACK_AND_FINISHED; - grpc_cq_end_op(exec_ctx, w->cq, w->tag, w->error, finished_completion, w, - &w->completion_storage); - break; - case CALLING_BACK_AND_FINISHED: - GPR_UNREACHABLE_CODE(return ); - break; - } - gpr_mu_unlock(&w->mu); - - GRPC_ERROR_UNREF(error); -} - -static void watch_complete(grpc_exec_ctx *exec_ctx, void *pw, - grpc_error *error) { - partly_done(exec_ctx, (state_watcher *)pw, true, GRPC_ERROR_REF(error)); -} - -static void timeout_complete(grpc_exec_ctx *exec_ctx, void *pw, - grpc_error *error) { - partly_done(exec_ctx, (state_watcher *)pw, false, GRPC_ERROR_REF(error)); -} - -typedef struct watcher_timer_init_arg { - state_watcher *w; - gpr_timespec deadline; -} watcher_timer_init_arg; - -static void watcher_timer_init(grpc_exec_ctx *exec_ctx, void *arg, - grpc_error *error_ignored) { - watcher_timer_init_arg *wa = (watcher_timer_init_arg *)arg; - - grpc_timer_init(exec_ctx, &wa->w->alarm, - gpr_convert_clock_type(wa->deadline, GPR_CLOCK_MONOTONIC), - &wa->w->on_timeout, gpr_now(GPR_CLOCK_MONOTONIC)); - gpr_free(wa); -} - -void grpc_channel_watch_connectivity_state_internal( - grpc_exec_ctx *exec_ctx, grpc_channel_element *client_channel_elem, - grpc_channel_stack *channel_stack, - grpc_connectivity_state last_observed_state, gpr_timespec deadline, - grpc_completion_queue *cq, void *tag) { - state_watcher *w = (state_watcher *)gpr_malloc(sizeof(*w)); - - GPR_ASSERT(grpc_cq_begin_op(cq, tag)); - - gpr_mu_init(&w->mu); - GRPC_CLOSURE_INIT(&w->on_complete, watch_complete, w, - grpc_schedule_on_exec_ctx); - GRPC_CLOSURE_INIT(&w->on_timeout, timeout_complete, w, - grpc_schedule_on_exec_ctx); - w->phase = WAITING; - w->state = last_observed_state; - w->cq = cq; - w->tag = tag; - w->client_channel_elem = client_channel_elem; - w->channel_stack = channel_stack; - w->error = NULL; - - watcher_timer_init_arg *wa = - (watcher_timer_init_arg *)gpr_malloc(sizeof(watcher_timer_init_arg)); - wa->w = w; - wa->deadline = deadline; - GRPC_CLOSURE_INIT(&w->watcher_timer_init, watcher_timer_init, wa, - grpc_schedule_on_exec_ctx); - - if (client_channel_elem->filter == &grpc_client_channel_filter) { - GRPC_CHANNEL_STACK_REF(channel_stack, "watch_channel_connectivity"); - grpc_client_channel_watch_connectivity_state( - exec_ctx, client_channel_elem, - grpc_polling_entity_create_from_pollset(grpc_cq_pollset(cq)), &w->state, - &w->on_complete, &w->watcher_timer_init); - } else { - abort(); - } -} diff --git a/src/core/ext/filters/client_channel/channel_connectivity_internal.h b/src/core/ext/filters/client_channel/channel_connectivity_internal.h deleted file mode 100644 index d260a20c07..0000000000 --- a/src/core/ext/filters/client_channel/channel_connectivity_internal.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - * - * Copyright 2015 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#ifndef GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_CHANNEL_CONNECTIVITY_INTERNAL_H -#define GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_CHANNEL_CONNECTIVITY_INTERNAL_H - -#include -#include "src/core/lib/channel/channel_stack.h" -#include "src/core/lib/iomgr/exec_ctx.h" - -void grpc_channel_watch_connectivity_state_internal( - grpc_exec_ctx *exec_ctx, grpc_channel_element *client_channel_elem, - grpc_channel_stack *channel_stack, - grpc_connectivity_state last_observed_state, gpr_timespec deadline, - grpc_completion_queue *cq, void *tag); - -#endif /* GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_CHANNEL_CONNECTIVITY_INTERNAL_H \ - */ diff --git a/src/core/ext/filters/client_channel/client_channel.cc b/src/core/ext/filters/client_channel/client_channel.cc index be8ea81a02..8223f25a33 100644 --- a/src/core/ext/filters/client_channel/client_channel.cc +++ b/src/core/ext/filters/client_channel/client_channel.cc @@ -31,7 +31,7 @@ #include #include -#include "src/core/ext/filters/client_channel/connectivity_watcher.h" +#include "src/core/ext/filters/client_channel/backup_poller.h" #include "src/core/ext/filters/client_channel/http_connect_handshaker.h" #include "src/core/ext/filters/client_channel/lb_policy_registry.h" #include "src/core/ext/filters/client_channel/proxy_mapper_registry.h" @@ -754,8 +754,7 @@ static grpc_error *cc_init_channel_elem(grpc_exec_ctx *exec_ctx, } chand->deadline_checking_enabled = grpc_deadline_checking_enabled(args->channel_args); - grpc_client_channel_start_watching_connectivity(exec_ctx, elem, - chand->owning_stack); + grpc_client_channel_start_backup_polling(exec_ctx, chand->interested_parties); return GRPC_ERROR_NONE; } @@ -793,6 +792,7 @@ static void cc_destroy_channel_elem(grpc_exec_ctx *exec_ctx, if (chand->method_params_table != NULL) { grpc_slice_hash_table_unref(exec_ctx, chand->method_params_table); } + grpc_client_channel_stop_backup_polling(exec_ctx, chand->interested_parties); grpc_connectivity_state_destroy(exec_ctx, &chand->state_tracker); grpc_pollset_set_destroy(exec_ctx, chand->interested_parties); GRPC_COMBINER_UNREF(exec_ctx, chand->combiner, "client_channel"); diff --git a/src/core/ext/filters/client_channel/connectivity_watcher.cc b/src/core/ext/filters/client_channel/connectivity_watcher.cc deleted file mode 100644 index da45929f26..0000000000 --- a/src/core/ext/filters/client_channel/connectivity_watcher.cc +++ /dev/null @@ -1,179 +0,0 @@ -/* - * - * Copyright 2015 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include "src/core/ext/filters/client_channel/connectivity_watcher.h" - -#include -#include -#include -#include -#include "src/core/ext/filters/client_channel/channel_connectivity_internal.h" -#include "src/core/ext/filters/client_channel/client_channel.h" -#include "src/core/lib/iomgr/timer.h" -#include "src/core/lib/support/env.h" -#include "src/core/lib/support/string.h" -#include "src/core/lib/surface/channel.h" -#include "src/core/lib/surface/completion_queue.h" - -#define DEFAULT_CONNECTIVITY_CHECK_INTERVAL_MS 500 - -typedef struct connectivity_watcher { - grpc_timer watcher_timer; - grpc_closure check_connectivity_closure; - grpc_completion_queue* cq; - gpr_refcount refs; - size_t channel_count; - bool shutting_down; -} connectivity_watcher; - -typedef struct channel_state { - grpc_channel_element* client_channel_elem; - grpc_channel_stack* channel_stack; - grpc_connectivity_state state; -} channel_state; - -static gpr_once g_once = GPR_ONCE_INIT; -static gpr_mu g_watcher_mu; -static connectivity_watcher* g_watcher = NULL; - -static void init_g_watcher_mu() { gpr_mu_init(&g_watcher_mu); } - -static void start_watching_locked(grpc_exec_ctx* exec_ctx, - grpc_channel_element* client_channel_elem, - grpc_channel_stack* channel_stack) { - gpr_ref(&g_watcher->refs); - ++g_watcher->channel_count; - channel_state* s = (channel_state*)gpr_zalloc(sizeof(channel_state)); - s->client_channel_elem = client_channel_elem; - s->channel_stack = channel_stack; - s->state = GRPC_CHANNEL_IDLE; - grpc_channel_watch_connectivity_state_internal( - exec_ctx, client_channel_elem, channel_stack, s->state, - gpr_inf_future(GPR_CLOCK_MONOTONIC), g_watcher->cq, (void*)s); -} - -static bool is_disabled() { - char* env = gpr_getenv("GRPC_DISABLE_CHANNEL_CONNECTIVITY_WATCHER"); - bool disabled = gpr_is_true(env); - gpr_free(env); - return disabled; -} - -static bool connectivity_watcher_unref(grpc_exec_ctx* exec_ctx) { - if (gpr_unref(&g_watcher->refs)) { - gpr_mu_lock(&g_watcher_mu); - grpc_completion_queue_destroy(g_watcher->cq); - gpr_free(g_watcher); - g_watcher = NULL; - gpr_mu_unlock(&g_watcher_mu); - return true; - } - return false; -} - -static void check_connectivity_state(grpc_exec_ctx* exec_ctx, void* ignored, - grpc_error* error) { - grpc_event ev; - while (true) { - gpr_mu_lock(&g_watcher_mu); - if (g_watcher->shutting_down) { - // Drain cq if the watcher is shutting down - ev = grpc_completion_queue_next( - g_watcher->cq, gpr_inf_future(GPR_CLOCK_MONOTONIC), NULL); - } else { - ev = grpc_completion_queue_next(g_watcher->cq, - gpr_inf_past(GPR_CLOCK_MONOTONIC), NULL); - // Make sure we've seen 2 TIMEOUTs before going to sleep - if (ev.type == GRPC_QUEUE_TIMEOUT) { - ev = grpc_completion_queue_next( - g_watcher->cq, gpr_inf_past(GPR_CLOCK_MONOTONIC), NULL); - if (ev.type == GRPC_QUEUE_TIMEOUT) { - gpr_timespec now = gpr_now(GPR_CLOCK_MONOTONIC); - grpc_timer_init( - exec_ctx, &g_watcher->watcher_timer, - gpr_time_add(now, gpr_time_from_millis( - DEFAULT_CONNECTIVITY_CHECK_INTERVAL_MS, - GPR_TIMESPAN)), - &g_watcher->check_connectivity_closure, now); - gpr_mu_unlock(&g_watcher_mu); - break; - } - } - } - gpr_mu_unlock(&g_watcher_mu); - if (ev.type != GRPC_OP_COMPLETE) { - break; - } - channel_state* s = (channel_state*)(ev.tag); - s->state = grpc_client_channel_check_connectivity_state( - exec_ctx, s->client_channel_elem, false /* try_to_connect */); - if (s->state == GRPC_CHANNEL_SHUTDOWN) { - GRPC_CHANNEL_STACK_UNREF(exec_ctx, s->channel_stack, - "connectivity_watcher_stop_watching"); - gpr_free(s); - if (connectivity_watcher_unref(exec_ctx)) { - break; - } - } else { - grpc_channel_watch_connectivity_state_internal( - exec_ctx, s->client_channel_elem, s->channel_stack, s->state, - gpr_inf_future(GPR_CLOCK_MONOTONIC), g_watcher->cq, s); - } - } -} - -void grpc_client_channel_start_watching_connectivity( - grpc_exec_ctx* exec_ctx, grpc_channel_element* client_channel_elem, - grpc_channel_stack* channel_stack) { - if (is_disabled()) return; - GRPC_CHANNEL_STACK_REF(channel_stack, "connectivity_watcher_start_watching"); - gpr_once_init(&g_once, init_g_watcher_mu); - gpr_mu_lock(&g_watcher_mu); - if (g_watcher == NULL) { - g_watcher = (connectivity_watcher*)gpr_zalloc(sizeof(connectivity_watcher)); - g_watcher->cq = grpc_completion_queue_create_internal( - GRPC_CQ_NEXT, GRPC_CQ_DEFAULT_POLLING); - gpr_ref_init(&g_watcher->refs, 0); - GRPC_CLOSURE_INIT(&g_watcher->check_connectivity_closure, - check_connectivity_state, NULL, - grpc_schedule_on_exec_ctx); - gpr_timespec now = gpr_now(GPR_CLOCK_MONOTONIC); - grpc_timer_init( - exec_ctx, &g_watcher->watcher_timer, - gpr_time_add( - now, gpr_time_from_millis(DEFAULT_CONNECTIVITY_CHECK_INTERVAL_MS, - GPR_TIMESPAN)), - &g_watcher->check_connectivity_closure, now); - } - start_watching_locked(exec_ctx, client_channel_elem, channel_stack); - gpr_mu_init(&g_watcher_mu); -} - -void grpc_client_channel_stop_watching_connectivity( - grpc_exec_ctx* exec_ctx, grpc_channel_element* client_channel_elem, - grpc_channel_stack* channel_stack) { - if (is_disabled()) return; - gpr_once_init(&g_once, init_g_watcher_mu); - gpr_mu_lock(&g_watcher_mu); - if (--g_watcher->channel_count == 0) { - g_watcher->shutting_down = true; - grpc_timer_cancel(exec_ctx, &g_watcher->watcher_timer); - connectivity_watcher_unref(exec_ctx); - } - gpr_mu_unlock(&g_watcher_mu); -} diff --git a/src/core/ext/filters/client_channel/connectivity_watcher.h b/src/core/ext/filters/client_channel/connectivity_watcher.h deleted file mode 100644 index e12d6c284a..0000000000 --- a/src/core/ext/filters/client_channel/connectivity_watcher.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * - * Copyright 2015 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#ifndef GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_CONNECTIVITY_WATCHER_H -#define GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_CONNECTIVITY_WATCHER_H - -#include -#include "src/core/lib/channel/channel_stack.h" -#include "src/core/lib/iomgr/exec_ctx.h" - -/* Constantly watches client channel connectivity status to reconnect a - * transiently disconnected channel */ -void grpc_client_channel_start_watching_connectivity( - grpc_exec_ctx* exec_ctx, grpc_channel_element* client_channel_elem, - grpc_channel_stack* channel_stack); - -#endif /* GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_CONNECTIVITY_WATCHER_H */ diff --git a/src/python/grpcio/grpc_core_dependencies.py b/src/python/grpcio/grpc_core_dependencies.py index 44a4f0401a..cf2e244e1e 100644 --- a/src/python/grpcio/grpc_core_dependencies.py +++ b/src/python/grpcio/grpc_core_dependencies.py @@ -254,12 +254,11 @@ CORE_SOURCE_FILES = [ 'src/core/tsi/transport_security_adapter.cc', 'src/core/ext/transport/chttp2/server/chttp2_server.cc', 'src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc', + 'src/core/ext/filters/client_channel/backup_poller.cc', 'src/core/ext/filters/client_channel/channel_connectivity.cc', - 'src/core/ext/filters/client_channel/channel_connectivity_internal.cc', 'src/core/ext/filters/client_channel/client_channel.cc', 'src/core/ext/filters/client_channel/client_channel_factory.cc', 'src/core/ext/filters/client_channel/client_channel_plugin.cc', - 'src/core/ext/filters/client_channel/connectivity_watcher.cc', 'src/core/ext/filters/client_channel/connector.cc', 'src/core/ext/filters/client_channel/http_connect_handshaker.cc', 'src/core/ext/filters/client_channel/http_proxy.cc', diff --git a/test/cpp/end2end/async_end2end_test.cc b/test/cpp/end2end/async_end2end_test.cc index b7634d0438..4d1beb1d1d 100644 --- a/test/cpp/end2end/async_end2end_test.cc +++ b/test/cpp/end2end/async_end2end_test.cc @@ -470,8 +470,9 @@ TEST_P(AsyncEnd2endTest, ReconnectChannel) { BuildAndStartServer(); // It needs more than kConnectivityCheckIntervalMsec time to reconnect the // channel. - gpr_sleep_until(gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), - gpr_time_from_millis(1600, GPR_TIMESPAN))); + gpr_sleep_until(gpr_time_add( + gpr_now(GPR_CLOCK_REALTIME), + gpr_time_from_millis(600 * grpc_test_slowdown_factor(), GPR_TIMESPAN))); SendRpc(1); } diff --git a/test/cpp/end2end/end2end_test.cc b/test/cpp/end2end/end2end_test.cc index 1aa547d4e3..73f5555539 100644 --- a/test/cpp/end2end/end2end_test.cc +++ b/test/cpp/end2end/end2end_test.cc @@ -709,8 +709,9 @@ TEST_P(End2endTest, ReconnectChannel) { RestartServer(std::shared_ptr()); // It needs more than kConnectivityCheckIntervalMsec time to reconnect the // channel. - gpr_sleep_until(gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), - gpr_time_from_millis(1600, GPR_TIMESPAN))); + gpr_sleep_until(gpr_time_add( + gpr_now(GPR_CLOCK_REALTIME), + gpr_time_from_millis(600 * grpc_test_slowdown_factor(), GPR_TIMESPAN))); SendRpc(stub_.get(), 1, false); } diff --git a/tools/doxygen/Doxyfile.core.internal b/tools/doxygen/Doxyfile.core.internal index 15ec466ded..46ca54bf76 100644 --- a/tools/doxygen/Doxyfile.core.internal +++ b/tools/doxygen/Doxyfile.core.internal @@ -907,16 +907,14 @@ src/core/ext/census/trace_string.h \ src/core/ext/census/tracing.cc \ src/core/ext/census/tracing.h \ src/core/ext/filters/client_channel/README.md \ +src/core/ext/filters/client_channel/backup_poller.cc \ +src/core/ext/filters/client_channel/backup_poller.h \ src/core/ext/filters/client_channel/channel_connectivity.cc \ -src/core/ext/filters/client_channel/channel_connectivity_internal.cc \ -src/core/ext/filters/client_channel/channel_connectivity_internal.h \ src/core/ext/filters/client_channel/client_channel.cc \ src/core/ext/filters/client_channel/client_channel.h \ src/core/ext/filters/client_channel/client_channel_factory.cc \ src/core/ext/filters/client_channel/client_channel_factory.h \ src/core/ext/filters/client_channel/client_channel_plugin.cc \ -src/core/ext/filters/client_channel/connectivity_watcher.cc \ -src/core/ext/filters/client_channel/connectivity_watcher.h \ src/core/ext/filters/client_channel/connector.cc \ src/core/ext/filters/client_channel/connector.h \ src/core/ext/filters/client_channel/http_connect_handshaker.cc \ diff --git a/tools/run_tests/generated/sources_and_headers.json b/tools/run_tests/generated/sources_and_headers.json index e6ee1cf733..9cd200fe5a 100644 --- a/tools/run_tests/generated/sources_and_headers.json +++ b/tools/run_tests/generated/sources_and_headers.json @@ -8467,10 +8467,9 @@ "grpc_deadline_filter" ], "headers": [ - "src/core/ext/filters/client_channel/channel_connectivity_internal.h", + "src/core/ext/filters/client_channel/backup_poller.h", "src/core/ext/filters/client_channel/client_channel.h", "src/core/ext/filters/client_channel/client_channel_factory.h", - "src/core/ext/filters/client_channel/connectivity_watcher.h", "src/core/ext/filters/client_channel/connector.h", "src/core/ext/filters/client_channel/http_connect_handshaker.h", "src/core/ext/filters/client_channel/http_proxy.h", @@ -8492,16 +8491,14 @@ "language": "c", "name": "grpc_client_channel", "src": [ + "src/core/ext/filters/client_channel/backup_poller.cc", + "src/core/ext/filters/client_channel/backup_poller.h", "src/core/ext/filters/client_channel/channel_connectivity.cc", - "src/core/ext/filters/client_channel/channel_connectivity_internal.cc", - "src/core/ext/filters/client_channel/channel_connectivity_internal.h", "src/core/ext/filters/client_channel/client_channel.cc", "src/core/ext/filters/client_channel/client_channel.h", "src/core/ext/filters/client_channel/client_channel_factory.cc", "src/core/ext/filters/client_channel/client_channel_factory.h", "src/core/ext/filters/client_channel/client_channel_plugin.cc", - "src/core/ext/filters/client_channel/connectivity_watcher.cc", - "src/core/ext/filters/client_channel/connectivity_watcher.h", "src/core/ext/filters/client_channel/connector.cc", "src/core/ext/filters/client_channel/connector.h", "src/core/ext/filters/client_channel/http_connect_handshaker.cc", -- cgit v1.2.3