diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/coprocessor/MasterObserver.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/coprocessor/MasterObserver.java index a17bc9f4f54..a37f21a8569 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/coprocessor/MasterObserver.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/coprocessor/MasterObserver.java @@ -209,20 +209,52 @@ public interface MasterObserver { * table RPC call. * @param ctx the environment to interact with the framework and master * @param tableName the name of the table - * @param htd the TableDescriptor + * @param newDescriptor after modify operation, table will have this descriptor + * @deprecated Since 2.1. Will be removed in 3.0. + */ + @Deprecated + default void preModifyTable(final ObserverContext ctx, + final TableName tableName, TableDescriptor newDescriptor) throws IOException {} + + /** + * Called prior to modifying a table's properties. Called as part of modify + * table RPC call. + * @param ctx the environment to interact with the framework and master + * @param tableName the name of the table + * @param currentDescriptor current TableDescriptor of the table + * @param newDescriptor after modify operation, table will have this descriptor */ default void preModifyTable(final ObserverContext ctx, - final TableName tableName, TableDescriptor htd) throws IOException {} + final TableName tableName, TableDescriptor currentDescriptor, TableDescriptor newDescriptor) + throws IOException { + preModifyTable(ctx, tableName, newDescriptor); + } /** * Called after the modifyTable operation has been requested. Called as part * of modify table RPC call. * @param ctx the environment to interact with the framework and master * @param tableName the name of the table - * @param htd the TableDescriptor + * @param currentDescriptor current TableDescriptor of the table + * @deprecated Since 2.1. Will be removed in 3.0. + */ + @Deprecated + default void postModifyTable(final ObserverContext ctx, + final TableName tableName, TableDescriptor currentDescriptor) throws IOException {} + + /** + * Called after the modifyTable operation has been requested. Called as part + * of modify table RPC call. + * @param ctx the environment to interact with the framework and master + * @param tableName the name of the table + * @param oldDescriptor descriptor of table before modify operation happened + * @param currentDescriptor current TableDescriptor of the table */ default void postModifyTable(final ObserverContext ctx, - final TableName tableName, TableDescriptor htd) throws IOException {} + final TableName tableName, TableDescriptor oldDescriptor, TableDescriptor currentDescriptor) + throws IOException { + postModifyTable(ctx, tableName, currentDescriptor); + } /** * Called prior to modifying a table's properties. Called as part of modify @@ -230,12 +262,31 @@ public interface MasterObserver { * * @param ctx the environment to interact with the framework and master * @param tableName the name of the table - * @param htd the TableDescriptor + * @param newDescriptor after modify operation, table will have this descriptor + * @deprecated Since 2.1. Will be removed in 3.0. + */ + @Deprecated + default void preModifyTableAction( + final ObserverContext ctx, + final TableName tableName, + final TableDescriptor newDescriptor) throws IOException {} + + /** + * Called prior to modifying a table's properties. Called as part of modify + * table procedure and it is async to the modify table RPC call. + * + * @param ctx the environment to interact with the framework and master + * @param tableName the name of the table + * @param currentDescriptor current TableDescriptor of the table + * @param newDescriptor after modify operation, table will have this descriptor */ default void preModifyTableAction( final ObserverContext ctx, final TableName tableName, - final TableDescriptor htd) throws IOException {} + final TableDescriptor currentDescriptor, + final TableDescriptor newDescriptor) throws IOException { + preModifyTableAction(ctx, tableName, newDescriptor); + } /** * Called after to modifying a table's properties. Called as part of modify @@ -243,12 +294,31 @@ public interface MasterObserver { * * @param ctx the environment to interact with the framework and master * @param tableName the name of the table - * @param htd the TableDescriptor + * @param currentDescriptor current TableDescriptor of the table + * @deprecated Since 2.1. Will be removed in 3.0. + */ + @Deprecated + default void postCompletedModifyTableAction( + final ObserverContext ctx, + final TableName tableName, + final TableDescriptor currentDescriptor) throws IOException {} + + /** + * Called after to modifying a table's properties. Called as part of modify + * table procedure and it is async to the modify table RPC call. + * + * @param ctx the environment to interact with the framework and master + * @param tableName the name of the table + * @param oldDescriptor descriptor of table before modify operation happened + * @param currentDescriptor current TableDescriptor of the table */ default void postCompletedModifyTableAction( final ObserverContext ctx, final TableName tableName, - final TableDescriptor htd) throws IOException {} + final TableDescriptor oldDescriptor, + final TableDescriptor currentDescriptor) throws IOException { + postCompletedModifyTableAction(ctx, tableName, currentDescriptor); + } /** * Called prior to enabling a table. Called as part of enable table RPC call. @@ -817,18 +887,46 @@ public interface MasterObserver { /** * Called prior to modifying a namespace's properties. * @param ctx the environment to interact with the framework and master - * @param ns the NamespaceDescriptor + * @param newNsDescriptor after modify operation, namespace will have this descriptor + * @deprecated Since 2.1. Will be removed in 3.0. + */ + @Deprecated + default void preModifyNamespace(final ObserverContext ctx, + NamespaceDescriptor newNsDescriptor) throws IOException {} + + /** + * Called prior to modifying a namespace's properties. + * @param ctx the environment to interact with the framework and master + * @param currentNsDescriptor current NamespaceDescriptor of the namespace + * @param newNsDescriptor after modify operation, namespace will have this descriptor */ default void preModifyNamespace(final ObserverContext ctx, - NamespaceDescriptor ns) throws IOException {} + NamespaceDescriptor currentNsDescriptor, NamespaceDescriptor newNsDescriptor) + throws IOException { + preModifyNamespace(ctx, newNsDescriptor); + } /** * Called after the modifyNamespace operation has been requested. * @param ctx the environment to interact with the framework and master - * @param ns the NamespaceDescriptor + * @param currentNsDescriptor current NamespaceDescriptor of the namespace + * @deprecated Since 2.1. Will be removed in 3.0. + */ + @Deprecated + default void postModifyNamespace(final ObserverContext ctx, + NamespaceDescriptor currentNsDescriptor) throws IOException {} + + /** + * Called after the modifyNamespace operation has been requested. + * @param ctx the environment to interact with the framework and master + * @param oldNsDescriptor descriptor of namespace before modify operation happened + * @param currentNsDescriptor current NamespaceDescriptor of the namespace */ default void postModifyNamespace(final ObserverContext ctx, - NamespaceDescriptor ns) throws IOException {} + NamespaceDescriptor oldNsDescriptor, NamespaceDescriptor currentNsDescriptor) + throws IOException { + postModifyNamespace(ctx, currentNsDescriptor); + } /** * Called before a getNamespaceDescriptor request has been processed. diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java index 6d0b58ba0c3..d0ecf234960 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java @@ -2362,16 +2362,18 @@ public class HMaster extends HRegionServer implements MasterServices { } @Override - public long modifyTable(final TableName tableName, final TableDescriptor descriptor, + public long modifyTable(final TableName tableName, final TableDescriptor newDescriptor, final long nonceGroup, final long nonce) throws IOException { checkInitialized(); - sanityCheckTableDescriptor(descriptor); + sanityCheckTableDescriptor(newDescriptor); return MasterProcedureUtil.submitProcedure( new MasterProcedureUtil.NonceProcedureRunnable(this, nonceGroup, nonce) { @Override protected void run() throws IOException { - getMaster().getMasterCoprocessorHost().preModifyTable(tableName, descriptor); + TableDescriptor oldDescriptor = getMaster().getTableDescriptors().get(tableName); + getMaster().getMasterCoprocessorHost() + .preModifyTable(tableName, oldDescriptor, newDescriptor); LOG.info(getClientIdAuditPrefix() + " modify " + tableName); @@ -2380,11 +2382,12 @@ public class HMaster extends HRegionServer implements MasterServices { // We need to wait for the procedure to potentially fail due to "prepare" sanity // checks. This will block only the beginning of the procedure. See HBASE-19953. ProcedurePrepareLatch latch = ProcedurePrepareLatch.createBlockingLatch(); - submitProcedure(new ModifyTableProcedure(procedureExecutor.getEnvironment(), - descriptor, latch)); + submitProcedure( + new ModifyTableProcedure(procedureExecutor.getEnvironment(), newDescriptor, latch)); latch.await(); - getMaster().getMasterCoprocessorHost().postModifyTable(tableName, descriptor); + getMaster().getMasterCoprocessorHost() + .postModifyTable(tableName, oldDescriptor, newDescriptor); } @Override @@ -2997,26 +3000,28 @@ public class HMaster extends HRegionServer implements MasterServices { * nonceGroup (the source must ensure each operation gets a unique id). * @return procedure id */ - long modifyNamespace(final NamespaceDescriptor namespaceDescriptor, final long nonceGroup, + long modifyNamespace(final NamespaceDescriptor newNsDescriptor, final long nonceGroup, final long nonce) throws IOException { checkInitialized(); - TableName.isLegalNamespaceName(Bytes.toBytes(namespaceDescriptor.getName())); + TableName.isLegalNamespaceName(Bytes.toBytes(newNsDescriptor.getName())); return MasterProcedureUtil.submitProcedure(new MasterProcedureUtil.NonceProcedureRunnable(this, nonceGroup, nonce) { @Override protected void run() throws IOException { - getMaster().getMasterCoprocessorHost().preModifyNamespace(namespaceDescriptor); + NamespaceDescriptor oldNsDescriptor = getNamespace(newNsDescriptor.getName()); + getMaster().getMasterCoprocessorHost().preModifyNamespace(oldNsDescriptor, newNsDescriptor); // We need to wait for the procedure to potentially fail due to "prepare" sanity // checks. This will block only the beginning of the procedure. See HBASE-19953. ProcedurePrepareLatch latch = ProcedurePrepareLatch.createBlockingLatch(); - LOG.info(getClientIdAuditPrefix() + " modify " + namespaceDescriptor); + LOG.info(getClientIdAuditPrefix() + " modify " + newNsDescriptor); // Execute the operation synchronously - wait for the operation to complete before // continuing. - setProcId(getClusterSchema().modifyNamespace(namespaceDescriptor, getNonceKey(), latch)); + setProcId(getClusterSchema().modifyNamespace(newNsDescriptor, getNonceKey(), latch)); latch.await(); - getMaster().getMasterCoprocessorHost().postModifyNamespace(namespaceDescriptor); + getMaster().getMasterCoprocessorHost().postModifyNamespace(oldNsDescriptor, + newNsDescriptor); } @Override diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/MasterCoprocessorHost.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/MasterCoprocessorHost.java index 8c8c02c01d8..072ae8ae660 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/MasterCoprocessorHost.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/MasterCoprocessorHost.java @@ -254,20 +254,22 @@ public class MasterCoprocessorHost }); } - public void preModifyNamespace(final NamespaceDescriptor ns) throws IOException { + public void preModifyNamespace(final NamespaceDescriptor currentNsDescriptor, + final NamespaceDescriptor newNsDescriptor) throws IOException { execOperation(coprocEnvironments.isEmpty() ? null : new MasterObserverOperation() { @Override public void call(MasterObserver observer) throws IOException { - observer.preModifyNamespace(this, ns); + observer.preModifyNamespace(this, currentNsDescriptor, newNsDescriptor); } }); } - public void postModifyNamespace(final NamespaceDescriptor ns) throws IOException { + public void postModifyNamespace(final NamespaceDescriptor oldNsDescriptor, + final NamespaceDescriptor currentNsDescriptor) throws IOException { execOperation(coprocEnvironments.isEmpty() ? null : new MasterObserverOperation() { @Override public void call(MasterObserver observer) throws IOException { - observer.postModifyNamespace(this, ns); + observer.postModifyNamespace(this, oldNsDescriptor, currentNsDescriptor); } }); } @@ -429,42 +431,44 @@ public class MasterCoprocessorHost }); } - public void preModifyTable(final TableName tableName, final TableDescriptor htd) - throws IOException { + public void preModifyTable(final TableName tableName, final TableDescriptor currentDescriptor, + final TableDescriptor newDescriptor) throws IOException { execOperation(coprocEnvironments.isEmpty() ? null : new MasterObserverOperation() { @Override public void call(MasterObserver observer) throws IOException { - observer.preModifyTable(this, tableName, htd); + observer.preModifyTable(this, tableName, currentDescriptor, newDescriptor); } }); } - public void postModifyTable(final TableName tableName, final TableDescriptor htd) - throws IOException { + public void postModifyTable(final TableName tableName, final TableDescriptor oldDescriptor, + final TableDescriptor currentDescriptor) throws IOException { execOperation(coprocEnvironments.isEmpty() ? null : new MasterObserverOperation() { @Override public void call(MasterObserver observer) throws IOException { - observer.postModifyTable(this, tableName, htd); + observer.postModifyTable(this, tableName, oldDescriptor, currentDescriptor); } }); } - public void preModifyTableAction(final TableName tableName, final TableDescriptor htd, - final User user) throws IOException { + public void preModifyTableAction(final TableName tableName, + final TableDescriptor currentDescriptor, final TableDescriptor newDescriptor, final User user) + throws IOException { execOperation(coprocEnvironments.isEmpty() ? null : new MasterObserverOperation(user) { @Override public void call(MasterObserver observer) throws IOException { - observer.preModifyTableAction(this, tableName, htd); + observer.preModifyTableAction(this, tableName, currentDescriptor, newDescriptor); } }); } - public void postCompletedModifyTableAction(final TableName tableName, final TableDescriptor htd, - final User user) throws IOException { + public void postCompletedModifyTableAction(final TableName tableName, + final TableDescriptor oldDescriptor, final TableDescriptor currentDescriptor, final User user) + throws IOException { execOperation(coprocEnvironments.isEmpty() ? null : new MasterObserverOperation(user) { @Override public void call(MasterObserver observer) throws IOException { - observer.postCompletedModifyTableAction(this, tableName, htd); + observer.postCompletedModifyTableAction(this, tableName, oldDescriptor, currentDescriptor); } }); } 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 1f1ba3cfeed..6fb9caa2dad 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 @@ -420,10 +420,12 @@ public class ModifyTableProcedure if (cpHost != null) { switch (state) { case MODIFY_TABLE_PRE_OPERATION: - cpHost.preModifyTableAction(getTableName(), modifiedTableDescriptor, getUser()); + cpHost.preModifyTableAction(getTableName(), unmodifiedTableDescriptor, + modifiedTableDescriptor, getUser()); break; case MODIFY_TABLE_POST_OPERATION: - cpHost.postCompletedModifyTableAction(getTableName(), modifiedTableDescriptor,getUser()); + cpHost.postCompletedModifyTableAction(getTableName(), unmodifiedTableDescriptor, + modifiedTableDescriptor,getUser()); break; default: throw new UnsupportedOperationException(this + " unhandled state=" + state);