HBASE-18909 Deprecate Admin's methods which used String regex

This commit is contained in:
Guanghao Zhang 2017-09-30 13:59:27 +08:00
parent 101079b5da
commit 8e5d88366d
7 changed files with 72 additions and 74 deletions

View File

@ -142,23 +142,13 @@ public interface Admin extends Abortable, Closeable {
* @param regex The regular expression to match against
* @return a list of read-only HTableDescriptors
* @throws IOException if a remote or network exception occurs
* @see #listTableDescriptors(java.lang.String)
* @deprecated since 2.0 version and will be removed in 3.0 version.
* Use {@link #listTableDescriptors(java.lang.String)}.
* @see #listTableDescriptors(Pattern)
* @deprecated since 2.0 version and will be removed in 3.0 version. Use
* {@link #listTableDescriptors(Pattern)} instead.
*/
@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 a list of TableDescriptors
* @throws IOException if a remote or network exception occurs
* @see #listTables(java.util.regex.Pattern)
*/
List<TableDescriptor> listTableDescriptors(String regex) throws IOException;
/**
* List all the tables matching the given pattern.
*
@ -196,24 +186,12 @@ public interface Admin extends Abortable, Closeable {
* @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)}.
* Use {@link #listTableDescriptors(Pattern, 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 <code>false</code> to match only against userspace tables
* @return a list of TableDescriptors
* @throws IOException if a remote or network exception occurs
* @see #listTables(java.util.regex.Pattern, boolean)
*/
List<TableDescriptor> listTableDescriptors(String regex, boolean includeSysTables)
throws IOException;
/**
* List all of the names of userspace tables.
*
@ -235,7 +213,10 @@ public interface Admin extends Abortable, Closeable {
* @param regex The regular expression to match against
* @return TableName[] table names
* @throws IOException if a remote or network exception occurs
* @deprecated since 2.0 version and will be removed in 3.0 version. Use
* {@link #listTableNames(Pattern)} instead.
*/
@Deprecated
TableName[] listTableNames(String regex) throws IOException;
/**
@ -254,7 +235,10 @@ public interface Admin extends Abortable, Closeable {
* @param includeSysTables <code>false</code> to match only against userspace tables
* @return TableName[] table names
* @throws IOException if a remote or network exception occurs
* @deprecated since 2.0 version and will be removed in 3.0 version. Use
* {@link #listTableNames(Pattern, boolean)} instead.
*/
@Deprecated
TableName[] listTableNames(String regex, boolean includeSysTables)
throws IOException;
@ -374,7 +358,7 @@ 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
* #listTableDescriptors(java.lang.String)}
* #listTableDescriptors(Pattern)}
* and {@link #deleteTable(org.apache.hadoop.hbase.TableName)}
*
* @param regex The regular expression to match table names against
@ -385,8 +369,8 @@ public interface Admin extends Abortable, Closeable {
* @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)}
* Consider using {@link #listTableDescriptors(Pattern)}
* and {@link #deleteTable(TableName)}
*/
@Deprecated
HTableDescriptor[] deleteTables(String regex) throws IOException;
@ -404,7 +388,7 @@ public interface Admin extends Abortable, Closeable {
* @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)}
* and {@link #deleteTable(TableName)}
*/
@Deprecated
HTableDescriptor[] deleteTables(Pattern pattern) throws IOException;
@ -466,7 +450,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
* #listTableDescriptors(java.lang.String)} and {@link #enableTable(org.apache.hadoop.hbase.TableName)}
* #listTableDescriptors(Pattern)} and {@link #enableTable(org.apache.hadoop.hbase.TableName)}
*
* @param regex The regular expression to match table names against
* @throws IOException
@ -476,7 +460,7 @@ public interface Admin extends Abortable, Closeable {
* @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)}
* Consider using {@link #listTableDescriptors(Pattern)}
* and {@link #enableTable(org.apache.hadoop.hbase.TableName)}
*/
@Deprecated
@ -529,8 +513,7 @@ 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
* #listTableDescriptors(java.lang.String)}
* and {@link #disableTable(org.apache.hadoop.hbase.TableName)}
* #listTableDescriptors(Pattern)} 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
@ -540,7 +523,7 @@ public interface Admin extends Abortable, Closeable {
* @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)}
* Consider using {@link #listTableDescriptors(Pattern)}
* and {@link #disableTable(org.apache.hadoop.hbase.TableName)}
*/
@Deprecated
@ -2032,7 +2015,10 @@ public interface Admin extends Abortable, Closeable {
* @param regex The regular expression to match against
* @return list of SnapshotDescription
* @throws IOException if a remote or network exception occurs
* @deprecated since 2.0 version and will be removed in 3.0 version.
* Use {@link #listSnapshots(Pattern)} instead.
*/
@Deprecated
List<SnapshotDescription> listSnapshots(String regex) throws IOException;
/**
@ -2051,7 +2037,10 @@ public interface Admin extends Abortable, Closeable {
* @param snapshotNameRegex The snapshot name regular expression to match against
* @return list of completed SnapshotDescription
* @throws IOException if a remote or network exception occurs
* @deprecated since 2.0 version and will be removed in 3.0 version.
* Use {@link #listTableSnapshots(Pattern, Pattern)} instead.
*/
@Deprecated
List<SnapshotDescription> listTableSnapshots(String tableNameRegex,
String snapshotNameRegex) throws IOException;
@ -2087,7 +2076,10 @@ public interface Admin extends Abortable, Closeable {
*
* @param regex The regular expression to match against
* @throws IOException if a remote or network exception occurs
* @deprecated since 2.0 version and will be removed in 3.0 version.
* Use {@link #deleteSnapshots(Pattern)} instead.
*/
@Deprecated
void deleteSnapshots(String regex) throws IOException;
/**
@ -2104,7 +2096,10 @@ public interface Admin extends Abortable, Closeable {
* @param tableNameRegex The table name regular expression to match against
* @param snapshotNameRegex The snapshot name regular expression to match against
* @throws IOException if a remote or network exception occurs
* @deprecated since 2.0 version and will be removed in 3.0 version.
* Use {@link #deleteTableSnapshots(Pattern, Pattern)} instead.
*/
@Deprecated
void deleteTableSnapshots(String tableNameRegex, String snapshotNameRegex) throws IOException;
/**
@ -2411,7 +2406,10 @@ public interface Admin extends Abortable, Closeable {
* @param regex The regular expression to match peer id
* @return a list of replication peers description
* @throws IOException
* @deprecated since 2.0 version and will be removed in 3.0 version. Use
* {@link #listReplicationPeers(Pattern)} instead.
*/
@Deprecated
default List<ReplicationPeerDescription> listReplicationPeers(String regex) throws IOException {
return new ArrayList<>();
}

View File

@ -318,11 +318,6 @@ public class HBaseAdmin implements Admin {
return listTableDescriptors(pattern, false);
}
@Override
public List<TableDescriptor> listTableDescriptors(String regex) throws IOException {
return listTableDescriptors(Pattern.compile(regex), false);
}
@Override
public List<TableDescriptor> listTableDescriptors(Pattern pattern, boolean includeSysTables) throws IOException {
return executeCallable(new MasterCallable<List<TableDescriptor>>(getConnection(),
@ -337,11 +332,6 @@ public class HBaseAdmin implements Admin {
});
}
@Override
public List<TableDescriptor> listTableDescriptors(String regex, boolean includeSysTables) throws IOException {
return listTableDescriptors(Pattern.compile(regex), includeSysTables);
}
@Override
public TableDescriptor getDescriptor(TableName tableName) throws TableNotFoundException, IOException {
return getTableDescriptor(tableName, getConnection(), rpcCallerFactory, rpcControllerFactory,

View File

@ -28,6 +28,7 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.regex.Pattern;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@ -42,7 +43,6 @@ import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.apache.hadoop.hbase.replication.ReplicationException;
import org.apache.hadoop.hbase.replication.ReplicationPeerConfig;
import org.apache.hadoop.hbase.replication.ReplicationPeerDescription;
import org.apache.hadoop.hbase.shaded.com.google.common.annotations.VisibleForTesting;
import org.apache.hadoop.hbase.shaded.com.google.common.collect.Lists;
@ -375,7 +375,7 @@ public class ReplicationAdmin implements Closeable {
*/
@Deprecated
public boolean getPeerState(String id) throws ReplicationException, IOException {
List<ReplicationPeerDescription> peers = admin.listReplicationPeers(id);
List<ReplicationPeerDescription> peers = admin.listReplicationPeers(Pattern.compile(id));
if (peers.isEmpty() || !id.equals(peers.get(0).getPeerId())) {
throw new ReplicationPeerNotFoundException(id);
}

View File

@ -19,6 +19,7 @@
package org.apache.hadoop.hbase.client;
import java.util.List;
import java.util.regex.Pattern;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@ -361,9 +362,10 @@ public class TestSnapshotCloneIndependence {
admin.deleteSnapshot(snapshotName);
// Wait for cleaner run and DFS heartbeats so that anything that is deletable is fully deleted
Pattern pattern = Pattern.compile(snapshotNameAsString);
do {
Thread.sleep(5000);
} while (!admin.listSnapshots(snapshotNameAsString).isEmpty());
} while (!admin.listSnapshots(pattern).isEmpty());
try (Table original = UTIL.getConnection().getTable(originalTableName)) {
try (Table clonedTable = UTIL.getConnection().getTable(cloneTableName)) {

View File

@ -24,6 +24,7 @@ import static org.junit.Assert.fail;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@ -53,7 +54,6 @@ import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.apache.hadoop.hbase.shaded.com.google.common.collect.Lists;
import org.junit.rules.TestName;
@ -72,6 +72,7 @@ public class TestSnapshotFromClient {
protected static final byte[] TEST_FAM = Bytes.toBytes("fam");
protected static final TableName TABLE_NAME =
TableName.valueOf(STRING_TABLE_NAME);
private static final Pattern MATCH_ALL = Pattern.compile(".*");
@Rule
public TestName name = new TestName();
@ -181,7 +182,7 @@ public class TestSnapshotFromClient {
LOG.debug(snapshot3 + " completed.");
// delete the first two snapshots
admin.deleteSnapshots("TableSnapshot.*");
admin.deleteSnapshots(Pattern.compile("TableSnapshot.*"));
List<SnapshotDescription> snapshots = admin.listSnapshots();
assertEquals(1, snapshots.size());
assertEquals(snapshots.get(0).getName(), snapshot3);
@ -336,7 +337,8 @@ public class TestSnapshotFromClient {
admin.snapshot(Bytes.toBytes(table2Snapshot1), tableName);
LOG.debug(table2Snapshot1 + " completed.");
List<SnapshotDescription> listTableSnapshots = admin.listTableSnapshots("test.*", ".*");
List<SnapshotDescription> listTableSnapshots =
admin.listTableSnapshots(Pattern.compile("test.*"), MATCH_ALL);
List<String> listTableSnapshotNames = new ArrayList<>();
assertEquals(3, listTableSnapshots.size());
for (SnapshotDescription s : listTableSnapshots) {
@ -348,7 +350,7 @@ public class TestSnapshotFromClient {
} finally {
if (admin != null) {
try {
admin.deleteSnapshots("Table.*");
admin.deleteSnapshots(Pattern.compile("Table.*"));
} catch (SnapshotDoesNotExistException ignore) {
}
if (admin.tableExists(tableName)) {
@ -378,7 +380,7 @@ public class TestSnapshotFromClient {
LOG.debug(table2Snapshot1 + " completed.");
List<SnapshotDescription> listTableSnapshots =
admin.listTableSnapshots("test.*", "Table1.*");
admin.listTableSnapshots(Pattern.compile("test.*"), Pattern.compile("Table1.*"));
List<String> listTableSnapshotNames = new ArrayList<>();
assertEquals(2, listTableSnapshots.size());
for (SnapshotDescription s : listTableSnapshots) {
@ -390,7 +392,7 @@ public class TestSnapshotFromClient {
} finally {
if (admin != null) {
try {
admin.deleteSnapshots("Table.*");
admin.deleteSnapshots(Pattern.compile("Table.*"));
} catch (SnapshotDoesNotExistException ignore) {
}
admin.close();
@ -420,8 +422,9 @@ public class TestSnapshotFromClient {
admin.snapshot(Bytes.toBytes(table2Snapshot1), tableName);
LOG.debug(table2Snapshot1 + " completed.");
admin.deleteTableSnapshots("test.*", ".*");
assertEquals(0, admin.listTableSnapshots("test.*", ".*").size());
Pattern tableNamePattern = Pattern.compile("test.*");
admin.deleteTableSnapshots(tableNamePattern, MATCH_ALL);
assertEquals(0, admin.listTableSnapshots(tableNamePattern, MATCH_ALL).size());
} finally {
if (admin != null) {
if (admin.tableExists(tableName)) {
@ -435,6 +438,7 @@ public class TestSnapshotFromClient {
@Test(timeout = 300000)
public void testDeleteTableSnapshotsWithRegex() throws Exception {
Admin admin = null;
Pattern tableNamePattern = Pattern.compile("test.*");
try {
admin = UTIL.getAdmin();
@ -450,12 +454,12 @@ public class TestSnapshotFromClient {
admin.snapshot(Bytes.toBytes(table2Snapshot1), TABLE_NAME);
LOG.debug(table2Snapshot1 + " completed.");
admin.deleteTableSnapshots("test.*", "Table1.*");
assertEquals(1, admin.listTableSnapshots("test.*", ".*").size());
admin.deleteTableSnapshots(tableNamePattern, Pattern.compile("Table1.*"));
assertEquals(1, admin.listTableSnapshots(tableNamePattern, MATCH_ALL).size());
} finally {
if (admin != null) {
try {
admin.deleteTableSnapshots("test.*", ".*");
admin.deleteTableSnapshots(tableNamePattern, MATCH_ALL);
} catch (SnapshotDoesNotExistException ignore) {
}
admin.close();

View File

@ -20,6 +20,7 @@ package org.apache.hadoop.hbase.tool;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@ -31,6 +32,7 @@ import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.regex.Pattern;
import java.util.stream.IntStream;
import org.apache.commons.logging.Log;
@ -76,7 +78,6 @@ import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.rules.TestName;
import org.mockito.Mockito;
import org.apache.hadoop.hbase.shaded.com.google.common.collect.Multimap;
import org.apache.hadoop.hbase.shaded.com.google.protobuf.RpcController;
import org.apache.hadoop.hbase.shaded.com.google.protobuf.ServiceException;
@ -248,8 +249,8 @@ public class TestLoadIncrementalHFilesSplitRecovery {
* @throws IOException
*/
void assertExpectedTable(TableName table, int count, int value) throws IOException {
List<TableDescriptor> htds = util.getAdmin().listTableDescriptors(table.getNameAsString());
assertEquals(htds.size(), 1);
TableDescriptor htd = util.getAdmin().getDescriptor(table);
assertNotNull(htd);
try (Table t = util.getConnection().getTable(table);
ResultScanner sr = t.getScanner(new Scan())) {
int i = 0;
@ -613,8 +614,8 @@ public class TestLoadIncrementalHFilesSplitRecovery {
*/
void assertExpectedTable(final Connection connection, TableName table, int count, int value)
throws IOException {
List<TableDescriptor> htds = util.getAdmin().listTableDescriptors(table.getNameAsString());
assertEquals(htds.size(), 1);
TableDescriptor htd = util.getAdmin().getDescriptor(table);
assertNotNull(htd);
try (Table t = connection.getTable(table); ResultScanner sr = t.getScanner(new Scan())) {
int i = 0;
for (Result r; (r = sr.next()) != null;) {

View File

@ -19,6 +19,7 @@
include Java
java_import java.util.Arrays
java_import java.util.regex.Pattern
java_import org.apache.hadoop.hbase.util.Pair
java_import org.apache.hadoop.hbase.util.RegionSplitter
java_import org.apache.hadoop.hbase.util.Bytes
@ -45,7 +46,7 @@ module Hbase
#----------------------------------------------------------------------------------------------
# Returns a list of tables in hbase
def list(regex = '.*')
@admin.listTableNames(regex).map(&:getNameAsString)
@admin.listTableNames(Pattern.compile(regex)).map(&:getNameAsString)
end
#----------------------------------------------------------------------------------------------
@ -269,7 +270,7 @@ module Hbase
# Enables all tables matching the given regex
def enable_all(regex)
regex = regex.to_s
@admin.enableTables(regex)
@admin.enableTables(Pattern.compile(regex))
end
#----------------------------------------------------------------------------------------------
@ -283,8 +284,8 @@ module Hbase
#----------------------------------------------------------------------------------------------
# Disables all tables matching the given regex
def disable_all(regex)
regex = regex.to_s
@admin.disableTables(regex).map { |t| t.getTableName.getNameAsString }
pattern = Pattern.compile(regex.to_s)
@admin.disableTables(pattern).map { |t| t.getTableName.getNameAsString }
end
#---------------------------------------------------------------------------------------------
@ -313,8 +314,8 @@ module Hbase
#----------------------------------------------------------------------------------------------
# Drops a table
def drop_all(regex)
regex = regex.to_s
failed = @admin.deleteTables(regex).map { |t| t.getTableName.getNameAsString }
pattern = Pattern.compile(regex.to_s)
failed = @admin.deleteTables(pattern).map { |t| t.getTableName.getNameAsString }
failed
end
@ -1005,25 +1006,27 @@ module Hbase
#----------------------------------------------------------------------------------------------
# Deletes the snapshots matching the given regex
def delete_all_snapshot(regex)
@admin.deleteSnapshots(regex).to_a
@admin.deleteSnapshots(Pattern.compile(regex)).to_a
end
#----------------------------------------------------------------------------------------------
# Deletes the table snapshots matching the given regex
def delete_table_snapshots(tableNameRegex, snapshotNameRegex = '.*')
@admin.deleteTableSnapshots(tableNameRegex, snapshotNameRegex).to_a
@admin.deleteTableSnapshots(Pattern.compile(tableNameRegex),
Pattern.compile(snapshotNameRegex)).to_a
end
#----------------------------------------------------------------------------------------------
# Returns a list of snapshots
def list_snapshot(regex = '.*')
@admin.listSnapshots(regex).to_a
@admin.listSnapshots(Pattern.compile(regex)).to_a
end
#----------------------------------------------------------------------------------------------
# Returns a list of table snapshots
def list_table_snapshots(tableNameRegex, snapshotNameRegex = '.*')
@admin.listTableSnapshots(tableNameRegex, snapshotNameRegex).to_a
@admin.listTableSnapshots(Pattern.compile(tableNameRegex),
Pattern.compile(snapshotNameRegex)).to_a
end
#----------------------------------------------------------------------------------------------