yuqi1129 opened a new pull request, #13729:
URL: https://github.com/apache/gravitino/pull/13729

   ### What changes were proposed in this pull request?
   
   Stop JDBC catalog operations from holding one pooled connection while 
borrowing another from the same data source.
   
   - `JdbcTableOperations.alterTable` and `create`, and 
`JdbcDatabaseOperations.dropDatabase`, generate their SQL before borrowing the 
connection that executes it. The MySQL-family alter generators load the table, 
Doris's create generator queries backends and version, and the default 
non-cascading drop checks for tables, each through its own connection.
   - `ClickHouseTableOperations.alterTable` now validates its settings and 
delegates to the base method instead of copying it.
   - `OceanBaseTableOperations.alterTable` generates each statement, then 
borrows a connection to execute it. Each change is still generated after the 
previous one is applied.
   - `JdbcTableOperations.load` caches the driver version from the connection 
it holds, so parsing datetime columns (MySQL, OceanBase, Doris) no longer 
borrows a connection per column.
   - The SQL generators' Javadoc states that callers must not hold a connection.
   
   ### Why are the changes needed?
   
   With the default pool size of 10, concurrent alters on distinct MySQL tables 
could take every slot with outer connections and then wait for another inside 
SQL generation, failing with `Timeout waiting for idle object` after 30 
seconds. Loading a table with datetime columns had the same nested borrow.
   
   Fix: #13591
   
   ### Does this PR introduce _any_ user-facing change?
   
   No API or configuration changes. Each JDBC operation holds at most one 
pooled connection at a time. Side effects of the reordering:
   
   - A generator's validation error, and Doris's backend and version queries, 
now come before a missing-database error from the execution connection.
   - When the generated SQL is empty, no execution connection is borrowed, so 
that step no longer reports a missing database.
   - OceanBase borrows one connection per non-empty statement, sequentially, 
instead of one for all changes. DDL statements were already applied one by one, 
so partial-failure behavior is unchanged.
   
   ### How was this patch tested?
   
   - New `TestJdbcOperationsConnectionUsage` (7 cases), 
`TestClickHouseTableOperationsConnectionUsage` and 
`TestOceanBaseTableOperationsConnectionUsage`. They use a counting data source 
to assert that no connection is held while SQL is generated and that at most 
one is borrowed at a time. Two cases use a real single-connection DBCP pool on 
SQLite and reproduce the `Timeout waiting for idle object` failure on the old 
code for both `alterTable` and `load`.
   - Every new case fails when its fix is reverted.
   - Existing `TestJdbcTableOperations`, `TestJdbcDatabaseOperations`, 
`TestJdbcCatalogOperations`, `TestClickHouseTableOperationsUnit`, 
`TestOceanBaseTableOperationsSqlGeneration`, `TestDorisTableCreation` and 
`TestDorisTableOperationsSqlGeneration` pass. Spotless and Javadoc pass for the 
changed modules.
   - Docker-based catalog tests and a real 32-client MySQL reproduction were 
not run locally.
   


-- 
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