V4版本模拟V3分布式事务执行情况

ob:4.2.1.8

启用V3版本路由(v4版本分布式事务路由功能默认true表示开启的,false表示启用v3的路由策略):

mysql> show proxyconfig like 'enable_transaction_internal_routing' \G show proxyconfig like 'enable_transaction_internal_routing' \G
*************************** 1. row ***************************
         name: enable_transaction_internal_routing
        value: False
         info: if enabled, proxy will route the dml statement in a transaction to different servers
  need_reboot: false
visible_level: USER
        range: 
 config_level: LEVEL_GLOBAL
1 row in set (0.00 sec)

*************************** 1. row ***************************
         name: enable_transaction_internal_routing
        value: False
         info: if enabled, proxy will route the dml statement in a transaction to different servers
  need_reboot: false
visible_level: USER
        range: 
 config_level: LEVEL_GLOBAL
1 row in set (0.00 sec)

创建表:

mysql> show create table t1 \G
*************************** 1. row ***************************
       Table: t1
Create Table: CREATE TABLE `t1` (
  `C1` int(11) DEFAULT NULL,
  `C2` int(11) DEFAULT NULL
) DEFAULT CHARSET = utf8mb4 ROW_FORMAT = DYNAMIC COMPRESSION = 'zstd_1.3.8' REPLICA_NUM = 3 BLOCK_SIZE = 16384 USE_BLOOM_FILTER = FALSE TABLET_SIZE = 134217728 PCTFREE = 0
 partition by hash(c1)
(partition `p0`,
partition `p1`)
1 row in set (0.00 sec)

CREATE TABLE T2(C1 INT,C2 INT) PARTITION BY HASH(C1) PARTITIONS 2; 

插入语句:

mysql> INSERT INTO T1 VALUES(1,1);  INSERT INTO T1 VALUES(2,2);  INSERT INTO T2 VALUES(11,11);  INSERT INTO T2 VALUES(22,22);
Query OK, 1 row affected (0.02 sec)

Query OK, 1 row affected (0.01 sec)

Query OK, 1 row affected (0.01 sec)

Query OK, 1 row affected (0.00 sec)

mysql> select * from t1;
+------+------+
| C1   | C2   |
+------+------+
|    1 |    1 |
|    2 |    2 |
+------+------+
2 rows in set (0.01 sec)

mysql> select * from t2;
+------+------+
| C1   | C2   |
+------+------+
|   22 |   22 |
|   11 |   11 |
+------+------+
2 rows in set (0.01 sec)

mysql> select * from t1 partition(p0);
+------+------+
| C1   | C2   |
+------+------+
|    2 |    2 |
+------+------+
1 row in set (0.00 sec)

mysql> select * from t1 partition(p1);
+------+------+
| C1   | C2   |
+------+------+
|    1 |    1 |
+------+------+
1 row in set (0.00 sec)

查看数据分布:

+---------------+------------+------------+----------------+-------+--------------+--------+
| DATABASE_NAME | TABLE_NAME | TABLE_TYPE | PARTITION_NAME | ZONE  | SVR_IP       | ROLE   |
+---------------+------------+------------+----------------+-------+--------------+--------+
| test          | t1         | USER TABLE | p0             | zone1 | 10.xx.xx.220 | LEADER |
| test          | t1         | USER TABLE | p1             | zone2 | 10.xx.xx.221 | LEADER |
+---------------+------------+------------+----------------+-------+--------------+--------+

可以看到p0的leader在220上,p1的leader在221上

模拟事务(在220上执行):

BEGIN; 
update t1 set c2=3 where c1=1; 
update t1 set c2=4 where c1=2; 
update t2 set c2=33 where c1=11; 
update t2 set c2=43 where c1=22;  
COMMIT; 

查看事务执行情况:

mysql> select query_sql,tx_id from oceanbase.gv$ob_sql_audit where query_sql like 'update t1 set c2=3 where c1=1%' order by request_time desc limit 1; 
+-------------------------------+----------+
| query_sql                     | tx_id    |
+-------------------------------+----------+
| update t1 set c2=3 where c1=1 | 11538142 |
+-------------------------------+----------+
1 row in set (0.11 sec)

mysql> select SVR_IP,SVR_PORT,query_sql,TX_ID,TX_INTERNAL_ROUTING,PLAN_TYPE ,PARTITION_HIT,FROM_UNIXTIME(request_time/1000000) from oceanbase.gv$ob_sql_audit where TX_ID=11538142 order by request_time;
+--------------+----------+---------------------------------+----------+---------------------+-----------+---------------+-------------------------------------+
| SVR_IP       | SVR_PORT | query_sql                       | TX_ID    | TX_INTERNAL_ROUTING | PLAN_TYPE | PARTITION_HIT | FROM_UNIXTIME(request_time/1000000) |
+--------------+----------+---------------------------------+----------+---------------------+-----------+---------------+-------------------------------------+
| 10.xx.xx.221 |     2882 | begin                           | 11538142 |                   1 |         0 |             1 | 2025-07-21 14:16:54.8814            |
| 10.xx.xx.221 |     2882 | update t1 set c2=3 where c1=1   | 11538142 |                   1 |         1 |             1 | 2025-07-21 14:17:13.5427            |
| 10.xx.xx.221 |     2882 | update t1 set c2=4 where c1=2   | 11538142 |                   1 |         2 |             0 | 2025-07-21 14:17:13.5462            |
| 10.xx.xx.221 |     2882 | update t2 set c2=33 where c1=11 | 11538142 |                   1 |         2 |             0 | 2025-07-21 14:17:13.5596            |
| 10.xx.xx.221 |     2882 | update t2 set c2=43 where c1=22 | 11538142 |                   1 |         1 |             1 | 2025-07-21 14:17:13.5705            |
| 10.xx.xx.221 |     2882 | COMMIT                          | 11538142 |                   0 |         0 |             1 | 2025-07-21 14:17:13.5716            |
+--------------+----------+---------------------------------+----------+---------------------+-----------+---------------+-------------------------------------+
6 rows in set (0.12 sec)

疑问:
模拟V3在事务执行(事务的工作方式是同一个事务的语句统一路由到一个数据节点上执行),在哪个节点开启事务就在那个节点执行,这里执行节点应该是220,
但是TX_INTERNAL_ROUTING 查询结果为0 才对,为什么这里是1呢?

2 个赞

1 个赞

没大看明白啊

将这个参数也设置为false再试试 enable_ob_protocol_v2

其实复制粘贴的有问题,其实两个参数都是false

链接的的是221节点吧?
看着update c2=2的语句是远程执行计划,符合预期

连接是220节点,都在220上执行的。

ODP版本是多少

image

可以链接odp执行一下explain route +sql语句看下具体的执行计划,帮忙把结果贴一下

上边的测试是通过2881端口连接的? 使用2883端口测试一下

1 个赞

测试都是连击ODP 2883,这里显示的observer节点

1 个赞

需要获取update语句的执行计划
执行下explain route update t1 set c2=3 where c1=1;
explain route update t1 set c2=4 where c1=2;

1 个赞

220、221每个上面都部署了observer和ODP
以下语句在220上的ODP执行:

Trans Current Query:"explain route update t1 set c2=3 where c1=1"

Route Prompts
-----------------
> ROUTE_INFO
  [INFO] Will do table partition location lookup to decide which OBServer to route to
> ROUTE_POLICY
  [INFO] Will route to table's partition leader replica(10.**.**.221:2881) using route policy PRIMARY_ZONE_FIRST because query for STRONG read

Route Plan
-----------------
> SQL_PARSE:{cmd:"OB_MYSQL_COM_QUERY", table:"t1"}
> ROUTE_INFO:{route_info_type:"USE_PARTITION_LOCATION_LOOKUP"}
> LOCATION_CACHE_LOOKUP:{mode:"oceanbase"}
  > TABLE_ENTRY_LOOKUP_DONE:{table:"t1", table_id:"500087", table_type:"USER TABLE", partition_num:2, entry_from_remote:false}
  > PARTITION_ID_CALC_START:{}
    > EXPR_PARSE:{col_val:"c1=1"}
    > RESOLVE_EXPR:{part_range:"[1 ; 1]"}
      > RESOLVE_TOKEN:{token_type:"TOKEN_INT_VAL", resolve:"BIGINT:1", token:"1"}
    > CALC_PARTITION_ID:{part_description:"partition by hash(INT<binary>) partitions 2"}
  > PARTITION_ID_CALC_DONE:{partition_id:200057, level:1, partitions:"(p1)"}
  > PARTITION_ENTRY_LOOKUP_DONE:{leader:"10.**.**.221:2881", entry_from_remote:false}
> ROUTE_POLICY:{route_policy:"", chosen_route_type:"ROUTE_TYPE_LEADER", type:"FULL"}
> CONGESTION_CONTROL:{svr_addr:"10.**.**.221:2881"}
 |
 
 Trans Current Query:"explain route update t1 set c2=4 where c1=2"

Route Prompts
-----------------
> ROUTE_INFO
  [INFO] Will do table partition location lookup to decide which OBServer to route to
> ROUTE_POLICY
  [INFO] Will route to table's partition leader replica(10.**.**.220:2881) using route policy PRIMARY_ZONE_FIRST because query for STRONG read


Route Plan
-----------------
> SQL_PARSE:{cmd:"OB_MYSQL_COM_QUERY", table:"t1"}
> ROUTE_INFO:{route_info_type:"USE_PARTITION_LOCATION_LOOKUP"}
> LOCATION_CACHE_LOOKUP:{mode:"oceanbase"}
  > TABLE_ENTRY_LOOKUP_DONE:{table:"t1", table_id:"500087", table_type:"USER TABLE", partition_num:2, entry_from_remote:false}
  > PARTITION_ID_CALC_START:{}
    > EXPR_PARSE:{col_val:"c1=2"}
    > RESOLVE_EXPR:{part_range:"[2 ; 2]"}
      > RESOLVE_TOKEN:{token_type:"TOKEN_INT_VAL", resolve:"BIGINT:2", token:"2"}
    > CALC_PARTITION_ID:{part_description:"partition by hash(INT<binary>) partitions 2"}
  > PARTITION_ID_CALC_DONE:{partition_id:200056, level:1, partitions:"(p0)"}
  > PARTITION_ENTRY_LOOKUP_DONE:{leader:"10.**.**.220:2881", entry_from_remote:false}
> ROUTE_POLICY:{route_policy:"", chosen_route_type:"ROUTE_TYPE_LEADER", type:"FULL"}
> CONGESTION_CONTROL:{svr_addr:"10.**.**.220:2881"}


1 个赞

odp关闭了事务路由确实都路由到了协调者就是221节点,查表TX_INTERNAL_ROUTING应该是0,可能是这张表显示的问题,这边需要先去确认下

你好,这边使用425.4版本测试TX_INTERNAL_ROUTING字段展示的为0.可能该问题是已修复的bug问题。建议更新一下数据库版本

1 个赞