danhuawang opened a new issue, #11401:
URL: https://github.com/apache/gravitino/issues/11401

   ### Version
   
   main branch
   
   ### Describe what's wrong
   
   `CALL gravitino.system.drop_catalog('gt_glue_xxx1')` fails with "Catalog 
trino_connector_metalake.gt_glue_xxx1 not exists", but immediately calling 
`create_catalog` for the same catalog fails with "already exists". The catalog 
is stuck in an inconsistent state where it cannot be dropped or re-created.
   
   The root cause is in `DropCatalogStoredProcedure.dropCatalog()`: it checks 
catalog existence via `catalogConnectorManager.getCatalogConnector()`, which 
only queries the Trino connector's **local in-memory cache** (the 
`catalogConnectors` map). If the catalog exists on the Gravitino server but was 
never successfully loaded into the connector (e.g., connector creation failed, 
cache was evicted, or Trino was restarted), the drop incorrectly reports "not 
exists" without ever consulting the Gravitino server.
   
   The correct behavior should be: when the local connector is not found, fall 
back to querying the Gravitino server to determine whether the catalog actually 
exists, and if so, proceed with the server-side drop.
   
   ### Error message and/or stacktrace
   
   ```
   trino> CALL gravitino.system.drop_catalog('gt_glue_xxx1');
   Query 20260602_164118_00410_q78qz failed: Drop catalog failed. Catalog 
trino_connector_metalake.gt_glue_xxx1 not exists.
   
   io.trino.spi.TrinoException: Drop catalog failed. Catalog 
trino_connector_metalake.gt_glue_xxx1 not exists.
        at 
org.apache.gravitino.trino.connector.system.storedprocedure.DropCatalogStoredProcedure.dropCatalog(DropCatalogStoredProcedure.java:123)
        at 
java.base/java.lang.invoke.MethodHandle.invokeWithArguments(MethodHandle.java:735)
        at 
java.base/java.lang.invoke.MethodHandle.invokeWithArguments(MethodHandle.java:760)
        at io.trino.execution.CallTask.execute(CallTask.java:210)
        ...
   Caused by: io.trino.spi.TrinoException: Catalog 
trino_connector_metalake.gt_glue_xxx1 not exists.
        at 
org.apache.gravitino.trino.connector.system.storedprocedure.DropCatalogStoredProcedure.dropCatalog(DropCatalogStoredProcedure.java:99)
        ... 15 more
   ```
   
   Immediately after:
   ```
   trino> CALL gravitino.system.create_catalog('gt_glue_xxx1', 'glue', ...);
   -- fails with: Catalog trino_connector_metalake.gt_glue_xxx1 already exists 
in the server.
   ```
   
   ### How to reproduce
   
   1. Deploy Gravitino + Trino with the Gravitino Trino connector (Trino 478).
   2. Create a catalog `gt_glue_xxx1` via `create_catalog` stored procedure 
with properties that will cause connector instantiation to fail (e.g., an 
invalid placeholder like `${?aws_glue_endpoint}` for the endpoint URL). The 
catalog metadata is persisted to the Gravitino server, but the Trino connector 
fails to load.
   3. The background scheduler (`gravitino-connector-schedule-0`) also attempts 
to load the catalog and fails — so no `CatalogConnectorContext` is ever stored 
in the local cache.
   4. Call `CALL gravitino.system.drop_catalog('gt_glue_xxx1')` → fails with 
"not exists" because `getCatalogConnector()` returns null.
   5. Call `CALL gravitino.system.create_catalog('gt_glue_xxx1', ...)` → fails 
with "already exists" because the Gravitino server still holds the metadata.
   6. The catalog is now in a zombie state: cannot be dropped, cannot be 
re-created.
   
   ### Additional context
   
   The problematic code is in `DropCatalogStoredProcedure.java` lines 91-99:
   
   ```java
   CatalogConnectorContext catalogConnector =
       catalogConnectorManager.getCatalogConnector(
           catalogConnectorManager.getTrinoCatalogName(metalake, catalogName));
   if (catalogConnector == null) {
       if (ignoreNotExist) {
           return;
       }
       throw new TrinoException(
           GravitinoErrorCode.GRAVITINO_CATALOG_NOT_EXISTS,
           "Catalog " + NameIdentifier.of(metalake, catalogName) + " not 
exists.");
   }
   ```
   
   **Suggested fix**: When `getCatalogConnector()` returns null, query the 
Gravitino server directly (via the Gravitino client API) to check if the 
catalog exists. If it does, issue the server-side drop. Only throw "not exists" 
if the catalog is absent from both the local cache and the server.
   
   **Workaround**: Use `CALL gravitino.system.drop_catalog('gt_glue_xxx1', 
true)` (with `ignoreNotExist=true`) to skip the local cache check, though this 
may not actually remove the catalog from the Gravitino server either.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to