This is an automated email from the ASF dual-hosted git repository. alexey pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/kudu.git
commit 75bb0ea1b1a543a32d87b0f14671aa9eb7571dfb Author: Alexey Serbin <[email protected]> AuthorDate: Mon Nov 9 12:19:09 2020 -0800 [client] use make_shared for a few call sites This changelist replaces std::shared_ptr<X> x = new X(...) with std::shared_ptr<X> x = std::make_shared<X>(...) in a few places in Kudu C++ client. The latter form is better from the standpoint of memory allocations count, as described at https://en.cppreference.com/w/cpp/memory/shared_ptr/make_shared#Notes I also modernized the code in updated files a bit. Change-Id: I0c1b8bdfffec596db6a262c195cc94796d1bc1d5 Reviewed-on: http://gerrit.cloudera.org:8080/16703 Tested-by: Kudu Jenkins Reviewed-by: Mahesh Reddy <[email protected]> Reviewed-by: Bankim Bhavsar <[email protected]> --- src/kudu/client/client-internal.cc | 5 +++-- src/kudu/client/meta_cache.cc | 12 ++++++++---- src/kudu/client/meta_cache.h | 4 +--- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/kudu/client/client-internal.cc b/src/kudu/client/client-internal.cc index 26fd9c9..a55e5aa 100644 --- a/src/kudu/client/client-internal.cc +++ b/src/kudu/client/client-internal.cc @@ -560,7 +560,7 @@ Status KuduClient::Data::GetTableSchema(KuduClient* client, rpc.SendRpc(); RETURN_NOT_OK(sync.Wait()); // Parse the server schema out of the response. - unique_ptr<Schema> new_schema(new Schema()); + unique_ptr<Schema> new_schema(new Schema); RETURN_NOT_OK(SchemaFromPB(resp.schema(), new_schema.get())); // Parse the server partition schema out of the response. @@ -662,7 +662,8 @@ void KuduClient::Data::ConnectedToClusterCb( location_ = connect_response.client_location(); cluster_id_ = connect_response.cluster_id(); - master_proxy_.reset(new MasterServiceProxy(messenger_, leader_addr, leader_hostname)); + master_proxy_ = std::make_shared<MasterServiceProxy>( + messenger_, leader_addr, leader_hostname); master_proxy_->set_user_credentials(user_credentials_); } } diff --git a/src/kudu/client/meta_cache.cc b/src/kudu/client/meta_cache.cc index 5e3d110..3abf7ab 100644 --- a/src/kudu/client/meta_cache.cc +++ b/src/kudu/client/meta_cache.cc @@ -115,12 +115,16 @@ void RemoteTabletServer::DnsResolutionFinished(const HostPort& hp, VLOG(1) << "Successfully resolved " << hp.ToString() << ": " << (*addrs)[0].ToString(); + auto proxy = std::make_shared<TabletServerServiceProxy>( + client->data_->messenger_, (*addrs)[0], hp.host()); + proxy->set_user_credentials(client->data_->user_credentials_); + auto admin_proxy = std::make_shared<TabletServerAdminServiceProxy>( + client->data_->messenger_, (*addrs)[0], hp.host()); { std::lock_guard<simple_spinlock> l(lock_); - proxy_.reset(new TabletServerServiceProxy(client->data_->messenger_, (*addrs)[0], hp.host())); - admin_proxy_.reset( - new TabletServerAdminServiceProxy(client->data_->messenger_, (*addrs)[0], hp.host())); + proxy_ = std::move(proxy); + admin_proxy_ = std::move(admin_proxy); proxy_->set_user_credentials(client->data_->user_credentials_); } user_callback(s); @@ -144,7 +148,7 @@ void RemoteTabletServer::InitProxy(KuduClient* client, const StatusCallback& cb) hp = rpc_hostports_[0]; } - auto addrs = new vector<Sockaddr>(); + auto addrs = new vector<Sockaddr>; if (FLAGS_client_use_unix_domain_sockets && unix_domain_socket_path_ && client->data_->IsLocalHostPort(hp)) { diff --git a/src/kudu/client/meta_cache.h b/src/kudu/client/meta_cache.h index 9daa8e5..d7e8481 100644 --- a/src/kudu/client/meta_cache.h +++ b/src/kudu/client/meta_cache.h @@ -16,8 +16,7 @@ // under the License. // // This module is internal to the client and not a public API. -#ifndef KUDU_CLIENT_META_CACHE_H -#define KUDU_CLIENT_META_CACHE_H +#pragma once #include <atomic> #include <map> @@ -530,4 +529,3 @@ class MetaCache : public RefCountedThreadSafe<MetaCache> { } // namespace internal } // namespace client } // namespace kudu -#endif /* KUDU_CLIENT_META_CACHE_H */
