HBASE-16522 Procedure v2 - Cache system user and avoid IOException

This commit is contained in:
Matteo Bertozzi 2016-08-30 11:53:15 -07:00
parent e46a073ed2
commit 57c6384b09
14 changed files with 37 additions and 61 deletions

View File

@ -42,6 +42,7 @@ public final class Superusers {
private static List<String> superUsers;
private static List<String> superGroups;
private static User systemUser;
private Superusers(){}
@ -55,17 +56,17 @@ public final class Superusers {
public static void initialize(Configuration conf) throws IOException {
superUsers = new ArrayList<>();
superGroups = new ArrayList<>();
User user = User.getCurrent();
systemUser = User.getCurrent();
if (user == null) {
if (systemUser == null) {
throw new IllegalStateException("Unable to obtain the current user, "
+ "authorization checks for internal operations will not work correctly!");
}
if (LOG.isTraceEnabled()) {
LOG.trace("Current user name is " + user.getShortName());
LOG.trace("Current user name is " + systemUser.getShortName());
}
String currentUser = user.getShortName();
String currentUser = systemUser.getShortName();
String[] superUserList = conf.getStrings(SUPERUSER_CONF_KEY, new String[0]);
for (String name : superUserList) {
if (AuthUtil.isGroupPrincipal(name)) {
@ -125,4 +126,8 @@ public final class Superusers {
public static List<String> getSuperUsers() {
return superUsers;
}
public static User getSystemUser() {
return systemUser;
}
}

View File

@ -66,10 +66,8 @@ public class AddColumnFamilyProcedure
this.traceEnabled = null;
}
public AddColumnFamilyProcedure(
final MasterProcedureEnv env,
final TableName tableName,
final HColumnDescriptor cfDescriptor) throws IOException {
public AddColumnFamilyProcedure(final MasterProcedureEnv env, final TableName tableName,
final HColumnDescriptor cfDescriptor) {
this.tableName = tableName;
this.cfDescriptor = cfDescriptor;
this.user = env.getRequestUser().getUGI();

View File

@ -55,9 +55,8 @@ public class CreateNamespaceProcedure
this.traceEnabled = null;
}
public CreateNamespaceProcedure(
final MasterProcedureEnv env,
final NamespaceDescriptor nsDescriptor) throws IOException {
public CreateNamespaceProcedure(final MasterProcedureEnv env,
final NamespaceDescriptor nsDescriptor) {
this.nsDescriptor = nsDescriptor;
this.traceEnabled = null;
this.setOwner(env.getRequestUser().getUGI().getShortUserName());

View File

@ -77,15 +77,13 @@ public class CreateTableProcedure
}
public CreateTableProcedure(final MasterProcedureEnv env,
final HTableDescriptor hTableDescriptor, final HRegionInfo[] newRegions)
throws IOException {
final HTableDescriptor hTableDescriptor, final HRegionInfo[] newRegions) {
this(env, hTableDescriptor, newRegions, null);
}
public CreateTableProcedure(final MasterProcedureEnv env,
final HTableDescriptor hTableDescriptor, final HRegionInfo[] newRegions,
final ProcedurePrepareLatch syncLatch)
throws IOException {
final ProcedurePrepareLatch syncLatch) {
this.hTableDescriptor = hTableDescriptor;
this.newRegions = newRegions != null ? Lists.newArrayList(newRegions) : null;
this.user = env.getRequestUser().getUGI();

View File

@ -67,10 +67,8 @@ public class DeleteColumnFamilyProcedure
this.traceEnabled = null;
}
public DeleteColumnFamilyProcedure(
final MasterProcedureEnv env,
final TableName tableName,
final byte[] familyName) throws IOException {
public DeleteColumnFamilyProcedure(final MasterProcedureEnv env, final TableName tableName,
final byte[] familyName) {
this.tableName = tableName;
this.familyName = familyName;
this.user = env.getRequestUser().getUGI();

View File

@ -63,9 +63,7 @@ public class DeleteNamespaceProcedure
this.traceEnabled = null;
}
public DeleteNamespaceProcedure(
final MasterProcedureEnv env,
final String namespaceName) throws IOException {
public DeleteNamespaceProcedure(final MasterProcedureEnv env, final String namespaceName) {
this.namespaceName = namespaceName;
this.nsDescriptor = null;
this.traceEnabled = null;

View File

@ -74,13 +74,12 @@ public class DeleteTableProcedure
syncLatch = null;
}
public DeleteTableProcedure(final MasterProcedureEnv env, final TableName tableName)
throws IOException {
public DeleteTableProcedure(final MasterProcedureEnv env, final TableName tableName) {
this(env, tableName, null);
}
public DeleteTableProcedure(final MasterProcedureEnv env, final TableName tableName,
final ProcedurePrepareLatch syncLatch) throws IOException {
final ProcedurePrepareLatch syncLatch) {
this.tableName = tableName;
this.user = env.getRequestUser().getUGI();
this.setOwner(this.user.getShortUserName());

View File

@ -83,12 +83,9 @@ public class DisableTableProcedure
* @param env MasterProcedureEnv
* @param tableName the table to operate on
* @param skipTableStateCheck whether to check table state
* @throws IOException
*/
public DisableTableProcedure(
final MasterProcedureEnv env,
final TableName tableName,
final boolean skipTableStateCheck) throws IOException {
public DisableTableProcedure(final MasterProcedureEnv env, final TableName tableName,
final boolean skipTableStateCheck) {
this(env, tableName, skipTableStateCheck, null);
}
@ -97,13 +94,9 @@ public class DisableTableProcedure
* @param env MasterProcedureEnv
* @param tableName the table to operate on
* @param skipTableStateCheck whether to check table state
* @throws IOException
*/
public DisableTableProcedure(
final MasterProcedureEnv env,
final TableName tableName,
final boolean skipTableStateCheck,
final ProcedurePrepareLatch syncLatch) throws IOException {
public DisableTableProcedure(final MasterProcedureEnv env, final TableName tableName,
final boolean skipTableStateCheck, final ProcedurePrepareLatch syncLatch) {
this.tableName = tableName;
this.skipTableStateCheck = skipTableStateCheck;
this.user = env.getRequestUser().getUGI();

View File

@ -82,12 +82,9 @@ public class EnableTableProcedure
* @param env MasterProcedureEnv
* @param tableName the table to operate on
* @param skipTableStateCheck whether to check table state
* @throws IOException
*/
public EnableTableProcedure(
final MasterProcedureEnv env,
final TableName tableName,
final boolean skipTableStateCheck) throws IOException {
public EnableTableProcedure(final MasterProcedureEnv env, final TableName tableName,
final boolean skipTableStateCheck) {
this(env, tableName, skipTableStateCheck, null);
}
@ -96,13 +93,9 @@ public class EnableTableProcedure
* @param env MasterProcedureEnv
* @param tableName the table to operate on
* @param skipTableStateCheck whether to check table state
* @throws IOException
*/
public EnableTableProcedure(
final MasterProcedureEnv env,
final TableName tableName,
final boolean skipTableStateCheck,
final ProcedurePrepareLatch syncLatch) throws IOException {
public EnableTableProcedure(final MasterProcedureEnv env, final TableName tableName,
final boolean skipTableStateCheck, final ProcedurePrepareLatch syncLatch) {
this.tableName = tableName;
this.skipTableStateCheck = skipTableStateCheck;
this.user = env.getRequestUser().getUGI();

View File

@ -36,7 +36,7 @@ import org.apache.hadoop.hbase.procedure2.Procedure;
import org.apache.hadoop.hbase.procedure2.store.ProcedureStore;
import org.apache.hadoop.hbase.procedure2.store.wal.WALProcedureStore;
import org.apache.hadoop.hbase.security.User;
import org.apache.hadoop.hbase.security.UserProvider;
import org.apache.hadoop.hbase.security.Superusers;
import org.apache.hadoop.hbase.util.CancelableProgressable;
import org.apache.hadoop.hbase.util.FSUtils;
@ -96,10 +96,10 @@ public class MasterProcedureEnv {
master.getTableLockManager());
}
public User getRequestUser() throws IOException {
public User getRequestUser() {
User user = RpcServer.getRequestUser();
if (user == null) {
user = UserProvider.instantiate(getMasterConfiguration()).getCurrent();
user = Superusers.getSystemUser();
}
return user;
}

View File

@ -64,10 +64,8 @@ public class ModifyColumnFamilyProcedure
this.traceEnabled = null;
}
public ModifyColumnFamilyProcedure(
final MasterProcedureEnv env,
final TableName tableName,
final HColumnDescriptor cfDescriptor) throws IOException {
public ModifyColumnFamilyProcedure(final MasterProcedureEnv env, final TableName tableName,
final HColumnDescriptor cfDescriptor) {
this.tableName = tableName;
this.cfDescriptor = cfDescriptor;
this.user = env.getRequestUser().getUGI();

View File

@ -55,9 +55,8 @@ public class ModifyNamespaceProcedure
this.traceEnabled = null;
}
public ModifyNamespaceProcedure(
final MasterProcedureEnv env,
final NamespaceDescriptor newNsDescriptor) throws IOException {
public ModifyNamespaceProcedure(final MasterProcedureEnv env,
final NamespaceDescriptor newNsDescriptor) {
this.oldNsDescriptor = null;
this.newNsDescriptor = newNsDescriptor;
this.traceEnabled = null;

View File

@ -72,9 +72,7 @@ public class ModifyTableProcedure
initilize();
}
public ModifyTableProcedure(
final MasterProcedureEnv env,
final HTableDescriptor htd) throws IOException {
public ModifyTableProcedure(final MasterProcedureEnv env, final HTableDescriptor htd) {
initilize();
this.modifiedHTableDescriptor = htd;
this.user = env.getRequestUser().getUGI();

View File

@ -61,7 +61,7 @@ public class TruncateTableProcedure
}
public TruncateTableProcedure(final MasterProcedureEnv env, final TableName tableName,
boolean preserveSplits) throws IOException {
boolean preserveSplits) {
this.tableName = tableName;
this.preserveSplits = preserveSplits;
this.user = env.getRequestUser().getUGI();