问题现象
OBProxy V4.x 版本中提供了 explain route <your_sql>; 命令用来获取 SQL 语句的路由状态信息,并展示详细的诊断信息。<your_sql> 语句将会在 OBProxy 内部进行处理,执行正常的 OBProxy 转发流程,但不会真正转发给 OBServer 节点。
示例如下:
对于按照 hash(id) 进行分区的分区表 t1。
$ mysql -hxx.xxx.80.111 -P2883 -uroot@mysqlt#oio_cluster -pxxx -A -c test
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MySQL connection id is 1619840
Server version: 5.6.25 OceanBase 4.2.5.3 (r103000142025033110-f5b88cd987f23383677f2eb53cf76ed38a48979b) (Built Mar 31 2025 11:04:29)
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MySQL [test]> explain route select * from t1 where id=1;
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Route Plan |
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
Trans Current Query:"explain route select * from t1 where id=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(xx.xxx.80.111:2881) using route policy PRIMARY_ZONE_FIRST because query for STRONG read
Route Plan
-----------------
> SQL_PARSE:{cmd:"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:"500033", table_type:"USER TABLE", partition_num:30, entry_from_remote:false}
> PARTITION_ID_CALC_START:{}
> EXPR_PARSE:{col_val:"id=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 30"}
> PARTITION_ID_CALC_DONE:{partition_id:200032, level:1, partitions:"(p1)"}
> PARTITION_ENTRY_LOOKUP_DONE:{leader:"xx.xxx.80.111:2881"}
> ROUTE_POLICY:{route_policy:"", chosen_route_type:"ROUTE_TYPE_LEADER"}
> CONGESTION_CONTROL:{svr_addr:"xx.xxx.80.111:2881"}
|
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.01 sec)
但是,如果需要 explain route 的 SQL 文本过长,该命令会遇到如下的报错。
$ mysql -hxx.xxx.80.111 -P2883 -uroot@mysqlt#oio_cluster -pxxx -A -c test
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MySQL connection id is 1619840
Server version: 5.6.25 OceanBase 4.2.5.3 (r103000142025033110-f5b88cd987f23383677f2eb53cf76ed38a48979b) (Built Mar 31 2025 11:04:29)
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MySQL [test]> source /tmp/explain_route_long_sql_text.sql;
+-----------------------------------------+
| Route Plan |
+-----------------------------------------+
| Route diagnosis not supports this query |
+-----------------------------------------+
1 row in set (0.000 sec)
问题原因
目前 OBProxy 在尝试获取 SQL 语句的路由信息时,如果在 request_buffer_length 长度内还没有解析到完整的表名,OBProxy 将无法获取路由信息。因此,如果 explain route 时遇到报错 “Route diagnosis not supports this query”,可以看看是不是这条 SQL 文本超长了,超过了 request_buffer_length 的限制,如果超过了可以考虑调大 OBProxy 配置项 request_buffer_length 的大小。
MySQL [(none)]> show proxyconfig like 'request_buffer_length'; // 用于设置每个请求分配的请求 buffer 的最大长度,取值范围:[1KB, 16MB]。默认值:4K(OBProxy V4.3.4 中将默认值由 4K 调大到 8K)
+-----------------------+-------+-----------------------------------------------------------------+-------------+---------------+
| name | value | info | need_reboot | visible_level |
+-----------------------+-------+-----------------------------------------------------------------+-------------+---------------+
| request_buffer_length | 4KB | the max length of request buffer we will alloc for each reqeust | false | USER |
+-----------------------+-------+-----------------------------------------------------------------+-------------+---------------+
1 row in set (0.00 sec)
说明:request_buffer_length 默认值为 4K,对超过 4KB 的还没有解析到表名的请求,OBProxy 无法获取路由信息会随机路由,可能会导致远程路由,对性能影响较大。业务中多次遇到此问题,因此 OBProxy V4.3.4 版本中将 request_buffer_length 配置项的默认值由 4KB 调大到 8KB。
问题的风险及影响
通过 explain route 命令来获取 SQL 语句的路由信息失败。
适用版本
OBProxy V4.x 版本。
解决方法
连接到 root@sys# 集群名,调大 OBProxy 配置项 request_buffer_length 的大小,比如将该配置项调大到超过需要 explain route 的 SQL 文本的长度。
$ mysql -hxx.xxx.80.111 -P2883 -uroot@sys#oio_cluster -pxxx -A -c oceanbase
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MySQL connection id is 1619874
Server version: 5.6.25 OceanBase 4.2.5.3 (r103000142025033110-f5b88cd987f23383677f2eb53cf76ed38a48979b) (Built Mar 31 2025 11:04:29)
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MySQL [oceanbase]> alter proxyconfig set request_buffer_length='64KB';
Query OK, 0 rows affected (0.03 sec)
MySQL [oceanbase]> Bye
然后再执行之前报错的 explain route 语句,应该就可以正常工作了。 注意:request_buffer_length 是 client 和 OBProxy 建连每个 SESSION 需要申请的内存一部分,所以如果只调大这个参数,而不将 OBProxy 内存也调大(默认值:2G),很容易将 OBProxy 内存打爆。建议同时调大 OBProxy 的内存上限 proxy_mem_limited,或者在解析完该超长 SQL 文本后,将 request_buffer_length 再恢复回去:
MySQL [oceanbase]> alter proxyconfig set request_buffer_length='4KB';
Query OK, 0 rows affected (0.00 sec)
规避方式
无。