Index: hbase-client/src/main/java/org/apache/hadoop/hbase/client/HTable.java =================================================================== --- hbase-client/src/main/java/org/apache/hadoop/hbase/client/HTable.java (revision 1552491) +++ hbase-client/src/main/java/org/apache/hadoop/hbase/client/HTable.java (working copy) @@ -573,6 +573,22 @@ } /** + * Gets the split keys of the currently open table. + * @return Array of table split keys + * @throws IOException if a remote or network exception occurs + */ + public byte[][] getSplitKeys() throws IOException { + List splitKeysList = new ArrayList(); + for (HRegionInfo regionInfo : getRegionLocations().keySet()) { + if (Bytes.equals(regionInfo.getStartKey(), HConstants.EMPTY_BYTE_ARRAY)) { + continue; + } + splitKeysList.add(regionInfo.getStartKey()); + } + return splitKeysList.toArray(new byte[splitKeysList.size()][]); + } + + /** * Gets the starting and ending row keys for every region in the currently * open table. *

Index: hbase-shell/src/main/ruby/hbase/admin.rb =================================================================== --- hbase-shell/src/main/ruby/hbase/admin.rb (revision 1552491) +++ hbase-shell/src/main/ruby/hbase/admin.rb (working copy) @@ -345,14 +345,14 @@ # Truncates table while maintaing region boundaries (deletes all records by recreating the table) def truncate_preserve(table_name, conf = @conf) h_table = org.apache.hadoop.hbase.client.HTable.new(conf, 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) + raise ArgumentError, "Table #{table_name} is not enabled. Enable it first.'" unless enabled?(table_name) + splits = h_table.getSplitKeys() table_description = h_table.getTableDescriptor() yield 'Disabling table...' if block_given? - disable(table_name) + @admin.disableTable(table_name) yield 'Dropping table...' if block_given? - drop(table_name) + @admin.deleteTable(table_name) yield 'Creating table with region boundaries...' if block_given? @admin.createTable(table_description, splits)