apache/cassandra · error · RuntimeException

java.net.UnknownHostException

Error message

java.net.UnknownHostException

What it means

getOwnershipByDcWithPort resolves endpoint IPs to hostnames (via resolveIp/DNS reverse lookup) while computing token ownership per datacenter, and any java.net.UnknownHostException is rethrown as a RuntimeException. It means DNS could not reverse-map one of the cluster member IPs.

Solutions

  1. Add the node IPs to /etc/hosts (or DNS PTR records) so reverse resolution succeeds.
  2. Fix the resolver configuration (resolv.conf) or VPN/DNS connectivity.
  3. Enable/verify `broadcast_address`/`listen_address` settings so ring IPs are resolvable.
  4. Report against the wrapped UnknownHostException cause to identify the failing IP.

Example fix

// before
# /etc/hosts missing cluster node IPs
// after
10.0.0.5 cassandra-1
10.0.0.6 cassandra-2  # add entries so reverse lookup succeeds
Defensive patterns

Strategy: try-catch

Validate before calling

// pre-resolve each endpoint IP before requesting ownership
InetAddress addr = InetAddress.getByName(ip); // throws UnknownHostException early, locally diagnosable

Try / catch

try { ownership = CommandUtils.getOwnershipByDcWithPort(probe, ...); }
catch (RuntimeException e) {
    if (e.getCause() instanceof java.net.UnknownHostException uhe) { /* fix DNS/hosts, or fall back to IP display */ }
    else throw e;
}

Prevention

When it happens

Trigger: Running ownership-reporting commands (e.g. `nodetool tablehistograms`, `nodetool tpstats`-style ownership output, RingState/OwnershipCommands) where a node's IP has no PTR record or DNS is unreachable.

Common situations: Cloud environments without reverse DNS for instance IPs; /etc/hosts entries missing; broken or slow DNS resolvers; nodes recently replaced leaving stale IPs in ring metadata.

Related errors


AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10). Data as JSON: /api/errors/715ec384d72d4de8. Report an issue: GitHub.

Appendix: source

Thrown at src/java/org/apache/cassandra/tools/nodetool/CommandUtils.java:250

    public static SortedMap<String, SetHostStatWithPort> getOwnershipByDcWithPort(NodeProbe probe, boolean resolveIp,
                                                                                  Map<String, String> tokenToEndpoint,
                                                                                  Map<String, Float> ownerships)
    {
        SortedMap<String, SetHostStatWithPort> ownershipByDc = Maps.newTreeMap();
        EndpointSnitchInfoMBean epSnitchInfo = probe.getEndpointSnitchInfoProxy();
        try
        {
            for (Map.Entry<String, String> tokenAndEndPoint : tokenToEndpoint.entrySet())
            {
                String dc = epSnitchInfo.getDatacenter(tokenAndEndPoint.getValue());
                if (!ownershipByDc.containsKey(dc))
                    ownershipByDc.put(dc, new SetHostStatWithPort(resolveIp));
                ownershipByDc.get(dc).add(tokenAndEndPoint.getKey(), tokenAndEndPoint.getValue(), ownerships);
            }
        }
        catch (UnknownHostException e)
        {
            throw new RuntimeException(e);
        }
        return ownershipByDc;
    }

    private enum KeyspaceSet
    {
        ALL, NON_SYSTEM, NON_LOCAL_STRATEGY, ACCORD_MANAGED
    }
}

View on GitHub (pinned to 88fd0f6a0e)