in tephra-core/src/main/java/org/apache/tephra/persist/HDFSTransactionStateStorage.java [393:454]
public static void main(String[] args) {
List<String> filenames = Lists.newArrayList();
CLIMode mode = null;
for (String arg : args) {
if ("-s".equals(arg)) {
mode = CLIMode.SNAPSHOT;
} else if ("-l".equals(arg)) {
mode = CLIMode.TXLOG;
} else if ("-h".equals(arg)) {
printUsage(null);
} else {
filenames.add(arg);
}
}
if (mode == null) {
printUsage("ERROR: Either -s or -l is required to set mode.", 1);
}
Configuration config = new ConfigurationFactory().get();
// Use the no-op metrics collector. We are being run as a command line tool, so there are no relevant metrics
// to report
HDFSTransactionStateStorage storage =
new HDFSTransactionStateStorage(config, new SnapshotCodecProvider(config), new TxMetricsCollector());
storage.startAndWait();
try {
switch (mode) {
case SNAPSHOT:
try {
if (filenames.isEmpty()) {
TransactionSnapshot snapshot = storage.getLatestSnapshot();
printSnapshot(snapshot);
}
for (String file : filenames) {
Path path = new Path(file);
TransactionSnapshot snapshot = storage.readSnapshotFile(path);
printSnapshot(snapshot);
System.out.println();
}
} catch (IOException ioe) {
System.err.println("Error reading snapshot files: " + ioe.getMessage());
ioe.printStackTrace();
System.exit(1);
}
break;
case TXLOG:
if (filenames.isEmpty()) {
printUsage("ERROR: At least one transaction log filename is required!", 1);
}
for (String file : filenames) {
TimestampedFilename timestampedFilename = new TimestampedFilename(new Path(file));
TransactionLog log = storage.openLog(timestampedFilename.getPath(), timestampedFilename.getTimestamp());
printLog(log);
System.out.println();
}
break;
}
} finally {
storage.stop();
}
}