HBASE-14769 Remove unused functions and duplicate javadocs from HBaseAdmin

This commit is contained in:
stack 2015-12-10 15:02:21 -08:00
parent 9511150bd6
commit bebcc09fb3
18 changed files with 158 additions and 1437 deletions

View File

@ -487,7 +487,10 @@ public interface Admin extends Abortable, Closeable {
* @return Pair indicating the number of regions updated Pair.getFirst() is the regions that are
* yet to be updated Pair.getSecond() is the total number of regions of the table
* @throws IOException if a remote or network exception occurs
* @deprecated Since 2.0.0. Will be removed in 3.0.0. Use {@link #getAlterStatus(TableName)}
* instead.
*/
@Deprecated
Pair<Integer, Integer> getAlterStatus(final byte[] tableName) throws IOException;
/**
@ -1181,9 +1184,8 @@ public interface Admin extends Abortable, Closeable {
throws IOException, SnapshotCreationException, IllegalArgumentException;
/**
* public void snapshot(final String snapshotName, Create a timestamp consistent snapshot for the
* given table. final byte[] tableName) throws IOException, Snapshots are considered unique based
* on <b>the name of the snapshot</b>. Attempts to take a snapshot with the same name (even a
* Create a timestamp consistent snapshot for the given table. Snapshots are considered unique
* based on <b>the name of the snapshot</b>. Attempts to take a snapshot with the same name (even
* different type or with different parameters) will fail with a {@link SnapshotCreationException}
* indicating the duplicate naming. Snapshot names follow the same naming constraints as tables in
* HBase.

View File

@ -718,7 +718,7 @@ public class IntegrationTestDDLMasterFailover extends IntegrationTestBase {
}
TableName tableName = selected.getTableName();
LOG.info("Deleting column family: " + cfd + " from table: " + tableName);
admin.deleteColumn(tableName, cfd.getName());
admin.deleteColumnFamily(tableName, cfd.getName());
// assertion
HTableDescriptor freshTableDesc = admin.getTableDescriptor(tableName);
Assert.assertFalse("Column family: " + cfd + " was not added",

View File

@ -121,7 +121,7 @@ public class IntegrationTestIngestWithMOB extends IntegrationTestIngest {
if(Arrays.equals(columnDescriptor.getName(), mobColumnFamily)) {
columnDescriptor.setMobEnabled(true);
columnDescriptor.setMobThreshold((long) threshold);
admin.modifyColumn(tableName, columnDescriptor);
admin.modifyColumnFamily(tableName, columnDescriptor);
}
}
LOG.info("Enabling table " + getTablename());

View File

@ -2682,13 +2682,15 @@ public class HBaseTestingUtility extends HBaseCommonTestingUtility {
/**
* Returns a Admin instance.
* This instance is shared between HBaseTestingUtility instance users.
* Closing it has no effect, it will be closed automatically when the
* cluster shutdowns
* This instance is shared between HBaseTestingUtility instance users. Closing it has no effect,
* it will be closed automatically when the cluster shutdowns
*
* @return An Admin instance.
* @throws IOException
* @return HBaseAdmin instance which is guaranteed to support only {@link Admin} interface.
* Functions in HBaseAdmin not provided by {@link Admin} interface can be changed/deleted
* anytime.
* @deprecated Since 2.0. Will be removed in 3.0. Use {@link #getAdmin()} instead.
*/
@Deprecated
public synchronized HBaseAdmin getHBaseAdmin()
throws IOException {
if (hbaseAdmin == null){
@ -2697,8 +2699,18 @@ public class HBaseTestingUtility extends HBaseCommonTestingUtility {
return hbaseAdmin;
}
private HBaseAdmin hbaseAdmin = null;
/**
* Returns an Admin instance which is shared between HBaseTestingUtility instance users.
* Closing it has no effect, it will be closed automatically when the cluster shutdowns
*/
public synchronized Admin getAdmin() throws IOException {
if (hbaseAdmin == null){
this.hbaseAdmin = (HBaseAdmin) getConnection().getAdmin();
}
return hbaseAdmin;
}
private HBaseAdmin hbaseAdmin = null;
/**
* Returns a ZooKeeperWatcher instance.

View File

@ -88,7 +88,7 @@ public class TestAcidGuarantees implements Tool {
// force mob enabled such that all data is mob data
hcd.setMobEnabled(true);
hcd.setMobThreshold(4);
util.getHBaseAdmin().modifyColumn(TABLE_NAME, hcd);
util.getHBaseAdmin().modifyColumnFamily(TABLE_NAME, hcd);
}
}

View File

@ -465,8 +465,8 @@ public class TestAdmin2 {
onlineRegions.contains(info));
}
private Admin createTable(TableName tableName) throws IOException {
Admin admin = TEST_UTIL.getHBaseAdmin();
private HBaseAdmin createTable(TableName tableName) throws IOException {
HBaseAdmin admin = TEST_UTIL.getHBaseAdmin();
HTableDescriptor htd = new HTableDescriptor(tableName);
HColumnDescriptor hcd = new HColumnDescriptor("value");

View File

@ -400,8 +400,8 @@ public class TestMetaWithReplicas {
}
}
assert(moveToServer != null);
String tableName = "randomTable5678";
TEST_UTIL.createTable(TableName.valueOf(tableName), "f");
TableName tableName = TableName.valueOf("randomTable5678");
TEST_UTIL.createTable(tableName, "f");
assertTrue(TEST_UTIL.getHBaseAdmin().tableExists(tableName));
TEST_UTIL.getHBaseAdmin().move(HRegionInfo.FIRST_META_REGIONINFO.getEncodedNameAsBytes(),
Bytes.toBytes(moveToServer.getServerName()));
@ -413,8 +413,8 @@ public class TestMetaWithReplicas {
i++;
} while (!moveToServer.equals(currentServer) && i < 1000); //wait for 10 seconds overall
assert(i != 1000);
TEST_UTIL.getHBaseAdmin().disableTable("randomTable5678");
assertTrue(TEST_UTIL.getHBaseAdmin().isTableDisabled("randomTable5678"));
TEST_UTIL.getHBaseAdmin().disableTable(tableName);
assertTrue(TEST_UTIL.getHBaseAdmin().isTableDisabled(tableName));
}
@Test

View File

@ -100,7 +100,7 @@ public class TestExpiredMobFileCleaner {
int timeToLive = expireDays * secondsOfDay();
hcd.setTimeToLive(timeToLive);
admin.modifyColumn(tableName, hcd);
admin.modifyColumnFamily(tableName, hcd);
}
private void putKVAndFlush(BufferedMutator table, byte[] row, byte[] value, long ts)

View File

@ -21,7 +21,6 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.io.IOException;
import java.util.Collection;
import java.util.List;
import java.util.Random;
@ -41,7 +40,6 @@ import org.apache.hadoop.hbase.regionserver.HRegionServer;
import org.apache.hadoop.hbase.regionserver.HStore;
import org.apache.hadoop.hbase.regionserver.Region;
import org.apache.hadoop.hbase.regionserver.Store;
import org.apache.hadoop.hbase.regionserver.StoreFile;
import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.apache.hadoop.hbase.testclassification.RegionServerTests;
import org.apache.hadoop.hbase.util.Bytes;
@ -151,7 +149,7 @@ public class TestFIFOCompactionPolicy {
TEST_UTIL.startMiniCluster(1);
HBaseAdmin admin = TEST_UTIL.getHBaseAdmin();
String tableName = this.tableName.getNameAsString()+"-TTL";
TableName tableName = TableName.valueOf(getClass().getSimpleName() + "-TTL");
if (admin.tableExists(tableName)) {
admin.disableTable(tableName);
admin.deleteTable(tableName);
@ -180,7 +178,7 @@ public class TestFIFOCompactionPolicy {
TEST_UTIL.startMiniCluster(1);
HBaseAdmin admin = TEST_UTIL.getHBaseAdmin();
String tableName = this.tableName.getNameAsString()+"-MinVersion";
TableName tableName = TableName.valueOf(getClass().getSimpleName() + "-MinVersion");
if (admin.tableExists(tableName)) {
admin.disableTable(tableName);
admin.deleteTable(tableName);
@ -211,7 +209,7 @@ public class TestFIFOCompactionPolicy {
TEST_UTIL.startMiniCluster(1);
HBaseAdmin admin = TEST_UTIL.getHBaseAdmin();
String tableName = this.tableName.getNameAsString()+"-MinVersion";
TableName tableName = TableName.valueOf(getClass().getSimpleName() + "-BlockingStoreFiles");
if (admin.tableExists(tableName)) {
admin.disableTable(tableName);
admin.deleteTable(tableName);

View File

@ -210,7 +210,7 @@ module Hbase
def enable(table_name)
tableExists(table_name)
return if enabled?(table_name)
@admin.enableTable(table_name)
@admin.enableTable(TableName.valueOf(table_name))
end
#----------------------------------------------------------------------------------------------
@ -225,7 +225,7 @@ module Hbase
def disable(table_name)
tableExists(table_name)
return if disabled?(table_name)
@admin.disableTable(table_name)
@admin.disableTable(TableName.valueOf(table_name))
end
#----------------------------------------------------------------------------------------------
@ -244,14 +244,15 @@ module Hbase
#----------------------------------------------------------------------------------------------
# Is table disabled?
def disabled?(table_name)
@admin.isTableDisabled(table_name)
@admin.isTableDisabled(TableName.valueOf(table_name))
end
#----------------------------------------------------------------------------------------------
# Drops a table
def drop(table_name)
tableExists(table_name)
raise ArgumentError, "Table #{table_name} is enabled. Disable it first." if enabled?(table_name)
raise ArgumentError, "Table #{table_name} is enabled. Disable it first." if enabled?(
table_name)
@admin.deleteTable(org.apache.hadoop.hbase.TableName.valueOf(table_name))
end
@ -447,15 +448,17 @@ module Hbase
#----------------------------------------------------------------------------------------------
# Truncates table (deletes all records by recreating the table)
def truncate(table_name, conf = @conf)
table_description = @admin.getTableDescriptor(TableName.valueOf(table_name))
raise ArgumentError, "Table #{table_name} is not enabled. Enable it first." unless enabled?(table_name)
def truncate(table_name_str, conf = @conf)
table_name = TableName.valueOf(table_name_str)
table_description = @admin.getTableDescriptor(table_name)
raise ArgumentError, "Table #{table_name_str} is not enabled. Enable it first." unless
enabled?(table_name_str)
yield 'Disabling table...' if block_given?
@admin.disableTable(table_name)
begin
yield 'Truncating table...' if block_given?
@admin.truncateTable(org.apache.hadoop.hbase.TableName.valueOf(table_name), false)
@admin.truncateTable(table_name, false)
rescue => e
# Handle the compatibility case, where the truncate method doesn't exists on the Master
raise e unless e.respond_to?(:cause) && e.cause != nil
@ -463,7 +466,7 @@ module Hbase
if rootCause.kind_of?(org.apache.hadoop.hbase.DoNotRetryIOException) then
# Handle the compatibility case, where the truncate method doesn't exists on the Master
yield 'Dropping table...' if block_given?
@admin.deleteTable(org.apache.hadoop.hbase.TableName.valueOf(table_name))
@admin.deleteTable(table_name)
yield 'Creating table...' if block_given?
@admin.createTable(table_description)
@ -475,9 +478,10 @@ module Hbase
#----------------------------------------------------------------------------------------------
# Truncates table while maintaing region boundaries (deletes all records by recreating the table)
def truncate_preserve(table_name, conf = @conf)
h_table = @connection.getTable(TableName.valueOf(table_name))
locator = @connection.getRegionLocator(TableName.valueOf(table_name))
def truncate_preserve(table_name_str, conf = @conf)
table_name = TableName.valueOf(table_name_str)
h_table = @connection.getTable(table_name)
locator = @connection.getRegionLocator(table_name)
begin
splits = locator.getAllRegionLocations().
map{|i| Bytes.toString(i.getRegionInfo().getStartKey)}.
@ -486,13 +490,13 @@ module Hbase
locator.close()
end
table_description = @admin.getTableDescriptor(TableName.valueOf(table_name))
table_description = @admin.getTableDescriptor(table_name)
yield 'Disabling table...' if block_given?
disable(table_name)
disable(table_name_str)
begin
yield 'Truncating table...' if block_given?
@admin.truncateTable(org.apache.hadoop.hbase.TableName.valueOf(table_name), true)
@admin.truncateTable(table_name, true)
rescue => e
# Handle the compatibility case, where the truncate method doesn't exists on the Master
raise e unless e.respond_to?(:cause) && e.cause != nil
@ -500,7 +504,7 @@ module Hbase
if rootCause.kind_of?(org.apache.hadoop.hbase.DoNotRetryIOException) then
# Handle the compatibility case, where the truncate method doesn't exists on the Master
yield 'Dropping table...' if block_given?
@admin.deleteTable(org.apache.hadoop.hbase.TableName.valueOf(table_name))
@admin.deleteTable(table_name)
yield 'Creating table with region boundaries...' if block_given?
@admin.createTable(table_description, splits)
@ -534,18 +538,21 @@ module Hbase
#----------------------------------------------------------------------------------------------
# Change table structure or table options
def alter(table_name, wait = true, *args)
def alter(table_name_str, wait = true, *args)
# Table name should be a string
raise(ArgumentError, "Table name must be of type String") unless table_name.kind_of?(String)
raise(ArgumentError, "Table name must be of type String") unless
table_name_str.kind_of?(String)
# Table should exist
raise(ArgumentError, "Can't find a table: #{table_name}") unless exists?(table_name)
raise(ArgumentError, "Can't find a table: #{table_name_str}") unless exists?(table_name_str)
# There should be at least one argument
raise(ArgumentError, "There should be at least one argument but the table name") if args.empty?
table_name = TableName.valueOf(table_name_str)
# Get table descriptor
htd = @admin.getTableDescriptor(TableName.valueOf(table_name))
htd = @admin.getTableDescriptor(table_name)
# Process all args
args.each do |arg|
@ -573,11 +580,11 @@ module Hbase
if wait == true
puts "Updating all regions with the new schema..."
alter_status(table_name)
alter_status(table_name_str)
end
# We bypass descriptor when adding column families; refresh it to apply other args correctly.
htd = @admin.getTableDescriptor(TableName.valueOf(table_name))
htd = @admin.getTableDescriptor(table_name)
next
end
@ -587,7 +594,7 @@ module Hbase
# Delete column family
if method == "delete"
raise(ArgumentError, "NAME parameter missing for delete method") unless name
@admin.deleteColumn(table_name, name)
@admin.deleteColumn(table_name, name.to_java_bytes)
# Unset table attributes
elsif method == "table_att_unset"
raise(ArgumentError, "NAME parameter missing for table_att_unset method") unless name
@ -604,7 +611,7 @@ module Hbase
end
htd.remove(name)
end
@admin.modifyTable(table_name.to_java_bytes, htd)
@admin.modifyTable(table_name, htd)
# Unknown method
else
raise ArgumentError, "Unknown method: #{method}"
@ -616,12 +623,12 @@ module Hbase
if wait == true
puts "Updating all regions with the new schema..."
alter_status(table_name)
alter_status(table_name_str)
end
if method == "delete"
# We bypass descriptor when deleting column families; refresh it to apply other args correctly.
htd = @admin.getTableDescriptor(TableName.valueOf(table_name))
htd = @admin.getTableDescriptor(table_name)
end
next
end
@ -667,7 +674,7 @@ module Hbase
arg.delete(key)
end
@admin.modifyTable(table_name.to_java_bytes, htd)
@admin.modifyTable(table_name, htd)
arg.each_key do |unknown_key|
puts("Unknown argument ignored: %s" % [unknown_key])
@ -675,7 +682,7 @@ module Hbase
if wait == true
puts "Updating all regions with the new schema..."
alter_status(table_name)
alter_status(table_name_str)
end
next
end
@ -792,13 +799,13 @@ module Hbase
# Does table exist?
def exists?(table_name)
@admin.tableExists(table_name)
@admin.tableExists(TableName.valueOf(table_name))
end
#----------------------------------------------------------------------------------------------
# Is table enabled
def enabled?(table_name)
@admin.isTableEnabled(table_name)
@admin.isTableEnabled(TableName.valueOf(table_name))
end
#----------------------------------------------------------------------------------------------
@ -910,14 +917,23 @@ module Hbase
#----------------------------------------------------------------------------------------------
# Take a snapshot of specified table
def snapshot(table, snapshot_name, *args)
# Table name should be a string
raise(ArgumentError, "Table name must be of type String") unless table.kind_of?(String)
# Snapshot name should be a string
raise(ArgumentError, "Snapshot name must be of type String") unless
snapshot_name.kind_of?(String)
table_name = TableName.valueOf(table)
if args.empty?
@admin.snapshot(snapshot_name.to_java_bytes, table.to_java_bytes)
@admin.snapshot(snapshot_name, table_name)
else
args.each do |arg|
if arg[SKIP_FLUSH] == true
@admin.snapshot(snapshot_name.to_java_bytes, table.to_java_bytes, SnapshotDescription::Type::SKIPFLUSH)
@admin.snapshot(snapshot_name, table_name,
SnapshotDescription::Type::SKIPFLUSH)
else
@admin.snapshot(snapshot_name.to_java_bytes, table.to_java_bytes)
@admin.snapshot(snapshot_name, table_name)
end
end
end
@ -926,19 +942,19 @@ module Hbase
#----------------------------------------------------------------------------------------------
# Restore specified snapshot
def restore_snapshot(snapshot_name)
@admin.restoreSnapshot(snapshot_name.to_java_bytes)
@admin.restoreSnapshot(snapshot_name)
end
#----------------------------------------------------------------------------------------------
# Create a new table by cloning the snapshot content
def clone_snapshot(snapshot_name, table)
@admin.cloneSnapshot(snapshot_name.to_java_bytes, table.to_java_bytes)
@admin.cloneSnapshot(snapshot_name, TableName.valueOf(table))
end
#----------------------------------------------------------------------------------------------
# Delete specified snapshot
def delete_snapshot(snapshot_name)
@admin.deleteSnapshot(snapshot_name.to_java_bytes)
@admin.deleteSnapshot(snapshot_name)
end
#----------------------------------------------------------------------------------------------

View File

@ -64,7 +64,7 @@ module Hbase
# Table should exist
raise(ArgumentError, "Can't find a table: #{table_name}") unless exists?(table_name)
tableName = org.apache.hadoop.hbase.TableName.valueOf(table_name.to_java_bytes)
tableName = org.apache.hadoop.hbase.TableName.valueOf(table_name)
htd = @admin.getTableDescriptor(tableName)
if (family != nil)
@ -106,7 +106,7 @@ module Hbase
# Table should exist
raise(ArgumentError, "Can't find a table: #{table_name}") unless exists?(table_name)
tableName = org.apache.hadoop.hbase.TableName.valueOf(table_name.to_java_bytes)
tableName = org.apache.hadoop.hbase.TableName.valueOf(table_name)
htd = @admin.getTableDescriptor(tableName)
if (family != nil)
@ -165,7 +165,7 @@ module Hbase
# Does table exist?
def exists?(table_name)
@admin.tableExists(table_name)
@admin.tableExists(TableName.valueOf(table_name))
end
def isNamespace?(table_name)

View File

@ -153,7 +153,7 @@ module Hbase
# Does table exist?
def exists?(table_name)
@admin.tableExists(table_name)
@admin.tableExists(TableName.valueOf(table_name))
end
end
end

View File

@ -405,21 +405,21 @@ module Hbase
end
#-------------------------------------------------------------------------------
define_test "Snapshot should fail with non-string snapshot name" do
assert_raise(NoMethodError) do
define_test "Snapshot should fail with non-string table name" do
assert_raise(ArgumentError) do
admin.snapshot(123, 'xxx')
end
end
define_test "Snapshot should fail with non-string table name" do
assert_raise(NoMethodError) do
admin.snapshot(@create_test_snapshot, 123)
define_test "Snapshot should fail with non-string snapshot name" do
assert_raise(ArgumentError) do
admin.snapshot(@test_name, 123)
end
end
define_test "Snapshot should fail without table name" do
define_test "Snapshot should fail without snapshot name" do
assert_raise(ArgumentError) do
admin.snapshot("hbase_create_test_snapshot")
admin.snapshot(@test_name)
end
end

View File

@ -421,7 +421,7 @@ onwards.
+
[source,java]
----
String tableName = "users";
TableName tableName = TableName.valueOf("users");
String path = "hdfs://<namenode>:<port>/user/<hadoop-user>/coprocessor.jar";
Configuration conf = HBaseConfiguration.create();
HBaseAdmin admin = new HBaseAdmin(conf);

View File

@ -741,7 +741,7 @@ the data, and deletes the table.
[source,jython]
----
import java.lang
from org.apache.hadoop.hbase import HBaseConfiguration, HTableDescriptor, HColumnDescriptor, HConstants
from org.apache.hadoop.hbase import HBaseConfiguration, HTableDescriptor, HColumnDescriptor, HConstants, TableName
from org.apache.hadoop.hbase.client import HBaseAdmin, HTable, Get
from org.apache.hadoop.hbase.io import Cell, RowResult
@ -753,7 +753,7 @@ conf = HBaseConfiguration()
# Create a table named 'test' that has two column families,
# one named 'content, and the other 'anchor'. The colons
# are required for column family names.
tablename = "test"
tablename = TableName.valueOf("test")
desc = HTableDescriptor(tablename)
desc.addFamily(HColumnDescriptor("content:"))

View File

@ -2214,7 +2214,7 @@ or in code it would be as follows:
[source,java]
----
void rename(Admin admin, String oldTableName, String newTableName) {
void rename(Admin admin, String oldTableName, TableName newTableName) {
String snapshotName = randomName();
admin.disableTable(oldTableName);
admin.snapshot(snapshotName, oldTableName);

View File

@ -53,7 +53,7 @@ Tables must be disabled when making ColumnFamily modifications, for example:
Configuration config = HBaseConfiguration.create();
Admin admin = new Admin(conf);
String table = "myTable";
TableName table = TableName.valueOf("myTable");
admin.disableTable(table);