apache/hadoop · error · IllegalArgumentException
Unable to determine the name service ID. This is an HA confi
Error message
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. What it means
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.
Source
Thrown at hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/NNHAServiceTarget.java:127
initializeFailoverConfig();
}
private void initializeNnConfig(Configuration conf,
String providedNsId, String providedNnId) {
Preconditions.checkNotNull(providedNnId);
if (providedNsId == null) {
providedNsId = DFSUtil.getOnlyNameServiceIdOrNull(conf);
if (providedNsId == null) {
String errorString = "Unable to determine the name service ID.";
String[] dfsNames = conf.getStrings(DFS_NAMESERVICES);
if ((dfsNames != null) && (dfsNames.length > 1)) {
errorString = "Unable to determine the name service ID. " +
"This is an HA configuration with multiple name services " +
"configured. " + DFS_NAMESERVICES + " is set to " +
Arrays.toString(dfsNames) + ". Please re-run with the -ns option.";
}
throw new IllegalArgumentException(errorString);
}
}
// Make a copy of the conf, and override configs based on the
// target node -- not the node we happen to be running on.
this.targetConf = new HdfsConfiguration(conf);
NameNode.initializeGenericKeys(targetConf, providedNsId, providedNnId);
this.nsId = providedNsId;
this.nnId = providedNnId;
}
private void initializeFailoverConfig() {
this.autoFailoverEnabled = targetConf.getBoolean(
DFSConfigKeys.DFS_HA_AUTO_FAILOVER_ENABLED_KEY,
DFSConfigKeys.DFS_HA_AUTO_FAILOVER_ENABLED_DEFAULT);
if (autoFailoverEnabled) {
int port = DFSZKFailoverController.getZkfcPort(targetConf);View on GitHub (pinned to 2add963021)
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.
Example fix
# before hdfs haadmin -getServiceState nn1 # Unable to determine the name service ID. ... dfs.nameservices is set to [ns1, ns2]. Please re-run with the -ns option. # after hdfs haadmin -ns ns1 -getServiceState nn1
Defensive patterns
Strategy: validation
Validate before calling
String[] nsIds = conf.getStrings(DFSConfigKeys.DFS_NAMESERVICES);
if (nsIds != null && nsIds.length > 1 && providedNsId == null) {
throw new IllegalArgumentException("Multiple nameservices "
+ Arrays.toString(nsIds) + " configured; pass -ns <id>");
}
new NNHAServiceTarget(conf, providedNsId, nnId); Try / catch
try {
new NNHAServiceTarget(conf, null, nnId);
} catch (IllegalArgumentException e) {
if (e.getMessage().contains("Please re-run with the -ns option")) {
// parse the listed ids from the message or re-read conf and prompt/select
throw new IllegalArgumentException("Ambiguous nameservice; rerun with -ns", e);
}
throw e;
} Prevention
- 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.
When it happens
Trigger: Running 'hdfs haadmin' (or anything constructing NNHAServiceTarget) without -ns on a cluster whose dfs.nameservices contains two or more ids (e.g. ns1,ns2).
Common situations: 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.
Related errors
- Unable to determine the name service ID.
- Unable to determine service address for namenode '{}'
- {} does not support method msync
- Not able to initialize fs in getDefaultBlockSize for path <
- Not able to initialize fs in getDefaultReplication for path
AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22).
Data as JSON: /api/errors/271ea0ef644f15d0.
Report an issue: GitHub.