Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1761,6 +1761,10 @@ private void processXml() throws Exception {
XMLEvent ev = expectTag("[section header]", true);
if (ev.getEventType() == XMLStreamConstants.END_ELEMENT) {
if (ev.asEndElement().getName().getLocalPart().equals("fsimage")) {
if(unprocessedSections.size() == 1 && unprocessedSections.contains
(SnapshotDiffSectionProcessor.NAME)){
break;
}
throw new IOException("FSImage XML ended prematurely, without " +
"including section(s) " + StringUtils.join(", ",
unprocessedSections));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1120,17 +1120,17 @@ public void testReverseXmlRoundTrip() throws Throwable {
LOG.info("Creating reverseImage.xml=" + reverseImageXml.getAbsolutePath() +
", reverseImage=" + reverseImage.getAbsolutePath() +
", reverseImage2Xml=" + reverseImage2Xml.getAbsolutePath());
if (OfflineImageViewerPB.run(new String[] { "-p", "XML",
if (OfflineImageViewerPB.run(new String[] {"-p", "XML",
"-i", originalFsimage.getAbsolutePath(),
"-o", reverseImageXml.getAbsolutePath() }) != 0) {
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(),
"-o", reverseImage.getAbsolutePath() }) != 0) {
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(),
"-o", reverseImage2Xml.getAbsolutePath() }) != 0) {
throw new IOException("oiv returned failure creating second " +
Expand All @@ -1139,7 +1139,7 @@ public void testReverseXmlRoundTrip() throws Throwable {
// The XML file we wrote based on the re-created fsimage should be the
// same as the one we dumped from the original fsimage.
Assert.assertEquals("",
GenericTestUtils.getFilesDiff(reverseImageXml, reverseImage2Xml));
GenericTestUtils.getFilesDiff(reverseImageXml, reverseImage2Xml));
}

/**
Expand Down Expand Up @@ -1174,6 +1174,40 @@ public void testReverseXmlWrongLayoutVersion() throws Throwable {
}
}

/**
* 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>-67</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
public void testFileDistributionCalculatorForException() throws Exception {
File fsimageFile = null;
Expand Down