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 AEB6C116D7 for ; Sun, 11 May 2014 11:40:25 +0000 (UTC) Received: (qmail 82761 invoked by uid 500); 11 May 2014 11:40:25 -0000 Delivered-To: apmail-hbase-commits-archive@hbase.apache.org Received: (qmail 82714 invoked by uid 500); 11 May 2014 11:40:25 -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 82706 invoked by uid 99); 11 May 2014 11:40:25 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 11 May 2014 11:40:25 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED,T_FILL_THIS_FORM_SHORT 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; Sun, 11 May 2014 11:40:24 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 0962223889F7; Sun, 11 May 2014 11:40:04 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1593777 - in /hbase/branches/0.96/hbase-server/src: main/java/org/apache/hadoop/hbase/snapshot/ExportSnapshot.java test/java/org/apache/hadoop/hbase/snapshot/TestExportSnapshot.java Date: Sun, 11 May 2014 11:40:03 -0000 To: commits@hbase.apache.org From: mbertozzi@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20140511114004.0962223889F7@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: mbertozzi Date: Sun May 11 11:40:03 2014 New Revision: 1593777 URL: http://svn.apache.org/r1593777 Log: HBASE-11128 Add -target option to ExportSnapshot to export with a different name Modified: hbase/branches/0.96/hbase-server/src/main/java/org/apache/hadoop/hbase/snapshot/ExportSnapshot.java hbase/branches/0.96/hbase-server/src/test/java/org/apache/hadoop/hbase/snapshot/TestExportSnapshot.java Modified: hbase/branches/0.96/hbase-server/src/main/java/org/apache/hadoop/hbase/snapshot/ExportSnapshot.java URL: http://svn.apache.org/viewvc/hbase/branches/0.96/hbase-server/src/main/java/org/apache/hadoop/hbase/snapshot/ExportSnapshot.java?rev=1593777&r1=1593776&r2=1593777&view=diff ============================================================================== --- hbase/branches/0.96/hbase-server/src/main/java/org/apache/hadoop/hbase/snapshot/ExportSnapshot.java (original) +++ hbase/branches/0.96/hbase-server/src/main/java/org/apache/hadoop/hbase/snapshot/ExportSnapshot.java Sun May 11 11:40:03 2014 @@ -661,6 +661,7 @@ public final class ExportSnapshot extend boolean verifyTarget = true; boolean verifyChecksum = true; String snapshotName = null; + String targetName = null; boolean overwrite = false; String filesGroup = null; String filesUser = null; @@ -676,6 +677,8 @@ public final class ExportSnapshot extend try { if (cmd.equals("-snapshot")) { snapshotName = args[++i]; + } else if (cmd.equals("-target")) { + targetName = args[++i]; } else if (cmd.equals("-copy-to")) { outputRoot = new Path(args[++i]); } else if (cmd.equals("-copy-from")) { @@ -719,6 +722,10 @@ public final class ExportSnapshot extend printUsageAndExit(); } + if (targetName == null) { + targetName = snapshotName; + } + Path inputRoot = FSUtils.getRootDir(conf); FileSystem inputFs = FileSystem.get(inputRoot.toUri(), conf); LOG.debug("inputFs=" + inputFs.getUri().toString() + " inputRoot=" + inputRoot); @@ -728,8 +735,8 @@ public final class ExportSnapshot extend boolean skipTmp = conf.getBoolean(CONF_SKIP_TMP, false); Path snapshotDir = SnapshotDescriptionUtils.getCompletedSnapshotDir(snapshotName, inputRoot); - Path snapshotTmpDir = SnapshotDescriptionUtils.getWorkingSnapshotDir(snapshotName, outputRoot); - Path outputSnapshotDir = SnapshotDescriptionUtils.getCompletedSnapshotDir(snapshotName, outputRoot); + Path snapshotTmpDir = SnapshotDescriptionUtils.getWorkingSnapshotDir(targetName, outputRoot); + Path outputSnapshotDir = SnapshotDescriptionUtils.getCompletedSnapshotDir(targetName, outputRoot); Path initialOutputSnapshotDir = skipTmp ? outputSnapshotDir : snapshotTmpDir; // Check if the snapshot already exists @@ -740,7 +747,7 @@ public final class ExportSnapshot extend return 1; } } else { - System.err.println("The snapshot '" + snapshotName + + System.err.println("The snapshot '" + targetName + "' already exists in the destination: " + outputSnapshotDir); return 1; } @@ -755,7 +762,7 @@ public final class ExportSnapshot extend return 1; } } else { - System.err.println("A snapshot with the same name '"+snapshotName+"' may be in-progress"); + System.err.println("A snapshot with the same name '"+ targetName +"' may be in-progress"); System.err.println("Please check "+snapshotTmpDir+". If the snapshot has completed, "); System.err.println("consider removing "+snapshotTmpDir+" by using the -overwrite option"); return 1; @@ -782,6 +789,16 @@ public final class ExportSnapshot extend snapshotDir + " to=" + initialOutputSnapshotDir, e); } + // Write a new .snapshotinfo if the target name is different from the source name + if (!targetName.equals(snapshotName)) { + SnapshotDescription snapshotDesc = + SnapshotDescriptionUtils.readSnapshotInfo(inputFs, snapshotDir) + .toBuilder() + .setName(targetName) + .build(); + SnapshotDescriptionUtils.writeSnapshotInfo(snapshotDesc, snapshotTmpDir, outputFs); + } + // Step 2 - Start MR Job to copy files // The snapshot references must be copied before the files otherwise the files gets removed // by the HFileArchiver, since they have no references. @@ -809,7 +826,7 @@ public final class ExportSnapshot extend verifySnapshot(conf, outputFs, outputRoot, outputSnapshotDir); } - LOG.info("Export Completed: " + snapshotName); + LOG.info("Export Completed: " + targetName); return 0; } catch (Exception e) { LOG.error("Snapshot export failed", e); Modified: hbase/branches/0.96/hbase-server/src/test/java/org/apache/hadoop/hbase/snapshot/TestExportSnapshot.java URL: http://svn.apache.org/viewvc/hbase/branches/0.96/hbase-server/src/test/java/org/apache/hadoop/hbase/snapshot/TestExportSnapshot.java?rev=1593777&r1=1593776&r2=1593777&view=diff ============================================================================== --- hbase/branches/0.96/hbase-server/src/test/java/org/apache/hadoop/hbase/snapshot/TestExportSnapshot.java (original) +++ hbase/branches/0.96/hbase-server/src/test/java/org/apache/hadoop/hbase/snapshot/TestExportSnapshot.java Sun May 11 11:40:03 2014 @@ -118,7 +118,7 @@ public class TestExportSnapshot { // Add some rows HTable table = new HTable(TEST_UTIL.getConfiguration(), tableName); - SnapshotTestingUtils.loadData(TEST_UTIL, tableName, 1000, FAMILY); + SnapshotTestingUtils.loadData(TEST_UTIL, tableName, 500, FAMILY); // take a snapshot admin.snapshot(snapshotName, tableName); @@ -174,28 +174,34 @@ public class TestExportSnapshot { */ @Test public void testExportFileSystemState() throws Exception { - testExportFileSystemState(tableName, snapshotName, 2); + testExportFileSystemState(tableName, snapshotName, snapshotName, 2); } @Test public void testExportFileSystemStateWithSkipTmp() throws Exception { TEST_UTIL.getConfiguration().setBoolean(ExportSnapshot.CONF_SKIP_TMP, true); - testExportFileSystemState(tableName, snapshotName, 2); + testExportFileSystemState(tableName, snapshotName, snapshotName, 2); } @Test public void testEmptyExportFileSystemState() throws Exception { - testExportFileSystemState(tableName, emptySnapshotName, 1); + testExportFileSystemState(tableName, emptySnapshotName, emptySnapshotName, 1); } @Test public void testConsecutiveExports() throws Exception { Path copyDir = getLocalDestinationDir(); - testExportFileSystemState(tableName, snapshotName, 2, copyDir, false); - testExportFileSystemState(tableName, snapshotName, 2, copyDir, true); + testExportFileSystemState(tableName, snapshotName, snapshotName, 2, copyDir, false); + testExportFileSystemState(tableName, snapshotName, snapshotName, 2, copyDir, true); removeExportDir(copyDir); } + @Test + public void testExportWithTargetName() throws Exception { + final byte[] targetName = Bytes.toBytes("testExportWithTargetName"); + testExportFileSystemState(tableName, snapshotName, targetName, 2); + } + /** * Mock a snapshot with files in the archive dir, * two regions, and one reference file. @@ -244,13 +250,14 @@ public class TestExportSnapshot { FileUtil.copy(fs, tableDir, fs, snapshotDir, false, conf); SnapshotDescriptionUtils.writeSnapshotInfo(sd, snapshotDir, fs); - testExportFileSystemState(tableWithRefsName, Bytes.toBytes(snapshotName), 2); + byte[] name = Bytes.toBytes(snapshotName); + testExportFileSystemState(tableWithRefsName, name, name, 2); } private void testExportFileSystemState(final TableName tableName, final byte[] snapshotName, - int filesExpected) throws Exception { + final byte[] targetName, int filesExpected) throws Exception { Path copyDir = getHdfsDestinationDir(); - testExportFileSystemState(tableName, snapshotName, filesExpected, copyDir, false); + testExportFileSystemState(tableName, snapshotName, targetName, filesExpected, copyDir, false); removeExportDir(copyDir); } @@ -258,7 +265,8 @@ public class TestExportSnapshot { * Test ExportSnapshot */ private void testExportFileSystemState(final TableName tableName, final byte[] snapshotName, - int filesExpected, Path copyDir, boolean overwrite) throws Exception { + final byte[] targetName, int filesExpected, Path copyDir, boolean overwrite) + throws Exception { URI hdfsUri = FileSystem.get(TEST_UTIL.getConfiguration()).getUri(); FileSystem fs = FileSystem.get(copyDir.toUri(), new Configuration()); copyDir = copyDir.makeQualified(fs); @@ -268,6 +276,10 @@ public class TestExportSnapshot { opts.add(Bytes.toString(snapshotName)); opts.add("-copy-to"); opts.add(copyDir.toString()); + if (targetName != snapshotName) { + opts.add("-target"); + opts.add(Bytes.toString(targetName)); + } if (overwrite) opts.add("-overwrite"); // Export Snapshot @@ -288,9 +300,10 @@ public class TestExportSnapshot { // compare the snapshot metadata and verify the hfiles final FileSystem hdfs = FileSystem.get(hdfsUri, TEST_UTIL.getConfiguration()); final Path snapshotDir = new Path(HConstants.SNAPSHOT_DIR_NAME, Bytes.toString(snapshotName)); + final Path targetDir = new Path(HConstants.SNAPSHOT_DIR_NAME, Bytes.toString(targetName)); verifySnapshot(hdfs, new Path(TEST_UTIL.getDefaultRootDirPath(), snapshotDir), - fs, new Path(copyDir, snapshotDir)); - verifyArchive(fs, copyDir, tableName, Bytes.toString(snapshotName)); + fs, new Path(copyDir, targetDir)); + verifyArchive(fs, copyDir, tableName, Bytes.toString(targetName)); FSUtils.logFileSystemState(hdfs, snapshotDir, LOG); } @@ -377,6 +390,11 @@ public class TestExportSnapshot { assertTrue(path + " should not be empty", fs.getFileStatus(path).getLen() > 0); } }); + + // Verify Snapshot description + SnapshotDescription desc = SnapshotDescriptionUtils.readSnapshotInfo(fs, exportedSnapshot); + assertTrue(desc.getName().equals(snapshotName)); + assertTrue(desc.getTable().equals(tableName.getNameAsString())); } private Set listFiles(final FileSystem fs, final Path root, final Path dir)