{"record":{"id":"76835a89eb109452","repo":"apache/seatunnel","slug":"failed-to-check-if-database-exists-dbname","errorCode":null,"errorMessage":"Failed to check if database exists: ${dbName}","messagePattern":"Failed to check if database exists: (.+?)","errorType":"exception","errorClass":"CatalogException","httpStatus":null,"severity":"error","filePath":"seatunnel-connectors-v2/connector-hive/src/main/java/org/apache/seatunnel/connectors/seatunnel/hive/utils/HiveMetaStoreCatalog.java","lineNumber":540,"sourceCode":"            return getClient().tableExists(dbName, tableName);\n        } catch (TException e) {\n            String msg = String.format(\"Failed to check if table %s.%s exists\", dbName, tableName);\n            throw new HiveConnectorException(\n                    HiveConnectorErrorCode.GET_HIVE_TABLE_INFORMATION_FAILED, msg, e);\n        }\n    }\n\n    @Override\n    public boolean databaseExists(String dbName) throws CatalogException {\n        try {\n            try {\n                getClient().getDatabase(dbName);\n                return true;\n            } catch (org.apache.hadoop.hive.metastore.api.NoSuchObjectException e) {\n                return false;\n            }\n        } catch (TException e) {\n            throw new CatalogException(\"Failed to check if database exists: \" + dbName, e);\n        }\n    }\n\n    public void dropTable(@NonNull String dbName, @NonNull String tableName) {\n        try {\n            getClient().dropTable(dbName, tableName, true, true);\n        } catch (TException e) {\n            String msg = String.format(\"Failed to drop table %s.%s\", dbName, tableName);\n            throw new HiveConnectorException(\n                    HiveConnectorErrorCode.CREATE_HIVE_TABLE_FAILED, msg, e);\n        }\n    }\n\n    public void createTableFromTemplate(@NonNull Table table) throws TException {\n        log.info(\"Create table from template {}.{}\", table.getDbName(), table.getTableName());\n        createTableIfNotExists(table);\n    }\n","sourceCodeStart":522,"sourceCodeEnd":558,"githubUrl":"https://github.com/apache/seatunnel/blob/cf67b549a7a6c35fa0beb12d83c62892427ea919/seatunnel-connectors-v2/connector-hive/src/main/java/org/apache/seatunnel/connectors/seatunnel/hive/utils/HiveMetaStoreCatalog.java#L522-L558","documentation":"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.","triggerScenarios":"Calling databaseExists (from listTables, createTable, dropDatabase flows) while the metastore connection fails, times out, or the Thrift client is in a broken state.","commonSituations":"Metastore restart while a job is running; stale client session after network interruption; DNS resolution failure for the metastore host.","solutions":["Inspect the chained TException cause for connection vs server errors.","Confirm metastore host/port are correct and reachable.","Reopen the catalog (open()) to rebuild the client if the session went stale.","Add retry with backoff around existence checks in long-running jobs."],"exampleFix":"// before: assuming false means missing\ndbExists = catalog.databaseExists(dbName);\n\n// after: retry transient failures\nfor (int i = 0; i < 3; i++) {\n    try { dbExists = catalog.databaseExists(dbName); break; }\n    catch (Exception e) { sleep(backoff(i)); }\n}","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    exists = catalog.databaseExists(dbName);\n} catch (CatalogException e) {\n    // transient metastore error: reopen client and retry once\n    catalog.open();\n    exists = catalog.databaseExists(dbName);\n}","preventionTips":["Reopen the catalog when the client session appears stale","Keep metastore.uris with multiple hosts for failover","Retry with exponential backoff on long-running jobs"],"tags":["hive","metastore","thrift","database"],"backgroundTag":"network-request-failed","analyzedSha":"cf67b549a7a6c35fa0beb12d83c62892427ea919","analyzedAt":"2026-09-10T21:44:55.265Z","contentChangedAt":"2026-09-10T21:44:55.265Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}