You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by nd...@apache.org on 2023/03/16 12:57:15 UTC

[hbase] branch branch-2 updated: HBASE-27708 CPU hot-spot resolving User subject

This is an automated email from the ASF dual-hosted git repository.

ndimiduk pushed a commit to branch branch-2
in repository https://gitbox.apache.org/repos/asf/hbase.git


The following commit(s) were added to refs/heads/branch-2 by this push:
     new 59434e9cd4e HBASE-27708 CPU hot-spot resolving User subject
59434e9cd4e is described below

commit 59434e9cd4ea4b1241cb25322f2d5d43274ed7b7
Author: Nick Dimiduk <nd...@apache.org>
AuthorDate: Thu Mar 16 09:15:45 2023 +0100

    HBASE-27708 CPU hot-spot resolving User subject
    
    Signed-off-by: Duo Zhang <zh...@apache.org>
---
 .../main/java/org/apache/hadoop/hbase/security/User.java    | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/security/User.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/security/User.java
index e2cac4b6b56..22a79adb95f 100644
--- a/hbase-common/src/main/java/org/apache/hadoop/hbase/security/User.java
+++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/security/User.java
@@ -270,20 +270,28 @@ public abstract class User {
   public static final class SecureHadoopUser extends User {
     private String shortName;
     private LoadingCache<String, String[]> cache;
+    /**
+     * Cache value of this instance's {@link #toString()} value. Computing this value is expensive.
+     * Assumes the UGI is never updated. See HBASE-27708.
+     */
+    private final String toString;
 
     public SecureHadoopUser() throws IOException {
       ugi = UserGroupInformation.getCurrentUser();
       this.cache = null;
+      this.toString = ugi.toString();
     }
 
     public SecureHadoopUser(UserGroupInformation ugi) {
       this.ugi = ugi;
       this.cache = null;
+      this.toString = ugi.toString();
     }
 
     public SecureHadoopUser(UserGroupInformation ugi, LoadingCache<String, String[]> cache) {
       this.ugi = ugi;
       this.cache = cache;
+      this.toString = ugi.toString();
     }
 
     @Override
@@ -320,6 +328,11 @@ public abstract class User {
       return ugi.doAs(action);
     }
 
+    @Override
+    public String toString() {
+      return toString;
+    }
+
     /**
      * Create a user for testing.
      * @see User#createUserForTesting(org.apache.hadoop.conf.Configuration, String, String[])