Author: todd Date: Sat Jan 25 20:19:28 2014 New Revision: 1561388 URL: http://svn.apache.org/r1561388 Log: HDFS-5719. FSImage#doRollback() should close prevState before return. Contributed by Ted Yu.
Modified: hadoop/common/branches/branch-2/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt hadoop/common/branches/branch-2/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSImage.java Modified: hadoop/common/branches/branch-2/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-2/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt?rev=1561388&r1=1561387&r2=1561388&view=diff ============================================================================== --- hadoop/common/branches/branch-2/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt (original) +++ hadoop/common/branches/branch-2/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt Sat Jan 25 20:19:28 2014 @@ -307,6 +307,9 @@ Release 2.4.0 - UNRELEASED HDFS-5728. Block recovery will fail if the metafile does not have crc for all chunks of the block (Vinay via kihwal) + HDFS-5719. FSImage#doRollback() should close prevState before return + (Ted Yu via todd) + BREAKDOWN OF HDFS-2832 SUBTASKS AND RELATED JIRAS HDFS-4985. Add storage type to the protocol and expose it in block report Modified: hadoop/common/branches/branch-2/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSImage.java URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-2/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSImage.java?rev=1561388&r1=1561387&r2=1561388&view=diff ============================================================================== --- hadoop/common/branches/branch-2/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSImage.java (original) +++ hadoop/common/branches/branch-2/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSImage.java Sat Jan 25 20:19:28 2014 @@ -408,60 +408,64 @@ public class FSImage implements Closeabl // Directories that don't have previous state do not rollback boolean canRollback = false; FSImage prevState = new FSImage(conf); - prevState.getStorage().layoutVersion = HdfsConstants.LAYOUT_VERSION; - for (Iterator<StorageDirectory> it = storage.dirIterator(); it.hasNext();) { - StorageDirectory sd = it.next(); - File prevDir = sd.getPreviousDir(); - if (!prevDir.exists()) { // use current directory then - LOG.info("Storage directory " + sd.getRoot() - + " does not contain previous fs state."); - // read and verify consistency with other directories - storage.readProperties(sd); - continue; - } - - // read and verify consistency of the prev dir - prevState.getStorage().readPreviousVersionProperties(sd); + try { + prevState.getStorage().layoutVersion = HdfsConstants.LAYOUT_VERSION; + for (Iterator<StorageDirectory> it = storage.dirIterator(); it.hasNext();) { + StorageDirectory sd = it.next(); + File prevDir = sd.getPreviousDir(); + if (!prevDir.exists()) { // use current directory then + LOG.info("Storage directory " + sd.getRoot() + + " does not contain previous fs state."); + // read and verify consistency with other directories + storage.readProperties(sd); + continue; + } - 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 + prevState.getStorage().readPreviousVersionProperties(sd); - // 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."); + 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."); + + // 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; + } finally { + prevState.close(); } - isUpgradeFinalized = true; } private void doFinalize(StorageDirectory sd) throws IOException {