apache/iceberg · error · LockException
Error generating host name
Error message
Error generating host name
What it means
Before requesting a metastore lock, MetastoreLock resolves the local hostname to populate the lock's agentInfo so it can later identify its own lock. If InetAddress.getLocalHost() throws UnknownHostException, the JVM cannot resolve the machine's own hostname and a LockException is thrown. This is an environment/DNS configuration problem, not a table-state problem.
Solutions
- Add the machine's hostname to /etc/hosts (e.g. '127.0.0.1 myhost') so InetAddress.getLocalHost() resolves.
- Fix resolver configuration (/etc/resolv.conf, /etc/nsswitch.conf) so the hostname resolves via DNS.
- In containers, set HOSTNAME and ensure the pod's hostname is resolvable, or use a hostNetwork/DNS policy that registers it.
- Verify with 'hostname -i' or a tiny JVM test calling InetAddress.getLocalHost() before deploying.
Example fix
// before (shell on the failing node) $ hostname # mypod-7f9c, not resolvable // after $ echo "127.0.0.1 mypod-7f9c" >> /etc/hosts # or fix cluster DNS
Defensive patterns
Strategy: validation
Validate before calling
import java.net.InetAddress;
boolean hostnameResolvable() {
try { return !InetAddress.getLocalHost().getHostName().isEmpty(); }
catch (UnknownHostException e) { return false; }
} Try / catch
try {
table.commit(apply);
} catch (LockException e) {
if (e.getMessage().contains("Error generating host name")) {
throw new IllegalStateException("Fix /etc/hosts or DNS so the node hostname resolves", e);
}
throw e;
} Prevention
- Add hostname -> 127.0.0.1 mapping in /etc/hosts on every worker node
- Validate hostname resolution in node startup health checks before running jobs
- In containers, set resolvable HOSTNAME or fix cluster DNS policy
- Test InetAddress.getLocalHost() in your deployment smoke tests
When it happens
Trigger: Any Hive-catalog table commit on a host whose hostname cannot be resolved: /etc/hosts missing the hostname entry, DNS misconfiguration, or containers with unresolvable hostnames.
Common situations: Kubernetes pods or Docker containers with random hostnames not registered in DNS; bare-metal clusters where /etc/hosts lacks the node's own hostname; IPv6-only or chrooted environments with broken resolver config.
Related errors
- Failed to connect to Hive Metastore
- Failed to heartbeat for lock
- Failed to list all tables under namespace
- Failed to reconnect to Hive Metastore
- Cannot call acquireLock twice for
AI-assisted analysis of apache/iceberg@86d9c8fc54 (2026-09-12).
Data as JSON: /api/errors/35d1c52ae07b098a.
Report an issue: GitHub.
Appendix: source
Thrown at hive-metastore/src/main/java/org/apache/iceberg/hive/MetastoreLock.java:277
}
}
/**
* Creates a lock, retrying if possible on failure.
*
* @return The {@link LockInfo} object for the successfully created lock
* @throws LockException When we are not able to fill the hostname for lock creation, or there is
* an error during lock creation
*/
@SuppressWarnings("ReverseDnsLookup")
private LockInfo createLock() throws LockException {
LockInfo lockInfo = new LockInfo();
String hostName;
try {
hostName = InetAddress.getLocalHost().getHostName();
} catch (UnknownHostException uhe) {
throw new LockException(uhe, "Error generating host name");
}
LockComponent lockComponent =
new LockComponent(LockType.EXCLUSIVE, LockLevel.TABLE, databaseName);
lockComponent.setTablename(tableName);
LockRequest lockRequest =
new LockRequest(Lists.newArrayList(lockComponent), HiveHadoopUtil.currentUser(), hostName);
// Only works in Hive 2 or later.
if (HiveVersion.min(HiveVersion.HIVE_2)) {
lockRequest.setAgentInfo(agentInfo);
}
AtomicBoolean interrupted = new AtomicBoolean(false);
Tasks.foreach(lockRequest)
.retry(Integer.MAX_VALUE - 100)
.exponentialBackoff(
lockCreationMinWaitTime, lockCreationMaxWaitTime, lockCreationTimeout, 2.0)View on GitHub (pinned to 86d9c8fc54)