hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From zhang...@apache.org
Subject [hbase] 18/28: HBASE-22281 Fix failed shell UTs
Date Sun, 02 Jun 2019 15:21:08 GMT
This is an automated email from the ASF dual-hosted git repository.

zhangduo pushed a commit to branch HBASE-21512
in repository https://gitbox.apache.org/repos/asf/hbase.git

commit 41ff90ca8bc4c59a1bda61737f75352d7c4ac969
Author: zhangduo <zhangduo@apache.org>
AuthorDate: Mon Apr 22 22:00:43 2019 +0800

    HBASE-22281 Fix failed shell UTs
---
 hbase-shell/src/main/ruby/hbase/admin.rb | 44 ++++++++++++++++++++++++--------
 hbase-shell/src/main/ruby/hbase/hbase.rb | 23 +++++++++++------
 hbase-shell/src/main/ruby/hbase/table.rb |  2 +-
 3 files changed, 50 insertions(+), 19 deletions(-)

diff --git a/hbase-shell/src/main/ruby/hbase/admin.rb b/hbase-shell/src/main/ruby/hbase/admin.rb
index 4187a0e..98b5392 100644
--- a/hbase-shell/src/main/ruby/hbase/admin.rb
+++ b/hbase-shell/src/main/ruby/hbase/admin.rb
@@ -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
 
diff --git a/hbase-shell/src/main/ruby/hbase/hbase.rb b/hbase-shell/src/main/ruby/hbase/hbase.rb
index 1f37f99..a9b35ed 100644
--- a/hbase-shell/src/main/ruby/hbase/hbase.rb
+++ b/hbase-shell/src/main/ruby/hbase/hbase.rb
@@ -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
diff --git a/hbase-shell/src/main/ruby/hbase/table.rb b/hbase-shell/src/main/ruby/hbase/table.rb
index 8c7144d..53b090e 100644
--- a/hbase-shell/src/main/ruby/hbase/table.rb
+++ b/hbase-shell/src/main/ruby/hbase/table.rb
@@ -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


Mime
View raw message