HDFS-16437 ReverseXML processor doesn't accept XML files without the … (#3926)

(cherry picked from commit 125e3b6160)

Change-Id: I03e4f2af17f0e4a8245c9c2c8ea1cb2cb41f777a
This commit is contained in:
singer-bin 2022-02-06 13:05:57 +08:00 committed by Steve Loughran
parent a1c0673526
commit 980fab9168
No known key found for this signature in database
GPG Key ID: D22CF846DBB162A0
2 changed files with 42 additions and 4 deletions

View File

@ -1761,6 +1761,10 @@ class OfflineImageReconstructor {
XMLEvent ev = expectTag("[section header]", true); XMLEvent ev = expectTag("[section header]", true);
if (ev.getEventType() == XMLStreamConstants.END_ELEMENT) { if (ev.getEventType() == XMLStreamConstants.END_ELEMENT) {
if (ev.asEndElement().getName().getLocalPart().equals("fsimage")) { if (ev.asEndElement().getName().getLocalPart().equals("fsimage")) {
if(unprocessedSections.size() == 1 && unprocessedSections.contains
(SnapshotDiffSectionProcessor.NAME)){
break;
}
throw new IOException("FSImage XML ended prematurely, without " + throw new IOException("FSImage XML ended prematurely, without " +
"including section(s) " + StringUtils.join(", ", "including section(s) " + StringUtils.join(", ",
unprocessedSections)); unprocessedSections));

View File

@ -1122,17 +1122,17 @@ public class TestOfflineImageViewer {
LOG.info("Creating reverseImage.xml=" + reverseImageXml.getAbsolutePath() + LOG.info("Creating reverseImage.xml=" + reverseImageXml.getAbsolutePath() +
", reverseImage=" + reverseImage.getAbsolutePath() + ", reverseImage=" + reverseImage.getAbsolutePath() +
", reverseImage2Xml=" + reverseImage2Xml.getAbsolutePath()); ", reverseImage2Xml=" + reverseImage2Xml.getAbsolutePath());
if (OfflineImageViewerPB.run(new String[] { "-p", "XML", if (OfflineImageViewerPB.run(new String[] {"-p", "XML",
"-i", originalFsimage.getAbsolutePath(), "-i", originalFsimage.getAbsolutePath(),
"-o", reverseImageXml.getAbsolutePath() }) != 0) { "-o", reverseImageXml.getAbsolutePath() }) != 0) {
throw new IOException("oiv returned failure creating first XML file."); throw new IOException("oiv returned failure creating first XML file.");
} }
if (OfflineImageViewerPB.run(new String[] { "-p", "ReverseXML", if (OfflineImageViewerPB.run(new String[] {"-p", "ReverseXML",
"-i", reverseImageXml.getAbsolutePath(), "-i", reverseImageXml.getAbsolutePath(),
"-o", reverseImage.getAbsolutePath() }) != 0) { "-o", reverseImage.getAbsolutePath() }) != 0) {
throw new IOException("oiv returned failure recreating fsimage file."); throw new IOException("oiv returned failure recreating fsimage file.");
} }
if (OfflineImageViewerPB.run(new String[] { "-p", "XML", if (OfflineImageViewerPB.run(new String[] {"-p", "XML",
"-i", reverseImage.getAbsolutePath(), "-i", reverseImage.getAbsolutePath(),
"-o", reverseImage2Xml.getAbsolutePath() }) != 0) { "-o", reverseImage2Xml.getAbsolutePath() }) != 0) {
throw new IOException("oiv returned failure creating second " + throw new IOException("oiv returned failure creating second " +
@ -1141,7 +1141,7 @@ public class TestOfflineImageViewer {
// The XML file we wrote based on the re-created fsimage should be the // The XML file we wrote based on the re-created fsimage should be the
// same as the one we dumped from the original fsimage. // same as the one we dumped from the original fsimage.
Assert.assertEquals("", Assert.assertEquals("",
GenericTestUtils.getFilesDiff(reverseImageXml, reverseImage2Xml)); GenericTestUtils.getFilesDiff(reverseImageXml, reverseImage2Xml));
} }
/** /**
@ -1176,6 +1176,40 @@ public class TestOfflineImageViewer {
} }
} }
/**
* Tests that the ReverseXML processor doesn't accept XML files without the SnapshotDiffSection.
*/
@Test
public void testReverseXmlWithoutSnapshotDiffSection() throws Throwable {
File imageWSDS = new File(tempDir, "imageWithoutSnapshotDiffSection.xml");
try(PrintWriter writer = new PrintWriter(imageWSDS, "UTF-8")) {
writer.println("<?xml version=\"1.0\"?>");
writer.println("<fsimage>");
writer.println("<version>");
writer.println("<layoutVersion>-66</layoutVersion>");
writer.println("<onDiskVersion>1</onDiskVersion>");
writer.println("<oivRevision>545bbef596c06af1c3c8dca1ce29096a64608478</oivRevision>");
writer.println("</version>");
writer.println("<FileUnderConstructionSection></FileUnderConstructionSection>");
writer.println("<ErasureCodingSection></ErasureCodingSection>");
writer.println("<INodeSection><lastInodeId>91488</lastInodeId><numInodes>0</numInodes>" +
"</INodeSection>");
writer.println("<SecretManagerSection><currentId>90</currentId><tokenSequenceNumber>35" +
"</tokenSequenceNumber><numDelegationKeys>0</numDelegationKeys><numTokens>0" +
"</numTokens></SecretManagerSection>");
writer.println("<INodeReferenceSection></INodeReferenceSection>");
writer.println("<SnapshotSection><snapshotCounter>0</snapshotCounter><numSnapshots>0" +
"</numSnapshots></SnapshotSection>");
writer.println("<NameSection><namespaceId>326384987</namespaceId></NameSection>");
writer.println("<CacheManagerSection><nextDirectiveId>1</nextDirectiveId><numPools>0" +
"</numPools><numDirectives>0</numDirectives></CacheManagerSection>");
writer.println("<INodeDirectorySection></INodeDirectorySection>");
writer.println("</fsimage>");
}
OfflineImageReconstructor.run(imageWSDS.getAbsolutePath(),
imageWSDS.getAbsolutePath() + ".out");
}
@Test @Test
public void testFileDistributionCalculatorForException() throws Exception { public void testFileDistributionCalculatorForException() throws Exception {
File fsimageFile = null; File fsimageFile = null;