HDFS-11112. Journal Nodes should refuse to format non-empty directories. Contributed by Yiqun Lin.
This commit is contained in:
parent
2f4cf07fb1
commit
b64d9093e1
|
@ -180,7 +180,14 @@ class JNStorage extends Storage {
|
|||
}
|
||||
|
||||
void format(NamespaceInfo nsInfo) throws IOException {
|
||||
unlockAll();
|
||||
try {
|
||||
sd.analyzeStorage(StartupOption.FORMAT, this, true);
|
||||
} finally {
|
||||
sd.unlock();
|
||||
}
|
||||
setStorageInfo(nsInfo);
|
||||
|
||||
LOG.info("Formatting journal " + sd + " with nsid: " + getNamespaceID());
|
||||
// Unlock the directory before formatting, because we will
|
||||
// re-analyze it after format(). The analyzeStorage() call
|
||||
|
|
|
@ -495,7 +495,7 @@ public abstract class Storage extends StorageInfo {
|
|||
Files.newDirectoryStream(currentDir.toPath())) {
|
||||
if (dirStream.iterator().hasNext()) {
|
||||
throw new InconsistentFSStateException(root,
|
||||
"Can't format the storage directory because the current/ "
|
||||
"Can't format the storage directory because the current "
|
||||
+ "directory is not empty.");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -204,6 +204,9 @@ public class TestJournal {
|
|||
|
||||
// Close the journal in preparation for reformatting it.
|
||||
journal.close();
|
||||
// Clear the storage directory before reformatting it
|
||||
journal.getStorage().getJournalManager()
|
||||
.getStorageDirectory().clearDirectory();
|
||||
journal.format(FAKE_NSINFO_2);
|
||||
|
||||
assertEquals(0, journal.getLastPromisedEpoch());
|
||||
|
@ -417,4 +420,18 @@ public class TestJournal {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFormatNonEmptyStorageDirectories() throws Exception {
|
||||
try {
|
||||
// Format again here and to format the non-empty directories in
|
||||
// journal node.
|
||||
journal.format(FAKE_NSINFO);
|
||||
fail("Did not fail to format non-empty directories in journal node.");
|
||||
} catch (IOException ioe) {
|
||||
GenericTestUtils.assertExceptionContains(
|
||||
"Can't format the storage directory because the current "
|
||||
+ "directory is not empty.", ioe);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue