apache/hadoop · error · IllegalArgumentException

Not allow to add an inner node: {}

Error message

Not allow to add an inner node: {}

What it means

NetworkTopology.add(Node) registers only leaf nodes (datanodes). InnerNode objects are the internal structural entities (racks/switches) that the topology creates and manages itself while inserting a leaf, so passing one is a usage error and throws IllegalArgumentException before the write lock is even taken.

Source

Thrown at hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/net/NetworkTopology.java:139

  // keeping the constructor because other components like MR still uses this.
  public NetworkTopology() {
    this.factory = InnerNodeImpl.FACTORY;
    this.clusterMap = factory.newInnerNode(NodeBase.ROOT);
  }

  /** Add a leaf node
   * Update node counter & rack counter if necessary
   * @param node node to be added; can be null
   * @exception IllegalArgumentException if add a node to a leave 
                                         or node to be added is not a leaf
   */
  public void add(Node node) {
    if (node==null) return;
    int newDepth = NodeBase.locationToDepth(node.getNetworkLocation()) + 1;
    netlock.writeLock().lock();
    try {
      if( node instanceof InnerNode ) {
        throw new IllegalArgumentException(
          "Not allow to add an inner node: "+NodeBase.getPath(node));
      }
      if ((depthOfAllLeaves != -1) && (depthOfAllLeaves != newDepth)) {
        LOG.error("Error: can't add leaf node {} at depth {} to topology:{}\n",
            NodeBase.getPath(node), newDepth, this);
        throw new InvalidTopologyException("Failed to add " + NodeBase.getPath(node) +
            ": You cannot have a rack and a non-rack node at the same " +
            "level of the network topology.");
      }
      Node rack = getNodeForNetworkLocation(node);
      if (rack != null && !(rack instanceof InnerNode)) {
        throw new IllegalArgumentException("Unexpected data node " 
                                           + node.toString() 
                                           + " at an illegal network location");
      }
      if (clusterMap.add(node)) {
        LOG.info("Adding a new node: "+NodeBase.getPath(node));
        if (rack == null) {

View on GitHub (pinned to 2add963021)

Solutions

  1. Pass only leaf nodes (DatanodeDescriptor, NodeBase, or a custom Node that does not extend InnerNode) to add()
  2. If the node came from getNode()/getLeaf()/getDatanodesInRack(), filter with !(node instanceof InnerNode) before calling add()
  3. Never construct InnerNodeImpl yourself; the topology builds rack levels automatically when a leaf is added

Example fix

// before
topology.add(nodeFromLookup); // nodeFromLookup may be an InnerNode

// after
if (nodeFromLookup instanceof InnerNode) {
  throw new IllegalArgumentException("Only leaf nodes can be added: "
      + NodeBase.getPath(nodeFromLookup));
}
topology.add(nodeFromLookup);
Defensive patterns

Strategy: validation

Validate before calling

if (node instanceof InnerNode) {
  throw new IllegalArgumentException(
      "Refusing to add inner node " + NodeBase.getPath(node));
}
topology.add(node);

Type guard

static boolean isAddableLeaf(Node n) {
  return n != null && !(n instanceof InnerNode);
}

Prevention

When it happens

Trigger: Calling clusterMap.add(node) where node instanceof InnerNode (InnerNodeImpl, InnerNodeWithNodeGroup, or any subclass). Typical: constructing an InnerNode directly and adding it, or re-adding a node previously fetched via getNode()/getDatanodesInRack(), which can return inner nodes.

Common situations: Custom Node implementations or test mocks that extend InnerNode; block-placement or replica code that round-trips nodes obtained from NetworkTopology lookups; code ported between NetworkTopology and NetworkTopologyWithNodeGroup where the same guard exists.

Related errors


AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22). Data as JSON: /api/errors/8fe08addc1e53486. Report an issue: GitHub.