HDFS-5719. FSImage#doRollback() should close prevState before return. Contributed by Ted Yu
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1556057 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
8deb7a6057
commit
bfd227bf09
|
@ -465,6 +465,9 @@ Trunk (Unreleased)
|
||||||
HDFS-5705. TestSecondaryNameNodeUpgrade#testChangeNsIDFails may fail due
|
HDFS-5705. TestSecondaryNameNodeUpgrade#testChangeNsIDFails may fail due
|
||||||
to ConcurrentModificationException. (Ted Yu via brandonli)
|
to ConcurrentModificationException. (Ted Yu via brandonli)
|
||||||
|
|
||||||
|
HDFS-5719. FSImage#doRollback() should close prevState before return
|
||||||
|
(Ted Yu via brandonli)
|
||||||
|
|
||||||
BREAKDOWN OF HDFS-2832 SUBTASKS AND RELATED JIRAS
|
BREAKDOWN OF HDFS-2832 SUBTASKS AND RELATED JIRAS
|
||||||
|
|
||||||
HDFS-4985. Add storage type to the protocol and expose it in block report
|
HDFS-4985. Add storage type to the protocol and expose it in block report
|
||||||
|
|
|
@ -405,60 +405,64 @@ public class FSImage implements Closeable {
|
||||||
// Directories that don't have previous state do not rollback
|
// Directories that don't have previous state do not rollback
|
||||||
boolean canRollback = false;
|
boolean canRollback = false;
|
||||||
FSImage prevState = new FSImage(conf);
|
FSImage prevState = new FSImage(conf);
|
||||||
prevState.getStorage().layoutVersion = HdfsConstants.LAYOUT_VERSION;
|
try {
|
||||||
for (Iterator<StorageDirectory> it = storage.dirIterator(); it.hasNext();) {
|
prevState.getStorage().layoutVersion = HdfsConstants.LAYOUT_VERSION;
|
||||||
StorageDirectory sd = it.next();
|
for (Iterator<StorageDirectory> it = storage.dirIterator(); it.hasNext();) {
|
||||||
File prevDir = sd.getPreviousDir();
|
StorageDirectory sd = it.next();
|
||||||
if (!prevDir.exists()) { // use current directory then
|
File prevDir = sd.getPreviousDir();
|
||||||
LOG.info("Storage directory " + sd.getRoot()
|
if (!prevDir.exists()) { // use current directory then
|
||||||
+ " does not contain previous fs state.");
|
LOG.info("Storage directory " + sd.getRoot()
|
||||||
// read and verify consistency with other directories
|
+ " does not contain previous fs state.");
|
||||||
storage.readProperties(sd);
|
// read and verify consistency with other directories
|
||||||
continue;
|
storage.readProperties(sd);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// read and verify consistency of the prev dir
|
||||||
|
prevState.getStorage().readPreviousVersionProperties(sd);
|
||||||
|
|
||||||
|
if (prevState.getLayoutVersion() != HdfsConstants.LAYOUT_VERSION) {
|
||||||
|
throw new IOException(
|
||||||
|
"Cannot rollback to storage version " +
|
||||||
|
prevState.getLayoutVersion() +
|
||||||
|
" using this version of the NameNode, which uses storage version " +
|
||||||
|
HdfsConstants.LAYOUT_VERSION + ". " +
|
||||||
|
"Please use the previous version of HDFS to perform the rollback.");
|
||||||
|
}
|
||||||
|
canRollback = true;
|
||||||
}
|
}
|
||||||
|
if (!canRollback)
|
||||||
|
throw new IOException("Cannot rollback. None of the storage "
|
||||||
|
+ "directories contain previous fs state.");
|
||||||
|
|
||||||
// read and verify consistency of the prev dir
|
// Now that we know all directories are going to be consistent
|
||||||
prevState.getStorage().readPreviousVersionProperties(sd);
|
// Do rollback for each directory containing previous state
|
||||||
|
for (Iterator<StorageDirectory> it = storage.dirIterator(); it.hasNext();) {
|
||||||
|
StorageDirectory sd = it.next();
|
||||||
|
File prevDir = sd.getPreviousDir();
|
||||||
|
if (!prevDir.exists())
|
||||||
|
continue;
|
||||||
|
|
||||||
if (prevState.getLayoutVersion() != HdfsConstants.LAYOUT_VERSION) {
|
LOG.info("Rolling back storage directory " + sd.getRoot()
|
||||||
throw new IOException(
|
+ ".\n new LV = " + prevState.getStorage().getLayoutVersion()
|
||||||
"Cannot rollback to storage version " +
|
+ "; new CTime = " + prevState.getStorage().getCTime());
|
||||||
prevState.getLayoutVersion() +
|
File tmpDir = sd.getRemovedTmp();
|
||||||
" using this version of the NameNode, which uses storage version " +
|
assert !tmpDir.exists() : "removed.tmp directory must not exist.";
|
||||||
HdfsConstants.LAYOUT_VERSION + ". " +
|
// rename current to tmp
|
||||||
"Please use the previous version of HDFS to perform the rollback.");
|
File curDir = sd.getCurrentDir();
|
||||||
|
assert curDir.exists() : "Current directory must exist.";
|
||||||
|
NNStorage.rename(curDir, tmpDir);
|
||||||
|
// rename previous to current
|
||||||
|
NNStorage.rename(prevDir, curDir);
|
||||||
|
|
||||||
|
// delete tmp dir
|
||||||
|
NNStorage.deleteDir(tmpDir);
|
||||||
|
LOG.info("Rollback of " + sd.getRoot()+ " is complete.");
|
||||||
}
|
}
|
||||||
canRollback = true;
|
isUpgradeFinalized = true;
|
||||||
|
} finally {
|
||||||
|
prevState.close();
|
||||||
}
|
}
|
||||||
if (!canRollback)
|
|
||||||
throw new IOException("Cannot rollback. None of the storage "
|
|
||||||
+ "directories contain previous fs state.");
|
|
||||||
|
|
||||||
// Now that we know all directories are going to be consistent
|
|
||||||
// Do rollback for each directory containing previous state
|
|
||||||
for (Iterator<StorageDirectory> it = storage.dirIterator(); it.hasNext();) {
|
|
||||||
StorageDirectory sd = it.next();
|
|
||||||
File prevDir = sd.getPreviousDir();
|
|
||||||
if (!prevDir.exists())
|
|
||||||
continue;
|
|
||||||
|
|
||||||
LOG.info("Rolling back storage directory " + sd.getRoot()
|
|
||||||
+ ".\n new LV = " + prevState.getStorage().getLayoutVersion()
|
|
||||||
+ "; new CTime = " + prevState.getStorage().getCTime());
|
|
||||||
File tmpDir = sd.getRemovedTmp();
|
|
||||||
assert !tmpDir.exists() : "removed.tmp directory must not exist.";
|
|
||||||
// rename current to tmp
|
|
||||||
File curDir = sd.getCurrentDir();
|
|
||||||
assert curDir.exists() : "Current directory must exist.";
|
|
||||||
NNStorage.rename(curDir, tmpDir);
|
|
||||||
// rename previous to current
|
|
||||||
NNStorage.rename(prevDir, curDir);
|
|
||||||
|
|
||||||
// delete tmp dir
|
|
||||||
NNStorage.deleteDir(tmpDir);
|
|
||||||
LOG.info("Rollback of " + sd.getRoot()+ " is complete.");
|
|
||||||
}
|
|
||||||
isUpgradeFinalized = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void doFinalize(StorageDirectory sd) throws IOException {
|
private void doFinalize(StorageDirectory sd) throws IOException {
|
||||||
|
|
Loading…
Reference in New Issue