HDFS-14148. HDFS OIV ReverseXML SnapshotSection parser throws exception when there are more than one snapshottable directory (#1274) Contributed by Siyao Meng.

(cherry picked from commit c92b49876a)
This commit is contained in:
Siyao Meng 2019-08-12 17:26:20 -07:00 committed by Wei-Chiu Chuang
parent c5aea8ca56
commit c5f433b11f
2 changed files with 15 additions and 3 deletions

View File

@ -1353,9 +1353,11 @@ class OfflineImageReconstructor {
if (sd == null) {
break;
}
Long dir = sd.removeChildLong(SNAPSHOT_SECTION_DIR);
sd.verifyNoRemainingKeys("<dir>");
bld.addSnapshottableDir(dir);
Long dir;
while ((dir = sd.removeChildLong(SNAPSHOT_SECTION_DIR)) != null) {
// Add all snapshottable directories, one by one
bld.addSnapshottableDir(dir);
}
}
header.verifyNoRemainingKeys("SnapshotSection");
bld.build().writeDelimitedTo(out);

View File

@ -269,6 +269,16 @@ public class TestOfflineImageViewer {
hdfs.truncate(file1, 1);
writtenFiles.put(file1.toString(), hdfs.getFileStatus(file1));
// HDFS-14148: Create a second snapshot-enabled directory. This can cause
// TestOfflineImageViewer#testReverseXmlRoundTrip to fail before the patch
final Path snapshotDir2 = new Path("/snapshotDir2");
hdfs.mkdirs(snapshotDir2);
// Simply enable snapshot on it, no need to create one
hdfs.allowSnapshot(snapshotDir2);
dirCount++;
writtenFiles.put(snapshotDir2.toString(),
hdfs.getFileStatus(snapshotDir2));
// Set XAttrs so the fsimage contains XAttr ops
final Path xattr = new Path("/xattr");
hdfs.mkdirs(xattr);