From af33f94513f84e811fb713cd2ccc4d50ff317844 Mon Sep 17 00:00:00 2001 From: Matteo Bertozzi Date: Tue, 30 Aug 2016 10:08:36 -0700 Subject: [PATCH] HBASE-16522 Procedure v2 - Cache system user and avoid IOException --- .../apache/hadoop/hbase/security/Superusers.java | 13 +++++++++---- .../procedure/AddColumnFamilyProcedure.java | 2 +- .../master/procedure/CloneSnapshotProcedure.java | 8 ++------ .../procedure/CreateNamespaceProcedure.java | 5 ++--- .../master/procedure/CreateTableProcedure.java | 6 ++---- .../procedure/DeleteColumnFamilyProcedure.java | 4 ++-- .../procedure/DeleteNamespaceProcedure.java | 4 +--- .../master/procedure/DeleteTableProcedure.java | 5 ++--- .../master/procedure/DisableTableProcedure.java | 15 ++++----------- .../DispatchMergingRegionsProcedure.java | 2 +- .../master/procedure/EnableTableProcedure.java | 15 ++++----------- .../master/procedure/MasterProcedureEnv.java | 6 +++--- .../procedure/ModifyColumnFamilyProcedure.java | 4 ++-- .../procedure/ModifyNamespaceProcedure.java | 5 ++--- .../master/procedure/ModifyTableProcedure.java | 5 ++--- .../procedure/RestoreSnapshotProcedure.java | 3 +-- .../master/procedure/TruncateTableProcedure.java | 4 ++-- 17 files changed, 42 insertions(+), 64 deletions(-) diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/security/Superusers.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/security/Superusers.java index f1a387728c9..c18928d4ffe 100644 --- a/hbase-common/src/main/java/org/apache/hadoop/hbase/security/Superusers.java +++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/security/Superusers.java @@ -42,6 +42,7 @@ public final class Superusers { private static List superUsers; private static List 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 getSuperUsers() { return superUsers; } + + public static User getSystemUser() { + return systemUser; + } } \ No newline at end of file diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/AddColumnFamilyProcedure.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/AddColumnFamilyProcedure.java index c9478cb819b..7c0b6917404 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/AddColumnFamilyProcedure.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/AddColumnFamilyProcedure.java @@ -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(); diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/CloneSnapshotProcedure.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/CloneSnapshotProcedure.java index 861ac56fcc8..1212072c303 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/CloneSnapshotProcedure.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/CloneSnapshotProcedure.java @@ -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(); diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/CreateNamespaceProcedure.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/CreateNamespaceProcedure.java index a9a09683d00..7c8bf9cc8be 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/CreateNamespaceProcedure.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/CreateNamespaceProcedure.java @@ -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()); diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/CreateTableProcedure.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/CreateTableProcedure.java index f6ade6edd30..ae8d2fb1048 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/CreateTableProcedure.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/CreateTableProcedure.java @@ -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(); diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/DeleteColumnFamilyProcedure.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/DeleteColumnFamilyProcedure.java index da24cefb686..9df9c0dc0ab 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/DeleteColumnFamilyProcedure.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/DeleteColumnFamilyProcedure.java @@ -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(); diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/DeleteNamespaceProcedure.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/DeleteNamespaceProcedure.java index bd71aa3f0b5..3f4de12d3e4 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/DeleteNamespaceProcedure.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/DeleteNamespaceProcedure.java @@ -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; diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/DeleteTableProcedure.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/DeleteTableProcedure.java index 2881ed5e197..64bdccc9280 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/DeleteTableProcedure.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/DeleteTableProcedure.java @@ -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()); diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/DisableTableProcedure.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/DisableTableProcedure.java index be21590b038..e2d7d163364 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/DisableTableProcedure.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/DisableTableProcedure.java @@ -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(); diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/DispatchMergingRegionsProcedure.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/DispatchMergingRegionsProcedure.java index b4f1bf05c59..cb091ce4355 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/DispatchMergingRegionsProcedure.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/DispatchMergingRegionsProcedure.java @@ -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; diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/EnableTableProcedure.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/EnableTableProcedure.java index 18935436c9f..1817a16dfac 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/EnableTableProcedure.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/EnableTableProcedure.java @@ -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(); diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/MasterProcedureEnv.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/MasterProcedureEnv.java index 3b5eced72fe..52e3d600dca 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/MasterProcedureEnv.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/MasterProcedureEnv.java @@ -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; } diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/ModifyColumnFamilyProcedure.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/ModifyColumnFamilyProcedure.java index 17693063674..b06ffe87052 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/ModifyColumnFamilyProcedure.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/ModifyColumnFamilyProcedure.java @@ -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(); diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/ModifyNamespaceProcedure.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/ModifyNamespaceProcedure.java index 1f885bd8b09..a16c8d15a26 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/ModifyNamespaceProcedure.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/ModifyNamespaceProcedure.java @@ -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; diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/ModifyTableProcedure.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/ModifyTableProcedure.java index 8299bccf938..64c26b9c561 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/ModifyTableProcedure.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/ModifyTableProcedure.java @@ -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(); diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/RestoreSnapshotProcedure.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/RestoreSnapshotProcedure.java index 23ab3ac669a..6ac6fe77c3e 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/RestoreSnapshotProcedure.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/RestoreSnapshotProcedure.java @@ -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 diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/TruncateTableProcedure.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/TruncateTableProcedure.java index 8e3ef3e01b5..75606c2eb07 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/TruncateTableProcedure.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/TruncateTableProcedure.java @@ -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();