RAL (Resource & Rule Administration Language) 为 Apache ShardingSphere 的管理语言, 负责强制路由、事务类型切换、弹性伸缩、分片执行计划查询等增量功能的操作。

强制路由

语句说明示例
set readwrite_splitting hint source = [auto / write]针对当前连接,设置读写分离的路由策略(自动路由或强制到写库)set readwrite_splitting hint source = write
set sharding hint database_value = yy针对当前连接,设置 hint 仅对数据库分片有效,并添加分片值,yy:数据库分片值set sharding hint database_value = 100
add sharding hint database_value xx = yy针对当前连接,为表 xx 添加分片值 yy,xx:逻辑表名称,yy:数据库分片值add sharding hint database_value t_order= 100
add sharding hint table_value xx = yy针对当前连接,为表 xx 添加分片值 yy,xx:逻辑表名称,yy:表分片值add sharding hint table_value t_order = 100
clear hint针对当前连接,清除 hint 所有设置clear hint
clear [sharding hint / readwrite_splitting hint]针对当前连接,清除 sharding 或 readwrite_splitting 的 hint 设置clear readwrite_splitting hint
show [sharding / readwrite_splitting] hint status针对当前连接,查询 sharding 或 readwrite_splitting 的 hint 设置show readwrite_splitting hint status

弹性伸缩

语句说明示例
show scaling list查询运行列表show scaling list
show scaling status xx查询任务状态,xx:任务idshow scaling status 1234
start scaling xx开始运行任务,xx:任务idstart scaling 1234
stop scaling xx停止运行任务,xx:任务idstop scaling 12345
drop scaling xx移除任务,xx:任务iddrop scaling 1234
reset scaling xx重置任务进度,xx:任务idreset scaling 1234
check scaling xx数据一致性校验,使用server.yaml里的校验算法,xx:任务idcheck scaling 1234
show scaling check algorithms展示可用的一致性校验算法show scaling check algorithms
check scaling {jobId} by type(name={algorithmType})数据一致性校验,使用指定的校验算法check scaling 1234 by type(name=DEFAULT)
stop scaling source writing xx旧的 ShardingSphere 数据源停写,xx:任务idstop scaling source writing 1234
checkout scaling xx切换至新的 ShardingSphere 数据源,xx:任务idcheckout scaling 1234

熔断

语句说明示例
[enable / disable] readwrite_splitting read xxx [from schema]启用 / 禁用读库enable readwrite_splitting read resource_0
[enable / disable] instance [IP=xxx, PORT=xxx / instanceId]启用 / 禁用 proxy 实例disable instance 127.0.0.1@3307
show instance list查询 proxy 实例信息show instance list
show readwrite_splitting read resources [from schema]查询所有读库的状态show readwrite_splitting read resources

解析引擎配置

语句说明示例
SHOW SQL_PARSER RULE查询当前解析引擎相关配置SHOW SQL_PARSER RULE
ALTER SQL_PARSER RULE SQL_COMMENT_PARSE_ENABLE=xx,PARSE_TREE_CACHE(INITIAL_CAPACITY=xx, MAXIMUM_SIZE=xx,CONCURRENCY_LEVEL=xx), SQL_STATEMENT_CACHE(INITIAL_CAPACITY=xxx, MAXIMUM_SIZE=xxx,CONCURRENCY_LEVEL=xxx)更新当前解析引擎配置,SQL_COMMENT_PARSE_ENABLE:是否解析 SQL 注释,PARSE_TREE_CACHE:语法树本地缓存配置,SQL_STATEMENT_CACHE:sql语句本地缓存配置项ALTER SQL_PARSER RULE SQL_COMMENT_PARSE_ENABLE=false,PARSE_TREE_CACHE(INITIAL_CAPACITY=10, MAXIMUM_SIZE=11,CONCURRENCY_LEVEL=1), SQL_STATEMENT_CACHE(INITIAL_CAPACITY=11, MAXIMUM_SIZE=11,CONCURRENCY_LEVEL=100)

其他

语句说明示例
set variable proxy_property_name = xxproxy_property_name 为 proxy 的属性配置 ,需使用下划线命名set variable sql_show = true
set variable transaction_type = xx修改当前连接的事务类型, 支持 LOCAL,XA,BASEset variable transaction_type = XA
set variable agent_plugins_enabled = [true / false]设置 agent 插件的启用状态,默认值 falseset variable agent_plugins_enabled = true
show all variables查询 proxy 所有的属性配置show all variable
show variable proxy_property_name查询 proxy 属性配置,需使用下划线命名show variable sql_show
show variable transaction_type查询当前连接的事务类型show variable transaction_type
show variable cached_connections查询当前连接中缓存的物理数据库连接个数show variable cached_connections
show variable agent_plugins_enabled查询 agent 插件的启用状态show variable agent_plugins_enabled
preview SQL预览实际 SQLpreview select from t_order
parse SQL解析 SQL 并输出抽象语法树 parse select from t_order
refresh table metadata刷新所有表的元数据refresh table metadata
refresh table metadata [tableName / tableName from resource resourceName]刷新指定表的元数据refresh table metadata t_order from resource ds_1

注意事项

ShardingSphere-Proxy 默认不支持 hint,如需支持,请在 conf/server.yaml 中,将 properties 的属性 proxy-hint-enabled 设置为 true。