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::ProxyMapperRegistry::Init();
grpc_core::RegisterHttpProxyMapper();
grpc_core::GlobalSubchannelPool::Init();
grpc_client_channel_global_init_backup_polling();
}
void grpc_client_channel_shutdown(void) {
grpc_core::GlobalSubchannelPool::Shutdown();
grpc_core::ProxyMapperRegistry::Shutdown();
grpc_core::LoadBalancingPolicyRegistry::Builder::ShutdownRegistry();
}

@ -24,27 +24,9 @@
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() {
GPR_ASSERT(instance_ != nullptr);
GPR_ASSERT(*instance_ != nullptr);
return *instance_;
static GlobalSubchannelPool* p = new GlobalSubchannelPool();
return p->Ref();
}
RefCountedPtr<Subchannel> GlobalSubchannelPool::RegisterSubchannel(
@ -59,8 +41,6 @@ RefCountedPtr<Subchannel> GlobalSubchannelPool::RegisterSubchannel(
return constructed;
}
RefCountedPtr<GlobalSubchannelPool>* GlobalSubchannelPool::instance_ = nullptr;
void GlobalSubchannelPool::UnregisterSubchannel(const SubchannelKey& key,
Subchannel* subchannel) {
MutexLock lock(&mu_);

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

Loading…
Cancel
Save