diff options
author | Yang Gao <yangg@google.com> | 2018-12-07 13:15:30 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-12-07 13:15:30 -0800 |
commit | b590167cf28365111de0e2f6ccae1a86536d52cc (patch) | |
tree | 55b94f815d4213e0a82ebeb3766758d6793afb0b /src/cpp/server | |
parent | 6dc358ca341faf1bcfb88b4635caf61ca2d6c598 (diff) | |
parent | 2246607dedfbad98c3aa4f39997907a203985863 (diff) |
Merge pull request #17435 from yang-g/health_service_shutdown
Add a Shutdown call to HealthCheckServiceInterface
Diffstat (limited to 'src/cpp/server')
-rw-r--r-- | src/cpp/server/health/default_health_check_service.cc | 19 | ||||
-rw-r--r-- | src/cpp/server/health/default_health_check_service.h | 3 |
2 files changed, 22 insertions, 0 deletions
diff --git a/src/cpp/server/health/default_health_check_service.cc b/src/cpp/server/health/default_health_check_service.cc index c951c69d51..44aebd2f9d 100644 --- a/src/cpp/server/health/default_health_check_service.cc +++ b/src/cpp/server/health/default_health_check_service.cc @@ -42,18 +42,37 @@ DefaultHealthCheckService::DefaultHealthCheckService() { void DefaultHealthCheckService::SetServingStatus( const grpc::string& service_name, bool serving) { std::unique_lock<std::mutex> lock(mu_); + if (shutdown_) { + // Set to NOT_SERVING in case service_name is not in the map. + serving = false; + } services_map_[service_name].SetServingStatus(serving ? SERVING : NOT_SERVING); } void DefaultHealthCheckService::SetServingStatus(bool serving) { const ServingStatus status = serving ? SERVING : NOT_SERVING; std::unique_lock<std::mutex> lock(mu_); + if (shutdown_) { + return; + } for (auto& p : services_map_) { ServiceData& service_data = p.second; service_data.SetServingStatus(status); } } +void DefaultHealthCheckService::Shutdown() { + std::unique_lock<std::mutex> lock(mu_); + if (shutdown_) { + return; + } + shutdown_ = true; + for (auto& p : services_map_) { + ServiceData& service_data = p.second; + service_data.SetServingStatus(NOT_SERVING); + } +} + DefaultHealthCheckService::ServingStatus DefaultHealthCheckService::GetServingStatus( const grpc::string& service_name) const { diff --git a/src/cpp/server/health/default_health_check_service.h b/src/cpp/server/health/default_health_check_service.h index 450bd543f5..9551cd2e2c 100644 --- a/src/cpp/server/health/default_health_check_service.h +++ b/src/cpp/server/health/default_health_check_service.h @@ -237,6 +237,8 @@ class DefaultHealthCheckService final : public HealthCheckServiceInterface { bool serving) override; void SetServingStatus(bool serving) override; + void Shutdown() override; + ServingStatus GetServingStatus(const grpc::string& service_name) const; HealthCheckServiceImpl* GetHealthCheckService( @@ -272,6 +274,7 @@ class DefaultHealthCheckService final : public HealthCheckServiceInterface { const std::shared_ptr<HealthCheckServiceImpl::CallHandler>& handler); mutable std::mutex mu_; + bool shutdown_ = false; // Guarded by mu_. std::map<grpc::string, ServiceData> services_map_; // Guarded by mu_. std::unique_ptr<HealthCheckServiceImpl> impl_; }; |