Skip to content

Commit

Permalink
HDFS-15987. Improve oiv tool to parse fsimage file in parallel with d…
Browse files Browse the repository at this point in the history
…elimited format. (apache#2918). Contributed by Hongbing Wang.

Signed-off-by: He Xiaoqiao <hexiaoqiao@apache.org>
  • Loading branch information
Hexiaoqiao authored and HarshitGupta11 committed Nov 28, 2022
1 parent 3244e67 commit b2bec77
Show file tree
Hide file tree
Showing 6 changed files with 306 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ public class OfflineImageViewerPB {
+ " Delimited outputs. If not set, the processor\n"
+ " constructs the namespace in memory \n"
+ " before outputting text.\n"
+ "-m,--multiThread <arg> Use multiThread to process sub-sections.\n"
+ "-h,--help Display usage information and exit\n";

/**
Expand All @@ -132,6 +133,7 @@ private static Options buildOptions() {
options.addOption("delimiter", true, "");
options.addOption("sp", false, "");
options.addOption("t", "temp", true, "");
options.addOption("m", "multiThread", true, "");

return options;
}
Expand Down Expand Up @@ -185,6 +187,7 @@ public static int run(String[] args) throws Exception {
String delimiter = cmd.getOptionValue("delimiter",
PBImageTextWriter.DEFAULT_DELIMITER);
String tempPath = cmd.getOptionValue("t", "");
int threads = Integer.parseInt(cmd.getOptionValue("m", "1"));

Configuration conf = new Configuration();
PrintStream out = null;
Expand Down Expand Up @@ -227,15 +230,14 @@ public static int run(String[] args) throws Exception {
boolean printStoragePolicy = cmd.hasOption("sp");
try (PBImageDelimitedTextWriter writer =
new PBImageDelimitedTextWriter(out, delimiter,
tempPath, printStoragePolicy);
RandomAccessFile r = new RandomAccessFile(inputFile, "r")) {
writer.visit(r);
tempPath, printStoragePolicy, threads, outputFile)) {
writer.visit(inputFile);
}
break;
case "DETECTCORRUPTION":
try (PBImageCorruptionDetector detector =
new PBImageCorruptionDetector(out, delimiter, tempPath)) {
detector.visit(new RandomAccessFile(inputFile, "r"));
detector.visit(inputFile);
}
break;
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ public void afterOutput() throws IOException {
if (parentId != -1) {
entryBuilder.setParentId(parentId);
}
printIfNotEmpty(entryBuilder.build());
printIfNotEmpty(serialOutStream(), entryBuilder.build());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,13 @@ public String build() {
PBImageDelimitedTextWriter(PrintStream out, String delimiter,
String tempPath, boolean printStoragePolicy)
throws IOException {
super(out, delimiter, tempPath);
this(out, delimiter, tempPath, printStoragePolicy, 1, "-");
}

PBImageDelimitedTextWriter(PrintStream out, String delimiter,
String tempPath, boolean printStoragePolicy, int threads,
String parallelOut) throws IOException {
super(out, delimiter, tempPath, threads, parallelOut);
this.printStoragePolicy = printStoragePolicy;
}

Expand Down
Loading

0 comments on commit b2bec77

Please sign in to comment.