HBASE-12801 Failed to truncate a table while maintaing binary region boundaries (Liu Shaohui)

This commit is contained in:
Andrew Purtell 2015-01-12 19:09:02 -08:00
parent 6e45269f2c
commit 40e9c22ea2
2 changed files with 14 additions and 2 deletions

View File

@ -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

View File

@ -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)