From 40e9c22ea2800746ad324ec807b6eba136f51a92 Mon Sep 17 00:00:00 2001 From: Andrew Purtell Date: Mon, 12 Jan 2015 19:09:02 -0800 Subject: [PATCH] HBASE-12801 Failed to truncate a table while maintaing binary region boundaries (Liu Shaohui) --- .../java/org/apache/hadoop/hbase/util/Bytes.java | 12 ++++++++++++ hbase-shell/src/main/ruby/hbase/admin.rb | 4 ++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/util/Bytes.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/util/Bytes.java index 9e79be35322..dd666e6ae26 100644 --- a/hbase-common/src/main/java/org/apache/hadoop/hbase/util/Bytes.java +++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/util/Bytes.java @@ -1785,6 +1785,18 @@ public class Bytes { return result; } + /** + * @param t operands + * @return Array of binary byte arrays made from passed array of binary strings + */ + public static byte[][] toBinaryByteArrays(final String[] t) { + byte[][] result = new byte[t.length][]; + for (int i = 0; i < t.length; i++) { + result[i] = Bytes.toBytesBinary(t[i]); + } + return result; + } + /** * @param column operand * @return A byte array of a byte array where first and only entry is diff --git a/hbase-shell/src/main/ruby/hbase/admin.rb b/hbase-shell/src/main/ruby/hbase/admin.rb index f7bcd83ba5e..0ce1a561b9a 100644 --- a/hbase-shell/src/main/ruby/hbase/admin.rb +++ b/hbase-shell/src/main/ruby/hbase/admin.rb @@ -398,8 +398,8 @@ module Hbase # Truncates table while maintaing region boundaries (deletes all records by recreating the table) def truncate_preserve(table_name, conf = @conf) h_table = @conn.getTable(table_name) - splits = h_table.getRegionLocations().keys().map{|i| Bytes.toString(i.getStartKey)}.delete_if{|k| k == ""}.to_java :String - splits = org.apache.hadoop.hbase.util.Bytes.toByteArrays(splits) + splits = h_table.getRegionLocations().keys().map{|i| Bytes.toStringBinary(i.getStartKey)}.delete_if{|k| k == ""}.to_java :String + splits = org.apache.hadoop.hbase.util.Bytes.toBinaryByteArrays(splits) table_description = h_table.getTableDescriptor() yield 'Disabling table...' if block_given? disable(table_name)