apache/seatunnel · error · CatalogException

Failed to check if database exists: ${dbName}

Error message

Failed to check if database exists: ${dbName}

What it means

CatalogException thrown by databaseExists when the metastore getDatabase(dbName) call fails with a TException other than NoSuchObjectException (which correctly returns false). It indicates the existence check itself could not be performed, not that the database is missing.

Source

Thrown at seatunnel-connectors-v2/connector-hive/src/main/java/org/apache/seatunnel/connectors/seatunnel/hive/utils/HiveMetaStoreCatalog.java:540

            return getClient().tableExists(dbName, tableName);
        } catch (TException e) {
            String msg = String.format("Failed to check if table %s.%s exists", dbName, tableName);
            throw new HiveConnectorException(
                    HiveConnectorErrorCode.GET_HIVE_TABLE_INFORMATION_FAILED, msg, e);
        }
    }

    @Override
    public boolean databaseExists(String dbName) throws CatalogException {
        try {
            try {
                getClient().getDatabase(dbName);
                return true;
            } catch (org.apache.hadoop.hive.metastore.api.NoSuchObjectException e) {
                return false;
            }
        } catch (TException e) {
            throw new CatalogException("Failed to check if database exists: " + dbName, e);
        }
    }

    public void dropTable(@NonNull String dbName, @NonNull String tableName) {
        try {
            getClient().dropTable(dbName, tableName, true, true);
        } catch (TException e) {
            String msg = String.format("Failed to drop table %s.%s", dbName, tableName);
            throw new HiveConnectorException(
                    HiveConnectorErrorCode.CREATE_HIVE_TABLE_FAILED, msg, e);
        }
    }

    public void createTableFromTemplate(@NonNull Table table) throws TException {
        log.info("Create table from template {}.{}", table.getDbName(), table.getTableName());
        createTableIfNotExists(table);
    }

View on GitHub (pinned to cf67b549a7)

Solutions

  1. Inspect the chained TException cause for connection vs server errors.
  2. Confirm metastore host/port are correct and reachable.
  3. Reopen the catalog (open()) to rebuild the client if the session went stale.
  4. Add retry with backoff around existence checks in long-running jobs.

Example fix

// before: assuming false means missing
dbExists = catalog.databaseExists(dbName);

// after: retry transient failures
for (int i = 0; i < 3; i++) {
    try { dbExists = catalog.databaseExists(dbName); break; }
    catch (Exception e) { sleep(backoff(i)); }
}
Defensive patterns

Strategy: retry

Try / catch

try {
    exists = catalog.databaseExists(dbName);
} catch (CatalogException e) {
    // transient metastore error: reopen client and retry once
    catalog.open();
    exists = catalog.databaseExists(dbName);
}

Prevention

When it happens

Trigger: Calling databaseExists (from listTables, createTable, dropDatabase flows) while the metastore connection fails, times out, or the Thrift client is in a broken state.

Common situations: Metastore restart while a job is running; stale client session after network interruption; DNS resolution failure for the metastore host.

Related errors


AI-assisted analysis of apache/seatunnel@cf67b549a7 (2026-09-10). Data as JSON: /api/errors/76835a89eb109452. Report an issue: GitHub.