HBASE-22178 Introduce a createTableAsync with TableDescriptor method in Admin

This commit is contained in:
zhangduo 2019-04-06 22:15:41 +08:00 committed by Apache9
parent b3f62a7f59
commit 11547b79f3
3 changed files with 38 additions and 19 deletions

View File

@ -196,7 +196,9 @@ public interface Admin extends Abortable, Closeable {
* threads, the table may have been created between test-for-existence and attempt-at-creation). * threads, the table may have been created between test-for-existence and attempt-at-creation).
* @throws IOException if a remote or network exception occurs * @throws IOException if a remote or network exception occurs
*/ */
void createTable(TableDescriptor desc) throws IOException; default void createTable(TableDescriptor desc) throws IOException {
get(createTableAsync(desc), getSyncWaitTimeout(), TimeUnit.MILLISECONDS);
}
/** /**
* Creates a new table with the specified number of regions. The start key specified will become * Creates a new table with the specified number of regions. The start key specified will become
@ -213,7 +215,6 @@ public interface Admin extends Abortable, Closeable {
* @throws org.apache.hadoop.hbase.MasterNotRunningException if master is not running * @throws org.apache.hadoop.hbase.MasterNotRunningException if master is not running
* @throws org.apache.hadoop.hbase.TableExistsException if table already exists (If concurrent * @throws org.apache.hadoop.hbase.TableExistsException if table already exists (If concurrent
* threads, the table may have been created between test-for-existence and attempt-at-creation). * threads, the table may have been created between test-for-existence and attempt-at-creation).
* @throws IOException
*/ */
void createTable(TableDescriptor desc, byte[] startKey, byte[] endKey, int numRegions) void createTable(TableDescriptor desc, byte[] startKey, byte[] endKey, int numRegions)
throws IOException; throws IOException;
@ -237,22 +238,35 @@ public interface Admin extends Abortable, Closeable {
} }
/** /**
* Creates a new table but does not block and wait for it to come online. * Creates a new table but does not block and wait for it to come online. You can use
* You can use Future.get(long, TimeUnit) to wait on the operation to complete. * Future.get(long, TimeUnit) to wait on the operation to complete. It may throw
* It may throw ExecutionException if there was an error while executing the operation * ExecutionException if there was an error while executing the operation or TimeoutException in
* or TimeoutException in case the wait timeout was not long enough to allow the * case the wait timeout was not long enough to allow the operation to complete.
* operation to complete. * <p/>
* Throws IllegalArgumentException Bad table name, if the split keys * Throws IllegalArgumentException Bad table name, if the split keys are repeated and if the split
* are repeated and if the split key has empty byte array. * key has empty byte array.
* * @param desc table descriptor for table
* @throws IOException if a remote or network exception occurs
* @return the result of the async creation. You can use Future.get(long, TimeUnit) to wait on the
* operation to complete.
*/
Future<Void> createTableAsync(TableDescriptor desc) throws IOException;
/**
* Creates a new table but does not block and wait for it to come online. You can use
* Future.get(long, TimeUnit) to wait on the operation to complete. It may throw
* ExecutionException if there was an error while executing the operation or TimeoutException in
* case the wait timeout was not long enough to allow the operation to complete.
* <p/>
* Throws IllegalArgumentException Bad table name, if the split keys are repeated and if the split
* key has empty byte array.
* @param desc table descriptor for table * @param desc table descriptor for table
* @param splitKeys keys to check if the table has been created with all split keys * @param splitKeys keys to check if the table has been created with all split keys
* @throws IOException if a remote or network exception occurs * @throws IOException if a remote or network exception occurs
* @return the result of the async creation. You can use Future.get(long, TimeUnit) * @return the result of the async creation. You can use Future.get(long, TimeUnit) to wait on the
* to wait on the operation to complete. * operation to complete.
*/ */
Future<Void> createTableAsync(TableDescriptor desc, byte[][] splitKeys) Future<Void> createTableAsync(TableDescriptor desc, byte[][] splitKeys) throws IOException;
throws IOException;
/** /**
* Deletes a table. Synchronous operation. * Deletes a table. Synchronous operation.

View File

@ -513,11 +513,6 @@ public class HBaseAdmin implements Admin {
return this.pause * HConstants.RETRY_BACKOFF[triesCount]; return this.pause * HConstants.RETRY_BACKOFF[triesCount];
} }
@Override
public void createTable(TableDescriptor desc) throws IOException {
createTable(desc, null);
}
@Override @Override
public void createTable(TableDescriptor desc, byte[] startKey, byte[] endKey, int numRegions) public void createTable(TableDescriptor desc, byte[] startKey, byte[] endKey, int numRegions)
throws IOException { throws IOException {
@ -3866,4 +3861,9 @@ public class HBaseAdmin implements Admin {
public Future<Void> splitRegionAsync(byte[] regionName) throws IOException { public Future<Void> splitRegionAsync(byte[] regionName) throws IOException {
return splitRegionAsync(regionName, null); return splitRegionAsync(regionName, null);
} }
@Override
public Future<Void> createTableAsync(TableDescriptor desc) throws IOException {
return createTableAsync(desc, null);
}
} }

View File

@ -1031,6 +1031,11 @@ public class ThriftAdmin implements Admin {
} }
@Override
public Future<Void> createTableAsync(TableDescriptor desc) {
throw new NotImplementedException("createTableAsync not supported in ThriftAdmin");
}
@Override @Override
public Future<Void> createTableAsync(TableDescriptor desc, byte[][] splitKeys) { public Future<Void> createTableAsync(TableDescriptor desc, byte[][] splitKeys) {
throw new NotImplementedException("createTableAsync not supported in ThriftAdmin"); throw new NotImplementedException("createTableAsync not supported in ThriftAdmin");