LuciferYang opened a new pull request, #15029: URL: https://github.com/apache/gravitino/pull/15029
### What changes were proposed in this pull request? `GravitinoMetadata.beginCreateTable` records each table it creates in Gravitino, and `GravitinoConnector` keeps each transaction's metadata. When Trino rolls the transaction back, the connector drops those tables after the internal rollback. It also drops them when the internal commit fails, since Trino does not roll back a transaction whose commit failed. A rollback that lands while `beginCreateTable` runs is handled by `beginCreateTable` itself. A new adapter method, `canDropFailedNewTable`, lets a catalog keep the table. Hive returns false for managed tables: dropping one deletes its location, and HMS reuses an existing directory for a new managed table, so the drop could delete files the statement did not write. Those tables are kept with a warning in the coordinator log. Drops on the planning thread clear its interrupt flag first: Trino interrupts that thread when the query fails, and the Gravitino client sends no request from an interrupted thread. ### Why are the changes needed? A failed CTAS left an empty table behind, and rerunning the statement failed because the table existed. Fixes #14603 ### Does this PR introduce _any_ user-facing change? Yes. A failed `CREATE TABLE AS SELECT` no longer leaves its table behind, with two caveats that the SQL support and Hive catalog docs describe: - A Hive managed table (the default type) is kept on every failure. This includes the existing cleanup in `beginCreateTable`, which used to drop a managed table and its location when `beginInsert` or a step before it failed. I'd like to hear reviewers' views on that change: it protects files already in a reused directory, but the user now has to drop the table by hand. - The table is visible to other queries while the statement runs. If another query writes to it or recreates it and the statement then fails, the connector still drops the table. For a JDBC catalog that deletes the other query's rows. If the drop itself fails, the coordinator logs a warning and the table stays. ### How was this patch tested? - `TestGravitinoConnector.testFailedCreateTableAsSelectLeavesNoTable` runs the issue's reproduction. - `TestGravitinoConnectorTransactions` covers a rollback, a rollback whose internal rollback throws, and a failed commit, which all drop; a commit and a shutdown, which do not; and metadata handed out after the transaction ended. - `TestGravitinoMetadataCreateTableAsSelect` covers which tables are dropped or kept, on rollback and on a `beginInsert` failure, a rollback during `beginCreateTable`, the interrupt flag around the drops, and the Hive and Glue checks. - `TestGravitinoConnectorForwardUser.testRollbackDropsCreatedTablesBeforeClosingEvictedClient` checks that rollback calls `dropCreatedTables` before it closes the evicted per-user client. -- 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]
