From 369f04419e71868a5d60238bc86d0949ffb3e5c2 Mon Sep 17 00:00:00 2001 From: Toshihiro Suzuki Date: Tue, 27 Mar 2018 17:02:14 +0900 Subject: [PATCH] HBASE-20293 get_splits returns duplicate split points when region replication is on --- 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(-) 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 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 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 -- 2.10.1 (Apple Git-78)