已关闭
[Bug]: dolphin OK/EOF 包缺少 SERVER_STATUS_IN_TRANS 导致 SeaORM 事务 BeginFailed #1630
Rourou2285创建于  16 天前关闭于  8 天前
Rourou2285
Rourou2285
16 天前 创建

问题描述

使用 SeaORM(底层为 SQLx 0.8 MySQL 驱动)连接 openGauss B 兼容库(dolphin,DBCOMPATIBILITY 'B')执行 db.transaction() 时,返回 BeginFailed,事务无法开始。

复现方式

use sea_orm::{ConnectionTrait, DatabaseConnection, DbBackend, Statement, TransactionTrait};

db.transaction(|txn| {
    Box::pin(async move {
        // 任意 DML
        Ok::<_, sea_orm::DbErr>(())
    })
})
.await.expect("transaction failed"); // BEGINFAILED

STAR TRANSACTION 之后 SQLx 事务管理器读取响应包的 status_flags 确认事务已开始,缺失 SERVER_STATUS_IN_TRANS 位则判定失败。

根因

dolphin 在构造 MySQL OK/EOF 包的 status_flags 字段时只设置了 SERVER_STATUS_AUTOCOMMIT(及多语句时的 SERVER_MORE_RESULTS_EXISTS),没有根据当前是否处于事务块设置 SERVER_STATUS_IN_TRANS。因此客户端在 START TRANSACTION 后无法确认事务已真正开始。

修复

contrib/dolphin/plugin_protocol/dqformat.cpp

  • send_network_ok_packet():当 IsTransactionBlock() 时给 server_status 或上 SERVER_STATUS_IN_TRANS
  • sendServerStatus()(EOF 包路径复用):同样处理;
  • 新增 #include "access/xact.h"

验证

  • 修复前:SeaORM db.transaction() 返回 BeginFailed
  • 修复后:事务内 insert/update 成功,count=2[PASS] transaction

结论

为符合 MySQL 协议语义,OK/EOF 包的状态位应反映事务状态。这是协议状态位补全,不影响其它路径。

关联 MR:基于 seaorm-fix-intrans 分支提交。

likedislike
opengauss_bot
opengauss_bot成员
16 天前 评论:

This issue requires an assignee. Since you haven't specified one, we've assigned TestManager as the default assignee for this issue.

likedislike
opengauss_botopengauss_bot成员
16 天前 将 TestManager 设为负责人
opengauss_botopengauss_bot成员
16 天前 添加了label:sig/Plugin
opengauss_bot
opengauss_bot成员
16 天前 评论:

Welcome To openGauss Community

Hey @Rourou2285 , thanks for your contribution to the community.

Bot Usage Manual

I'm the Bot here serving you. You can find the instructions on how to interact with me at Here . That means you can comment below every pull request or issue to trigger Bot Commands. You can self-configure the PR merge rules for this repository. For more details, please refer to Here.

Contact Guide

If you have any questions, please contact the SIG: Plugin ,
and any of the maintainers: @CarrotGo, @chendong76, @chenxiaobin19, @congzhou2603, @dodders, @hwworkholic, @jemappellehc, @libiao2024, @muyulinzhong, @quemingjian, @shenzheng4, @shirley_zhengx, @superlchf, @totaj, @wlff234, @wofanzheng, @ywzq1161327784 ,
and any of the committers: @dreamalloc, @huyinghao, @libiao2024, @wangfeihuo, @wmy_ld, @wuyuechuan, @xiong_xjun, @zhangxubo, @zhaojunv3z810 .

likedislike
Rourou2285Rourou2285
16 天前 关联了pull request:[dolphin] SeaORM: 修复 OK/EOF 包缺 SERVER_STATUS_IN_TRANS 导致事务 BeginFailed
liuzhen001liuzhen001成员
13 天前 关联了看板:openGauss 7.0.0-LTS
ywzq1161327784ywzq1161327784成员
13 天前 移除了负责人 TestManager
opengauss_bot
opengauss_bot成员
13 天前 评论:

This issue requires an assignee. Since you haven't specified one, we've assigned TestManager as the default assignee for this issue.

likedislike
opengauss_botopengauss_bot成员
13 天前 将 TestManager 设为负责人
ywzq1161327784ywzq1161327784成员
13 天前 将 superlchf 设为负责人,移除负责人 TestManager
Rourou2285Rourou2285
12 天前 关联了pull request:[实习#45] SeaORM 兼容性测试工程(含 #1630/#1631 测试用例)
Rourou2285Rourou2285
12 天前 关联了pull request:【回合 7.0.0】dolphin MySQL 协议修复回合(出站>16MB 分包 / OK·EOF 事务标志 / prepared 参数剥离高位标志)
Rourou2285
Rourou2285
11 天前 评论:

验证结果:通过(PASS)

测例:SeaORM transactions 模块(examples 测例链接 https://atomgit.com/opengauss/examples/merge_requests/115

用例 覆盖 结果
TX1 db.transaction() 提交 PASS
TX2 事务回滚 PASS
TX3 连续 3 个事务 PASS
TX4 原始 SQLx BEGIN/COMMIT PASS
TX5 原始 SQLx 回滚 PASS
TX6 事务内结果集(EOF 路径)后提交 PASS
TX7 SAVEPOINT + ROLLBACK TO SAVEPOINT 后提交 PASS
TX8 事务内语句失败后,新事务可正常开启 PASS
TX9 SET autocommit=0 + COMMIT PASS
TX10 事务隔离:未提交不可见 / 提交后可见 PASS
likedislike
Ssuperlchf成员
10 天前 issue状态由 待办的 改变为 已完成
Ssuperlchf成员
10 天前 issue状态由 已完成 改变为 待回归
superlchf成员
9 天前 评论:

测试通过:
image.png

likedislike
ywzq1161327784ywzq1161327784成员
8 天前 issue状态由 待回归 改变为 已验收
ywzq1161327784ywzq1161327784成员
8 天前 关闭了 issue