Skip to content

Commit

Permalink
HBASE-27708 CPU hot-spot resolving User subject
Browse files Browse the repository at this point in the history
Signed-off-by: Duo Zhang <[email protected]>
  • Loading branch information
ndimiduk authored Mar 16, 2023
1 parent b0cfd74 commit 22b0c3e
Showing 1 changed file with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -270,20 +270,28 @@ public static boolean shouldLoginFromKeytab(Configuration conf) {
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
Expand Down Expand Up @@ -320,6 +328,11 @@ public <T> T runAs(PrivilegedExceptionAction<T> action)
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[])
Expand Down

0 comments on commit 22b0c3e

Please sign in to comment.