{"record":{"id":"e8e234819a348230","repo":"apache/hadoop","slug":"getrole-still-not-leave-safemode","errorCode":null,"errorMessage":"{getRole()} still not leave safemode","messagePattern":"(.+?) still not leave safemode","errorType":"exception","errorClass":"ServiceFailedException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNode.java","lineNumber":2023,"sourceCode":"    if (notBecomeActiveInSafemode && isInSafeMode()) {\n      throw new HealthCheckFailedException(\"The NameNode is configured to \" +\n          \"report UNHEALTHY to ZKFC in Safemode.\");\n    }\n  }\n  \n  synchronized void transitionToActive() throws IOException {\n    String operationName = \"transitionToActive\";\n    namesystem.checkSuperuserPrivilege(operationName);\n    if (!haEnabled) {\n      throw new ServiceFailedException(\"HA for namenode is not enabled\");\n    }\n    if (state == OBSERVER_STATE) {\n      throw new ServiceFailedException(\n          \"Cannot transition from '\" + OBSERVER_STATE + \"' to '\" +\n              ACTIVE_STATE + \"'\");\n    }\n    if (notBecomeActiveInSafemode && isInSafeMode()) {\n      throw new ServiceFailedException(getRole() + \" still not leave safemode\");\n    }\n    state.setState(haContext, ACTIVE_STATE);\n  }\n\n  synchronized void transitionToStandby() throws IOException {\n    String operationName = \"transitionToStandby\";\n    namesystem.checkSuperuserPrivilege(operationName);\n    if (!haEnabled) {\n      throw new ServiceFailedException(\"HA for namenode is not enabled\");\n    }\n    state.setState(haContext, STANDBY_STATE);\n  }\n\n  synchronized void transitionToObserver() throws IOException {\n    String operationName = \"transitionToObserver\";\n    namesystem.checkSuperuserPrivilege(operationName);\n    if (notBecomeActiveInSafemode && isInSafeMode()) {\n      throw new ServiceFailedException(getRole() + \" still not leave safemode\");","sourceCodeStart":2005,"sourceCodeEnd":2041,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNode.java#L2005-L2041","documentation":"transitionToActive throws ServiceFailedException '<role> still not leave safemode' when dfs.ha.nn.not-become-active-in-safemode=true and the NameNode is still in safemode. The NN refuses promotion to active until it has read enough block reports to exit safemode, so an under-initialized NN never becomes responsible for writes.","triggerScenarios":"Issuing transitionToActive (manual haadmin or failover controller) to a NN that is still in safemode while notBecomeActiveInSafemode is enabled - common right after restart or when datanodes have not reported yet.","commonSituations":"Post-restart failover before block reports complete; safemode extended because of missing blocks; operators manually promoting during incident recovery hitting the deliberate guard.","solutions":["Wait for safemode to exit ('hdfs dfsadmin -safemode get' returns OFF) and retry the transition.","If safemode is stuck, resolve the cause: datanode availability, missing blocks ('hdfs fsck /'), then retry.","If your operational policy allows active-in-safemode, remove dfs.ha.nn.not-become-active-in-safemode from hdfs-site.xml."],"exampleFix":"# before\nhdfs haadmin -transitionToActive nn1   # nn1 in safemode + not-become-active-in-safemode=true\n\n# after\nhdfs dfsadmin -safemode get   # wait until 'Safe mode is OFF' (fix missing blocks if stuck)\nhdfs haadmin -transitionToActive nn1","handlingStrategy":"validation","validationCode":"// block the transition while safemode holds\nif (haConf.notBecomeActiveInSafemode() && namenode.isInSafeMode())\n  throw new IllegalStateException(\"wait for safemode exit before transitionToActive\");\nnamenode.transitionToActive();","typeGuard":"boolean isSafemodeTransitionDenied(Throwable t) {\n  return t instanceof ServiceFailedException\n      && String.valueOf(t.getMessage()).contains(\"still not leave safemode\");\n}","tryCatchPattern":null,"preventionTips":["Wait for 'Safe mode is OFF' ('hdfs dfsadmin -safemode get') before any promotion command.","Automate transitions with a safemode gate plus retry, not fire-and-forget.","Understand your dfs.ha.nn.not-become-active-in-safemode setting: it turns this into a hard refusal."],"tags":["hdfs","namenode","ha","safemode","state-transition","failover"],"backgroundTag":"ha-state-transition-failed","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}