private boolean askForFix(Scanner scanner) throws TxnLogToolkitException { while (true) { System.out.print("Would you like to fix it (Yes/No/Abort) ? "); char answer = Character.toUpperCase(scanner.next().charAt(0)); switch (answer) { case 'Y': return true; case 'N': return false; case 'A': throw new TxnLogToolkitException(0, "Recovery aborted."); } } }
fhdr.deserialize(logStream, "fileheader"); if (fhdr.getMagic() != TXNLOG_MAGIC) { throw new TxnLogToolkitException(2, "Invalid magic number for %s", txnLogFile.getName()); throw new TxnLogToolkitException(1, "Last transaction was partial.");
fhdr.deserialize(logStream, "fileheader"); if (fhdr.getMagic() != TXNLOG_MAGIC) { throw new TxnLogToolkitException(ExitCode.INVALID_INVOCATION.getValue(), "Invalid magic number for %s", txnLogFile.getName()); throw new TxnLogToolkitException(ExitCode.UNEXPECTED_ERROR.getValue(), "Last transaction was partial.");
public TxnLogToolkit(boolean recoveryMode, boolean verbose, String txnLogFileName, boolean force) throws FileNotFoundException, TxnLogToolkitException { this.recoveryMode = recoveryMode; this.verbose = verbose; this.force = force; txnLogFile = new File(txnLogFileName); if (!txnLogFile.exists() || !txnLogFile.canRead()) { throw new TxnLogToolkitException(1, "File doesn't exist or not readable: %s", txnLogFile); } if (recoveryMode) { recoveryLogFile = new File(txnLogFile.toString() + ".fixed"); if (recoveryLogFile.exists()) { throw new TxnLogToolkitException(1, "Recovery file %s already exists or not writable", recoveryLogFile); } } openTxnLogFile(); if (recoveryMode) { openRecoveryFile(); } }
/** * @param args Command line arguments */ public static void main(String[] args) throws Exception { final TxnLogToolkit lt = parseCommandLine(args); try { lt.dump(new Scanner(System.in)); lt.printStat(); } catch (TxnLogToolkitParseException e) { System.err.println(e.getMessage() + "\n"); printHelpAndExit(e.getExitCode()); } catch (TxnLogToolkitException e) { System.err.println(e.getMessage()); System.exit(e.getExitCode()); } finally { lt.close(); } }
/** * @param args Command line arguments */ public static void main(String[] args) throws Exception { try (final TxnLogToolkit lt = parseCommandLine(args)) { if (lt.isDumpMode()) { lt.dump(new Scanner(System.in)); lt.printStat(); } else { lt.chop(); } } catch (TxnLogToolkitParseException e) { System.err.println(e.getMessage() + "\n"); printHelpAndExit(e.getExitCode(), e.getOptions()); } catch (TxnLogToolkitException e) { System.err.println(e.getMessage()); System.exit(e.getExitCode()); } }
public TxnLogToolkit(boolean recoveryMode, boolean verbose, String txnLogFileName, boolean force) throws FileNotFoundException, TxnLogToolkitException { this.recoveryMode = recoveryMode; this.verbose = verbose; this.force = force; txnLogFile = loadTxnFile(txnLogFileName); if (recoveryMode) { recoveryLogFile = new File(txnLogFile.toString() + ".fixed"); if (recoveryLogFile.exists()) { throw new TxnLogToolkitException(ExitCode.UNEXPECTED_ERROR.getValue(), "Recovery file %s already exists or not writable", recoveryLogFile); } } openTxnLogFile(); if (recoveryMode) { openRecoveryFile(); } }
private boolean askForFix(Scanner scanner) throws TxnLogToolkitException { while (true) { System.out.print("Would you like to fix it (Yes/No/Abort) ? "); char answer = Character.toUpperCase(scanner.next().charAt(0)); switch (answer) { case 'Y': return true; case 'N': return false; case 'A': throw new TxnLogToolkitException(ExitCode.EXECUTION_FINISHED.getValue(), "Recovery aborted."); } } }
public void chop() { File targetFile = new File(txnLogFile.getParentFile(), txnLogFile.getName() + ".chopped" + zxid); try ( InputStream is = new BufferedInputStream(new FileInputStream(txnLogFile)); OutputStream os = new BufferedOutputStream(new FileOutputStream(targetFile)) ) { if (!LogChopper.chop(is, os, zxid)) { throw new TxnLogToolkitException(ExitCode.INVALID_INVOCATION.getValue(), "Failed to chop %s", txnLogFile.getName()); } } catch (Exception e) { System.out.println("Got exception: " + e.getMessage()); } }
private File loadTxnFile(String txnLogFileName) throws TxnLogToolkitException { File logFile = new File(txnLogFileName); if (!logFile.exists() || !logFile.canRead()) { throw new TxnLogToolkitException(ExitCode.UNEXPECTED_ERROR.getValue(), "File doesn't exist or not readable: %s", logFile); } return logFile; }