HBASE-18129 truncate_preserve fails when the truncate method doesn't exist on the master
Signed-off-by: tedyu <yuzhihong@gmail.com>
This commit is contained in:
parent
c945d2b2d9
commit
dda9ae0295
@ -35,6 +35,7 @@ module Hbase
|
|||||||
@connection = connection
|
@connection = connection
|
||||||
# Java Admin instance
|
# Java Admin instance
|
||||||
@admin = @connection.getAdmin
|
@admin = @connection.getAdmin
|
||||||
|
@conf = @connection.getConfiguration
|
||||||
end
|
end
|
||||||
|
|
||||||
def close
|
def close
|
||||||
@ -515,14 +516,15 @@ module Hbase
|
|||||||
|
|
||||||
#----------------------------------------------------------------------------------------------
|
#----------------------------------------------------------------------------------------------
|
||||||
# Truncates table while maintaing region boundaries (deletes all records by recreating the table)
|
# Truncates table while maintaing region boundaries (deletes all records by recreating the table)
|
||||||
def truncate_preserve(table_name_str)
|
def truncate_preserve(table_name_str, conf = @conf)
|
||||||
puts "Truncating '#{table_name_str}' table (it may take a while):"
|
puts "Truncating '#{table_name_str}' table (it may take a while):"
|
||||||
table_name = TableName.valueOf(table_name_str)
|
table_name = TableName.valueOf(table_name_str)
|
||||||
locator = @connection.getRegionLocator(table_name)
|
locator = @connection.getRegionLocator(table_name)
|
||||||
begin
|
begin
|
||||||
splits = locator.getAllRegionLocations().
|
splits = locator.getAllRegionLocations().
|
||||||
map{|i| Bytes.toString(i.getRegionInfo().getStartKey)}.
|
map{|i| Bytes.toStringBinary(i.getRegionInfo().getStartKey)}.
|
||||||
delete_if{|k| k == ""}.to_java :String
|
delete_if{|k| k == ""}.to_java :String
|
||||||
|
splits = org.apache.hadoop.hbase.util.Bytes.toBinaryByteArrays(splits)
|
||||||
ensure
|
ensure
|
||||||
locator.close()
|
locator.close()
|
||||||
end
|
end
|
||||||
@ -533,6 +535,10 @@ module Hbase
|
|||||||
|
|
||||||
begin
|
begin
|
||||||
puts 'Truncating table...'
|
puts 'Truncating table...'
|
||||||
|
#just for test
|
||||||
|
unless conf.getBoolean("hbase.client.truncatetable.support", true)
|
||||||
|
raise UnsupportedMethodException.new('truncateTable')
|
||||||
|
end
|
||||||
@admin.truncateTable(table_name, true)
|
@admin.truncateTable(table_name, true)
|
||||||
rescue => e
|
rescue => e
|
||||||
# Handle the compatibility case, where the truncate method doesn't exists on the Master
|
# Handle the compatibility case, where the truncate method doesn't exists on the Master
|
||||||
@ -551,6 +557,16 @@ module Hbase
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
class UnsupportedMethodException < StandardError
|
||||||
|
def initialize(name)
|
||||||
|
@method_name = name
|
||||||
|
end
|
||||||
|
|
||||||
|
def cause
|
||||||
|
return org.apache.hadoop.hbase.DoNotRetryIOException.new("#@method_name is not support")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
#----------------------------------------------------------------------------------------------
|
#----------------------------------------------------------------------------------------------
|
||||||
# Check the status of alter command (number of regions reopened)
|
# Check the status of alter command (number of regions reopened)
|
||||||
def alter_status(table_name)
|
def alter_status(table_name)
|
||||||
|
@ -272,6 +272,23 @@ module Hbase
|
|||||||
output = capture_stdout { command(:truncate, @test_name) }
|
output = capture_stdout { command(:truncate, @test_name) }
|
||||||
assert(!output.empty?)
|
assert(!output.empty?)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
define_test "truncate_preserve should maintain the previous region boundaries" do
|
||||||
|
drop_test_table(@create_test_name)
|
||||||
|
admin.create(@create_test_name, 'a', {NUMREGIONS => 10, SPLITALGO => 'HexStringSplit'})
|
||||||
|
splits = table(@create_test_name)._get_splits_internal()
|
||||||
|
command(:truncate_preserve, @create_test_name)
|
||||||
|
assert_equal(splits, table(@create_test_name)._get_splits_internal())
|
||||||
|
end
|
||||||
|
|
||||||
|
define_test "truncate_preserve should be fine when truncateTable method doesn't support" do
|
||||||
|
drop_test_table(@create_test_name)
|
||||||
|
admin.create(@create_test_name, 'a', {NUMREGIONS => 10, SPLITALGO => 'HexStringSplit'})
|
||||||
|
splits = table(@create_test_name)._get_splits_internal()
|
||||||
|
$TEST_CLUSTER.getConfiguration.setBoolean("hbase.client.truncatetable.support", false)
|
||||||
|
admin.truncate_preserve(@create_test_name, $TEST_CLUSTER.getConfiguration)
|
||||||
|
assert_equal(splits, table(@create_test_name)._get_splits_internal())
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Simple administration methods tests
|
# Simple administration methods tests
|
||||||
|
Loading…
x
Reference in New Issue
Block a user