{"record":{"id":"a04ecdff15489641","repo":"apache/hadoop","slug":"cannot-transition-from-active-to-observer","errorCode":null,"errorMessage":"Cannot transition from 'active' to 'observer'","messagePattern":"Cannot transition from 'active' to 'observer'","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":2048,"sourceCode":"    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\");\n    }\n    if (!haEnabled) {\n      throw new ServiceFailedException(\"HA for namenode is not enabled\");\n    }\n    // Transition from ACTIVE to OBSERVER is forbidden.\n    if (state == ACTIVE_STATE) {\n      throw new ServiceFailedException(\n          \"Cannot transition from '\" + ACTIVE_STATE + \"' to '\" +\n              OBSERVER_STATE + \"'\");\n    }\n    state.setState(haContext, OBSERVER_STATE);\n  }\n\n  synchronized HAServiceStatus getServiceStatus()\n      throws ServiceFailedException, AccessControlException {\n    if (!haEnabled) {\n      throw new ServiceFailedException(\"HA for namenode is not enabled\");\n    }\n    if (state == null) {\n      return new HAServiceStatus(HAServiceState.INITIALIZING);\n    }\n    HAServiceState retState = state.getServiceState();\n    HAServiceStatus ret = new HAServiceStatus(retState);\n    if (retState == HAServiceState.STANDBY) {\n      if (namesystem.isInSafeMode()) {","sourceCodeStart":2030,"sourceCodeEnd":2066,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNode.java#L2030-L2066","documentation":"transitionToObserver forbids ACTIVE -> OBSERVER directly (the code comment states 'Transition from ACTIVE to OBSERVER is forbidden'). An active NameNode owns the edit log; an observer merely tails it, so the demotion must pass through standby where edit ownership is relinquished first.","triggerScenarios":"'hdfs haadmin -transitionToObserver <nnId>' while that NameNode is the active node of the nameservice - e.g., trying to convert the current primary into a read node in one step.","commonSituations":"Reshaping a cluster's roles (want fewer actives, more observers) and issuing observer transitions against the still-active NN; manual drills that skip the standby step; automation assuming any-to-any transitions.","solutions":["Go active -> standby -> observer: 'hdfs haadmin -transitionToStandby <nnId>' (after ensuring/failing over another NN to active), then 'hdfs haadmin -transitionToObserver <nnId>'.","In automatic-failover deployments, trigger failover so a standby becomes active, then demote the old active to observer.","Check current role first with 'hdfs haadmin -getServiceStatus <nnId>' and never issue observer transitions to an ACTIVE node."],"exampleFix":"# before\nhdfs haadmin -transitionToObserver nn1   # nn1 is Active -> rejected\n\n# after\nhdfs haadmin -transitionToStandby nn1\nhdfs haadmin -transitionToObserver nn1   # active -> standby -> observer","handlingStrategy":"validation","validationCode":"// never send observer transitions to an ACTIVE nn\nHAServiceStatus st = haProxy.getServiceStatus(nnId);\nif (\"ACTIVE\".equals(String.valueOf(st.getState())))\n  throw new IllegalStateException(\"demote to standby before transitionToObserver\");\nhaProxy.transitionToObserver(nnId);","typeGuard":"boolean isActiveToObserverDenied(Throwable t) {\n  return t instanceof ServiceFailedException\n      && String.valueOf(t.getMessage()).contains(\"'active' to 'observer'\");\n}","tryCatchPattern":null,"preventionTips":["Encode the legal transitions in tooling: active->standby->observer, observer->standby->active.","Run 'hdfs haadmin -getServiceStatus' before every manual transition.","During role reshuffles, fail over writes to another NN first, then demote the old active."],"tags":["hdfs","namenode","ha","observer","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"}