diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt index afc0b0922cf..7c2bedf640d 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt @@ -851,6 +851,8 @@ Release 2.6.0 - UNRELEASED HDFS-7147. Update archival storage user documentation. (Tsz Wo Nicholas Sze via wheat9) + HDFS-7340. Make rollingUpgrade start/finalize idempotent. (jing9) + BREAKDOWN OF HDFS-6134 AND HADOOP-10150 SUBTASKS AND RELATED JIRAS HDFS-6387. HDFS CLI admin tool for creating & deleting an 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 dedf4bee84d..a3bf793ca29 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 @@ -8300,6 +8300,9 @@ RollingUpgradeInfo startRollingUpgrade() throws IOException { writeLock(); try { checkOperation(OperationCategory.WRITE); + if (isRollingUpgrade()) { + return rollingUpgradeInfo; + } long startTime = now(); if (!haEnabled) { // for non-HA, we require NN to be in safemode startRollingUpgradeInternalForNonHA(startTime); @@ -8408,13 +8411,16 @@ void checkRollingUpgrade(String action) throws RollingUpgradeException { } } - RollingUpgradeInfo finalizeRollingUpgrade() throws IOException { + void finalizeRollingUpgrade() throws IOException { checkSuperuserPrivilege(); checkOperation(OperationCategory.WRITE); writeLock(); final RollingUpgradeInfo returnInfo; try { checkOperation(OperationCategory.WRITE); + if (!isRollingUpgrade()) { + return; + } checkNameNodeSafeMode("Failed to finalize rolling upgrade"); returnInfo = finalizeRollingUpgradeInternal(now()); @@ -8438,16 +8444,11 @@ RollingUpgradeInfo finalizeRollingUpgrade() throws IOException { if (auditLog.isInfoEnabled() && isExternalInvocation()) { logAuditEvent(true, "finalizeRollingUpgrade", null, null, null); } - return returnInfo; + return; } RollingUpgradeInfo finalizeRollingUpgradeInternal(long finalizeTime) throws RollingUpgradeException { - if (!isRollingUpgrade()) { - throw new RollingUpgradeException( - "Failed to finalize rolling upgrade since there is no rolling upgrade in progress."); - } - final long startTime = rollingUpgradeInfo.getStartTime(); rollingUpgradeInfo = null; return new RollingUpgradeInfo(blockPoolId, false, startTime, finalizeTime); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNodeRpcServer.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNodeRpcServer.java index 0b74e092325..4100ba72241 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNodeRpcServer.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNodeRpcServer.java @@ -954,7 +954,8 @@ public RollingUpgradeInfo rollingUpgrade(RollingUpgradeAction action) throws IOE case PREPARE: return namesystem.startRollingUpgrade(); case FINALIZE: - return namesystem.finalizeRollingUpgrade(); + namesystem.finalizeRollingUpgrade(); + return null; default: throw new UnsupportedActionException(action + " is not yet supported."); } diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/DFSAdmin.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/DFSAdmin.java index fed516b089c..484ac1238be 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/DFSAdmin.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/DFSAdmin.java @@ -334,7 +334,8 @@ private static void printMessage(RollingUpgradeInfo info, out.println(info); } } else { - out.println("There is no rolling upgrade in progress."); + out.println("There is no rolling upgrade in progress or rolling " + + "upgrade has already been finalized."); } } @@ -356,7 +357,7 @@ static int run(DistributedFileSystem dfs, String[] argv, int idx) throws IOExcep Preconditions.checkState(info.isStarted()); break; case FINALIZE: - Preconditions.checkState(info.isFinalized()); + Preconditions.checkState(info == null || info.isFinalized()); break; } printMessage(info, System.out); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestRollingUpgrade.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestRollingUpgrade.java index a22312f3980..aa3f362bb06 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestRollingUpgrade.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestRollingUpgrade.java @@ -239,9 +239,9 @@ public void testRollingUpgradeWithQJM() throws Exception { Assert.assertTrue(dfs2.exists(baz)); //finalize rolling upgrade - final RollingUpgradeInfo finalize = dfs2.rollingUpgrade(RollingUpgradeAction.FINALIZE); - LOG.info("FINALIZE: " + finalize); - Assert.assertEquals(info1.getStartTime(), finalize.getStartTime()); + final RollingUpgradeInfo finalize = dfs2.rollingUpgrade( + RollingUpgradeAction.FINALIZE); + Assert.assertNull(finalize); LOG.info("RESTART cluster 2 with regular startup option"); cluster2.getNameNodeInfos()[0].setStartOpt(StartupOption.REGULAR); @@ -385,7 +385,7 @@ public void testFinalize() throws Exception { Assert.assertTrue(fsimage.hasRollbackFSImage()); info = dfs.rollingUpgrade(RollingUpgradeAction.FINALIZE); - Assert.assertTrue(info.isFinalized()); + Assert.assertNull(info); Assert.assertTrue(dfs.exists(foo)); // Once finalized, there should be no more fsimage for rollbacks.