HDFS-17368. HA: Standby should exit safemode when resources are available. (#6518). Contributed by Zilong Zhu.

Signed-off-by: He Xiaoqiao <hexiaoqiao@apache.org>
This commit is contained in:
Zilong Zhu 2024-03-26 17:35:55 +08:00 committed by GitHub
parent 8bc4939ee2
commit 37f9ccdc86
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 14 additions and 4 deletions

View File

@ -1578,6 +1578,10 @@ void startStandbyServices(final Configuration conf, boolean isObserver)
standbyCheckpointer = new StandbyCheckpointer(conf, this); standbyCheckpointer = new StandbyCheckpointer(conf, this);
standbyCheckpointer.start(); 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."; String cmd = "Use \"hdfs dfsadmin -safemode leave\" to turn safe mode off.";
synchronized (this) { synchronized (this) {
if (resourceLowSafeMode) { if (resourceLowSafeMode) {
return "Resources are low on NN. Please add or free up more resources" 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 " + "NOTE: If you turn off safe mode before adding resources, the "
+ "mode before adding resources, the NN will immediately return to " + "NN will immediately return to safe mode. ";
+ "safe mode. " + cmd;
} else if (manualSafeMode) { } else if (manualSafeMode) {
return "It was turned on manually. " + cmd; return "It was turned on manually. " + cmd;
} }

View File

@ -999,4 +999,11 @@ public void testTransitionToObserverWhenSafeMode() throws Exception {
() -> miniCluster.transitionToObserver(0)); () -> 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());
}
} }