From 5cd20237de6b521480d09c68d06ba7668d26d356 Mon Sep 17 00:00:00 2001 From: Xiaobing Zhou Date: Fri, 19 May 2017 07:54:33 -0700 Subject: [PATCH] HBASE-18079. [C++] Optimize ClientBootstrap in ConnectionPool --- hbase-native-client/connection/connection-pool.cc | 16 +++++++++------- hbase-native-client/connection/connection-pool.h | 7 +++---- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/hbase-native-client/connection/connection-pool.cc b/hbase-native-client/connection/connection-pool.cc index 3121294..180d045 100644 --- a/hbase-native-client/connection/connection-pool.cc +++ b/hbase-native-client/connection/connection-pool.cc @@ -38,11 +38,15 @@ using folly::SocketAddress; ConnectionPool::ConnectionPool(std::shared_ptr io_executor, std::shared_ptr codec, nanoseconds connect_timeout) : cf_(std::make_shared(io_executor, codec, connect_timeout)), - clients_(), connections_(), - map_mutex_() {} + map_mutex_() { + client_bootstrap_ = cf_->MakeBootstrap(); +} + ConnectionPool::ConnectionPool(std::shared_ptr cf) - : cf_(cf), clients_(), connections_(), map_mutex_() {} + : cf_(cf), connections_(), map_mutex_() { + client_bootstrap_ = cf_->MakeBootstrap(); +} ConnectionPool::~ConnectionPool() { Close(); } @@ -88,12 +92,11 @@ std::shared_ptr ConnectionPool::GetNewConnection( connections_.erase(remote_id); /* create new connection */ - auto clientBootstrap = cf_->MakeBootstrap(); - auto dispatcher = cf_->Connect(clientBootstrap, remote_id->host(), remote_id->port()); + auto dispatcher = cf_->Connect(client_bootstrap_, remote_id->host(), + remote_id->port()); auto connection = std::make_shared(remote_id, dispatcher); connections_.insert(std::make_pair(remote_id, connection)); - clients_.insert(std::make_pair(remote_id, clientBootstrap)); return connection; } @@ -120,5 +123,4 @@ void ConnectionPool::Close() { con->Close(); } connections_.clear(); - clients_.clear(); } diff --git a/hbase-native-client/connection/connection-pool.h b/hbase-native-client/connection/connection-pool.h index 2a8f195..d22a7d6 100644 --- a/hbase-native-client/connection/connection-pool.h +++ b/hbase-native-client/connection/connection-pool.h @@ -87,12 +87,11 @@ class ConnectionPool { std::unordered_map, std::shared_ptr, ConnectionIdHash, ConnectionIdEquals> connections_; - std::unordered_map, - std::shared_ptr>, ConnectionIdHash, - ConnectionIdEquals> - clients_; folly::SharedMutexWritePriority map_mutex_; std::shared_ptr cf_; + + private: + std::shared_ptr> client_bootstrap_; }; } // namespace hbase -- 2.10.1 (Apple Git-78)