Skip to content

Commit 8897549

Browse files
committed
HDFS-14617. Improve oiv tool to parse fsimage file in parallel with delimited format. (apache#2918). Contributed by Hongbing Wang.
Signed-off-by: He Xiaoqiao <hexiaoqiao@apache.org>
1 parent 708a0ce commit 8897549

File tree

6 files changed

+306
-42
lines changed

6 files changed

+306
-42
lines changed

hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/OfflineImageViewerPB.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ public class OfflineImageViewerPB {
107107
+ " Delimited outputs. If not set, the processor\n"
108108
+ " constructs the namespace in memory \n"
109109
+ " before outputting text.\n"
110+
+ "-m,--multiThread <arg> Use multiThread to process sub-sections.\n"
110111
+ "-h,--help Display usage information and exit\n";
111112

112113
/**
@@ -132,6 +133,7 @@ private static Options buildOptions() {
132133
options.addOption("delimiter", true, "");
133134
options.addOption("sp", false, "");
134135
options.addOption("t", "temp", true, "");
136+
options.addOption("m", "multiThread", true, "");
135137

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

189192
Configuration conf = new Configuration();
190193
PrintStream out = null;
@@ -227,15 +230,14 @@ public static int run(String[] args) throws Exception {
227230
boolean printStoragePolicy = cmd.hasOption("sp");
228231
try (PBImageDelimitedTextWriter writer =
229232
new PBImageDelimitedTextWriter(out, delimiter,
230-
tempPath, printStoragePolicy);
231-
RandomAccessFile r = new RandomAccessFile(inputFile, "r")) {
232-
writer.visit(r);
233+
tempPath, printStoragePolicy, threads, outputFile)) {
234+
writer.visit(inputFile);
233235
}
234236
break;
235237
case "DETECTCORRUPTION":
236238
try (PBImageCorruptionDetector detector =
237239
new PBImageCorruptionDetector(out, delimiter, tempPath)) {
238-
detector.visit(new RandomAccessFile(inputFile, "r"));
240+
detector.visit(inputFile);
239241
}
240242
break;
241243
default:

hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/PBImageCorruptionDetector.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ public void afterOutput() throws IOException {
337337
if (parentId != -1) {
338338
entryBuilder.setParentId(parentId);
339339
}
340-
printIfNotEmpty(entryBuilder.build());
340+
printIfNotEmpty(serialOutStream(), entryBuilder.build());
341341
}
342342
}
343343
}

hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/PBImageDelimitedTextWriter.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,13 @@ public String build() {
146146
PBImageDelimitedTextWriter(PrintStream out, String delimiter,
147147
String tempPath, boolean printStoragePolicy)
148148
throws IOException {
149-
super(out, delimiter, tempPath);
149+
this(out, delimiter, tempPath, printStoragePolicy, 1, "-");
150+
}
151+
152+
PBImageDelimitedTextWriter(PrintStream out, String delimiter,
153+
String tempPath, boolean printStoragePolicy, int threads,
154+
String parallelOut) throws IOException {
155+
super(out, delimiter, tempPath, threads, parallelOut);
150156
this.printStoragePolicy = printStoragePolicy;
151157
}
152158

0 commit comments

Comments
 (0)