Repository navigation
Description
Description
A connection routed through MatrixOne Proxy loses its session temporary tables after transparent CN migration. If a server-side prepared statement references the temporary table, migration cannot complete and Proxy retries the migration every 5 seconds while the session remains on the draining CN.
Environment
- Branch:
main - Commit:
705d5fbb625d32090b9a8acadcead08c3e1d4535 - Test date: 2026-08-25
- Deployment: one Log service, one TN, two CNs and one Proxy started as separate processes with
etc/launch-with-proxy/*.toml - Client: MySQL Connector/J 8.4.0 with
useServerPrepStmts=true - Proxy port:
6001; CN SQL ports:16001and16002
Steps to reproduce
- Open a long-lived JDBC connection through Proxy and create a temporary table:
create database if not exists proxy_migration_probe;
use proxy_migration_probe;
create temporary table tmp_group (
id int primary key,
grp int,
val varchar(30)
);
insert into tmp_group values
(1, 1, 'beta'),
(2, 1, 'alpha'),
(3, 2, 'gamma');
select group_concat(val order by id separator '|')
from tmp_group where grp = 1;
-- beta|alpha
select @@server_id;- From a separate administrative connection, mark the current backend CN as draining:
select mo_ctl('cn', 'workstate', '<current-cn-uuid>:2');-
Poll
select @@server_idon the original JDBC connection until the UUID changes. -
Execute the same query on the original connection:
select group_concat(val order by id separator '|')
from tmp_group where grp = 1;- Variant: before step 2, create both a SQL
PREPAREand a Connector/J server prepared statement that referencetmp_group.
Actual behavior
Temporary table without prepared statements
Proxy completes the migration (prepare stmt num: 0), but the same JDBC connection loses the temporary table:
TEMP_TABLE_MIGRATION=dd1dccb5->dd1dccb4
SQL parser error: table "tmp_group" does not exist
Prepared statements reference the temporary table
The source exports the prepared statements, but the target CN cannot rebuild them because the temporary table does not exist. Proxy keeps retrying every 5 seconds:
connection migrate from server ... DB=proxy_migration_probe prepare stmt num=2
connection migrate to server ...
failed to migrate connection to cn, will retry ...
error="SQL parser error: table \"tmp_group\" does not exist"
The original connection remains usable on the draining CN, but cannot be drained while those prepared statements are present.
Expected behavior
Transparent Proxy migration must preserve session-visible temporary tables and prepared statements that reference them. If temporary tables are intentionally not migratable, Proxy must detect that state before migration and use an explicit, documented policy that does not silently lose tables or endlessly retry draining.
Stability and controls
- Minimal temporary-table reproducer: 3/3 failed after successful CN migration, alternating both CN directions.
- Prepared-statement variant: reproduced; migration retried every 5 seconds with the same target-side error.
- Passing control: 3/3 passed for ordinary server prepared statements across CN migration.
- Passing control: a pre-migration server prepared statement successfully inserted and read back a deterministic 256 KiB streamed BLOB after migration in every repetition.
- Transaction controls passed: an active transaction stayed on the source CN; commit and rollback both allowed migration afterward; uncommitted and rolled-back values did not leak.
- No CN crash, restart, panic or client disconnection was observed.
Evidence
Successful migration without prepared statements followed by table loss:
connection migrate from server ... ConnID=822 ... prepare stmt num=0
connection migrate to server ... ConnID=822 ...
TEMP_TABLE_MIGRATION=dd1dccb5->dd1dccb4
SQL parser error: table "tmp_group" does not exist
Prepared-statement migration failure:
failed to migrate conn to: SQL parser error: table "tmp_group" does not exist
failed to migrate connection to cn, will retry
Code analysis
pkg/frontend/session.gokeeps temporary-table aliases in CN-local session state.pkg/proxy/conn_migration.gotransfers the current database, prepared statements, variables, affected/found rows and related state, but no temporary-table mapping or temporary-table objects are included inMigrateConnToRequest.- The observed target-side failure occurs while replaying exported prepared statements before the temporary table exists.
Regression coverage
After the product fix, add a multi-process/JDBC regression covering:
- temporary-table data survives Proxy CN migration;
- SQL and binary-protocol prepared statements referencing a temporary table remain executable;
- commit/rollback migration gating remains unchanged;
- draining does not enter an unbounded retry loop.
This belongs in motr because it requires Connector/J, Proxy, two CNs and deterministic work-state switching.
Related
Discovered during extended Connector/J, PREPARE, GROUP_CONCAT and cross-CN Proxy migration exploration. No matching open/closed MatrixOne issue or fix PR was found.
Activity
fix(proxy): preserve temporary tables during CN migration (#27623)
Ariznawlll commentedon Sep 3, 2026
测试版本
maind37cc0f7b14c3dbd5bc810fc85950cf4da1e9a9bmo-search-commit-d37cc0f7b-20260903,3 CN、2 Proxy、1 TN、3 Log原问题验证
通过 Proxy 建立长连接,在会话中创建临时表和 server-side prepared statement;随后将当前后端 CN 置为 Draining,等待 Proxy 完成 CN migration,再在同一会话执行原 prepared statement。
Happy Path 覆盖
beta|alpha。beta|alpha。Working。Unhappy Path 覆盖
@@server_id,避免误切换其他 CN。白盒验证
本轮未做白盒注入,仅验证 Proxy/CN migration 的客户端可见行为。
回归测试
已完成 3 轮 Proxy + 多 CN prepared 临时表迁移验证。后续 MOTR 应保留 Connector/J binary prepared、双向迁移和事务 gating 场景。
测试证据
run1: before=beta|alpha after=beta|alpha migrated=True pass=True;run2、run3同样通过。测试结束后已恢复 CN 状态并清理测试对象。测试结论
测试通过。
Ariznawlll commentedon Sep 5, 2026
测试验收结论
maind37cc0f7b14c3dbd5bc810fc85950cf4da1e9a9bmo-search-commit-d37cc0f7b-20260903测试步骤
beta|alpha。Draining,等待 Proxy 完成 CN migration。Working。结果
beta|alpha。Working。结论:原问题在当前 main/TKE 多 CN + Proxy 环境下验证通过,现关闭 issue。
fix(proxy): preserve temporary tables during CN migration (matrixorig…
fix(proxy): preserve temporary tables during CN migration (matrixorig…
fix(proxy): preserve temporary tables during CN migration (matrixorig…