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 57565D4D5 for ; Thu, 16 May 2013 21:31:30 +0000 (UTC) Received: (qmail 30391 invoked by uid 500); 16 May 2013 21:31:30 -0000 Delivered-To: apmail-hbase-commits-archive@hbase.apache.org Received: (qmail 30337 invoked by uid 500); 16 May 2013 21:31:30 -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 30327 invoked by uid 99); 16 May 2013 21:31:30 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 16 May 2013 21:31:30 +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, 16 May 2013 21:31:27 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 139322388962; Thu, 16 May 2013 21:31:06 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1483574 - in /hbase/trunk: hbase-client/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestSnapshotFromClient.java Date: Thu, 16 May 2013 21:31:05 -0000 To: commits@hbase.apache.org From: tedyu@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20130516213106.139322388962@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: tedyu Date: Thu May 16 21:31:05 2013 New Revision: 1483574 URL: http://svn.apache.org/r1483574 Log: HBASE-8461 Provide the ability to delete multiple snapshots through single command (Ted Yu) Modified: hbase/trunk/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestSnapshotFromClient.java Modified: hbase/trunk/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java?rev=1483574&r1=1483573&r2=1483574&view=diff ============================================================================== --- hbase/trunk/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java (original) +++ hbase/trunk/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java Thu May 16 21:31:05 2013 @@ -2553,6 +2553,35 @@ public class HBaseAdmin implements Abort } /** + * List all the completed snapshots matching the given regular expression. + * + * @param regex The regular expression to match against + * @return - returns a List of SnapshotDescription + * @throws IOException if a remote or network exception occurs + */ + public List listSnapshots(String regex) throws IOException { + return listSnapshots(Pattern.compile(regex)); + } + + /** + * List all the completed snapshots matching the given pattern. + * + * @param pattern The compiled regular expression to match against + * @return - returns a List of SnapshotDescription + * @throws IOException if a remote or network exception occurs + */ + public List listSnapshots(Pattern pattern) throws IOException { + List matched = new LinkedList(); + List snapshots = listSnapshots(); + for (SnapshotDescription snapshot : snapshots) { + if (pattern.matcher(snapshot.getName()).matches()) { + matched.add(snapshot); + } + } + return matched; + } + + /** * Delete an existing snapshot. * @param snapshotName name of the snapshot * @throws IOException if a remote or network exception occurs @@ -2583,6 +2612,36 @@ public class HBaseAdmin implements Abort } /** + * Delete existing snapshots whose names match the pattern passed. + * @param regex The regular expression to match against + * @throws IOException if a remote or network exception occurs + */ + public void deleteSnapshots(final String regex) throws IOException { + deleteSnapshots(Pattern.compile(regex)); + } + + /** + * Delete existing snapshots whose names match the pattern passed. + * @param pattern pattern for names of the snapshot to match + * @throws IOException if a remote or network exception occurs + */ + public void deleteSnapshots(final Pattern pattern) throws IOException { + List snapshots = listSnapshots(pattern); + for (final SnapshotDescription snapshot : snapshots) { + // do the delete + execute(new MasterAdminCallable() { + @Override + public Void call() throws ServiceException { + masterAdmin.deleteSnapshot( + null, + DeleteSnapshotRequest.newBuilder().setSnapshot(snapshot).build()); + return null; + } + }); + } + } + + /** * @see {@link #execute(MasterAdminCallable)} */ private abstract static class MasterAdminCallable implements Callable{ Modified: hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestSnapshotFromClient.java URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestSnapshotFromClient.java?rev=1483574&r1=1483573&r2=1483574&view=diff ============================================================================== --- hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestSnapshotFromClient.java (original) +++ hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestSnapshotFromClient.java Thu May 16 21:31:05 2013 @@ -17,12 +17,14 @@ */ package org.apache.hadoop.hbase.client; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; import java.io.IOException; import java.util.HashSet; import java.util.List; import java.util.Set; +import java.util.regex.Pattern; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -141,6 +143,43 @@ public class TestSnapshotFromClient { } /** + * Test HBaseAdmin#deleteSnapshots(String) which deletes snapshots whose names match the parameter + * + * @throws Exception + */ + @Test + public void testSnapshotDeletionWithRegex() throws Exception { + HBaseAdmin admin = UTIL.getHBaseAdmin(); + // make sure we don't fail on listing snapshots + SnapshotTestingUtils.assertNoSnapshots(admin); + + // put some stuff in the table + HTable table = new HTable(UTIL.getConfiguration(), TABLE_NAME); + UTIL.loadTable(table, TEST_FAM); + table.close(); + + byte[] snapshot1 = Bytes.toBytes("TableSnapshot1"); + admin.snapshot(snapshot1, TABLE_NAME); + LOG.debug("Snapshot1 completed."); + + byte[] snapshot2 = Bytes.toBytes("TableSnapshot2"); + admin.snapshot(snapshot2, TABLE_NAME); + LOG.debug("Snapshot2 completed."); + + String snapshot3 = "3rdTableSnapshot"; + admin.snapshot(Bytes.toBytes(snapshot3), TABLE_NAME); + LOG.debug(snapshot3 + " completed."); + + // delete the first two snapshots + admin.deleteSnapshots("TableSnapshot.*"); + List snapshots = admin.listSnapshots(); + assertEquals(1, snapshots.size()); + assertEquals(snapshots.get(0).getName(), snapshot3); + + admin.deleteSnapshot(snapshot3); + admin.close(); + } + /** * Test snapshotting a table that is offline * @throws Exception */