HBASE-16522 Procedure v2 - Cache system user and avoid IOException
This commit is contained in:
parent
c66bb48ce8
commit
af33f94513
|
@ -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)) {
|
||||
|
@ -104,4 +105,8 @@ public final class Superusers {
|
|||
public static List<String> getSuperUsers() {
|
||||
return superUsers;
|
||||
}
|
||||
|
||||
public static User getSystemUser() {
|
||||
return systemUser;
|
||||
}
|
||||
}
|
|
@ -75,7 +75,7 @@ public class AddColumnFamilyProcedure
|
|||
}
|
||||
|
||||
public AddColumnFamilyProcedure(final MasterProcedureEnv env, final TableName tableName,
|
||||
final HColumnDescriptor cfDescriptor, final ProcedurePrepareLatch latch) throws IOException {
|
||||
final HColumnDescriptor cfDescriptor, final ProcedurePrepareLatch latch) {
|
||||
this.tableName = tableName;
|
||||
this.cfDescriptor = cfDescriptor;
|
||||
this.user = env.getRequestUser();
|
||||
|
|
|
@ -97,13 +97,9 @@ public class CloneSnapshotProcedure
|
|||
* @param env MasterProcedureEnv
|
||||
* @param hTableDescriptor the table to operate on
|
||||
* @param snapshot snapshot to clone from
|
||||
* @throws IOException
|
||||
*/
|
||||
public CloneSnapshotProcedure(
|
||||
final MasterProcedureEnv env,
|
||||
final HTableDescriptor hTableDescriptor,
|
||||
final SnapshotDescription snapshot)
|
||||
throws IOException {
|
||||
public CloneSnapshotProcedure(final MasterProcedureEnv env,
|
||||
final HTableDescriptor hTableDescriptor, final SnapshotDescription snapshot) {
|
||||
this.hTableDescriptor = hTableDescriptor;
|
||||
this.snapshot = snapshot;
|
||||
this.user = env.getRequestUser();
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -76,15 +76,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();
|
||||
|
|
|
@ -73,12 +73,12 @@ public class DeleteColumnFamilyProcedure
|
|||
}
|
||||
|
||||
public DeleteColumnFamilyProcedure(final MasterProcedureEnv env, final TableName tableName,
|
||||
final byte[] familyName) throws IOException {
|
||||
final byte[] familyName) {
|
||||
this(env, tableName, familyName, null);
|
||||
}
|
||||
|
||||
public DeleteColumnFamilyProcedure(final MasterProcedureEnv env, final TableName tableName,
|
||||
final byte[] familyName, final ProcedurePrepareLatch latch) throws IOException {
|
||||
final byte[] familyName, final ProcedurePrepareLatch latch) {
|
||||
this.tableName = tableName;
|
||||
this.familyName = familyName;
|
||||
this.user = env.getRequestUser();
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -76,13 +76,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();
|
||||
this.setOwner(this.user.getShortName());
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -84,7 +84,7 @@ implements TableProcedureInterface {
|
|||
final MasterProcedureEnv env,
|
||||
final TableName tableName,
|
||||
final HRegionInfo [] regionsToMerge,
|
||||
final boolean forcible) throws IOException {
|
||||
final boolean forcible) {
|
||||
this.traceEnabled = isTraceEnabled();
|
||||
this.assignmentManager = getAssignmentManager(env);
|
||||
this.tableName = tableName;
|
||||
|
|
|
@ -80,12 +80,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);
|
||||
}
|
||||
|
||||
|
@ -94,13 +91,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();
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -69,12 +69,12 @@ public class ModifyColumnFamilyProcedure
|
|||
}
|
||||
|
||||
public ModifyColumnFamilyProcedure(final MasterProcedureEnv env, final TableName tableName,
|
||||
final HColumnDescriptor cfDescriptor) throws IOException {
|
||||
final HColumnDescriptor cfDescriptor) {
|
||||
this(env, tableName, cfDescriptor, null);
|
||||
}
|
||||
|
||||
public ModifyColumnFamilyProcedure(final MasterProcedureEnv env, final TableName tableName,
|
||||
final HColumnDescriptor cfDescriptor, final ProcedurePrepareLatch latch) throws IOException {
|
||||
final HColumnDescriptor cfDescriptor, final ProcedurePrepareLatch latch) {
|
||||
this.tableName = tableName;
|
||||
this.cfDescriptor = cfDescriptor;
|
||||
this.user = env.getRequestUser();
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -76,13 +76,12 @@ public class ModifyTableProcedure
|
|||
this.syncLatch = null;
|
||||
}
|
||||
|
||||
public ModifyTableProcedure(final MasterProcedureEnv env, final HTableDescriptor htd)
|
||||
throws IOException {
|
||||
public ModifyTableProcedure(final MasterProcedureEnv env, final HTableDescriptor htd) {
|
||||
this(env, htd, null);
|
||||
}
|
||||
|
||||
public ModifyTableProcedure(final MasterProcedureEnv env, final HTableDescriptor htd,
|
||||
final ProcedurePrepareLatch latch) throws IOException {
|
||||
final ProcedurePrepareLatch latch) {
|
||||
initilize();
|
||||
this.modifiedHTableDescriptor = htd;
|
||||
this.user = env.getRequestUser();
|
||||
|
|
|
@ -99,8 +99,7 @@ public class RestoreSnapshotProcedure
|
|||
public RestoreSnapshotProcedure(
|
||||
final MasterProcedureEnv env,
|
||||
final HTableDescriptor hTableDescriptor,
|
||||
final SnapshotDescription snapshot)
|
||||
throws IOException {
|
||||
final SnapshotDescription snapshot) {
|
||||
// This is the new schema we are going to write out as this modification.
|
||||
this.modifiedHTableDescriptor = hTableDescriptor;
|
||||
// Snapshot information
|
||||
|
|
|
@ -65,12 +65,12 @@ public class TruncateTableProcedure
|
|||
}
|
||||
|
||||
public TruncateTableProcedure(final MasterProcedureEnv env, final TableName tableName,
|
||||
boolean preserveSplits) throws IOException {
|
||||
boolean preserveSplits) {
|
||||
this(env, tableName, preserveSplits, null);
|
||||
}
|
||||
|
||||
public TruncateTableProcedure(final MasterProcedureEnv env, final TableName tableName,
|
||||
boolean preserveSplits, ProcedurePrepareLatch latch) throws IOException {
|
||||
boolean preserveSplits, ProcedurePrepareLatch latch) {
|
||||
this.tableName = tableName;
|
||||
this.preserveSplits = preserveSplits;
|
||||
this.user = env.getRequestUser();
|
||||
|
|
Loading…
Reference in New Issue