From: <tho...@us...> - 2014-04-04 16:12:11
|
Revision: 8050 http://sourceforge.net/p/bigdata/code/8050 Author: thompsonbry Date: 2014-04-04 16:12:05 +0000 (Fri, 04 Apr 2014) Log Message: ----------- Modified the HARestoreUtility to optionally accept the name of the file onto which the most recent snapshot (or the specified snapshot) will be decompressed. This is to support automatic restore scenarios, e.g., to SSD on EC2 from EBS. Modified Paths: -------------- branches/BIGDATA_RELEASE_1_3_0/bigdata-jini/src/java/com/bigdata/journal/jini/ha/HARestore.java Modified: branches/BIGDATA_RELEASE_1_3_0/bigdata-jini/src/java/com/bigdata/journal/jini/ha/HARestore.java =================================================================== --- branches/BIGDATA_RELEASE_1_3_0/bigdata-jini/src/java/com/bigdata/journal/jini/ha/HARestore.java 2014-04-04 16:05:53 UTC (rev 8049) +++ branches/BIGDATA_RELEASE_1_3_0/bigdata-jini/src/java/com/bigdata/journal/jini/ha/HARestore.java 2014-04-04 16:12:05 UTC (rev 8050) @@ -48,8 +48,14 @@ /** * Utility class may be used to apply HALog files to a {@link Journal}, rolling - * it forward to a specific commit point. + * it forward to a specific commit point. This class can decompress a snapshot + * file for processing. It can also identify the most recent snapshot in the + * snapshot directory, and then decompress that snapshot for processing. When + * starting with a snapshot, the target journal file may be specified on the + * command line. * + * @see #main(String[]) + * * @author <a href="mailto:tho...@us...">Bryan Thompson</a> */ public class HARestore { @@ -384,17 +390,31 @@ * @param args * <code>[options] journalOrSnapshotFileOrSnapshotDir haLogDir</code> * <br> - * where <code>journalFile</code> is the name of the journal file<br> + * where <code>journalOrSnapshotFileOrSnapshotDir</code> is the + * name of the journal file (ending in <code>.jnl</code>), the + * name of a specific snapshot file (ending in + * <code>.jnl.gz</code>), or the name of the snapshot directory + * (this is generally a directory named <code>snapshot</code> + * that is a child of the service directory) <br> * where <code>haLogDir</code> is the name of a directory - * containing zero or more HALog files<br> + * containing zero or more HALog files (this is generally a + * directory name <code>HALog</code> that is a child of the + * service directory)<br> * where <code>options</code> are any of: * <dl> - * <dt>-l</dt> <dd>List available commit points, but do not apply + * <dt>-l</dt> + * <dd>List available commit points, but do not apply * them. This option provides information about the current * commit point on the journal and the commit points available in - * the HALog files.</dd> <dt>-h commitCounter</dt> <dd>The last - * commit counter that will be applied (halting point for - * restore).</dd> + * the HALog files.</dd> + * <dt>-h commitCounter</dt> + * <dd>The last commit counter that will be applied (halting + * point for restore).</dd> + * <dt>-o journalFile</dt> + * <dd>When restoring from a snapshot, this parameter specifies + * the name of the journal file to be created. It is an error + * if the file exists (this utility will not overwrite an existing + * journal file).</dd> * </dl> * * @return <code>0</code> iff the operation was fully successful. @@ -424,6 +444,8 @@ int i = 0; boolean listCommitPoints = false; + + String decompressTargetFile = null; // Defaults to Long.MAX_VALUE. long haltingCommitCounter = Long.MAX_VALUE; @@ -447,10 +469,16 @@ else if (arg.equals("-h")) { - haltingCommitCounter = Long.parseLong(args[i + 1]); + haltingCommitCounter = Long.parseLong(args[++i]); } + else if (arg.equals("-o")) { + + decompressTargetFile = args[++i]; + + } + else throw new RuntimeException("Unknown argument: " + arg); @@ -475,10 +503,12 @@ /* * File is a directory. * + * We assume that it is the snapshot directory. + * * Locate the most recent snapshot in that directory structure. */ - File tmp = CommitCounterUtility.findGreatestCommitCounter( + final File tmp = CommitCounterUtility.findGreatestCommitCounter( journalFile, SnapshotManager.SNAPSHOT_FILTER); if (tmp == null) { @@ -507,8 +537,8 @@ /* * File is a snapshot. * - * Decompress the snapshot onto a temporary file in the current - * working directory. + * Decompress the snapshot onto either a temporary file or the file + * specified by the caller (in which case the file must not exist). */ // source is the snapshot. @@ -517,10 +547,24 @@ final long commitCounter = SnapshotManager .parseCommitCounterFile(journalFile.getName()); - // temporary file in the same directory as the snapshot. - final File out = File.createTempFile("" + commitCounter + "-", - Journal.Options.JNL, journalFile.getAbsoluteFile() - .getParentFile()); + final File out; + if (decompressTargetFile == null) { + /* + * Temporary file in the current working directory + */ + out = File.createTempFile("restored-from-snapshot" + "-" + + commitCounter + "-", Journal.Options.JNL, journalFile + .getAbsoluteFile().getParentFile()); + } else { + /* + * Decompress onto a file specified by the caller. + */ + out = new File(decompressTargetFile); + if (out.exists()) { + // Do not decompress onto an existing file. + throw new IOException("File exists: " + out); + } + } System.out.println("Decompressing " + in + " to " + out); @@ -531,7 +575,9 @@ } - // Validate journal file. + /* + * Log some metadata about the journal file. + */ { System.out.println("Journal File: " + journalFile); @@ -559,6 +605,9 @@ } + /* + * Open the journal. + */ try { final Properties properties = new Properties(); @@ -579,6 +628,9 @@ try { + /* + * Apply zero or more HALog files to roll forward the journal. + */ final HARestore util = new HARestore(journal, haLogDir); util.restore(listCommitPoints, haltingCommitCounter); @@ -601,7 +653,7 @@ private static void usage(final String[] args) { - System.err.println("usage: (-l|-h commitPoint) <journalFile> haLogDir"); + System.err.println("usage: (-l|-h haltingCommitPoint|-o outputJournalFile) <journalFile|snapshotFile|snapshotDir> haLogDir"); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |