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 # Requests a table or region or region server flush
def flush(name) def flush(name)
@admin.flushRegion(name.to_java_bytes) @admin.flushRegion(name.to_java_bytes)
rescue java.lang.IllegalArgumentException rescue java.lang.IllegalArgumentException, org.apache.hadoop.hbase.UnknownRegionException
# Unknown region. Try table. # Unknown region. Try table.
begin begin
@admin.flush(TableName.valueOf(name)) @admin.flush(TableName.valueOf(name))
@ -79,11 +79,19 @@ module Hbase
end end
begin begin
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) @admin.compactRegion(table_or_region_name.to_java_bytes, family_bytes)
rescue java.lang.IllegalArgumentException => e 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) @admin.compact(TableName.valueOf(table_or_region_name), family_bytes, compact_type)
end end
end end
end
#---------------------------------------------------------------------------------------------- #----------------------------------------------------------------------------------------------
# Switch compaction on/off at runtime on a region server # Switch compaction on/off at runtime on a region server
@ -124,11 +132,19 @@ module Hbase
end end
begin begin
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) @admin.majorCompactRegion(table_or_region_name.to_java_bytes, family_bytes)
rescue java.lang.IllegalArgumentException => e 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) @admin.majorCompact(TableName.valueOf(table_or_region_name), family_bytes, compact_type)
end end
end end
end
#---------------------------------------------------------------------------------------------- #----------------------------------------------------------------------------------------------
# Requests a regionserver's WAL roll # Requests a regionserver's WAL roll
@ -144,11 +160,19 @@ module Hbase
split_point_bytes = nil split_point_bytes = nil
split_point_bytes = split_point.to_java_bytes unless split_point.nil? split_point_bytes = split_point.to_java_bytes unless split_point.nil?
begin begin
@admin.splitRegionAsync(table_or_region_name.to_java_bytes, split_point_bytes).get if split_point_bytes.nil?
rescue java.lang.IllegalArgumentException, org.apache.hadoop.hbase.UnknownRegionException => e 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) @admin.split(TableName.valueOf(table_or_region_name), split_point_bytes)
end end
end end
end
#---------------------------------------------------------------------------------------------- #----------------------------------------------------------------------------------------------
# Enable/disable one split or merge switch # Enable/disable one split or merge switch

View File

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

View File

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