Remove subchannel pool from global init (#28987)

* Remove subchannel pool from global init

This can be initialized independently, so let's do so.

* fix

* fix

* cleanup
pull/28994/head
Craig Tiller 3 years ago committed by GitHub
parent 3eba748552
commit 4633121440
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      src/core/ext/filters/client_channel/client_channel_plugin.cc
  2. 24
      src/core/ext/filters/client_channel/global_subchannel_pool.cc
  3. 18
      src/core/ext/filters/client_channel/global_subchannel_pool.h

@ -42,12 +42,10 @@ void grpc_client_channel_init(void) {
grpc_core::LoadBalancingPolicyRegistry::Builder::InitRegistry(); grpc_core::LoadBalancingPolicyRegistry::Builder::InitRegistry();
grpc_core::ProxyMapperRegistry::Init(); grpc_core::ProxyMapperRegistry::Init();
grpc_core::RegisterHttpProxyMapper(); grpc_core::RegisterHttpProxyMapper();
grpc_core::GlobalSubchannelPool::Init();
grpc_client_channel_global_init_backup_polling(); grpc_client_channel_global_init_backup_polling();
} }
void grpc_client_channel_shutdown(void) { void grpc_client_channel_shutdown(void) {
grpc_core::GlobalSubchannelPool::Shutdown();
grpc_core::ProxyMapperRegistry::Shutdown(); grpc_core::ProxyMapperRegistry::Shutdown();
grpc_core::LoadBalancingPolicyRegistry::Builder::ShutdownRegistry(); grpc_core::LoadBalancingPolicyRegistry::Builder::ShutdownRegistry();
} }

@ -24,27 +24,9 @@
namespace grpc_core { namespace grpc_core {
#define GRPC_REGISTER_SUBCHANNEL_CALM_DOWN_AFTER_ATTEMPTS 100
#define GRPC_REGISTER_SUBCHANNEL_CALM_DOWN_MICROS 10
void GlobalSubchannelPool::Init() {
instance_ = new RefCountedPtr<GlobalSubchannelPool>(
MakeRefCounted<GlobalSubchannelPool>());
}
void GlobalSubchannelPool::Shutdown() {
// To ensure Init() was called before.
GPR_ASSERT(instance_ != nullptr);
// To ensure Shutdown() was not called before.
GPR_ASSERT(*instance_ != nullptr);
instance_->reset();
delete instance_;
}
RefCountedPtr<GlobalSubchannelPool> GlobalSubchannelPool::instance() { RefCountedPtr<GlobalSubchannelPool> GlobalSubchannelPool::instance() {
GPR_ASSERT(instance_ != nullptr); static GlobalSubchannelPool* p = new GlobalSubchannelPool();
GPR_ASSERT(*instance_ != nullptr); return p->Ref();
return *instance_;
} }
RefCountedPtr<Subchannel> GlobalSubchannelPool::RegisterSubchannel( RefCountedPtr<Subchannel> GlobalSubchannelPool::RegisterSubchannel(
@ -59,8 +41,6 @@ RefCountedPtr<Subchannel> GlobalSubchannelPool::RegisterSubchannel(
return constructed; return constructed;
} }
RefCountedPtr<GlobalSubchannelPool>* GlobalSubchannelPool::instance_ = nullptr;
void GlobalSubchannelPool::UnregisterSubchannel(const SubchannelKey& key, void GlobalSubchannelPool::UnregisterSubchannel(const SubchannelKey& key,
Subchannel* subchannel) { Subchannel* subchannel) {
MutexLock lock(&mu_); MutexLock lock(&mu_);

@ -29,20 +29,9 @@
namespace grpc_core { namespace grpc_core {
// The global subchannel pool. It shares subchannels among channels. There // The global subchannel pool. It shares subchannels among channels. There
// should be only one instance of this class. Init() should be called once at // should be only one instance of this class.
// the filter initialization time; Shutdown() should be called once at the
// filter shutdown time.
class GlobalSubchannelPool final : public SubchannelPoolInterface { class GlobalSubchannelPool final : public SubchannelPoolInterface {
public: public:
// The ctor and dtor are not intended to use directly.
GlobalSubchannelPool() {}
~GlobalSubchannelPool() override {}
// Should be called exactly once at filter initialization time.
static void Init();
// Should be called exactly once at filter shutdown time.
static void Shutdown();
// Gets the singleton instance. // Gets the singleton instance.
static RefCountedPtr<GlobalSubchannelPool> instance(); static RefCountedPtr<GlobalSubchannelPool> instance();
@ -57,9 +46,8 @@ class GlobalSubchannelPool final : public SubchannelPoolInterface {
ABSL_LOCKS_EXCLUDED(mu_); ABSL_LOCKS_EXCLUDED(mu_);
private: private:
// The singleton instance. (It's a pointer to RefCountedPtr so that this GlobalSubchannelPool() {}
// non-local static object can be trivially destructible.) ~GlobalSubchannelPool() override {}
static RefCountedPtr<GlobalSubchannelPool>* instance_;
// A map from subchannel key to subchannel. // A map from subchannel key to subchannel.
std::map<SubchannelKey, Subchannel*> subchannel_map_ ABSL_GUARDED_BY(mu_); std::map<SubchannelKey, Subchannel*> subchannel_map_ ABSL_GUARDED_BY(mu_);

Loading…
Cancel
Save