Skip to content

Commit

Permalink
HDFS-17231. HA: Safemode should exit when resources are from low to a…
Browse files Browse the repository at this point in the history
…vailable. (apache#6207). Contributed by Gu Peng.

Reviewed-by: Xing Lin <[email protected]>
Signed-off-by: He Xiaoqiao <[email protected]>
  • Loading branch information
gp1314 authored and jiajunmao committed Feb 6, 2024
1 parent c6d36d0 commit 1355958
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4534,6 +4534,11 @@ public void run () {
LOG.warn(lowResourcesMsg + "Already in safe mode.");
}
enterSafeMode(true);
} else {
if (isNoManualAndResourceLowSafeMode()) {
LOG.info("Namenode has sufficient available resources, exiting safe mode.");
leaveSafeMode(false);
}
}
try {
Thread.sleep(resourceRecheckInterval);
Expand Down Expand Up @@ -5265,6 +5270,13 @@ private synchronized boolean isInManualOrResourceLowSafeMode() {
return manualSafeMode || resourceLowSafeMode;
}

/**
* @return true if it is not in manual safe mode and resource low safe mode.
*/
private synchronized boolean isNoManualAndResourceLowSafeMode() {
return !manualSafeMode && resourceLowSafeMode;
}

private synchronized void setManualAndResourceLowSafeMode(boolean manual,
boolean resourceLow) {
this.manualSafeMode = manual;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,14 @@ public void testCheckThatNameNodeResourceMonitorIsRunning()

assertTrue("NN should be in safe mode after resources crossed threshold",
cluster.getNameNode().isInSafeMode());

mockResourceChecker.setResourcesAvailable(true);
while (cluster.getNameNode().isInSafeMode() &&
Time.now() < startMillis + (60 * 1000)) {
Thread.sleep(1000);
}
assertTrue("NN should leave safe mode after resources not crossed threshold",
!cluster.getNameNode().isInSafeMode());
} finally {
if (cluster != null)
cluster.shutdown();
Expand Down

0 comments on commit 1355958

Please sign in to comment.