From 32802c9ffc9d595fa548f3c7c3029c70d7633288 Mon Sep 17 00:00:00 2001 From: Guangxu Cheng Date: Sat, 27 May 2017 13:54:36 +0800 Subject: [PATCH] HBASE-18129 truncate_preserve fails when the truncate method doesn't exists on the master --- hbase-shell/src/main/ruby/hbase/admin.rb | 3 ++- hbase-shell/src/test/ruby/hbase/admin_test.rb | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletions(-) diff --git a/hbase-shell/src/main/ruby/hbase/admin.rb b/hbase-shell/src/main/ruby/hbase/admin.rb index 9925df3..3b46e3e 100644 --- a/hbase-shell/src/main/ruby/hbase/admin.rb +++ b/hbase-shell/src/main/ruby/hbase/admin.rb @@ -482,8 +482,9 @@ module Hbase locator = @connection.getRegionLocator(TableName.valueOf(table_name)) begin splits = locator.getAllRegionLocations(). - map{|i| Bytes.toString(i.getRegionInfo().getStartKey)}. + map{|i| Bytes.toStringBinary(i.getRegionInfo().getStartKey)}. delete_if{|k| k == ""}.to_java :String + splits = org.apache.hadoop.hbase.util.Bytes.toBinaryByteArrays(splits) ensure locator.close() end diff --git a/hbase-shell/src/test/ruby/hbase/admin_test.rb b/hbase-shell/src/test/ruby/hbase/admin_test.rb index e53c6be..a92d459 100644 --- a/hbase-shell/src/test/ruby/hbase/admin_test.rb +++ b/hbase-shell/src/test/ruby/hbase/admin_test.rb @@ -271,6 +271,14 @@ module Hbase end assert(!logs.empty?) end + + define_test "truncate_preserve should maintain the previous region boundaries" do + drop_test_table(@create_test_name) + admin.create(@create_test_name, 'a', {NUMREGIONS => 10, SPLITALGO => 'HexStringSplit'}) + splits = table(@create_test_name)._get_splits_internal() + admin.truncate_preserve(@create_test_name, $TEST_CLUSTER.getConfiguration) + assert_equal(splits, table(@create_test_name)._get_splits_internal()) + end end # Simple administration methods tests -- 1.7.1