kudu-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t...@apache.org
Subject [1/2] kudu git commit: rpc: some small cleanup in ConnectionId
Date Fri, 18 Aug 2017 02:39:10 GMT
Repository: kudu
Updated Branches:
  refs/heads/master a15f1863e -> 351337ee2


rpc: some small cleanup in ConnectionId

Change-Id: I0788052f8c943ef102f3f551a85a8b219c65c361
Reviewed-on: http://gerrit.cloudera.org:8080/7686
Reviewed-by: Alexey Serbin <aserbin@cloudera.com>
Tested-by: Kudu Jenkins


Project: http://git-wip-us.apache.org/repos/asf/kudu/repo
Commit: http://git-wip-us.apache.org/repos/asf/kudu/commit/e32faf92
Tree: http://git-wip-us.apache.org/repos/asf/kudu/tree/e32faf92
Diff: http://git-wip-us.apache.org/repos/asf/kudu/diff/e32faf92

Branch: refs/heads/master
Commit: e32faf92dd8560eb398f719de370624a51cf4a2d
Parents: a15f186
Author: Todd Lipcon <todd@apache.org>
Authored: Tue Aug 15 15:38:04 2017 -0700
Committer: Todd Lipcon <todd@apache.org>
Committed: Fri Aug 18 00:38:41 2017 +0000

----------------------------------------------------------------------
 src/kudu/rpc/connection_id.cc    | 26 ++++----------------------
 src/kudu/rpc/connection_id.h     | 12 +++---------
 src/kudu/rpc/proxy.cc            |  5 +++--
 src/kudu/rpc/user_credentials.cc |  4 ++--
 src/kudu/rpc/user_credentials.h  |  2 +-
 5 files changed, 13 insertions(+), 36 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kudu/blob/e32faf92/src/kudu/rpc/connection_id.cc
----------------------------------------------------------------------
diff --git a/src/kudu/rpc/connection_id.cc b/src/kudu/rpc/connection_id.cc
index e4a4dba..a17b783 100644
--- a/src/kudu/rpc/connection_id.cc
+++ b/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/kudu/blob/e32faf92/src/kudu/rpc/connection_id.h
----------------------------------------------------------------------
diff --git a/src/kudu/rpc/connection_id.h b/src/kudu/rpc/connection_id.h
index ae34b29..09f1738 100644
--- a/src/kudu/rpc/connection_id.h
+++ b/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/kudu/blob/e32faf92/src/kudu/rpc/proxy.cc
----------------------------------------------------------------------
diff --git a/src/kudu/rpc/proxy.cc b/src/kudu/rpc/proxy.cc
index 3ec907d..0d946ed 100644
--- a/src/kudu/rpc/proxy.cc
+++ b/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/kudu/blob/e32faf92/src/kudu/rpc/user_credentials.cc
----------------------------------------------------------------------
diff --git a/src/kudu/rpc/user_credentials.cc b/src/kudu/rpc/user_credentials.cc
index fdc3ac2..0debd01 100644
--- a/src/kudu/rpc/user_credentials.cc
+++ b/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/kudu/blob/e32faf92/src/kudu/rpc/user_credentials.h
----------------------------------------------------------------------
diff --git a/src/kudu/rpc/user_credentials.h b/src/kudu/rpc/user_credentials.h
index 56af70a..8cb68cc 100644
--- a/src/kudu/rpc/user_credentials.h
+++ b/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.


Mime
View raw message