kudu-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject [kudu] branch branch-1.7.x updated: KUDU-2395 (part 1): cache logged-in user
Date Mon, 13 May 2019 19:31:51 GMT
This is an automated email from the ASF dual-hosted git repository.

adar pushed a commit to branch branch-1.7.x
in repository https://gitbox.apache.org/repos/asf/kudu.git

The following commit(s) were added to refs/heads/branch-1.7.x by this push:
     new 55c68fe  KUDU-2395 (part 1): cache logged-in user
55c68fe is described below

commit 55c68fee11d3f702aefde34a6d2c3c3f07281128
Author: Todd Lipcon <todd@apache.org>
AuthorDate: Mon Apr 2 16:12:33 2018 -0700

    KUDU-2395 (part 1): cache logged-in user
    The name of the current logged-in user is not expected to change over
    time once the process is running. If it did change this could cause
    strange effects with ACL enforcement, for one, or result in outbound RPC
    connections switching credentials during the process lifetime.
    Additionally, as pointed at in KUDU-2395, the lookup of the user name
    from the UID sometimes needs to go to external services which may be
    slow and incur lock contention.
    This patch switches to computing the local username only once and
    reusing the result on all subsequent lookups.
    Change-Id: Ib4500d89dd91e8eed6e4ae0661b886ab3c105130
    Reviewed-on: http://gerrit.cloudera.org:8080/9895
    Tested-by: Kudu Jenkins
    Reviewed-by: Todd Lipcon <todd@apache.org>
    (cherry picked from commit 52b50b7a91c61925a7bc42992fe1001e74425d4d)
    Reviewed-on: http://gerrit.cloudera.org:8080/13250
    Reviewed-by: Alexey Serbin <aserbin@cloudera.com>
    Tested-by: Will Berkeley <wdberkeley@gmail.com>
 src/kudu/util/user.cc | 25 +++++++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)

diff --git a/src/kudu/util/user.cc b/src/kudu/util/user.cc
index 1b73e53..2d12267 100644
--- a/src/kudu/util/user.cc
+++ b/src/kudu/util/user.cc
@@ -22,19 +22,23 @@
 #include <cerrno>
 #include <cstdlib>
+#include <mutex>
 #include <string>
+#include <utility>
 #include <glog/logging.h>
 #include "kudu/gutil/gscoped_ptr.h"
+#include "kudu/util/debug/leakcheck_disabler.h"
 #include "kudu/util/errno.h"
 #include "kudu/util/status.h"
 using std::string;
 namespace kudu {
+namespace {
-Status GetLoggedInUser(string* user_name) {
+Status DoGetLoggedInUser(string* user_name) {
   DCHECK(user_name != nullptr);
   struct passwd pwd;
@@ -59,9 +63,26 @@ Status GetLoggedInUser(string* user_name) {
       return Status::RuntimeError("Error calling getpwuid_r()", ErrnoToString(ret), ret);
   *user_name = pwd.pw_name;
+  return Status::OK();
+} // anonymous namespace
+Status GetLoggedInUser(string* user_name) {
+  static std::once_flag once;
+  static string* once_user_name;
+  static Status* once_status;
+  std::call_once(once, [](){
+      string u;
+      Status s = DoGetLoggedInUser(&u);
+      debug::ScopedLeakCheckDisabler ignore_leaks;
+      once_status = new Status(std::move(s));
+      once_user_name = new string(std::move(u));
+    });
+  RETURN_NOT_OK(*once_status);
+  *user_name = *once_user_name;
   return Status::OK();

View raw message