{"record":{"id":"af38796a9cd7093c","repo":"apache/hadoop","slug":"cannot-finalize-with-no-namenode-active","errorCode":null,"errorMessage":"Cannot finalize with no NameNode active","messagePattern":"Cannot finalize with no NameNode active","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/DFSAdmin.java","lineNumber":1500,"sourceCode":"  /**\n   * Command to ask the namenode to finalize previously performed upgrade.\n   * Usage: hdfs dfsadmin -finalizeUpgrade\n   * @exception IOException \n   */\n  public int finalizeUpgrade() throws IOException {\n    DistributedFileSystem dfs = getDFS();\n    \n    Configuration dfsConf = dfs.getConf();\n    URI dfsUri = dfs.getUri();\n    boolean isHaAndLogicalUri = HAUtilClient.isLogicalUri(dfsConf, dfsUri);\n    if (isHaAndLogicalUri) {\n      // In the case of HA and logical URI, run finalizeUpgrade for all\n      // NNs in this nameservice.\n      String nsId = dfsUri.getHost();\n      List<ClientProtocol> namenodes =\n          HAUtil.getProxiesForAllNameNodesInNameservice(dfsConf, nsId);\n      if (!HAUtil.isAtLeastOneActive(namenodes)) {\n        throw new IOException(\"Cannot finalize with no NameNode active\");\n      }\n\n      List<ProxyAndInfo<ClientProtocol>> proxies =\n          HAUtil.getProxiesForAllNameNodesInNameservice(dfsConf,\n          nsId, ClientProtocol.class);\n      List<IOException> exceptions = new ArrayList<>();\n      for (ProxyAndInfo<ClientProtocol> proxy : proxies) {\n        try{\n          proxy.getProxy().finalizeUpgrade();\n          System.out.println(\"Finalize upgrade successful for \" +\n              proxy.getAddress());\n        }catch (IOException ioe){\n          System.err.println(\"Finalize upgrade failed for \" +\n              proxy.getAddress());\n          exceptions.add(ioe);\n        }\n      }\n      if(!exceptions.isEmpty()){","sourceCodeStart":1482,"sourceCodeEnd":1518,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/DFSAdmin.java#L1482-L1518","documentation":"Implements `hdfs dfsadmin -finalizeUpgrade` when the filesystem URI is an HA logical URI (hdfs://<nameservice>). DFSAdmin resolves every NameNode of the nameservice, checks HAUtil.isAtLeastOneActive, and fails fast with IOException('Cannot finalize with no NameNode active') before issuing any finalize RPC — meaning both NameNodes are in STANDBY at that moment.","triggerScenarios":"Active NameNode crashed without failover (ZKFC down, ZooKeeper quorum loss); both NNs deliberately put in standby for maintenance and finalizeUpgrade run anyway; script running right after stopping the active for a restart; failover disabled in a manual-HA setup.","commonSituations":"Post failover-drill cleanup; ZooKeeper outage leaving no elected active; maintenance windows where operators forget finalize needs a writer NN; fresh HA clusters before first election.","solutions":["Check states: hdfs haadmin -ns <ns> -getAllServiceState","Make one NameNode active: hdfs haadmin -transitionToActive <nnId>, or fix ZKFC/ZooKeeper so automatic failover elects one","Retry hdfs dfsadmin -finalizeUpgrade once an active exists","If dual-standby was planned (e.g. full-cluster stop for upgrade), run finalize from the active after it starts, or use the non-HA URI of a single NN"],"exampleFix":"# before\n$ hdfs dfsadmin -finalizeUpgrade\n# IOException: Cannot finalize with no NameNode active\n\n# after\n$ hdfs haadmin -ns mycluster -getAllServiceState\n$ hdfs haadmin -transitionToActive nn1\n$ hdfs dfsadmin -finalizeUpgrade","handlingStrategy":"validation","validationCode":"# pre-flight: require at least one active NN in the nameservice\nhdfs haadmin -ns \"$NS\" -getAllServiceState | grep -q ': active' || {\n  echo \"no active NameNode in $NS; refusing to finalize\" >&2; exit 2;\n}\nhdfs dfsadmin -finalizeUpgrade","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Automate the active-state check before finalizeUpgrade in upgrade runbooks","Monitor ZKFC and ZooKeeper health so a no-active state never surprises you","During planned dual-standby maintenance, defer finalize until an active is restored"],"tags":["hdfs","dfsadmin","ha","namenode","finalize-upgrade","high-availability"],"backgroundTag":"no-active-namenode","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}