From 9a37c96ca670311908762d81100ee97b75f52f0b 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 | 1 + hbase-shell/src/test/ruby/hbase/table_test.rb | 11 +++++++++++ hbase-shell/src/test/ruby/test_helper.rb | 12 ++++++++++++ 3 files changed, 24 insertions(+) diff --git a/hbase-shell/src/main/ruby/hbase/table.rb b/hbase-shell/src/main/ruby/hbase/table.rb index 07c74d8..e703ea7 100644 --- a/hbase-shell/src/main/ruby/hbase/table.rb +++ b/hbase-shell/src/main/ruby/hbase/table.rb @@ -805,6 +805,7 @@ EOF def _get_splits_internal locator = @table.getRegionLocator splits = locator.getAllRegionLocations + .select { |s| org.apache.hadoop.hbase.client.RegionReplicaUtil.isDefaultReplica(s.getRegion) } .map { |i| Bytes.toStringBinary(i.getRegionInfo.getStartKey) }.delete_if { |k| k == '' } locator.close puts(format('Total number of splits = %s', splits.size + 1)) diff --git a/hbase-shell/src/test/ruby/hbase/table_test.rb b/hbase-shell/src/test/ruby/hbase/table_test.rb index e7e1b23..eed7ae3 100644 --- a/hbase-shell/src/test/ruby/hbase/table_test.rb +++ b/hbase-shell/src/test/ruby/hbase/table_test.rb @@ -695,5 +695,16 @@ module Hbase assert_equal(0, splits.size) assert_equal([], splits) end + + define_test "Split count for a table with region replicas" do + @testTableName = "tableWithRegionReplicas" + create_test_table_with_region_replicas(@testTableName, 3, SPLITS => ['10']) + @table = table(@testTableName) + 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(@testTableName) + end end end diff --git a/hbase-shell/src/test/ruby/test_helper.rb b/hbase-shell/src/test/ruby/test_helper.rb index 874b554..b15116a9 100644 --- a/hbase-shell/src/test/ruby/test_helper.rb +++ b/hbase-shell/src/test/ruby/test_helper.rb @@ -112,6 +112,18 @@ 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 + unless admin.enabled?(name) + admin.enable(name) + end + end + def drop_test_table(name) return unless admin.exists?(name) begin -- 2.10.1 (Apple Git-78)