rishi-rana opened a new pull request, #39882:
URL: https://github.com/apache/shardingsphere/pull/39882

   Fixes #35166.
   
   Changes proposed in this pull request:
   
   Meta data refresh runs immediately after execute, over a **new physical 
connection**, so it cannot see DDL that the current transaction has not 
committed yet. This PR defers the refresh to commit.
   
   - Add `DeferredMetaDataRefreshContext`, a transaction-scoped queue of 
pending push down refreshes held by `ProxyDatabaseConnectionManager`. It stores 
the database name rather than a `ShardingSphereDatabase` reference, so the 
database is re-resolved when the refresh actually runs.
   - `StandardDatabaseProxyConnector#doExecute` now enqueues the refresh when 
the session is in a transaction, and refreshes immediately otherwise. The 
existing `DDLCommitPolicy.COMMIT_CURRENT_TRANSACTION` path is unchanged: it 
commits first, so the refresh still runs immediately.
   - `ProxyBackendTransactionManager` drains the queue after the underlying 
commit succeeds and before the connection context is cleared, discards it on 
rollback, records the queue position on `SAVEPOINT`, and rolls back to that 
position on `ROLLBACK TO SAVEPOINT`.
   - Set `isSupportMetaDataRefreshInTransaction` to `true` for PostgreSQL. 
`ProxySQLExecutor#checkExecutePrerequisites` rejects metadata-changing DDL in a 
transaction while that flag is `false`, so the deferral mechanism and the flag 
have to change together.
   
   Notes on scope:
   
   - This covers XA and BASE as well. `ProxyBackendTransactionManager#commit` 
is the single commit entry point for all three transaction types, with the 
local/distributed split inside it, so the deferral is transaction-type 
agnostic. PostgreSQL already declared `isSupportDDLInXATransaction = true`, so 
this adds no new claim about XA beyond making the refresh correct.
   - Rolling back to a savepoint must drop the refreshes recorded after it. 
`DropTablePushDownMetaDataRefresher` removes the table from meta data purely 
from the statement rather than reloading it, so keeping a rolled-back `DROP 
TABLE` in the queue would delete a still-existing table from meta data.
   - The deferred refreshes are only rolled back when the savepoint rollback 
succeeded on every connection. If it failed, the DDL is still applied and its 
refresh must be kept.
   - `DriverJDBCPushDownExecuteExecutor` and 
`DriverJDBCPushDownExecuteUpdateExecutor` have the same immediate-refresh 
shape, so ShardingSphere-JDBC appears to have the analogous behaviour. They 
never read `isSupportMetaDataRefreshInTransaction`, so this PR does not change 
them. Happy to open a separate issue if you would like that covered.
   
   Local verification:
   
   - `./mvnw -pl proxy/backend/core,database/connector/dialect/postgresql test` 
— 597 tests, 0 failures.
   - `./mvnw -pl proxy/backend/core,database/connector/dialect/postgresql 
spotless:check checkstyle:check -Pcheck` — 0 violations.
   - `./mvnw apache-rat:check -Pcheck` — passed.
   - Each new test was confirmed to fail against the unfixed implementation 
before being accepted.
   
   ---
   
   Before committing this PR, I'm sure that I have checked the following 
options:
   - [x] My code follows the [code of 
conduct](https://shardingsphere.apache.org/community/en/involved/conduct/code/) 
of this project.
   - [x] I have self-reviewed the commit code.
   - [ ] I have (or in comment I request) added corresponding labels for the 
pull request.
   - [ ] I have passed maven check locally : `./mvnw clean install -B -T1C 
-Dmaven.javadoc.skip -Dmaven.jacoco.skip -e`. I ran the targeted module builds, 
style checks and RAT listed above rather than the full reactor build; please 
let me know if you would like the full build result before review.
   - [ ] I have made corresponding changes to the documentation.
   - [x] I have added corresponding unit tests for my changes.
   - [x] I have updated the Release Notes of the current development version.
   - [x] I have disclosed the tool and affected files or scope for any material 
AI assistance, as required by the [AI-assisted contribution policy].
   
   AI assistance disclosure, per `AI_POLICY.md`: this change was assisted by AI 
(Claude Code), covering the investigation, implementation and tests across all 
files in this PR, under my review and with the verification listed above.
   
   [AI-assisted contribution policy]: 
https://github.com/apache/shardingsphere/blob/master/AI_POLICY.md
   


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