rpc: some small cleanup in ConnectionId Change-Id: I0788052f8c943ef102f3f551a85a8b219c65c361 Reviewed-on: http://gerrit.cloudera.org:8080/7686 Reviewed-by: Alexey Serbin <[email protected]> Tested-by: Kudu Jenkins Reviewed-on: http://gerrit.cloudera.org:8080/7896 Reviewed-by: Sailesh Mukil <[email protected]> Tested-by: Sailesh Mukil <[email protected]>
Project: http://git-wip-us.apache.org/repos/asf/incubator-impala/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-impala/commit/1b70eb66 Tree: http://git-wip-us.apache.org/repos/asf/incubator-impala/tree/1b70eb66 Diff: http://git-wip-us.apache.org/repos/asf/incubator-impala/diff/1b70eb66 Branch: refs/heads/master Commit: 1b70eb661a04ff1642d7862df9cd30a3e7d9ab6f Parents: 7d41b96 Author: Todd Lipcon <[email protected]> Authored: Tue Aug 15 15:38:04 2017 -0700 Committer: Sailesh Mukil <[email protected]> Committed: Fri Sep 1 03:12:49 2017 +0000 ---------------------------------------------------------------------- be/src/kudu/rpc/connection_id.cc | 26 ++++---------------------- be/src/kudu/rpc/connection_id.h | 12 +++--------- be/src/kudu/rpc/proxy.cc | 5 +++-- be/src/kudu/rpc/user_credentials.cc | 4 ++-- be/src/kudu/rpc/user_credentials.h | 2 +- 5 files changed, 13 insertions(+), 36 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/1b70eb66/be/src/kudu/rpc/connection_id.cc ---------------------------------------------------------------------- diff --git a/be/src/kudu/rpc/connection_id.cc b/be/src/kudu/rpc/connection_id.cc index e4a4dba..a17b783 100644 --- a/be/src/kudu/rpc/connection_id.cc +++ b/be/src/kudu/rpc/connection_id.cc @@ -19,7 +19,7 @@ #include <boost/functional/hash.hpp> -#include "kudu/gutil/stringprintf.h" +#include "kudu/gutil/strings/substitute.h" using std::string; @@ -28,37 +28,19 @@ namespace rpc { ConnectionId::ConnectionId() {} -ConnectionId::ConnectionId(const ConnectionId& other) { - DoCopyFrom(other); -} - ConnectionId::ConnectionId(const Sockaddr& remote, UserCredentials user_credentials) { remote_ = remote; user_credentials_ = std::move(user_credentials); } -void ConnectionId::set_remote(const Sockaddr& remote) { - remote_ = remote; -} - void ConnectionId::set_user_credentials(UserCredentials user_credentials) { user_credentials_ = std::move(user_credentials); } -void ConnectionId::CopyFrom(const ConnectionId& other) { - DoCopyFrom(other); -} - string ConnectionId::ToString() const { - // Does not print the password. - return StringPrintf("{remote=%s, user_credentials=%s}", - remote_.ToString().c_str(), - user_credentials_.ToString().c_str()); -} - -void ConnectionId::DoCopyFrom(const ConnectionId& other) { - remote_ = other.remote_; - user_credentials_ = other.user_credentials_; + return strings::Substitute("{remote=$0, user_credentials=$1}", + remote_.ToString(), + user_credentials_.ToString()); } size_t ConnectionId::HashCode() const { http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/1b70eb66/be/src/kudu/rpc/connection_id.h ---------------------------------------------------------------------- diff --git a/be/src/kudu/rpc/connection_id.h b/be/src/kudu/rpc/connection_id.h index ae34b29..09f1738 100644 --- a/be/src/kudu/rpc/connection_id.h +++ b/be/src/kudu/rpc/connection_id.h @@ -32,19 +32,18 @@ class ConnectionId { ConnectionId(); // Copy constructor required for use with STL unordered_map. - ConnectionId(const ConnectionId& other); + ConnectionId(const ConnectionId& other) = default; // Convenience constructor. ConnectionId(const Sockaddr& remote, UserCredentials user_credentials); // The remote address. - void set_remote(const Sockaddr& remote); const Sockaddr& remote() const { return remote_; } // The credentials of the user associated with this connection, if any. void set_user_credentials(UserCredentials user_credentials); + const UserCredentials& user_credentials() const { return user_credentials_; } - UserCredentials* mutable_user_credentials() { return &user_credentials_; } // Copy state from another object to this one. void CopyFrom(const ConnectionId& other); @@ -58,13 +57,8 @@ class ConnectionId { private: // Remember to update HashCode() and Equals() when new fields are added. Sockaddr remote_; - UserCredentials user_credentials_; - // Implementation of CopyFrom that can be shared with copy constructor. - void DoCopyFrom(const ConnectionId& other); - - // Disable assignment operator. - void operator=(const ConnectionId&); + UserCredentials user_credentials_; }; class ConnectionIdHash { http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/1b70eb66/be/src/kudu/rpc/proxy.cc ---------------------------------------------------------------------- diff --git a/be/src/kudu/rpc/proxy.cc b/be/src/kudu/rpc/proxy.cc index 3ec907d..0d946ed 100644 --- a/be/src/kudu/rpc/proxy.cc +++ b/be/src/kudu/rpc/proxy.cc @@ -64,8 +64,9 @@ Proxy::Proxy(std::shared_ptr<Messenger> messenger, << s.ToString() << " before connecting to remote: " << remote.ToString(); } - conn_id_.set_remote(remote); - conn_id_.mutable_user_credentials()->set_real_user(real_user); + UserCredentials creds; + creds.set_real_user(std::move(real_user)); + conn_id_ = ConnectionId(remote, std::move(creds)); } Proxy::~Proxy() { http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/1b70eb66/be/src/kudu/rpc/user_credentials.cc ---------------------------------------------------------------------- diff --git a/be/src/kudu/rpc/user_credentials.cc b/be/src/kudu/rpc/user_credentials.cc index fdc3ac2..0debd01 100644 --- a/be/src/kudu/rpc/user_credentials.cc +++ b/be/src/kudu/rpc/user_credentials.cc @@ -32,8 +32,8 @@ bool UserCredentials::has_real_user() const { return !real_user_.empty(); } -void UserCredentials::set_real_user(const string& real_user) { - real_user_ = real_user; +void UserCredentials::set_real_user(string real_user) { + real_user_ = std::move(real_user); } string UserCredentials::ToString() const { http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/1b70eb66/be/src/kudu/rpc/user_credentials.h ---------------------------------------------------------------------- diff --git a/be/src/kudu/rpc/user_credentials.h b/be/src/kudu/rpc/user_credentials.h index 56af70a..8cb68cc 100644 --- a/be/src/kudu/rpc/user_credentials.h +++ b/be/src/kudu/rpc/user_credentials.h @@ -29,7 +29,7 @@ class UserCredentials { public: // Real user. bool has_real_user() const; - void set_real_user(const std::string& real_user); + void set_real_user(std::string real_user); const std::string& real_user() const { return real_user_; } // Returns a string representation of the object.
