You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by md...@apache.org on 2018/05/16 19:04:10 UTC

[2/3] hbase git commit: HBASE-20567 Pass both old and new descriptors to pre/post hooks of modify operations for table and namespace.

HBASE-20567 Pass both old and new descriptors to pre/post hooks of modify operations for table and namespace.

Signed-off-by: Mike Drob <md...@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/61f2b5f0
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/61f2b5f0
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/61f2b5f0

Branch: refs/heads/branch-2
Commit: 61f2b5f0711c2cde98252980dfe2de25fe1ac7ee
Parents: 77eaff0
Author: Apekshit Sharma <ap...@apache.org>
Authored: Thu May 10 20:34:14 2018 -0700
Committer: Mike Drob <md...@apache.org>
Committed: Wed May 16 14:03:36 2018 -0500

----------------------------------------------------------------------
 .../hbase/coprocessor/MasterObserver.java       | 122 +++++++++++++++++--
 .../org/apache/hadoop/hbase/master/HMaster.java |  29 +++--
 .../hbase/master/MasterCoprocessorHost.java     |  36 +++---
 .../master/procedure/ModifyTableProcedure.java  |   6 +-
 4 files changed, 151 insertions(+), 42 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/61f2b5f0/hbase-server/src/main/java/org/apache/hadoop/hbase/coprocessor/MasterObserver.java
----------------------------------------------------------------------
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 a17bc9f..a37f21a 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,67 @@ 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<MasterCoprocessorEnvironment> ctx,
-      final TableName tableName, TableDescriptor htd) throws IOException {}
+    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<MasterCoprocessorEnvironment> ctx,
+      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<MasterCoprocessorEnvironment> ctx,
-      final TableName tableName, TableDescriptor htd) throws IOException {}
+    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<MasterCoprocessorEnvironment> ctx,
+      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
+   * 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 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<MasterCoprocessorEnvironment> ctx,
+    final TableName tableName,
+    final TableDescriptor newDescriptor) throws IOException {}
 
   /**
    * Called prior to modifying a table's properties.  Called as part of modify
@@ -230,12 +277,16 @@ 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
+   * @param newDescriptor after modify operation, table will have this descriptor
    */
   default void preModifyTableAction(
       final ObserverContext<MasterCoprocessorEnvironment> 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<MasterCoprocessorEnvironment> 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<MasterCoprocessorEnvironment> 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<MasterCoprocessorEnvironment> ctx,
-      NamespaceDescriptor ns) throws IOException {}
+    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<MasterCoprocessorEnvironment> ctx,
+      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<MasterCoprocessorEnvironment> ctx,
-      NamespaceDescriptor ns) throws IOException {}
+    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<MasterCoprocessorEnvironment> ctx,
+      NamespaceDescriptor oldNsDescriptor, NamespaceDescriptor currentNsDescriptor)
+    throws IOException {
+    postModifyNamespace(ctx, currentNsDescriptor);
+  }
 
   /**
    * Called before a getNamespaceDescriptor request has been processed.

http://git-wip-us.apache.org/repos/asf/hbase/blob/61f2b5f0/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java
----------------------------------------------------------------------
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 6d0b58b..d0ecf23 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 {
    * <code>nonceGroup</code> (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

http://git-wip-us.apache.org/repos/asf/hbase/blob/61f2b5f0/hbase-server/src/main/java/org/apache/hadoop/hbase/master/MasterCoprocessorHost.java
----------------------------------------------------------------------
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 8c8c02c..072ae8a 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);
       }
     });
   }

http://git-wip-us.apache.org/repos/asf/hbase/blob/61f2b5f0/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/ModifyTableProcedure.java
----------------------------------------------------------------------
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 1f1ba3c..6fb9caa 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);