feat: add oracle xa support#1119
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #1119 +/- ##
==========================================
+ Coverage 58.26% 59.08% +0.81%
==========================================
Files 282 282
Lines 19269 19718 +449
==========================================
+ Hits 11227 11650 +423
+ Misses 7083 7056 -27
- Partials 959 1012 +53 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
这个 PR 对应 #1116 里拆分路线的第一个 PR,目标是先让 Oracle XA 能在现在的 registry-based SQL XA 框架里真实跑起来。也就是说,这个 PR 主要处理的是 Oracle XA 的基础接入和基础生命周期,而不是一次性把完整 Oracle XA 能力全部做完。 这个 PR 包含的范围主要是:
实际代码部分情况:
我本地用 OrbStack 启了一个 Oracle Free 容器做真实验证:
这里的 DSN 是本地测试容器的连接串,不是生产环境配置。 验证命令: go test ./pkg/datasource/sql -count=1
go test ./pkg/datasource/sql/xa ./pkg/datasource/sql/types ./pkg/protocol/branch -count=1
ORACLE_XA_DSN='oracle://system:OraclePwd123@localhost:1521/FREEPDB1' \
go test ./pkg/datasource/sql \
-run 'TestOracleXAIntegration_SeataXAOracle(FirstAndSecondPhase|Rollback|ReadOnlySkipsSecondPhaseCommit)$' \
-count=1 -v真实 Oracle 环境里验证通过的场景包括:
|
There was a problem hiding this comment.
Pull request overview
This PR makes Oracle usable in the registry-based SQL XA framework by introducing an Oracle XAResource implementation backed by DBMS_XA, wiring a dedicated seata-xa-oracle driver (go-ora), and updating XA connection/manager logic to support Oracle’s first-phase behavior (including read-only prepare handling) with accompanying unit/integration tests.
Changes:
- Add
OracleXAConnXAResource implementation usingDBMS_XA(start/end/prepare/commit/rollback) plus Oracle-specific XA error classification and XID mapping. - Register
seata-xa-oracle(go-ora) and enhance DSN parsing/resource-id/db-name extraction to correctly identify Oracle resources. - Update XA connection lifecycle to support Oracle’s first phase (target tx coordination, read-only prepare sentinel, held-connection detachment) and adjust phase-two handling; add extensive tests including an env-gated Oracle integration test.
Reviewed changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| pkg/datasource/sql/xa/xa_resource.go | Adds read-only prepare sentinel and optional commit/rollback idempotency classifier interfaces. |
| pkg/datasource/sql/xa/oracle_xa_connection.go | Implements Oracle XAResource via DBMS_XA, including XID encoding and Oracle error classification. |
| pkg/datasource/sql/xa/oracle_xa_connection_test.go | Unit tests for Oracle XAResource SQL/PLSQL generation, flags, and error/return-code handling. |
| pkg/datasource/sql/xa_resource_manager.go | Refactors timeout close logic; improves phase-two commit/rollback status handling and branch-status caching safety. |
| pkg/datasource/sql/xa_resource_manager_test.go | Adds tests for DBResource/XAResourceManager behavior with held connections and idempotent outcomes. |
| pkg/datasource/sql/tx_xa.go | Updates rollback log messaging to match new END flag behavior. |
| pkg/datasource/sql/oracle_xa_integration_test.go | Adds ORACLE_XA_DSN-gated integration tests covering prepare/commit, rollback, and read-only prepare behavior. |
| pkg/datasource/sql/driver.go | Registers seata-xa-oracle; adds Oracle-aware resource-id/db-name parsing; avoids MySQL DSN parsing for non-MySQL. |
| pkg/datasource/sql/driver_test.go | Adds tests for Oracle resource-id/db-name parsing and MySQL table-cache selection logic. |
| pkg/datasource/sql/db.go | Marks Oracle resources as “should be held”; ensures XAConn gets a cached error classifier. |
| pkg/datasource/sql/connector.go | Ensures Conn inherits DB type/name from DBResource; propagates dbType->driverName into seataDriver. |
| pkg/datasource/sql/connector_test.go | Tests that connector-created Conn uses DBResource’s DB type/name. |
| pkg/datasource/sql/conn.go | Normalizes nil driver.Result; adjusts XA-mode BeginTx to optionally begin a target tx for Oracle. |
| pkg/datasource/sql/conn_xa.go | Adds ResetSession detachment for held prepared Oracle connections; adds read-only prepare handling; improves state restoration and phase-two completion behavior. |
| pkg/datasource/sql/conn_xa_test.go | Adds broad test coverage for Oracle XA begin/rollback/commit edge cases, ResetSession detachment, and nil-result normalization. |
Comments suppressed due to low confidence (1)
pkg/datasource/sql/xa_resource_manager.go:181
- In BranchCommit, if finishBranch() fails (e.g., resource not found / connection acquisition failure), the method currently returns BranchStatusPhasetwoRollbackFailedUnretryable. That status is for rollback paths and is inconsistent with a commit operation; it can cause TC to interpret the outcome incorrectly. Return an appropriate commit failure status (retryable or unretryable depending on the error) instead.
connectionProxyXA, err := xaManager.finishBranch(ctx, xaID, branchResource)
if err != nil {
return branch.BranchStatusPhasetwoRollbackFailedUnretryable, err
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Check if the comment copilot given need resolve. |
|
Plz fix conflicts. |
Signed-off-by: CAICAIIs <3360776475@qq.com>
thanks, done |
What this PR does:
This PR adds the first-stage Oracle XA support needed to make the Oracle XA path usable in the registry-based SQL XA framework.
Which issue(s) this PR fixes:
Part of #1116
Special notes for your reviewer:
This is intentionally scoped to PR1 from the issue discussion: make Oracle XA actually usable through the current XA framework first.
The real Oracle test is gated by
ORACLE_XA_DSNand skips when the environment is not configured.Validated with:
go test ./pkg/datasource/sql/xa ./pkg/datasource/sql/types ./pkg/protocol/branchgo test ./pkg/datasource/sql -count=1go test ./pkg/datasource/sql/... -run '^$'ORACLE_XA_DSN=... go test ./pkg/datasource/sql -run TestOracleXAIntegration_SeataXAOracleFirstAndSecondPhase -count=1 -vDoes this PR introduce a user-facing change?: