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 075398f000..542cc37046 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 @@ -1578,6 +1578,10 @@ void startStandbyServices(final Configuration conf, boolean isObserver) standbyCheckpointer = new StandbyCheckpointer(conf, this); standbyCheckpointer.start(); } + if (isNoManualAndResourceLowSafeMode()) { + LOG.info("Standby should not enter safe mode when resources are low, exiting safe mode."); + leaveSafeMode(false); + } } /** @@ -5253,10 +5257,9 @@ String getSafeModeTip() { String cmd = "Use \"hdfs dfsadmin -safemode leave\" to turn safe mode off."; synchronized (this) { if (resourceLowSafeMode) { - return "Resources are low on NN. Please add or free up more resources" - + "then turn off safe mode manually. NOTE: If you turn off safe " - + "mode before adding resources, the NN will immediately return to " - + "safe mode. " + cmd; + return "Resources are low on NN. Please add or free up more resources. " + + "NOTE: If you turn off safe mode before adding resources, the " + + "NN will immediately return to safe mode. "; } else if (manualSafeMode) { return "It was turned on manually. " + cmd; } diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestHASafeMode.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestHASafeMode.java index 4766c4cecc..0ac9eae7f5 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestHASafeMode.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestHASafeMode.java @@ -999,4 +999,11 @@ public void testTransitionToObserverWhenSafeMode() throws Exception { () -> miniCluster.transitionToObserver(0)); } } + + @Test + public void testTransitionToStandbyWhenSafeModeWithResourcesLow() throws Exception { + NameNodeAdapter.enterSafeMode(nn0, true); + cluster.transitionToStandby(0); + assertFalse("SNN should not enter safe mode when resources low", nn0.isInSafeMode()); + } }