You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by hu...@apache.org on 2018/04/17 22:43:27 UTC

hbase git commit: HBASE-20293 get_splits returns duplicate split points when region replication is on

Repository: hbase
Updated Branches:
  refs/heads/master 357a089e0 -> fd2cec75f


HBASE-20293 get_splits returns duplicate split points when region replication is on


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

Branch: refs/heads/master
Commit: fd2cec75f38689bcc450978cdee394a252dd3fd9
Parents: 357a089
Author: Toshihiro Suzuki <br...@gmail.com>
Authored: Tue Apr 17 15:40:50 2018 -0700
Committer: Huaxiang Sun <hs...@cloudera.com>
Committed: Tue Apr 17 15:42:25 2018 -0700

----------------------------------------------------------------------
 hbase-shell/src/main/ruby/hbase/table.rb      |  2 ++
 hbase-shell/src/test/ruby/hbase/table_test.rb | 20 ++++++++++++++++++--
 hbase-shell/src/test/ruby/test_helper.rb      | 11 +++++++++++
 3 files changed, 31 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/fd2cec75/hbase-shell/src/main/ruby/hbase/table.rb
----------------------------------------------------------------------
diff --git a/hbase-shell/src/main/ruby/hbase/table.rb b/hbase-shell/src/main/ruby/hbase/table.rb
index 6af6cfa..d12b30f 100644
--- a/hbase-shell/src/main/ruby/hbase/table.rb
+++ b/hbase-shell/src/main/ruby/hbase/table.rb
@@ -20,6 +20,7 @@
 include Java
 
 java_import org.apache.hadoop.hbase.util.Bytes
+java_import org.apache.hadoop.hbase.client.RegionReplicaUtil
 
 # Wrapper for org.apache.hadoop.hbase.client.Table
 
@@ -808,6 +809,7 @@ EOF
     def _get_splits_internal
       locator = @table.getRegionLocator
       locator.getAllRegionLocations
+             .select { |s| RegionReplicaUtil.isDefaultReplica(s.getRegion) }
              .map { |i| Bytes.toStringBinary(i.getRegionInfo.getStartKey) }
              .delete_if { |k| k == '' }
     ensure

http://git-wip-us.apache.org/repos/asf/hbase/blob/fd2cec75/hbase-shell/src/test/ruby/hbase/table_test.rb
----------------------------------------------------------------------
diff --git a/hbase-shell/src/test/ruby/hbase/table_test.rb b/hbase-shell/src/test/ruby/hbase/table_test.rb
index c1b288c..0885761 100644
--- a/hbase-shell/src/test/ruby/hbase/table_test.rb
+++ b/hbase-shell/src/test/ruby/hbase/table_test.rb
@@ -199,6 +199,7 @@ module Hbase
   end
 
   # Complex data management methods tests
+  # rubocop:disable Metrics/ClassLength
   class TableComplexMethodsTest < Test::Unit::TestCase
     include TestHelpers
 
@@ -337,8 +338,9 @@ module Hbase
       assert_nil(res['x:a'])
       assert_not_nil(res['x:b'])
     end
-    
-     define_test "get should work with hash columns spec and TIMESTAMP and AUTHORIZATIONS" do
+
+    define_test 'get should work with hash columns spec and TIMESTAMP and' \
+                ' AUTHORIZATIONS' do
       res = @test_table._get_internal('1', TIMESTAMP => 1234, AUTHORIZATIONS=>['PRIVATE'])
       assert_nil(res)
     end
@@ -696,6 +698,19 @@ module Hbase
       assert_equal([], splits)
     end
 
+    define_test 'Split count for a table with region replicas' do
+      @test_table_name = 'tableWithRegionReplicas'
+      create_test_table_with_region_replicas(@test_table_name, 3,
+                                             SPLITS => ['10'])
+      @table = table(@test_table_name)
+      splits = @table._get_splits_internal
+      # In this case, total splits should be 1 even if the number of region
+      # replicas is 3.
+      assert_equal(1, splits.size)
+      assert_equal(['10'], splits)
+      drop_test_table(@test_table_name)
+    end
+
     define_test "scan should throw an exception on a disabled table" do
       @test_table.disable
       begin
@@ -707,4 +722,5 @@ module Hbase
       end
     end
   end
+  # rubocop:enable Metrics/ClassLength
 end

http://git-wip-us.apache.org/repos/asf/hbase/blob/fd2cec75/hbase-shell/src/test/ruby/test_helper.rb
----------------------------------------------------------------------
diff --git a/hbase-shell/src/test/ruby/test_helper.rb b/hbase-shell/src/test/ruby/test_helper.rb
index ec6bb6a..f72a1c6 100644
--- a/hbase-shell/src/test/ruby/test_helper.rb
+++ b/hbase-shell/src/test/ruby/test_helper.rb
@@ -112,6 +112,17 @@ module Hbase
       end
     end
 
+    def create_test_table_with_region_replicas(name, num_of_replicas, splits)
+      # Create the table if needed
+      unless admin.exists?(name)
+        command(:create, name, 'f1', { REGION_REPLICATION => num_of_replicas },
+                splits)
+      end
+
+      # Enable the table if needed
+      admin.enable(name) unless admin.enabled?(name)
+    end
+
     def drop_test_table(name)
       return unless admin.exists?(name)
       begin