{"record":{"id":"271ea0ef644f15d0","repo":"apache/hadoop","slug":"unable-to-determine-the-name-service-id-this-is-a","errorCode":null,"errorMessage":"Unable to determine the name service ID. This is an HA configuration with multiple name services configured. dfs.nameservices is set to {}. Please re-run with the -ns option.","messagePattern":"Unable to determine the name service ID\\. This is an HA configuration with multiple name services configured\\. dfs\\.nameservices is set to (.+?)\\. Please re-run with the -ns option\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/NNHAServiceTarget.java","lineNumber":127,"sourceCode":"    initializeFailoverConfig();\n  }\n\n  private void initializeNnConfig(Configuration conf,\n      String providedNsId, String providedNnId) {\n    Preconditions.checkNotNull(providedNnId);\n\n    if (providedNsId == null) {\n      providedNsId = DFSUtil.getOnlyNameServiceIdOrNull(conf);\n      if (providedNsId == null) {\n        String errorString = \"Unable to determine the name service ID.\";\n        String[] dfsNames = conf.getStrings(DFS_NAMESERVICES);\n        if ((dfsNames != null) && (dfsNames.length > 1)) {\n          errorString = \"Unable to determine the name service ID. \" +\n              \"This is an HA configuration with multiple name services \" +\n              \"configured. \" + DFS_NAMESERVICES + \" is set to \" +\n              Arrays.toString(dfsNames) + \". Please re-run with the -ns option.\";\n        }\n        throw new IllegalArgumentException(errorString);\n      }\n    }\n\n    // Make a copy of the conf, and override configs based on the\n    // target node -- not the node we happen to be running on.\n    this.targetConf = new HdfsConfiguration(conf);\n    NameNode.initializeGenericKeys(targetConf, providedNsId, providedNnId);\n\n    this.nsId = providedNsId;\n    this.nnId = providedNnId;\n  }\n\n  private void initializeFailoverConfig() {\n    this.autoFailoverEnabled = targetConf.getBoolean(\n        DFSConfigKeys.DFS_HA_AUTO_FAILOVER_ENABLED_KEY,\n        DFSConfigKeys.DFS_HA_AUTO_FAILOVER_ENABLED_DEFAULT);\n    if (autoFailoverEnabled) {\n      int port = DFSZKFailoverController.getZkfcPort(targetConf);","sourceCodeStart":109,"sourceCodeEnd":145,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/NNHAServiceTarget.java#L109-L145","documentation":"Same guard as the generic nameservice-resolution failure, but this branch fires when dfs.nameservices lists more than one nameservice: DFSUtil.getOnlyNameServiceIdOrNull cannot pick one, no -ns was supplied, and the error message is enriched with the full dfs.nameservices value and instructions to pass -ns. It exists because HA clusters with several federated namespaces cannot have a default nameservice.","triggerScenarios":"Running 'hdfs haadmin' (or anything constructing NNHAServiceTarget) without -ns on a cluster whose dfs.nameservices contains two or more ids (e.g. ns1,ns2).","commonSituations":"Federated clusters after adding a second nameservice — commands that used to work without -ns start failing; scripts written for a single-namespace cluster reused on a federated one.","solutions":["Add -ns to the command: 'hdfs haadmin -ns ns1 -nn nn1 -getServiceState' (use one of the ids printed in the error).","Update automation/scripts to always pass -ns on federated clusters.","Alternatively configure the tool host with a single-nameservice view of the config if federation is not needed there."],"exampleFix":"# before\nhdfs haadmin -getServiceState nn1\n# Unable to determine the name service ID. ... dfs.nameservices is set to [ns1, ns2]. Please re-run with the -ns option.\n\n# after\nhdfs haadmin -ns ns1 -getServiceState nn1","handlingStrategy":"validation","validationCode":"String[] nsIds = conf.getStrings(DFSConfigKeys.DFS_NAMESERVICES);\nif (nsIds != null && nsIds.length > 1 && providedNsId == null) {\n  throw new IllegalArgumentException(\"Multiple nameservices \"\n      + Arrays.toString(nsIds) + \" configured; pass -ns <id>\");\n}\nnew NNHAServiceTarget(conf, providedNsId, nnId);","typeGuard":null,"tryCatchPattern":"try {\n  new NNHAServiceTarget(conf, null, nnId);\n} catch (IllegalArgumentException e) {\n  if (e.getMessage().contains(\"Please re-run with the -ns option\")) {\n    // parse the listed ids from the message or re-read conf and prompt/select\n    throw new IllegalArgumentException(\"Ambiguous nameservice; rerun with -ns\", e);\n  }\n  throw e;\n}","preventionTips":["On federated clusters, require -ns in every haadmin invocation from day one.","After adding a nameservice, sweep cron jobs and runbooks for bare haadmin commands that omit -ns."],"tags":["hadoop","hdfs","ha","federation","haadmin","nameservice-id"],"backgroundTag":"nameservice-id-unresolved","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}