Repository navigation
Description
1. Is there an existing issue for this?
- I searched open and closed MatrixOne issues for Proxy migration / connection transfer /
LAST_INSERT_IDand found no duplicate.
2. Bug description and error info with logs
When Proxy migrates an idle JDBC session away from a draining CN, the session's LAST_INSERT_ID() state is reset to 0. Other session status from the same source session—ROW_COUNT(), FOUND_ROWS(), and a user variable—is restored correctly.
This changes the observable state of one logical client connection after a transparent Proxy handoff. Applications that execute an auto-increment insert and read LAST_INSERT_ID() in a later statement can receive 0 if a CN drain occurs between those statements.
Environment
- MatrixOne
main:57c280ed48fdccec3c2eb25042820deaf1eca3c1 - Topology: 1 Log / 1 TN / 2 CN / Proxy
- Endpoints: CN1
127.0.0.1:16001, CN2127.0.0.1:16002, Proxy127.0.0.1:6001 - Client: Connector/J 8.3.0
- Both
useServerPrepStmts=trueandfalsecovered
Reproducer
Through one Proxy JDBC connection:
create table jdbc_proxy_status(
id bigint unsigned auto_increment primary key,
v int,
note varchar(32)
) auto_increment=424242;
insert into jdbc_proxy_status(v,note)
values(10,'seed-a'),(20,'seed-b'),(30,'seed-c'),(40,'seed-d');Then on the same JDBC connection:
- Execute another auto-increment insert and capture its generated key.
- Execute a limited
SQL_CALC_FOUND_ROWSquery. - Execute an update that affects exactly two rows.
- Set a user variable.
- Mark the session's source CN
Drainingand the other CNWorking. - Wait until the Proxy log contains
connection migrate from server,connection migrate to server, andtransfer endfor this connection. - On the original JDBC connection, execute:
select last_insert_id(), row_count(), found_rows(), @proxy_status_tag;Actual behavior
Three confirmed handoffs, alternating both CN directions:
server prepared, CN1 -> CN2:
expected LAST_INSERT_ID=434242
actual=0,2,5,migration
server prepared, CN2 -> CN1:
expected LAST_INSERT_ID=424246
actual=0,2,5,migration
client prepared, CN1 -> CN2:
expected LAST_INSERT_ID=424246
actual=0,2,5,migration
Each round had exactly one successful transfer end in the Proxy log. In all three rounds only LAST_INSERT_ID() changed; ROW_COUNT()=2, FOUND_ROWS()=5, and @proxy_status_tag='migration' were preserved.
Non-migration control
The same sequence without a CN drain preserves all four values:
expected LAST_INSERT_ID=434242
actual=434242,2,5,control
3. Expected and actual behavior
- Expected: a successful transparent Proxy migration preserves the source session's
LAST_INSERT_ID()value. - Actual: the target session returns
0after migration.
4. Code analysis
The migration payload restores adjacent session state but does not contain lastInsertID:
pkg/frontend/routine.goexportsLastAffectedRowsandFoundRows.pkg/proxy/conn_migration.goforwards those fields.pkg/frontend/session.gorestoresROW_COUNT()andFOUND_ROWS()after replay.proto/query.protohas no corresponding field for the session'slastInsertID.
Session already owns this state through SetLastInsertID / GetLastInsertID; it is simply absent from the migration snapshot and restore path.
5. Suggested regression coverage
Add a two-CN + Proxy JDBC migration case that sets non-zero values for LAST_INSERT_ID, ROW_COUNT, and FOUND_ROWS, drains the owning CN, verifies one successful handoff, and checks all three values plus user variables on the original client connection. Cover both server- and client-prepared Connector/J modes.
This is session-state correctness and does not require big-data coverage.
Activity
fix(proxy): preserve LAST_INSERT_ID across connection migration (#29192)
Lundomn commentedon Sep 22, 2026
转 QA 验收:PR #29192 已合并(merge commit 1634996)。
请在 2 CN + Proxy 环境验证 drain migration 后 JDBC 会话的 LAST_INSERT_ID(),覆盖 client/server prepared 两种模式及迁移后 INSERT。请回报测试环境、版本/commit、结果;失败时附最小复现。
Ariznawlll commentedon Sep 24, 2026
测试版本
maind7d940e93bd037e9aacdc0f1256b91e32df84642原问题验证
按 issue 中的真实 CN draining 流程执行:同一 JDBC 连接先完成自增 INSERT 并读取
LAST_INSERT_ID(),随后将当前 CN 切到 draining,等待 Proxy 把原连接迁移到另一 CN,再次读取LAST_INSERT_ID()并执行新的 INSERT。两种 prepared 模式各连续执行 3 轮,共发生 6 次真实 CN 迁移。迁移前后的连接身份由
@@server_id确认,6/6 均保持原LAST_INSERT_ID(),迁移后的 INSERT 也都返回并落盘正确的新自增 ID。Proxy 日志同时确认 session transfer;server-prepared 路径确认迁移了 3 个 prepared statements。正常场景覆盖
异常与边界覆盖
白盒验证
回归测试
issue_29184_proxy_last_insert_id.py,包含 3 轮真实 draining、迁移和自增 ID 断言。测试证据
LAST_INSERT_ID()保持、迁移后新 INSERT ID 正确。测试结论
测试通过。