From 8e7a2b8d5d9975690da20d3ff41d04f361171f0a Mon Sep 17 00:00:00 2001 From: Jing Zhao Date: Sun, 23 Feb 2014 21:35:07 +0000 Subject: [PATCH] HDFS-5999. Do not create rollback fsimage when it already exists. Contributed by Jing Zhao. git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/HDFS-5535@1571096 13f79535-47bb-0310-9956-ffa450edef68 --- .../hadoop-hdfs/CHANGES_HDFS-5535.txt | 2 ++ .../hdfs/server/namenode/FSEditLogLoader.java | 8 +++----- .../hadoop/hdfs/server/namenode/FSImage.java | 17 ++++++++++++++++- .../hdfs/server/namenode/FSNamesystem.java | 9 ++++----- 4 files changed, 25 insertions(+), 11 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES_HDFS-5535.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES_HDFS-5535.txt index 4d27ae99d4..63340e2d7c 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES_HDFS-5535.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES_HDFS-5535.txt @@ -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) diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSEditLogLoader.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSEditLogLoader.java index 95d38b6525..5300fec0bb 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSEditLogLoader.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSEditLogLoader.java @@ -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: { diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSImage.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSImage.java index 6988233458..f26fd6fd73 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSImage.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSImage.java @@ -327,6 +327,21 @@ public class FSImage implements Closeable { } } + /** + * @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 Closeable { } /** - * Renames new image + * Rename FSImage */ private void renameCheckpoint(long txid, NameNodeFile fromNnf, NameNodeFile toNnf, boolean renameMD5) throws IOException { diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java index 10bc2b4854..a67b4bda46 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java @@ -7147,7 +7147,7 @@ public class FSNamesystem implements Namesystem, FSClusterStats, 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 Namesystem, FSClusterStats, * 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."); }