You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by st...@apache.org on 2013/04/04 06:58:55 UTC

svn commit: r1464290 - in /hbase/trunk/hbase-server/src/main/ruby: hbase/admin.rb shell.rb

Author: stack
Date: Thu Apr  4 04:58:55 2013
New Revision: 1464290

URL: http://svn.apache.org/r1464290
Log:
HBASE-5525 Truncate and preserve region boundaries option

Modified:
    hbase/trunk/hbase-server/src/main/ruby/hbase/admin.rb
    hbase/trunk/hbase-server/src/main/ruby/shell.rb

Modified: hbase/trunk/hbase-server/src/main/ruby/hbase/admin.rb
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/main/ruby/hbase/admin.rb?rev=1464290&r1=1464289&r2=1464290&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/main/ruby/hbase/admin.rb (original)
+++ hbase/trunk/hbase-server/src/main/ruby/hbase/admin.rb Thu Apr  4 04:58:55 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/trunk/hbase-server/src/main/ruby/shell.rb
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/main/ruby/shell.rb?rev=1464290&r1=1464289&r2=1464290&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/main/ruby/shell.rb (original)
+++ hbase/trunk/hbase-server/src/main/ruby/shell.rb Thu Apr  4 04:58:55 2013
@@ -266,6 +266,7 @@ Shell.load_command_group(
     put
     scan
     truncate
+    truncate_preserve
   ]
 )