HBASE-22281 Fix failed shell UTs

This commit is contained in:
zhangduo 2019-04-22 22:00:43 +08:00
parent bd109506f3
commit 47cb6295fa
3 changed files with 50 additions and 19 deletions

View File

@ -54,7 +54,7 @@ module Hbase
# Requests a table or region or region server flush
def flush(name)
@admin.flushRegion(name.to_java_bytes)
rescue java.lang.IllegalArgumentException
rescue java.lang.IllegalArgumentException, org.apache.hadoop.hbase.UnknownRegionException
# Unknown region. Try table.
begin
@admin.flush(TableName.valueOf(name))
@ -79,9 +79,17 @@ module Hbase
end
begin
@admin.compactRegion(table_or_region_name.to_java_bytes, family_bytes)
rescue java.lang.IllegalArgumentException => e
@admin.compact(TableName.valueOf(table_or_region_name), family_bytes, compact_type)
if family_bytes.nil?
@admin.compactRegion(table_or_region_name.to_java_bytes)
else
@admin.compactRegion(table_or_region_name.to_java_bytes, family_bytes)
end
rescue java.lang.IllegalArgumentException, org.apache.hadoop.hbase.UnknownRegionException
if family_bytes.nil?
@admin.compact(TableName.valueOf(table_or_region_name), compact_type)
else
@admin.compact(TableName.valueOf(table_or_region_name), family_bytes, compact_type)
end
end
end
@ -124,9 +132,17 @@ module Hbase
end
begin
@admin.majorCompactRegion(table_or_region_name.to_java_bytes, family_bytes)
rescue java.lang.IllegalArgumentException => e
@admin.majorCompact(TableName.valueOf(table_or_region_name), family_bytes, compact_type)
if family_bytes.nil?
@admin.majorCompactRegion(table_or_region_name.to_java_bytes)
else
@admin.majorCompactRegion(table_or_region_name.to_java_bytes, family_bytes)
end
rescue java.lang.IllegalArgumentException, org.apache.hadoop.hbase.UnknownRegionException
if family_bytes.nil?
@admin.majorCompact(TableName.valueOf(table_or_region_name), compact_type)
else
@admin.majorCompact(TableName.valueOf(table_or_region_name), family_bytes, compact_type)
end
end
end
@ -144,9 +160,17 @@ module Hbase
split_point_bytes = nil
split_point_bytes = split_point.to_java_bytes unless split_point.nil?
begin
@admin.splitRegionAsync(table_or_region_name.to_java_bytes, split_point_bytes).get
rescue java.lang.IllegalArgumentException, org.apache.hadoop.hbase.UnknownRegionException => e
@admin.split(TableName.valueOf(table_or_region_name), split_point_bytes)
if split_point_bytes.nil?
org.apache.hadoop.hbase.util.FutureUtils.get(@admin.splitRegionAsync(table_or_region_name.to_java_bytes))
else
org.apache.hadoop.hbase.util.FutureUtils.get(@admin.splitRegionAsync(table_or_region_name.to_java_bytes, split_point_bytes))
end
rescue java.lang.IllegalArgumentException, org.apache.hadoop.hbase.UnknownRegionException
if split_point_bytes.nil?
@admin.split(TableName.valueOf(table_or_region_name))
else
@admin.split(TableName.valueOf(table_or_region_name), split_point_bytes)
end
end
end

View File

@ -42,16 +42,21 @@ module Hbase
configuration.setInt('hbase.client.retries.number', 7)
configuration.setInt('hbase.ipc.client.connect.max.retries', 3)
end
@connection = ConnectionFactory.createConnection(configuration)
end
def connection
if @connection.nil?
@connection = ConnectionFactory.createConnection(configuration)
end
@connection
end
# Returns ruby's Admin class from admin.rb
def admin
::Hbase::Admin.new(@connection)
::Hbase::Admin.new(self.connection)
end
def rsgroup_admin
::Hbase::RSGroupAdmin.new(@connection)
::Hbase::RSGroupAdmin.new(self.connection)
end
def taskmonitor
@ -60,7 +65,7 @@ module Hbase
# Create new one each time
def table(table, shell)
::Hbase::Table.new(@connection.getTable(TableName.valueOf(table)), shell)
::Hbase::Table.new(self.connection.getTable(TableName.valueOf(table)), shell)
end
def replication_admin
@ -68,19 +73,21 @@ module Hbase
end
def security_admin
::Hbase::SecurityAdmin.new(@connection.getAdmin)
::Hbase::SecurityAdmin.new(self.connection.getAdmin)
end
def visibility_labels_admin
::Hbase::VisibilityLabelsAdmin.new(@connection.getAdmin)
::Hbase::VisibilityLabelsAdmin.new(self.connection.getAdmin)
end
def quotas_admin
::Hbase::QuotasAdmin.new(@connection.getAdmin)
::Hbase::QuotasAdmin.new(self.connection.getAdmin)
end
def shutdown
@connection.close
if @connection != nil
@connection.close
end
end
end
end

View File

@ -717,7 +717,7 @@ EOF
# Returns a list of column names in the table
def get_all_columns
@table.table_descriptor.getFamilies.map do |family|
@table.descriptor.getColumnFamilies.map do |family|
"#{family.getNameAsString}:"
end
end