Return-Path: X-Original-To: apmail-hbase-commits-archive@www.apache.org Delivered-To: apmail-hbase-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id C414CFE4B for ; Thu, 4 Apr 2013 04:59:42 +0000 (UTC) Received: (qmail 81990 invoked by uid 500); 4 Apr 2013 04:59:42 -0000 Delivered-To: apmail-hbase-commits-archive@hbase.apache.org Received: (qmail 81952 invoked by uid 500); 4 Apr 2013 04:59:42 -0000 Mailing-List: contact commits-help@hbase.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@hbase.apache.org Delivered-To: mailing list commits@hbase.apache.org Received: (qmail 81940 invoked by uid 99); 4 Apr 2013 04:59:42 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 04 Apr 2013 04:59:42 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 04 Apr 2013 04:59:39 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 20EB723888FD; Thu, 4 Apr 2013 04:59:19 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1464291 - in /hbase/branches/0.95/hbase-server/src/main/ruby: hbase/admin.rb shell.rb Date: Thu, 04 Apr 2013 04:59:19 -0000 To: commits@hbase.apache.org From: stack@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20130404045919.20EB723888FD@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 ] )