HBASE-27708 CPU hot-spot resolving User subject

Signed-off-by: Duo Zhang <zhangduo@apache.org>
This commit is contained in:
Nick Dimiduk 2023-03-16 09:15:45 +01:00 committed by Nick Dimiduk
parent dbb78388e5
commit 59434e9cd4
1 changed files with 13 additions and 0 deletions

View File

@ -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[])