From 2e1895d20b8df5fc57aeea00b0cef104660c1860 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 | 15 +++++++++++++++ hbase-shell/src/test/ruby/test_helper.rb | 11 +++++++++++ 3 files changed, 28 insertions(+) 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..b1a6efd 100644 --- a/hbase-shell/src/test/ruby/hbase/table_test.rb +++ b/hbase-shell/src/test/ruby/hbase/table_test.rb @@ -22,6 +22,8 @@ require 'hbase_constants' include HBaseConstants module Hbase + # rubocop:disable Metrics/ClassLength + # Constructor tests class TableConstructorTest < Test::Unit::TestCase include TestHelpers @@ -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 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)