@Override public TransactionSnapshot getLatestSnapshot() throws IOException { InputStream in = getLatestSnapshotInputStream(); if (in == null) { return null; } try { return readSnapshotInputStream(in); } finally { in.close(); } }
@Override public TransactionLog createLog(long timestamp) throws IOException { Path newLog = new Path(snapshotDir, LOG_FILE_PREFIX + timestamp); return openLog(newLog, timestamp); }
private static void printUsage(String message) { printUsage(message, 0); }
@Override public TransactionVisibilityState getLatestTransactionVisibilityState() throws IOException { InputStream in = getLatestSnapshotInputStream(); if (in == null) { return null; } try { return readTransactionVisibilityStateFromInputStream(in); } finally { in.close(); } }
mode = CLIMode.TXLOG; } else if ("-h".equals(arg)) { printUsage(null); } else { filenames.add(arg); printUsage("ERROR: Either -s or -l is required to set mode.", 1); new HDFSTransactionStateStorage(config, new SnapshotCodecProvider(config), new TxMetricsCollector()); storage.startAndWait(); try { switch (mode) { try { if (filenames.isEmpty()) { TransactionSnapshot snapshot = storage.getLatestSnapshot(); printSnapshot(snapshot); TransactionSnapshot snapshot = storage.readSnapshotFile(path); printSnapshot(snapshot); System.out.println(); case TXLOG: if (filenames.isEmpty()) { printUsage("ERROR: At least one transaction log filename is required!", 1); TransactionLog log = storage.openLog(timestampedFilename.getPath(), timestampedFilename.getTimestamp()); printLog(log); System.out.println();
/** * Try to initialize the Configuration and TransactionStateStorage instances. Obtaining the Configuration may * fail until ReactorServiceMain has been started. */ private void tryInit() { try { Configuration conf = getSnapshotConfiguration(); if (conf != null) { // Since this is only used for background loading of transaction snapshots, we use the no-op metrics collector, // as there are no relevant metrics to report this.storage = new HDFSTransactionStateStorage(conf, new SnapshotCodecProvider(conf), new TxMetricsCollector()); this.storage.startAndWait(); this.snapshotRefreshFrequency = conf.getLong(TxConstants.Manager.CFG_TX_SNAPSHOT_INTERVAL, TxConstants.Manager.DEFAULT_TX_SNAPSHOT_INTERVAL) * 1000; this.initialized = true; } else { LOG.info("Could not load configuration"); } } catch (Exception e) { LOG.info("Failed to initialize TransactionStateCache due to: " + e.getMessage()); } }
private InputStream getLatestSnapshotInputStream() throws IOException { TimestampedFilename[] snapshots = listSnapshotFiles(); Arrays.sort(snapshots); if (snapshots.length > 0) { // last is the most recent return fs.open(snapshots[snapshots.length - 1].getPath(), BUFFER_SIZE); } LOG.info("No snapshot files found in {}", snapshotDir); return null; }
private TransactionSnapshot readSnapshotFile(Path filePath) throws IOException { FSDataInputStream in = fs.open(filePath, BUFFER_SIZE); try { return readSnapshotInputStream(in); } finally { in.close(); } }
mode = CLIMode.TXLOG; } else if ("-h".equals(arg)) { printUsage(null); } else { filenames.add(arg); printUsage("ERROR: Either -s or -l is required to set mode.", 1); new HDFSTransactionStateStorage(config, new SnapshotCodecProvider(config), new TxMetricsCollector()); storage.startAndWait(); try { switch (mode) { try { if (filenames.isEmpty()) { TransactionSnapshot snapshot = storage.getLatestSnapshot(); printSnapshot(snapshot); TransactionSnapshot snapshot = storage.readSnapshotFile(path); printSnapshot(snapshot); System.out.println(); case TXLOG: if (filenames.isEmpty()) { printUsage("ERROR: At least one transaction log filename is required!", 1); TransactionLog log = storage.openLog(timestampedFilename.getPath(), timestampedFilename.getTimestamp()); printLog(log); System.out.println();
/** * Try to initialize the Configuration and TransactionStateStorage instances. Obtaining the Configuration may * fail until ReactorServiceMain has been started. */ private void tryInit() { try { Configuration conf = getSnapshotConfiguration(); if (conf != null) { // Since this is only used for background loading of transaction snapshots, we use the no-op metrics collector, // as there are no relevant metrics to report this.storage = new HDFSTransactionStateStorage(conf, new SnapshotCodecProvider(conf), new TxMetricsCollector()); this.storage.startAndWait(); this.snapshotRefreshFrequency = conf.getLong(TxConstants.Manager.CFG_TX_SNAPSHOT_INTERVAL, TxConstants.Manager.DEFAULT_TX_SNAPSHOT_INTERVAL) * 1000; this.initialized = true; } else { LOG.info("Could not load configuration"); } } catch (Exception e) { LOG.info("Failed to initialize TransactionStateCache due to: " + e.getMessage()); } }
@Override public TransactionVisibilityState getLatestTransactionVisibilityState() throws IOException { InputStream in = getLatestSnapshotInputStream(); if (in == null) { return null; } try { return readTransactionVisibilityStateFromInputStream(in); } finally { in.close(); } }
private InputStream getLatestSnapshotInputStream() throws IOException { TimestampedFilename[] snapshots = listSnapshotFiles(); Arrays.sort(snapshots); if (snapshots.length > 0) { // last is the most recent return fs.open(snapshots[snapshots.length - 1].getPath(), BUFFER_SIZE); } LOG.info("No snapshot files found in {}", snapshotDir); return null; }
private TransactionSnapshot readSnapshotFile(Path filePath) throws IOException { FSDataInputStream in = fs.open(filePath, BUFFER_SIZE); try { return readSnapshotInputStream(in); } finally { in.close(); } }
@Override protected AbstractTransactionStateStorage getStorage(Configuration conf) { return new HDFSTransactionStateStorage(conf, new SnapshotCodecProvider(conf), new TxMetricsCollector()); } }
@Override public TransactionSnapshot getLatestSnapshot() throws IOException { InputStream in = getLatestSnapshotInputStream(); if (in == null) { return null; } try { return readSnapshotInputStream(in); } finally { in.close(); } }
@Override public long deleteOldSnapshots(int numberToKeep) throws IOException { TimestampedFilename[] snapshots = listSnapshotFiles(); if (snapshots.length == 0) { return -1; } Arrays.sort(snapshots, Collections.reverseOrder()); if (snapshots.length <= numberToKeep) { // nothing to remove, oldest timestamp is the last snapshot return snapshots[snapshots.length - 1].getTimestamp(); } int toRemoveCount = snapshots.length - numberToKeep; TimestampedFilename[] toRemove = new TimestampedFilename[toRemoveCount]; System.arraycopy(snapshots, numberToKeep, toRemove, 0, toRemoveCount); for (TimestampedFilename f : toRemove) { LOG.debug("Removing old snapshot file {}", f.getPath()); fs.delete(f.getPath(), false); } long oldestTimestamp = snapshots[numberToKeep - 1].getTimestamp(); LOG.debug("Removed {} old snapshot files prior to {}", toRemoveCount, oldestTimestamp); return oldestTimestamp; }
@Override public TransactionLog createLog(long timestamp) throws IOException { Path newLog = new Path(snapshotDir, LOG_FILE_PREFIX + timestamp); return openLog(newLog, timestamp); }
private static void printUsage(String message) { printUsage(message, 0); }
@Override public long deleteOldSnapshots(int numberToKeep) throws IOException { TimestampedFilename[] snapshots = listSnapshotFiles(); if (snapshots.length == 0) { return -1; } Arrays.sort(snapshots, Collections.reverseOrder()); if (snapshots.length <= numberToKeep) { // nothing to remove, oldest timestamp is the last snapshot return snapshots[snapshots.length - 1].getTimestamp(); } int toRemoveCount = snapshots.length - numberToKeep; TimestampedFilename[] toRemove = new TimestampedFilename[toRemoveCount]; System.arraycopy(snapshots, numberToKeep, toRemove, 0, toRemoveCount); for (TimestampedFilename f : toRemove) { LOG.debug("Removing old snapshot file {}", f.getPath()); fs.delete(f.getPath(), false); } long oldestTimestamp = snapshots[numberToKeep - 1].getTimestamp(); LOG.debug("Removed {} old snapshot files prior to {}", toRemoveCount, oldestTimestamp); return oldestTimestamp; }