apache/iceberg · error · RuntimeException

Failed to create namespace ${namespace} in Hive Metastore

Error message

Failed to create namespace ${namespace} in Hive Metastore

What it means

createNamespace wraps any generic Thrift TException from the Hive Metastore client in a RuntimeException indicating the namespace could not be created. This covers metastore connectivity, schema, or server-side failures that are not AlreadyExistsException.

Source

Thrown at hive-metastore/src/main/java/org/apache/iceberg/hive/HiveCatalog.java:554

    Preconditions.checkArgument(
        meta.get(HMS_DB_OWNER_TYPE) == null || meta.get(HMS_DB_OWNER) != null,
        "Create namespace setting %s without setting %s is not allowed",
        HMS_DB_OWNER_TYPE,
        HMS_DB_OWNER);
    try {
      clients.run(
          client -> {
            client.createDatabase(convertToDatabase(namespace, meta));
            return null;
          });

      LOG.info("Created namespace: {}", namespace);

    } catch (org.apache.hadoop.hive.metastore.api.AlreadyExistsException e) {
      throw new AlreadyExistsException(e, "Namespace already exists: %s", namespace);

    } catch (TException e) {
      throw new RuntimeException(
          "Failed to create namespace " + namespace + " in Hive Metastore", e);

    } catch (InterruptedException e) {
      Thread.currentThread().interrupt();
      throw new RuntimeException(
          "Interrupted in call to createDatabase(name) " + namespace + " in Hive Metastore", e);
    }
  }

  @Override
  public List<Namespace> listNamespaces(Namespace namespace) {
    if (!namespace.isEmpty() && (!isValidateNamespace(namespace) || !namespaceExists(namespace))) {
      throw new NoSuchNamespaceException("Namespace does not exist: %s", namespace);
    }
    if (!namespace.isEmpty()) {
      return ImmutableList.of();
    }
    try {

View on GitHub (pinned to 86d9c8fc54)

Solutions

  1. Verify Hive Metastore connectivity (URI in catalog config, metastore service running) and inspect the chained cause
  2. Check that the database location URI is valid and writable by the metastore user
  3. Check authentication (Kerberos/DelegationTokens) between client and metastore
  4. Retry after confirming the metastore is healthy; the error carries the underlying cause

Example fix

// before
catalog.createNamespace(Namespace.of("reports"));
// after
try {
  catalog.createNamespace(Namespace.of("reports"));
} catch (RuntimeException e) {
  LOG.error("Check metastore connectivity and cause", e);
  throw e;
}
Defensive patterns

Strategy: try-catch

Validate before calling

// verify metastore reachability first
client.getAllDatabases(); // probe call before createNamespace

Try / catch

try {
  catalog.createNamespace(ns);
} catch (RuntimeException e) {
  LOG.error("createNamespace failed; cause: {}", e.getCause(), e);
  throw e;
}

Prevention

When it happens

Trigger: catalog.createNamespace(...) when the metastore client throws TException — e.g. connection failure, invalid database metadata (bad location URI), metastore-side errors during createDatabase.

Common situations: Metastore URIs misconfigured; metastore service down; invalid HDFS/Warehouse location or permissions for the new database path; Kerberos/auth failures surfacing as TException.

Related errors


AI-assisted analysis of apache/iceberg@86d9c8fc54 (2026-09-12). Data as JSON: /api/errors/bf689f7524af5fce. Report an issue: GitHub.