hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From els...@apache.org
Subject hbase git commit: HBASE-17973 Fix incorrect method call in list_regions and expand tests (addendum)
Date Tue, 02 May 2017 21:43:44 GMT
Repository: hbase
Updated Branches:
  refs/heads/master 757bf379c -> de78c1189


HBASE-17973 Fix incorrect method call in list_regions and expand tests (addendum)


Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/de78c118
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/de78c118
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/de78c118

Branch: refs/heads/master
Commit: de78c11893d7c25f9faaf4bcb0ef10a9df1cd96e
Parents: 757bf37
Author: Josh Elser <elserj@apache.org>
Authored: Tue May 2 11:05:09 2017 -0400
Committer: Josh Elser <elserj@apache.org>
Committed: Tue May 2 17:42:47 2017 -0400

----------------------------------------------------------------------
 .../main/ruby/shell/commands/list_regions.rb    | 22 +++++++++++++++-----
 .../ruby/hbase/list_regions_test_no_cluster.rb  | 18 ++++++++++++++++
 2 files changed, 35 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/de78c118/hbase-shell/src/main/ruby/shell/commands/list_regions.rb
----------------------------------------------------------------------
diff --git a/hbase-shell/src/main/ruby/shell/commands/list_regions.rb b/hbase-shell/src/main/ruby/shell/commands/list_regions.rb
index 94b7a29..892653e 100644
--- a/hbase-shell/src/main/ruby/shell/commands/list_regions.rb
+++ b/hbase-shell/src/main/ruby/shell/commands/list_regions.rb
@@ -49,13 +49,11 @@ EOF
         hregion_locator_instance = conn_instance.getRegionLocator(TableName.valueOf(table_name))
         hregion_locator_list = hregion_locator_instance.getAllRegionLocations().to_a
         results = Array.new
+        desired_server_name = options[SERVER_NAME]
 
         begin
           # Filter out region servers which we don't want, default to all RS
-          regions = hregion_locator_list.filter do |hregion|
-            server_name = options[SERVER_NAME] || '*'
-            accept_server_name? server_name, hregion.getServerName().toString()
-          end
+          regions = get_regions_for_table_and_server(table_name, conn_instance, desired_server_name)
           # A locality threshold of "1.0" would be all regions (cannot have greater than
1 locality)
           # Regions which have a `dataLocality` less-than-or-equal to this value are accepted
           locality_threshold = 1.0
@@ -101,8 +99,22 @@ EOF
         value >= 0 and value <= 1.0
       end
 
+      def get_regions_for_table_and_server(table_name, conn, server_name)
+        get_regions_for_server(get_regions_for_table(table_name, conn), server_name)
+      end
+
+      def get_regions_for_server(regions_for_table, server_name)
+        regions_for_table.select do |hregion|
+          accept_server_name? server_name, hregion.getServerName().toString()
+        end
+      end
+
+      def get_regions_for_table(table_name, conn)
+        conn.getRegionLocator(TableName.valueOf(table_name)).getAllRegionLocations().to_a
+      end
+
       def accept_server_name?(desired_server_name, actual_server_name)
-        desired_server_name.eql? '*' or actual_server_name.start_with? desired_server_name
+        desired_server_name.nil? or actual_server_name.start_with? desired_server_name
       end
 
       def accept_region_for_locality?(actual_locality, locality_threshold)

http://git-wip-us.apache.org/repos/asf/hbase/blob/de78c118/hbase-shell/src/test/ruby/hbase/list_regions_test_no_cluster.rb
----------------------------------------------------------------------
diff --git a/hbase-shell/src/test/ruby/hbase/list_regions_test_no_cluster.rb b/hbase-shell/src/test/ruby/hbase/list_regions_test_no_cluster.rb
index 657b1bd..b7a14b6 100644
--- a/hbase-shell/src/test/ruby/hbase/list_regions_test_no_cluster.rb
+++ b/hbase-shell/src/test/ruby/hbase/list_regions_test_no_cluster.rb
@@ -20,6 +20,10 @@ require 'hbase_constants'
 
 include HBaseConstants
 
+java_import 'org.apache.hadoop.hbase.HRegionLocation'
+java_import 'org.apache.hadoop.hbase.HRegionInfo'
+java_import 'org.apache.hadoop.hbase.ServerName'
+
 module Hbase
   class NoClusterListRegionsTest < Test::Unit::TestCase
     include TestHelpers
@@ -57,5 +61,19 @@ module Hbase
       assert_equal false, command.accept_region_for_locality?(1.0, 0.999)
       assert_equal false, command.accept_region_for_locality?(0.5, 0.3)
     end
+
+    define_test 'filter nondesired servers' do
+      command = ::Shell::Commands::ListRegions.new(nil)
+      server1 = create_region_location('server1,16020,1234')
+      server2 = create_region_location('server2,16020,1234')
+      server3 = create_region_location('server3,16020,1234')
+      assert_equal [server2], command.get_regions_for_server([server1, server2, server3],
'server2')
+      assert_equal [server3], command.get_regions_for_server([server1, server2, server3],
'server3')
+      assert_equal [], command.get_regions_for_server([server1, server2, server3], 'server5')
+    end
+
+    def create_region_location(server_name)
+      HRegionLocation.new(HRegionInfo.new(TableName.valueOf('t1')), ServerName.valueOf(server_name))
+    end
   end
 end


Mime
View raw message