Author: stack
Date: Thu Apr 4 04:59:18 2013
New Revision: 1464291
URL: http://svn.apache.org/r1464291
Log:
HBASE-5525 Truncate and preserve region boundaries option
Modified:
hbase/branches/0.95/hbase-server/src/main/ruby/hbase/admin.rb
hbase/branches/0.95/hbase-server/src/main/ruby/shell.rb
Modified: hbase/branches/0.95/hbase-server/src/main/ruby/hbase/admin.rb
URL:
http://svn.apache.org/viewvc/hbase/branches/0.95/hbase-server/src/main/ruby/hbase/admin.rb?rev=1464291&r1=1464290&r2=1464291&view=diff
==============================================================================
--- hbase/branches/0.95/hbase-server/src/main/ruby/hbase/admin.rb (original)
+++ hbase/branches/0.95/hbase-server/src/main/ruby/hbase/admin.rb Thu Apr 4
04:59:18 2013
@@ -20,6 +20,7 @@
include Java
java_import org.apache.hadoop.hbase.util.Pair
java_import org.apache.hadoop.hbase.util.RegionSplitter
+java_import org.apache.hadoop.hbase.util.Bytes
# Wrapper for org.apache.hadoop.hbase.client.HBaseAdmin
@@ -344,6 +345,24 @@ module Hbase
@admin.createTable(table_description)
end
+
#----------------------------------------------------------------------------------------------
+ # 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.getRegionsInfo().keys().map{|i|
Bytes.toString(i.getStartKey)}.delete_if{|k| k == ""}.to_java :String
+ splits = org.apache.hadoop.hbase.util.Bytes.toByteArrays(splits)
+ table_description = h_table.getTableDescriptor()
+ yield 'Disabling table...' if block_given?
+ disable(table_name)
+
+ yield 'Dropping table...' if block_given?
+ drop(table_name)
+
+ yield 'Creating table with region boundaries...' if block_given?
+ @admin.createTable(table_description, splits)
+ end
+
+
#----------------------------------------------------------------------------------------------
# Check the status of alter command (number of regions reopened)
def alter_status(table_name)
# Table name should be a string
Modified: hbase/branches/0.95/hbase-server/src/main/ruby/shell.rb
URL:
http://svn.apache.org/viewvc/hbase/branches/0.95/hbase-server/src/main/ruby/shell.rb?rev=1464291&r1=1464290&r2=1464291&view=diff
==============================================================================
--- hbase/branches/0.95/hbase-server/src/main/ruby/shell.rb (original)
+++ hbase/branches/0.95/hbase-server/src/main/ruby/shell.rb Thu Apr 4 04:59:18
2013
@@ -266,6 +266,7 @@ Shell.load_command_group(
put
scan
truncate
+ truncate_preserve
]
)