apache/hadoop · error · IllegalArgumentException
Not allow to remove an inner node: {}
Error message
Not allow to remove an inner node: {} What it means
NetworkTopology.remove(Node) removes only leaf nodes. Inner nodes (racks/switches) are structural: their counters (numOfRacks, empty-rack bookkeeping) are updated by removing their leaves, so removing an InnerNode directly is rejected with IllegalArgumentException before the write lock is taken.
Source
Thrown at hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/net/NetworkTopology.java:224
if (!NodeBase.ROOT.equals(loc)) {
loc = loc.substring(1);
}
InnerNode rack = (InnerNode) clusterMap.getLoc(loc);
return (rack == null) ? new ArrayList<>(0)
: new ArrayList<>(rack.getChildren());
} finally {
netlock.readLock().unlock();
}
}
/** Remove a node
* Update node counter and rack counter if necessary
* @param node node to be removed; can be null
*/
public void remove(Node node) {
if (node==null) return;
if( node instanceof InnerNode ) {
throw new IllegalArgumentException(
"Not allow to remove an inner node: "+NodeBase.getPath(node));
}
LOG.info("Removing a node: "+NodeBase.getPath(node));
netlock.writeLock().lock();
try {
if (clusterMap.remove(node)) {
InnerNode rack = (InnerNode)getNode(node.getNetworkLocation());
if (rack == null) {
numOfRacks--;
}
interRemoveNodeWithEmptyRack(node);
}
LOG.debug("NetworkTopology became:\n{}", this);
} finally {
netlock.writeLock().unlock();
}
}
View on GitHub (pinned to 2add963021)
Solutions
- Remove each leaf under the rack instead of the rack itself — the rack disappears automatically when its last leaf is removed
- Filter nodes with !(node instanceof InnerNode) before calling remove()
- To reset the whole map, rebuild the topology object rather than removing inner nodes
Example fix
// before
topology.remove(nodeFromLookup); // may be an InnerNode
// after
if (!(nodeFromLookup instanceof InnerNode)) {
topology.remove(nodeFromLookup);
} Defensive patterns
Strategy: validation
Validate before calling
if (node instanceof InnerNode) {
throw new IllegalArgumentException(
"Refusing to remove inner node " + NodeBase.getPath(node));
}
topology.remove(node); Type guard
static boolean isRemovableLeaf(Node n) {
return n != null && !(n instanceof InnerNode);
} Prevention
- Type-check every node obtained from path-based lookups before remove()
- Model rack teardown as iteration over leaves, not removal of the rack object
When it happens
Trigger: Calling remove(node) where node instanceof InnerNode — e.g. a node obtained from getNode(path)/getDatanodesInRack() that is actually a rack, or a test stub extending InnerNode.
Common situations: Decommissioning or cluster-drain tooling that fetches nodes by path and removes them without a type check; unit tests with mock nodes extending InnerNodeImpl.
Related errors
- Not allow to add an inner node: {}
- Network Locationpath doesn't start with /: {}
- Not allow to add an inner node: {}
- Not allow to remove an inner node: {}
- Network location name contains /: {}
AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22).
Data as JSON: /api/errors/93655fee611deec1.
Report an issue: GitHub.