Skip to content

feat: add oracle xa support#1119

Open
CAICAIIs wants to merge 7 commits into
apache:masterfrom
CAICAIIs:oracle-xa
Open

feat: add oracle xa support#1119
CAICAIIs wants to merge 7 commits into
apache:masterfrom
CAICAIIs:oracle-xa

Conversation

@CAICAIIs
Copy link
Copy Markdown
Contributor

@CAICAIIs CAICAIIs commented May 6, 2026

  • I have registered the PR changes.

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_DSN and skips when the environment is not configured.

Validated with:

  • go test ./pkg/datasource/sql/xa ./pkg/datasource/sql/types ./pkg/protocol/branch
  • go test ./pkg/datasource/sql -count=1
  • go test ./pkg/datasource/sql/... -run '^$'
  • ORACLE_XA_DSN=... go test ./pkg/datasource/sql -run TestOracleXAIntegration_SeataXAOracleFirstAndSecondPhase -count=1 -v

Does this PR introduce a user-facing change?:

Add first-stage Oracle XA support for the SQL XA framework via the `seata-xa-oracle` driver.

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented May 7, 2026

Codecov Report

❌ Patch coverage is 68.31502% with 173 lines in your changes missing coverage. Please review.
✅ Project coverage is 59.08%. Comparing base (baabdf7) to head (3994385).

Files with missing lines Patch % Lines
pkg/datasource/sql/xa/oracle_xa_connection.go 62.56% 53 Missing and 14 partials ⚠️
pkg/datasource/sql/conn_xa.go 71.91% 32 Missing and 18 partials ⚠️
pkg/datasource/sql/xa_resource_manager.go 25.58% 23 Missing and 9 partials ⚠️
pkg/datasource/sql/driver.go 84.15% 9 Missing and 7 partials ⚠️
pkg/datasource/sql/conn.go 77.77% 6 Missing and 2 partials ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions github-actions Bot removed the rm label May 8, 2026
@CAICAIIs
Copy link
Copy Markdown
Contributor Author

CAICAIIs commented May 8, 2026

这个 PR 对应 #1116 里拆分路线的第一个 PR,目标是先让 Oracle XA 能在现在的 registry-based SQL XA 框架里真实跑起来。也就是说,这个 PR 主要处理的是 Oracle XA 的基础接入和基础生命周期,而不是一次性把完整 Oracle XA 能力全部做完。

这个 PR 包含的范围主要是:

  • 增加 seata-xa-oracle driver 接入;
  • 接入 Oracle Go driver;
  • 让 Oracle 能通过现有 XA driver / connector / resource 路径创建资源;
  • 基于 Oracle DBMS_XA 实现基础生命周期:StartEndPrepareCommitRollback
  • 对当前不支持的能力给出明确错误,比如 RecoverForget
  • 修复 Oracle PR1 要能跑通所必需的通用 XA branch-status / held connection 处理;
  • 补充对应单测,以及需要真实 Oracle 环境才会跑的 integration test。

实际代码部分情况:

  1. pkg/datasource/sql/xa/oracle_xa_connection.go

    这里是 Oracle DBMS_XA 生命周期的主要实现。里面比较关键的点是:

    • Oracle rollback 路径不能使用 TMFAIL,所以这里使用 XA_END(..., TMSUCCESS)
    • XA_PREPARE 返回 XA_RDONLY 时,这个 branch 已经是终态成功,不应该再继续走二阶段 commit。
  2. pkg/datasource/sql/driver.goconnector.godb.go

    这里主要是 Oracle driver 注册、资源创建,以及 Oracle resource id / db name 的处理。

  3. pkg/datasource/sql/conn_xa.goxa_resource_manager.go

    这里是为了让 Oracle XA 基础生命周期能跑通所需的通用 XA 处理,包括 prepared connection 的保留、二阶段连接清理、branch status 处理等。

  4. 测试文件

    • pkg/datasource/sql/xa/oracle_xa_connection_test.go
    • pkg/datasource/sql/conn_xa_test.go
    • pkg/datasource/sql/xa_resource_manager_test.go
    • pkg/datasource/sql/oracle_xa_integration_test.go

我本地用 OrbStack 启了一个 Oracle Free 容器做真实验证:

  • 容器名:seata-oracle-xa
  • 镜像:gvenzl/oracle-free:23-slim
  • 连接方式:ORACLE_XA_DSN='oracle://system:<password>@localhost:1521/FREEPDB1'

这里的 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 环境里验证通过的场景包括:

  • 一阶段 prepare 后二阶段 commit;
  • rollback;
  • readonly branch,也就是 XA_PREPARE 返回 XA_RDONLY 后跳过二阶段 commit。

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 OracleXAConn XAResource implementation using DBMS_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.

Comment thread pkg/datasource/sql/oracle_xa_integration_test.go Outdated
@thunguo
Copy link
Copy Markdown
Contributor

thunguo commented May 23, 2026

Check if the comment copilot given need resolve.

@ssshr-66
Copy link
Copy Markdown
Contributor

ssshr-66 commented Jun 5, 2026

Plz fix conflicts.

Signed-off-by: CAICAIIs <3360776475@qq.com>
@CAICAIIs
Copy link
Copy Markdown
Contributor Author

CAICAIIs commented Jun 6, 2026

Plz fix conflicts.

thanks, done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants