Author: jing9 Date: Sun Feb 23 21:35:07 2014 New Revision: 1571096 URL: http://svn.apache.org/r1571096 Log: HDFS-5999. Do not create rollback fsimage when it already exists. Contributed by Jing Zhao.
Modified: hadoop/common/branches/HDFS-5535/hadoop-hdfs-project/hadoop-hdfs/CHANGES_HDFS-5535.txt hadoop/common/branches/HDFS-5535/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSEditLogLoader.java hadoop/common/branches/HDFS-5535/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSImage.java hadoop/common/branches/HDFS-5535/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java Modified: hadoop/common/branches/HDFS-5535/hadoop-hdfs-project/hadoop-hdfs/CHANGES_HDFS-5535.txt URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-5535/hadoop-hdfs-project/hadoop-hdfs/CHANGES_HDFS-5535.txt?rev=1571096&r1=1571095&r2=1571096&view=diff ============================================================================== --- hadoop/common/branches/HDFS-5535/hadoop-hdfs-project/hadoop-hdfs/CHANGES_HDFS-5535.txt (original) +++ hadoop/common/branches/HDFS-5535/hadoop-hdfs-project/hadoop-hdfs/CHANGES_HDFS-5535.txt Sun Feb 23 21:35:07 2014 @@ -73,3 +73,5 @@ HDFS-5535 subtasks: TestOfflineEditsViewer. (szetszwo) HDFS-5994. Fix TestDataNodeRollingUpgrade. (Arpit Agarwal via szetszwo) + + HDFS-5999. Do not create rollback fsimage when it already exists. (jing9) Modified: hadoop/common/branches/HDFS-5535/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSEditLogLoader.java URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-5535/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSEditLogLoader.java?rev=1571096&r1=1571095&r2=1571096&view=diff ============================================================================== --- hadoop/common/branches/HDFS-5535/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSEditLogLoader.java (original) +++ hadoop/common/branches/HDFS-5535/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSEditLogLoader.java Sun Feb 23 21:35:07 2014 @@ -727,12 +727,10 @@ public class FSEditLogLoader { break; } } - - // save namespace if this is not the second edit transaction - // (the first must be OP_START_LOG_SEGMENT) - final boolean saveNamespace = totalEdits > 1; + + // save namespace if there is no rollback image existing final long startTime = ((RollingUpgradeOp) op).getTime(); - fsNamesys.startRollingUpgradeInternal(startTime, saveNamespace); + fsNamesys.startRollingUpgradeInternal(startTime, op.txid - 2); break; } case OP_ROLLING_UPGRADE_FINALIZE: { Modified: hadoop/common/branches/HDFS-5535/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/HDFS-5535/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSImage.java?rev=1571096&r1=1571095&r2=1571096&view=diff ============================================================================== --- hadoop/common/branches/HDFS-5535/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSImage.java (original) +++ hadoop/common/branches/HDFS-5535/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSImage.java Sun Feb 23 21:35:07 2014 @@ -327,6 +327,21 @@ public class FSImage implements Closeabl } } + /** + * @return true if there is rollback fsimage (for rolling upgrade) for the + * given txid in storage. + */ + boolean hasRollbackFSImage(long txid) { + for (StorageDirectory sd : storage.dirIterable(NameNodeDirType.IMAGE)) { + final File rollbackImageFile = NNStorage.getStorageFile(sd, + NameNodeFile.IMAGE_ROLLBACK, txid); + if (rollbackImageFile.exists()) { + return true; + } + } + return false; + } + void doUpgrade(FSNamesystem target) throws IOException { checkUpgrade(target); @@ -1071,7 +1086,7 @@ public class FSImage implements Closeabl } /** - * Renames new image + * Rename FSImage */ private void renameCheckpoint(long txid, NameNodeFile fromNnf, NameNodeFile toNnf, boolean renameMD5) throws IOException { Modified: hadoop/common/branches/HDFS-5535/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-5535/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java?rev=1571096&r1=1571095&r2=1571096&view=diff ============================================================================== --- hadoop/common/branches/HDFS-5535/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java (original) +++ hadoop/common/branches/HDFS-5535/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java Sun Feb 23 21:35:07 2014 @@ -7147,7 +7147,7 @@ public class FSNamesystem implements Nam try { checkOperation(OperationCategory.WRITE); checkNameNodeSafeMode("Failed to start rolling upgrade"); - startRollingUpgradeInternal(now(), true); + startRollingUpgradeInternal(now(), -1); getEditLog().logStartRollingUpgrade(rollingUpgradeInfo.getStartTime()); } finally { writeUnlock(); @@ -7165,15 +7165,14 @@ public class FSNamesystem implements Nam * Update internal state to indicate that a rolling upgrade is in progress. * Ootionally create a checkpoint before starting the RU. * @param startTime - * @param saveNamespace If true then a checkpoint is created before initiating - * the rolling upgrade. */ - void startRollingUpgradeInternal(long startTime, boolean saveNamespace) + void startRollingUpgradeInternal(long startTime, long txid) throws IOException { checkRollingUpgrade("start rolling upgrade"); getFSImage().checkUpgrade(this); - if (saveNamespace) { + // if we have not made a rollback image, do it + if (txid < 0 || !getFSImage().hasRollbackFSImage(txid)) { getFSImage().saveNamespace(this, NameNodeFile.IMAGE_ROLLBACK, null); LOG.info("Successfully saved namespace for preparing rolling upgrade."); }