diff --git hbase-client/src/main/java/org/apache/hadoop/hbase/client/Admin.java hbase-client/src/main/java/org/apache/hadoop/hbase/client/Admin.java index 930037299a..098aba4942 100644 --- hbase-client/src/main/java/org/apache/hadoop/hbase/client/Admin.java +++ hbase-client/src/main/java/org/apache/hadoop/hbase/client/Admin.java @@ -98,30 +98,67 @@ public interface Admin extends Abortable, Closeable { * * @return - returns an array of read-only HTableDescriptors * @throws IOException if a remote or network exception occurs + * @deprecated since 2.0 version and will be removed in 3.0 version. + * use {@link #listTableDescriptors()} */ + @Deprecated HTableDescriptor[] listTables() throws IOException; /** + * List all the userspace tables. + * + * @return - returns a list of TableDescriptors + * @throws IOException if a remote or network exception occurs + */ + List listTableDescriptors() throws IOException; + + /** * List all the userspace tables matching the given pattern. * * @param pattern The compiled regular expression to match against * @return - returns an array of read-only HTableDescriptors * @throws IOException if a remote or network exception occurs * @see #listTables() + * @deprecated since 2.0 version and will be removed in 3.0 version. + * use {@link #listTableDescriptors(java.util.regex.Pattern)} */ + @Deprecated HTableDescriptor[] listTables(Pattern pattern) throws IOException; /** + * List all the userspace tables matching the given pattern. + * + * @param pattern The compiled regular expression to match against + * @return - returns a list of TableDescriptors + * @throws IOException if a remote or network exception occurs + * @see #listTables() + */ + List listTableDescriptors(Pattern pattern) throws IOException; + + /** * List all the userspace tables matching the given regular expression. * * @param regex The regular expression to match against - * @return - returns an array of HTableDescriptors + * @return - returns an array of read-only HTableDescriptors * @throws IOException if a remote or network exception occurs * @see #listTables(java.util.regex.Pattern) + * @deprecated since 2.0 version and will be removed in 3.0 version. + * use {@link #listTableDescriptors(java.lang.String)} */ + @Deprecated HTableDescriptor[] listTables(String regex) throws IOException; /** + * List all the userspace tables matching the given regular expression. + * + * @param regex The regular expression to match against + * @return - returns a list of TableDescriptors + * @throws IOException if a remote or network exception occurs + * @see #listTables(java.util.regex.Pattern) + */ + List listTableDescriptors(String regex) throws IOException; + + /** * List all the tables matching the given pattern. * * @param pattern The compiled regular expression to match against @@ -129,23 +166,53 @@ public interface Admin extends Abortable, Closeable { * @return - returns an array of read-only HTableDescriptors * @throws IOException if a remote or network exception occurs * @see #listTables() + * @deprecated since 2.0 version and will be removed in 3.0 version. + * use {@link #listTableDescriptors(java.util.regex.Pattern, boolean)} */ + @Deprecated HTableDescriptor[] listTables(Pattern pattern, boolean includeSysTables) throws IOException; /** * List all the tables matching the given pattern. * + * @param pattern The compiled regular expression to match against + * @param includeSysTables False to match only against userspace tables + * @return - returns a list of TableDescriptors + * @throws IOException if a remote or network exception occurs + * @see #listTables() + */ + List listTableDescriptors(Pattern pattern, boolean includeSysTables) + throws IOException; + + /** + * List all the tables matching the given pattern. + * * @param regex The regular expression to match against * @param includeSysTables False to match only against userspace tables * @return - returns an array of read-only HTableDescriptors * @throws IOException if a remote or network exception occurs * @see #listTables(java.util.regex.Pattern, boolean) + * @deprecated since 2.0 version and will be removed in 3.0 version. + * use {@link #listTableDescriptors(java.lang.String, boolean)} */ + @Deprecated HTableDescriptor[] listTables(String regex, boolean includeSysTables) throws IOException; /** + * List all the tables matching the given pattern. + * + * @param regex The regular expression to match against + * @param includeSysTables False to match only against userspace tables + * @return - returns a list of TableDescriptors + * @throws IOException if a remote or network exception occurs + * @see #listTables(java.util.regex.Pattern, boolean) + */ + List listTableDescriptors(String regex, boolean includeSysTables) + throws IOException; + + /** * List all of the names of userspace tables. * * @return TableName[] table names @@ -196,11 +263,25 @@ public interface Admin extends Abortable, Closeable { * @return the read-only tableDescriptor * @throws org.apache.hadoop.hbase.TableNotFoundException * @throws IOException if a remote or network exception occurs + * @deprecated since 2.0 version and will be removed in 3.0 version. + * use {@link #listTableDescriptor(TableName)} */ + @Deprecated HTableDescriptor getTableDescriptor(final TableName tableName) throws TableNotFoundException, IOException; /** + * Method for getting the tableDescriptor + * + * @param tableName as a {@link TableName} + * @return the tableDescriptor + * @throws org.apache.hadoop.hbase.TableNotFoundException + * @throws IOException if a remote or network exception occurs + */ + TableDescriptor listTableDescriptor(final TableName tableName) + throws TableNotFoundException, IOException; + + /** * Creates a new table. Synchronous operation. * * @param desc table descriptor for table @@ -210,7 +291,7 @@ public interface Admin extends Abortable, Closeable { * threads, the table may have been created between test-for-existence and attempt-at-creation). * @throws IOException if a remote or network exception occurs */ - void createTable(HTableDescriptor desc) throws IOException; + void createTable(TableDescriptor desc) throws IOException; /** * Creates a new table with the specified number of regions. The start key specified will become @@ -229,7 +310,7 @@ public interface Admin extends Abortable, Closeable { * threads, the table may have been created between test-for-existence and attempt-at-creation). * @throws IOException */ - void createTable(HTableDescriptor desc, byte[] startKey, byte[] endKey, int numRegions) + void createTable(TableDescriptor desc, byte[] startKey, byte[] endKey, int numRegions) throws IOException; /** @@ -246,7 +327,7 @@ public interface Admin extends Abortable, Closeable { * threads, the table may have been created between test-for-existence and attempt-at-creation). * @throws IOException */ - void createTable(final HTableDescriptor desc, byte[][] splitKeys) throws IOException; + void createTable(final TableDescriptor desc, byte[][] splitKeys) throws IOException; /** * Creates a new table but does not block and wait for it to come online. @@ -263,7 +344,7 @@ public interface Admin extends Abortable, Closeable { * @return the result of the async creation. You can use Future.get(long, TimeUnit) * to wait on the operation to complete. */ - Future createTableAsync(final HTableDescriptor desc, final byte[][] splitKeys) + Future createTableAsync(final TableDescriptor desc, final byte[][] splitKeys) throws IOException; /** @@ -291,7 +372,8 @@ public interface Admin extends Abortable, Closeable { /** * Deletes tables matching the passed in pattern and wait on completion. Warning: Use this method * carefully, there is no prompting and the effect is immediate. Consider using {@link - * #listTables(java.lang.String)} and {@link #deleteTable(org.apache.hadoop.hbase.TableName)} + * #listTableDescriptors(java.lang.String)} + * and {@link #deleteTable(org.apache.hadoop.hbase.TableName)} * * @param regex The regular expression to match table names against * @return Table descriptors for tables that couldn't be deleted. @@ -299,20 +381,30 @@ public interface Admin extends Abortable, Closeable { * @throws IOException * @see #deleteTables(java.util.regex.Pattern) * @see #deleteTable(org.apache.hadoop.hbase.TableName) + * @deprecated since 2.0 version and will be removed in 3.0 version + * This is just a trivial helper method without any magic. + * Consider using {@link #listTableDescriptors(java.lang.String)} + * and {@link #enableTable(org.apache.hadoop.hbase.TableName)} */ + @Deprecated HTableDescriptor[] deleteTables(String regex) throws IOException; /** * Delete tables matching the passed in pattern and wait on completion. Warning: Use this method * carefully, there is no prompting and the effect is immediate. Consider using {@link - * #listTables(java.util.regex.Pattern) } and + * #listTableDescriptors(java.util.regex.Pattern)} and * {@link #deleteTable(org.apache.hadoop.hbase.TableName)} * * @param pattern The pattern to match table names against * @return Table descriptors for tables that couldn't be deleted * The return htds are read-only * @throws IOException + * @deprecated since 2.0 version and will be removed in 3.0 version + * This is just a trivial helper method without any magic. + * Consider using {@link #listTableDescriptors(java.util.regex.Pattern)} + * and {@link #enableTable(org.apache.hadoop.hbase.TableName)} */ + @Deprecated HTableDescriptor[] deleteTables(Pattern pattern) throws IOException; /** @@ -372,7 +464,7 @@ public interface Admin extends Abortable, Closeable { /** * Enable tables matching the passed in pattern and wait on completion. Warning: Use this method * carefully, there is no prompting and the effect is immediate. Consider using {@link - * #listTables(java.lang.String)} and {@link #enableTable(org.apache.hadoop.hbase.TableName)} + * #listTableDescriptors(java.lang.String)} and {@link #enableTable(org.apache.hadoop.hbase.TableName)} * * @param regex The regular expression to match table names against * @throws IOException @@ -380,20 +472,30 @@ public interface Admin extends Abortable, Closeable { * The return HTDs are read-only. * @see #enableTables(java.util.regex.Pattern) * @see #enableTable(org.apache.hadoop.hbase.TableName) + * @deprecated since 2.0 version and will be removed in 3.0 version + * This is just a trivial helper method without any magic. + * Consider using {@link #listTableDescriptors(java.lang.String)} + * and {@link #enableTable(org.apache.hadoop.hbase.TableName)} */ + @Deprecated HTableDescriptor[] enableTables(String regex) throws IOException; /** * Enable tables matching the passed in pattern and wait on completion. Warning: Use this method * carefully, there is no prompting and the effect is immediate. Consider using {@link - * #listTables(java.util.regex.Pattern) } and + * #listTableDescriptors(java.util.regex.Pattern)} and * {@link #enableTable(org.apache.hadoop.hbase.TableName)} * * @param pattern The pattern to match table names against * @throws IOException * @return Table descriptors for tables that couldn't be enabled. * The return HTDs are read-only. + * @deprecated since 2.0 version and will be removed in 3.0 version + * This is just a trivial helper method without any magic. + * Consider using {@link #listTableDescriptors(java.util.regex.Pattern)} + * and {@link #enableTable(org.apache.hadoop.hbase.TableName)} */ + @Deprecated HTableDescriptor[] enableTables(Pattern pattern) throws IOException; /** @@ -425,7 +527,8 @@ public interface Admin extends Abortable, Closeable { /** * Disable tables matching the passed in pattern and wait on completion. Warning: Use this method * carefully, there is no prompting and the effect is immediate. Consider using {@link - * #listTables(java.lang.String)} and {@link #disableTable(org.apache.hadoop.hbase.TableName)} + * #listTableDescriptors(java.lang.String)} + * and {@link #disableTable(org.apache.hadoop.hbase.TableName)} * * @param regex The regular expression to match table names against * @return Table descriptors for tables that couldn't be disabled @@ -433,20 +536,30 @@ public interface Admin extends Abortable, Closeable { * @throws IOException * @see #disableTables(java.util.regex.Pattern) * @see #disableTable(org.apache.hadoop.hbase.TableName) + * @deprecated since 2.0 version and will be removed in 3.0 version + * This is just a trivial helper method without any magic. + * Consider using {@link #listTableDescriptors(java.lang.String)} + * and {@link #disableTable(org.apache.hadoop.hbase.TableName)} */ + @Deprecated HTableDescriptor[] disableTables(String regex) throws IOException; /** * Disable tables matching the passed in pattern and wait on completion. Warning: Use this method * carefully, there is no prompting and the effect is immediate. Consider using {@link - * #listTables(java.util.regex.Pattern) } and + * #listTableDescriptors(java.util.regex.Pattern)} and * {@link #disableTable(org.apache.hadoop.hbase.TableName)} * * @param pattern The pattern to match table names against * @return Table descriptors for tables that couldn't be disabled * The return htds are read-only * @throws IOException + * @deprecated since 2.0 version and will be removed in 3.0 version + * This is just a trivial helper method without any magic. + * Consider using {@link #listTableDescriptors(java.util.regex.Pattern)} + * and {@link #disableTable(org.apache.hadoop.hbase.TableName)} */ + @Deprecated HTableDescriptor[] disableTables(Pattern pattern) throws IOException; /** @@ -1014,11 +1127,22 @@ public interface Admin extends Abortable, Closeable { * @param tableName name of table. * @param htd modified description of the table * @throws IOException if a remote or network exception occurs + * @deprecated since 2.0 version and will be removed in 3.0 version. + * use {@link #modifyTable(TableDescriptor)} */ + @Deprecated void modifyTable(final TableName tableName, final HTableDescriptor htd) throws IOException; /** + * Modify an existing table, more IRB friendly version. + * + * @param td modified description of the table + * @throws IOException if a remote or network exception occurs + */ + void modifyTable(final TableDescriptor td) throws IOException; + + /** * Modify an existing table, more IRB friendly version. Asynchronous operation. This means that * it may be a while before your schema change is updated across all of the table. * You can use Future.get(long, TimeUnit) to wait on the operation to complete. @@ -1031,11 +1155,30 @@ public interface Admin extends Abortable, Closeable { * @throws IOException if a remote or network exception occurs * @return the result of the async modify. You can use Future.get(long, TimeUnit) to wait on the * operation to complete + * @deprecated since 2.0 version and will be removed in 3.0 version. + * use {@link #modifyTableAsync(TableDescriptor)} */ + @Deprecated Future modifyTableAsync(final TableName tableName, final HTableDescriptor htd) throws IOException; /** + * Modify an existing table, more IRB friendly version. Asynchronous operation. This means that + * it may be a while before your schema change is updated across all of the table. + * 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. + * + * @param td description of the table + * @throws IOException if a remote or network exception occurs + * @return the result of the async modify. You can use Future.get(long, TimeUnit) to wait on the + * operation to complete + */ + Future modifyTableAsync(TableDescriptor td) + throws IOException; + + /** * Shuts down the HBase cluster * * @throws IOException if a remote or network exception occurs @@ -1177,11 +1320,24 @@ public interface Admin extends Abortable, Closeable { * @param name namespace name * @return HTD[] the read-only tableDescriptors * @throws IOException + * @deprecated since 2.0 version and will be removed in 3.0 version. + * use {@link #listTableDescriptorsByNamespace(byte[])} */ + @Deprecated HTableDescriptor[] listTableDescriptorsByNamespace(final String name) throws IOException; /** + * Get list of table descriptors by namespace + * + * @param name namespace name + * @return returns a list of TableDescriptors + * @throws IOException + */ + List listTableDescriptorsByNamespace(final byte[] name) + throws IOException; + + /** * Get list of table names by namespace * * @param name namespace name @@ -1210,17 +1366,33 @@ public interface Admin extends Abortable, Closeable { * @param tableNames List of table names * @return HTD[] the read-only tableDescriptors * @throws IOException if a remote or network exception occurs + * @deprecated since 2.0 version and will be removed in 3.0 version. + * use {@link #listTableDescriptors(List)} */ + @Deprecated HTableDescriptor[] getTableDescriptorsByTableName(List tableNames) throws IOException; /** * Get tableDescriptors * + * @param tableNames List of table names + * @return returns a list of TableDescriptors + * @throws IOException if a remote or network exception occurs + */ + List listTableDescriptors(List tableNames) + throws IOException; + + /** + * Get tableDescriptors + * * @param names List of table names * @return HTD[] the read-only tableDescriptors * @throws IOException if a remote or network exception occurs + * @deprecated since 2.0 version and will be removed in 3.0 version. + * use {@link #listTableDescriptors(List)} */ + @Deprecated HTableDescriptor[] getTableDescriptors(List names) throws IOException; diff --git hbase-client/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java hbase-client/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java index 1c6ea03b0c..7518b9cff6 100644 --- hbase-client/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java +++ hbase-client/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java @@ -206,6 +206,7 @@ import com.google.common.annotations.VisibleForTesting; import com.google.protobuf.Descriptors; import com.google.protobuf.Message; import com.google.protobuf.RpcController; +import java.util.stream.Collectors; /** * HBaseAdmin is no longer a client API. It is marked InterfaceAudience.Private indicating that @@ -307,6 +308,96 @@ public class HBaseAdmin implements Admin { return new AbortProcedureFuture(this, procId, abortProcResponse); } + @Override + public List listTableDescriptors() throws IOException { + return listTableDescriptors((Pattern)null, false); + } + + @Override + public List listTableDescriptors(Pattern pattern) throws IOException { + return listTableDescriptors(pattern, false); + } + + @Override + public List listTableDescriptors(String regex) throws IOException { + return listTableDescriptors(Pattern.compile(regex), false); + } + + @Override + public List listTableDescriptors(Pattern pattern, boolean includeSysTables) throws IOException { + return executeCallable(new MasterCallable>(getConnection(), + getRpcControllerFactory()) { + @Override + protected List rpcCall() throws Exception { + GetTableDescriptorsRequest req = + RequestConverter.buildGetTableDescriptorsRequest(pattern, includeSysTables); + return ProtobufUtil.toTableDescriptorList(master.getTableDescriptors(getRpcController(), + req)); + } + }); + } + + @Override + public List listTableDescriptors(String regex, boolean includeSysTables) throws IOException { + return listTableDescriptors(Pattern.compile(regex), includeSysTables); + } + + @Override + public TableDescriptor listTableDescriptor(TableName tableName) throws TableNotFoundException, IOException { + return getTableDescriptor(tableName, getConnection(), rpcCallerFactory, rpcControllerFactory, + operationTimeout, rpcTimeout); + } + + @Override + public void modifyTable(TableDescriptor td) throws IOException { + get(modifyTableAsync(td), syncWaitTimeout, TimeUnit.MILLISECONDS); + } + + @Override + public Future modifyTableAsync(TableDescriptor td) throws IOException { + ModifyTableResponse response = executeCallable( + new MasterCallable(getConnection(), getRpcControllerFactory()) { + @Override + protected ModifyTableResponse rpcCall() throws Exception { + setPriority(td.getTableName()); + ModifyTableRequest request = RequestConverter.buildModifyTableRequest( + td.getTableName(), td, ng.getNonceGroup(), ng.newNonce()); + return master.modifyTable(getRpcController(), request); + } + }); + return new ModifyTableFuture(this, td.getTableName(), response); + } + + @Override + public List listTableDescriptorsByNamespace(byte[] name) throws IOException { + return executeCallable(new MasterCallable>(getConnection(), + getRpcControllerFactory()) { + @Override + protected List rpcCall() throws Exception { + return master.listTableDescriptorsByNamespace(getRpcController(), + ListTableDescriptorsByNamespaceRequest.newBuilder() + .setNamespaceName(Bytes.toString(name)).build()) + .getTableSchemaList() + .stream() + .map(ProtobufUtil::convertToTableDesc) + .collect(Collectors.toList()); + } + }); + } + + @Override + public List listTableDescriptors(List tableNames) throws IOException { + return executeCallable(new MasterCallable>(getConnection(), + getRpcControllerFactory()) { + @Override + protected List rpcCall() throws Exception { + GetTableDescriptorsRequest req = + RequestConverter.buildGetTableDescriptorsRequest(tableNames); + return ProtobufUtil.toTableDescriptorList(master.getTableDescriptors(getRpcController(), req)); + } + }); + } + private static class AbortProcedureFuture extends ProcedureFuture { private boolean isAbortInProgress; @@ -419,11 +510,40 @@ public class HBaseAdmin implements Admin { @Override public HTableDescriptor getTableDescriptor(final TableName tableName) throws IOException { - return getTableDescriptor(tableName, getConnection(), rpcCallerFactory, rpcControllerFactory, + return getHTableDescriptor(tableName, getConnection(), rpcCallerFactory, rpcControllerFactory, operationTimeout, rpcTimeout); } - static HTableDescriptor getTableDescriptor(final TableName tableName, Connection connection, + static TableDescriptor getTableDescriptor(final TableName tableName, Connection connection, + RpcRetryingCallerFactory rpcCallerFactory, final RpcControllerFactory rpcControllerFactory, + int operationTimeout, int rpcTimeout) throws IOException { + if (tableName == null) return null; + TableDescriptor td = + executeCallable(new MasterCallable(connection, rpcControllerFactory) { + @Override + protected TableDescriptor rpcCall() throws Exception { + GetTableDescriptorsRequest req = + RequestConverter.buildGetTableDescriptorsRequest(tableName); + GetTableDescriptorsResponse htds = master.getTableDescriptors(getRpcController(), req); + if (!htds.getTableSchemaList().isEmpty()) { + return ProtobufUtil.convertToTableDesc(htds.getTableSchemaList().get(0)); + } + return null; + } + }, rpcCallerFactory, operationTimeout, rpcTimeout); + if (td != null) { + return td; + } + throw new TableNotFoundException(tableName.getNameAsString()); + } + + /** + * @deprecated since 2.0 version and will be removed in 3.0 version. + * use {@link #getTableDescriptor(TableName, + * Connection, RpcRetryingCallerFactory,RpcControllerFactory,int,int)} + */ + @Deprecated + static HTableDescriptor getHTableDescriptor(final TableName tableName, Connection connection, RpcRetryingCallerFactory rpcCallerFactory, final RpcControllerFactory rpcControllerFactory, int operationTimeout, int rpcTimeout) throws IOException { if (tableName == null) return null; @@ -455,13 +575,13 @@ public class HBaseAdmin implements Admin { } @Override - public void createTable(HTableDescriptor desc) + public void createTable(TableDescriptor desc) throws IOException { createTable(desc, null); } @Override - public void createTable(HTableDescriptor desc, byte [] startKey, + public void createTable(TableDescriptor desc, byte [] startKey, byte [] endKey, int numRegions) throws IOException { if(numRegions < 3) { @@ -481,13 +601,13 @@ public class HBaseAdmin implements Admin { } @Override - public void createTable(final HTableDescriptor desc, byte [][] splitKeys) + public void createTable(final TableDescriptor desc, byte [][] splitKeys) throws IOException { get(createTableAsync(desc, splitKeys), syncWaitTimeout, TimeUnit.MILLISECONDS); } @Override - public Future createTableAsync(final HTableDescriptor desc, final byte[][] splitKeys) + public Future createTableAsync(final TableDescriptor desc, final byte[][] splitKeys) throws IOException { if (desc.getTableName() == null) { throw new IllegalArgumentException("TableName cannot be null"); @@ -524,19 +644,19 @@ public class HBaseAdmin implements Admin { } private static class CreateTableFuture extends TableFuture { - private final HTableDescriptor desc; + private final TableDescriptor desc; private final byte[][] splitKeys; - public CreateTableFuture(final HBaseAdmin admin, final HTableDescriptor desc, + public CreateTableFuture(final HBaseAdmin admin, final TableDescriptor desc, final byte[][] splitKeys, final CreateTableResponse response) { super(admin, desc.getTableName(), (response != null && response.hasProcId()) ? response.getProcId() : null); this.splitKeys = splitKeys; - this.desc = new ImmutableHTableDescriptor(desc); + this.desc = desc; } @Override - protected HTableDescriptor getTableDescriptor() { + protected TableDescriptor getTableDescriptor() { return desc; } @@ -3546,7 +3666,7 @@ public class HBaseAdmin implements Admin { /** * @return the table descriptor */ - protected HTableDescriptor getTableDescriptor() throws IOException { + protected TableDescriptor getTableDescriptor() throws IOException { return getAdmin().getTableDescriptorByTableName(getTableName()); } @@ -3642,7 +3762,7 @@ public class HBaseAdmin implements Admin { protected void waitForAllRegionsOnline(final long deadlineTs, final byte[][] splitKeys) throws IOException, TimeoutException { - final HTableDescriptor desc = getTableDescriptor(); + final TableDescriptor desc = getTableDescriptor(); final AtomicInteger actualRegCount = new AtomicInteger(0); final MetaTableAccessor.Visitor visitor = new MetaTableAccessor.Visitor() { @Override diff --git hbase-client/src/main/java/org/apache/hadoop/hbase/client/HTable.java hbase-client/src/main/java/org/apache/hadoop/hbase/client/HTable.java index d207f6a098..46ce902c16 100644 --- hbase-client/src/main/java/org/apache/hadoop/hbase/client/HTable.java +++ hbase-client/src/main/java/org/apache/hadoop/hbase/client/HTable.java @@ -263,7 +263,17 @@ public class HTable implements Table { */ @Override public HTableDescriptor getTableDescriptor() throws IOException { - HTableDescriptor htd = HBaseAdmin.getTableDescriptor(tableName, connection, rpcCallerFactory, + HTableDescriptor htd = HBaseAdmin.getHTableDescriptor(tableName, connection, rpcCallerFactory, + rpcControllerFactory, operationTimeout, readRpcTimeout); + if (htd != null) { + return new ImmutableHTableDescriptor(htd); + } + return null; + } + + @Override + public TableDescriptor getDescriptor() throws IOException { + HTableDescriptor htd = HBaseAdmin.getHTableDescriptor(tableName, connection, rpcCallerFactory, rpcControllerFactory, operationTimeout, readRpcTimeout); if (htd != null) { return new ImmutableHTableDescriptor(htd); diff --git hbase-client/src/main/java/org/apache/hadoop/hbase/client/Table.java hbase-client/src/main/java/org/apache/hadoop/hbase/client/Table.java index 933329f734..c76c2f5f63 100644 --- hbase-client/src/main/java/org/apache/hadoop/hbase/client/Table.java +++ hbase-client/src/main/java/org/apache/hadoop/hbase/client/Table.java @@ -65,10 +65,19 @@ public interface Table extends Closeable { /** * Gets the {@link org.apache.hadoop.hbase.HTableDescriptor table descriptor} for this table. * @throws java.io.IOException if a remote or network exception occurs. + * @deprecated since 2.0 version and will be removed in 3.0 version. + * use {@link #getDescriptor()} */ + @Deprecated HTableDescriptor getTableDescriptor() throws IOException; /** + * Gets the {@link org.apache.hadoop.hbase.client.TableDescriptor table descriptor} for this table. + * @throws java.io.IOException if a remote or network exception occurs. + */ + TableDescriptor getDescriptor() throws IOException; + + /** * Test for the existence of columns in the table, as specified by the Get. *

* @@ -604,7 +613,7 @@ public interface Table extends Closeable { /** * Get timeout (millisecond) of each rpc request in this Table instance. * - * @returns Currently configured read timeout + * @return Currently configured read timeout * @deprecated Use getReadRpcTimeout or getWriteRpcTimeout instead */ @Deprecated diff --git hbase-client/src/main/java/org/apache/hadoop/hbase/shaded/protobuf/RequestConverter.java hbase-client/src/main/java/org/apache/hadoop/hbase/shaded/protobuf/RequestConverter.java index 39ae6a5171..e1d898e496 100644 --- hbase-client/src/main/java/org/apache/hadoop/hbase/shaded/protobuf/RequestConverter.java +++ hbase-client/src/main/java/org/apache/hadoop/hbase/shaded/protobuf/RequestConverter.java @@ -1288,17 +1288,17 @@ public final class RequestConverter { * Creates a protocol buffer ModifyTableRequest * * @param tableName - * @param hTableDesc + * @param tableDesc * @return a ModifyTableRequest */ public static ModifyTableRequest buildModifyTableRequest( final TableName tableName, - final HTableDescriptor hTableDesc, + final TableDescriptor tableDesc, final long nonceGroup, final long nonce) { ModifyTableRequest.Builder builder = ModifyTableRequest.newBuilder(); builder.setTableName(ProtobufUtil.toProtoTableName((tableName))); - builder.setTableSchema(ProtobufUtil.convertToTableSchema(hTableDesc)); + builder.setTableSchema(ProtobufUtil.convertToTableSchema(tableDesc)); builder.setNonceGroup(nonceGroup); builder.setNonce(nonce); return builder.build(); diff --git hbase-rest/src/main/java/org/apache/hadoop/hbase/rest/client/RemoteHTable.java hbase-rest/src/main/java/org/apache/hadoop/hbase/rest/client/RemoteHTable.java index 5012a5a941..63dfcaabfd 100644 --- hbase-rest/src/main/java/org/apache/hadoop/hbase/rest/client/RemoteHTable.java +++ hbase-rest/src/main/java/org/apache/hadoop/hbase/rest/client/RemoteHTable.java @@ -54,6 +54,7 @@ import org.apache.hadoop.hbase.client.Row; import org.apache.hadoop.hbase.client.RowMutations; import org.apache.hadoop.hbase.client.Scan; import org.apache.hadoop.hbase.client.Table; +import org.apache.hadoop.hbase.client.TableDescriptor; import org.apache.hadoop.hbase.client.coprocessor.Batch; import org.apache.hadoop.hbase.client.coprocessor.Batch.Callback; import org.apache.hadoop.hbase.client.metrics.ScanMetrics; @@ -508,6 +509,11 @@ public class RemoteHTable implements Table { // no-op } + @Override + public TableDescriptor getDescriptor() throws IOException { + return getTableDescriptor(); + } + class Scanner implements ResultScanner { String uri; diff --git hbase-server/src/main/java/org/apache/hadoop/hbase/client/HTableWrapper.java hbase-server/src/main/java/org/apache/hadoop/hbase/client/HTableWrapper.java index 051a8f26e9..8824872416 100644 --- hbase-server/src/main/java/org/apache/hadoop/hbase/client/HTableWrapper.java +++ hbase-server/src/main/java/org/apache/hadoop/hbase/client/HTableWrapper.java @@ -220,6 +220,11 @@ public final class HTableWrapper implements Table { } @Override + public TableDescriptor getDescriptor() throws IOException { + return table.getDescriptor(); + } + + @Override public TableName getName() { return table.getName(); } diff --git hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java index b460d1ac9e..78742683ea 100644 --- hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java +++ hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java @@ -117,6 +117,7 @@ import org.apache.hadoop.hbase.client.RegionReplicaUtil; import org.apache.hadoop.hbase.client.Result; import org.apache.hadoop.hbase.client.RowMutations; import org.apache.hadoop.hbase.client.Scan; +import org.apache.hadoop.hbase.client.TableDescriptor; import org.apache.hadoop.hbase.conf.ConfigurationManager; import org.apache.hadoop.hbase.conf.PropagatingConfigurationObserver; import org.apache.hadoop.hbase.coprocessor.RegionObserver.MutationType; @@ -1846,6 +1847,11 @@ public class HRegion implements HeapSize, PropagatingConfigurationObserver, Regi return this.htableDescriptor; } + @Override + public TableDescriptor getTableDescriptor() { + return this.htableDescriptor; + } + /** @return WAL in use for this region */ public WAL getWAL() { return this.wal; diff --git hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/Region.java hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/Region.java index 63e18c3fe6..a94b5647fb 100644 --- hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/Region.java +++ hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/Region.java @@ -41,6 +41,7 @@ import org.apache.hadoop.hbase.client.Put; import org.apache.hadoop.hbase.client.Result; import org.apache.hadoop.hbase.client.RowMutations; import org.apache.hadoop.hbase.client.Scan; +import org.apache.hadoop.hbase.client.TableDescriptor; import org.apache.hadoop.hbase.conf.ConfigurationObserver; import org.apache.hadoop.hbase.exceptions.FailedSanityCheckException; import org.apache.hadoop.hbase.filter.ByteArrayComparable; @@ -78,9 +79,17 @@ public interface Region extends ConfigurationObserver { /** @return region information for this region */ HRegionInfo getRegionInfo(); - /** @return table descriptor for this region */ + /** + * @return table descriptor for this region + * @deprecated since 2.0 version and will be removed in 3.0 version. + * use {@link #getTableDescriptor()} + */ + @Deprecated HTableDescriptor getTableDesc(); + /** @return table descriptor for this region */ + TableDescriptor getTableDescriptor(); + /** @return true if region is available (not closed and not closing) */ boolean isAvailable(); diff --git hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/RegionAsTable.java hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/RegionAsTable.java index 9b96ff2547..74eae8b409 100644 --- hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/RegionAsTable.java +++ hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/RegionAsTable.java @@ -40,6 +40,7 @@ import org.apache.hadoop.hbase.client.Row; import org.apache.hadoop.hbase.client.RowMutations; import org.apache.hadoop.hbase.client.Scan; import org.apache.hadoop.hbase.client.Table; +import org.apache.hadoop.hbase.client.TableDescriptor; import org.apache.hadoop.hbase.client.coprocessor.Batch.Call; import org.apache.hadoop.hbase.client.coprocessor.Batch.Callback; import org.apache.hadoop.hbase.client.metrics.ScanMetrics; @@ -87,6 +88,11 @@ public class RegionAsTable implements Table { } @Override + public TableDescriptor getDescriptor() throws IOException { + return this.region.getTableDescriptor(); + } + + @Override public boolean exists(Get get) throws IOException { if (!get.isCheckExistenceOnly()) throw new IllegalArgumentException(); return get(get) != null;