[03/16] hbase git commit: HBASE-21550 Add a new method preCreateTableRegionInfos for MasterObserver which allows CPs to modify the TableDescriptor

2018-12-10 Thread zhangduo
HBASE-21550 Add a new method preCreateTableRegionInfos for MasterObserver which 
allows CPs to modify the TableDescriptor


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

Branch: refs/heads/HBASE-21512
Commit: f49baf259ec6bc2c8634debd2dbfc592753245d3
Parents: 8bf966c
Author: Duo Zhang 
Authored: Wed Dec 5 18:19:15 2018 +0800
Committer: zhangduo 
Committed: Thu Dec 6 08:30:32 2018 +0800

--
 .../hbase/coprocessor/MasterObserver.java   | 15 +
 .../org/apache/hadoop/hbase/master/HMaster.java | 68 ++--
 .../hbase/master/MasterCoprocessorHost.java | 14 
 .../hbase/coprocessor/TestMasterObserver.java   | 14 +++-
 4 files changed, 75 insertions(+), 36 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/hbase/blob/f49baf25/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 573ac7a..a0863e4 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
@@ -70,6 +70,21 @@ import org.apache.yetus.audience.InterfaceStability;
 @InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.COPROC)
 @InterfaceStability.Evolving
 public interface MasterObserver {
+
+  /**
+   * Called before we create the region infos for this table. Called as part 
of create table RPC
+   * call.
+   * @param ctx the environment to interact with the framework and master
+   * @param desc the TableDescriptor for the table
+   * @return the TableDescriptor used to create the table. Default is the one 
passed in. Return
+   * {@code null} means cancel the creation.
+   */
+  default TableDescriptor preCreateTableRegionsInfos(
+  final ObserverContext ctx, TableDescriptor 
desc)
+  throws IOException {
+return desc;
+  }
+
   /**
* Called before a new table is created by
* {@link org.apache.hadoop.hbase.master.HMaster}.  Called as part of create

http://git-wip-us.apache.org/repos/asf/hbase/blob/f49baf25/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 132e271..e96dc36 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
@@ -2030,45 +2030,45 @@ public class HMaster extends HRegionServer implements 
MasterServices {
   }
 
   @Override
-  public long createTable(
-  final TableDescriptor tableDescriptor,
-  final byte [][] splitKeys,
-  final long nonceGroup,
-  final long nonce) throws IOException {
+  public long createTable(final TableDescriptor tableDescriptor, final 
byte[][] splitKeys,
+  final long nonceGroup, final long nonce) throws IOException {
 checkInitialized();
-
-String namespace = tableDescriptor.getTableName().getNamespaceAsString();
+TableDescriptor desc = 
getMasterCoprocessorHost().preCreateTableRegionsInfos(tableDescriptor);
+if (desc == null) {
+  throw new IOException("Creation for " + tableDescriptor + " is canceled 
by CP");
+}
+String namespace = desc.getTableName().getNamespaceAsString();
 this.clusterSchemaService.getNamespace(namespace);
 
-RegionInfo[] newRegions = 
ModifyRegionUtils.createRegionInfos(tableDescriptor, splitKeys);
-sanityCheckTableDescriptor(tableDescriptor);
-
-return MasterProcedureUtil.submitProcedure(
-new MasterProcedureUtil.NonceProcedureRunnable(this, nonceGroup, 
nonce) {
-  @Override
-  protected void run() throws IOException {
-getMaster().getMasterCoprocessorHost().preCreateTable(tableDescriptor, 
newRegions);
-
-LOG.info(getClientIdAuditPrefix() + " create " + tableDescriptor);
-
-// TODO: We can handle/merge duplicate requests, and differentiate the 
case of
-//   TableExistsException by saying if the schema is the same or 
not.
-//
-// 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 = 

[42/51] [abbrv] hbase git commit: HBASE-21550 Add a new method preCreateTableRegionInfos for MasterObserver which allows CPs to modify the TableDescriptor

2018-12-07 Thread elserj
HBASE-21550 Add a new method preCreateTableRegionInfos for MasterObserver which 
allows CPs to modify the TableDescriptor


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

Branch: refs/heads/HBASE-20952
Commit: f49baf259ec6bc2c8634debd2dbfc592753245d3
Parents: 8bf966c
Author: Duo Zhang 
Authored: Wed Dec 5 18:19:15 2018 +0800
Committer: zhangduo 
Committed: Thu Dec 6 08:30:32 2018 +0800

--
 .../hbase/coprocessor/MasterObserver.java   | 15 +
 .../org/apache/hadoop/hbase/master/HMaster.java | 68 ++--
 .../hbase/master/MasterCoprocessorHost.java | 14 
 .../hbase/coprocessor/TestMasterObserver.java   | 14 +++-
 4 files changed, 75 insertions(+), 36 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/hbase/blob/f49baf25/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 573ac7a..a0863e4 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
@@ -70,6 +70,21 @@ import org.apache.yetus.audience.InterfaceStability;
 @InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.COPROC)
 @InterfaceStability.Evolving
 public interface MasterObserver {
+
+  /**
+   * Called before we create the region infos for this table. Called as part 
of create table RPC
+   * call.
+   * @param ctx the environment to interact with the framework and master
+   * @param desc the TableDescriptor for the table
+   * @return the TableDescriptor used to create the table. Default is the one 
passed in. Return
+   * {@code null} means cancel the creation.
+   */
+  default TableDescriptor preCreateTableRegionsInfos(
+  final ObserverContext ctx, TableDescriptor 
desc)
+  throws IOException {
+return desc;
+  }
+
   /**
* Called before a new table is created by
* {@link org.apache.hadoop.hbase.master.HMaster}.  Called as part of create

http://git-wip-us.apache.org/repos/asf/hbase/blob/f49baf25/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 132e271..e96dc36 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
@@ -2030,45 +2030,45 @@ public class HMaster extends HRegionServer implements 
MasterServices {
   }
 
   @Override
-  public long createTable(
-  final TableDescriptor tableDescriptor,
-  final byte [][] splitKeys,
-  final long nonceGroup,
-  final long nonce) throws IOException {
+  public long createTable(final TableDescriptor tableDescriptor, final 
byte[][] splitKeys,
+  final long nonceGroup, final long nonce) throws IOException {
 checkInitialized();
-
-String namespace = tableDescriptor.getTableName().getNamespaceAsString();
+TableDescriptor desc = 
getMasterCoprocessorHost().preCreateTableRegionsInfos(tableDescriptor);
+if (desc == null) {
+  throw new IOException("Creation for " + tableDescriptor + " is canceled 
by CP");
+}
+String namespace = desc.getTableName().getNamespaceAsString();
 this.clusterSchemaService.getNamespace(namespace);
 
-RegionInfo[] newRegions = 
ModifyRegionUtils.createRegionInfos(tableDescriptor, splitKeys);
-sanityCheckTableDescriptor(tableDescriptor);
-
-return MasterProcedureUtil.submitProcedure(
-new MasterProcedureUtil.NonceProcedureRunnable(this, nonceGroup, 
nonce) {
-  @Override
-  protected void run() throws IOException {
-getMaster().getMasterCoprocessorHost().preCreateTable(tableDescriptor, 
newRegions);
-
-LOG.info(getClientIdAuditPrefix() + " create " + tableDescriptor);
-
-// TODO: We can handle/merge duplicate requests, and differentiate the 
case of
-//   TableExistsException by saying if the schema is the same or 
not.
-//
-// 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 = 

hbase git commit: HBASE-21550 Add a new method preCreateTableRegionInfos for MasterObserver which allows CPs to modify the TableDescriptor

2018-12-05 Thread zhangduo
Repository: hbase
Updated Branches:
  refs/heads/branch-2 564833754 -> 7e8ce1c5c


HBASE-21550 Add a new method preCreateTableRegionInfos for MasterObserver which 
allows CPs to modify the TableDescriptor


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

Branch: refs/heads/branch-2
Commit: 7e8ce1c5cc9f0f15e5a456869435c96221fbfa8b
Parents: 5648337
Author: Duo Zhang 
Authored: Wed Dec 5 18:19:15 2018 +0800
Committer: zhangduo 
Committed: Thu Dec 6 08:30:37 2018 +0800

--
 .../hbase/coprocessor/MasterObserver.java   | 15 +
 .../org/apache/hadoop/hbase/master/HMaster.java | 68 ++--
 .../hbase/master/MasterCoprocessorHost.java | 14 
 .../hbase/coprocessor/TestMasterObserver.java   | 14 +++-
 4 files changed, 75 insertions(+), 36 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/hbase/blob/7e8ce1c5/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 a37f21a..a1e9be5 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
@@ -69,6 +69,21 @@ import org.apache.yetus.audience.InterfaceStability;
 @InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.COPROC)
 @InterfaceStability.Evolving
 public interface MasterObserver {
+
+  /**
+   * Called before we create the region infos for this table. Called as part 
of create table RPC
+   * call.
+   * @param ctx the environment to interact with the framework and master
+   * @param desc the TableDescriptor for the table
+   * @return the TableDescriptor used to create the table. Default is the one 
passed in. Return
+   * {@code null} means cancel the creation.
+   */
+  default TableDescriptor preCreateTableRegionsInfos(
+  final ObserverContext ctx, TableDescriptor 
desc)
+  throws IOException {
+return desc;
+  }
+
   /**
* Called before a new table is created by
* {@link org.apache.hadoop.hbase.master.HMaster}.  Called as part of create

http://git-wip-us.apache.org/repos/asf/hbase/blob/7e8ce1c5/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 ecc9bde..a023a4f 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
@@ -2009,45 +2009,45 @@ public class HMaster extends HRegionServer implements 
MasterServices {
   }
 
   @Override
-  public long createTable(
-  final TableDescriptor tableDescriptor,
-  final byte [][] splitKeys,
-  final long nonceGroup,
-  final long nonce) throws IOException {
+  public long createTable(final TableDescriptor tableDescriptor, final 
byte[][] splitKeys,
+  final long nonceGroup, final long nonce) throws IOException {
 checkInitialized();
-
-String namespace = tableDescriptor.getTableName().getNamespaceAsString();
+TableDescriptor desc = 
getMasterCoprocessorHost().preCreateTableRegionsInfos(tableDescriptor);
+if (desc == null) {
+  throw new IOException("Creation for " + tableDescriptor + " is canceled 
by CP");
+}
+String namespace = desc.getTableName().getNamespaceAsString();
 this.clusterSchemaService.getNamespace(namespace);
 
-RegionInfo[] newRegions = 
ModifyRegionUtils.createRegionInfos(tableDescriptor, splitKeys);
-sanityCheckTableDescriptor(tableDescriptor);
-
-return MasterProcedureUtil.submitProcedure(
-new MasterProcedureUtil.NonceProcedureRunnable(this, nonceGroup, 
nonce) {
-  @Override
-  protected void run() throws IOException {
-getMaster().getMasterCoprocessorHost().preCreateTable(tableDescriptor, 
newRegions);
-
-LOG.info(getClientIdAuditPrefix() + " create " + tableDescriptor);
-
-// TODO: We can handle/merge duplicate requests, and differentiate the 
case of
-//   TableExistsException by saying if the schema is the same or 
not.
-//
-// 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.
-   

hbase git commit: HBASE-21550 Add a new method preCreateTableRegionInfos for MasterObserver which allows CPs to modify the TableDescriptor

2018-12-05 Thread zhangduo
Repository: hbase
Updated Branches:
  refs/heads/master 8bf966c8e -> f49baf259


HBASE-21550 Add a new method preCreateTableRegionInfos for MasterObserver which 
allows CPs to modify the TableDescriptor


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

Branch: refs/heads/master
Commit: f49baf259ec6bc2c8634debd2dbfc592753245d3
Parents: 8bf966c
Author: Duo Zhang 
Authored: Wed Dec 5 18:19:15 2018 +0800
Committer: zhangduo 
Committed: Thu Dec 6 08:30:32 2018 +0800

--
 .../hbase/coprocessor/MasterObserver.java   | 15 +
 .../org/apache/hadoop/hbase/master/HMaster.java | 68 ++--
 .../hbase/master/MasterCoprocessorHost.java | 14 
 .../hbase/coprocessor/TestMasterObserver.java   | 14 +++-
 4 files changed, 75 insertions(+), 36 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/hbase/blob/f49baf25/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 573ac7a..a0863e4 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
@@ -70,6 +70,21 @@ import org.apache.yetus.audience.InterfaceStability;
 @InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.COPROC)
 @InterfaceStability.Evolving
 public interface MasterObserver {
+
+  /**
+   * Called before we create the region infos for this table. Called as part 
of create table RPC
+   * call.
+   * @param ctx the environment to interact with the framework and master
+   * @param desc the TableDescriptor for the table
+   * @return the TableDescriptor used to create the table. Default is the one 
passed in. Return
+   * {@code null} means cancel the creation.
+   */
+  default TableDescriptor preCreateTableRegionsInfos(
+  final ObserverContext ctx, TableDescriptor 
desc)
+  throws IOException {
+return desc;
+  }
+
   /**
* Called before a new table is created by
* {@link org.apache.hadoop.hbase.master.HMaster}.  Called as part of create

http://git-wip-us.apache.org/repos/asf/hbase/blob/f49baf25/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 132e271..e96dc36 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
@@ -2030,45 +2030,45 @@ public class HMaster extends HRegionServer implements 
MasterServices {
   }
 
   @Override
-  public long createTable(
-  final TableDescriptor tableDescriptor,
-  final byte [][] splitKeys,
-  final long nonceGroup,
-  final long nonce) throws IOException {
+  public long createTable(final TableDescriptor tableDescriptor, final 
byte[][] splitKeys,
+  final long nonceGroup, final long nonce) throws IOException {
 checkInitialized();
-
-String namespace = tableDescriptor.getTableName().getNamespaceAsString();
+TableDescriptor desc = 
getMasterCoprocessorHost().preCreateTableRegionsInfos(tableDescriptor);
+if (desc == null) {
+  throw new IOException("Creation for " + tableDescriptor + " is canceled 
by CP");
+}
+String namespace = desc.getTableName().getNamespaceAsString();
 this.clusterSchemaService.getNamespace(namespace);
 
-RegionInfo[] newRegions = 
ModifyRegionUtils.createRegionInfos(tableDescriptor, splitKeys);
-sanityCheckTableDescriptor(tableDescriptor);
-
-return MasterProcedureUtil.submitProcedure(
-new MasterProcedureUtil.NonceProcedureRunnable(this, nonceGroup, 
nonce) {
-  @Override
-  protected void run() throws IOException {
-getMaster().getMasterCoprocessorHost().preCreateTable(tableDescriptor, 
newRegions);
-
-LOG.info(getClientIdAuditPrefix() + " create " + tableDescriptor);
-
-// TODO: We can handle/merge duplicate requests, and differentiate the 
case of
-//   TableExistsException by saying if the schema is the same or 
not.
-//
-// 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.
-