-
Notifications
You must be signed in to change notification settings - Fork 479
[配置]schema
jamie12221 edited this page Nov 29, 2020
·
1 revision
{库名}.schema.json保存在schemas文件夹
{
"customTables": {},
"globalTables": {},
"normalTables": {},
"schemaName": "test",
"shadingTables": {},
"targetName": "prototype"
}
自动从prototype目标加载test库下的物理表或者视图作为单表
{
"schemaName": "mysql-test",
"normalTables": {
"role_edges": {
"createTableSQL":null,//可选
"dataNode": {
"schemaName": "mysql",//物理库
"tableName": "role_edges",//物理表
"targetName": "prototype"//指向集群,或者数据源
}
}
......
{
"schemaName": "mysql-test",
"globalTables": {
"role_edges": {
"dataNodes": [{"targetName": "c0"},{"targetName": "c1"}]
}
......
{
"customTables": {},
"globalTables": {},
"normalTables": {},
"schemaName": "db1",
"shadingTables": {
"travelrecord": {
"function": {
"properties": {
"dbNum": "2",//分库数量
"tableNum": "2",//分表数量
"tableMethod": "hash(id)",//分表分片函数
"storeNum": 2,//实际存储节点数量
"dbMethod": "hash(id)"//分库分片函数
}
}
}
}
}
上述配置自动使用c0,c1两个集群作为存储节点
{
"customTables": {},
"globalTables": {},
"normalTables": {},
"schemaName": "db1",
"shadingTables": {
"travelrecord": {
"function": {
"properties": {
"dbNum": "2",//分库数量
"tableNum": "2",//分表数量
"tableMethod": "hash(id)",//分表分片函数
"storeNum": 2,//实际存储节点数量
"dbMethod": "hash(id)"//分库分片函数
}
},
"dataNode":{
"targetNames":"c${targetIndex}",
"schemaNames":"db1_${dbIndex}",
"tableNames":"t1_${tableIndex}"
}
}
}
}
targetIndex,dbIndex,tableIndex总是从0开始计算,支持groovy运算生成目标名,库名,表名
{
"customTables": {},
"globalTables": {},
"normalTables": {},
"schemaName": "db1",
"shadingTables": {
"travelrecord": {
"function": {
"properties": {
"clazz": //具体自定义分片算法
...分片算法参数
}
},
"dataNode":{
"targetNames":"c$0-1",
"schemaNames":"db1_$0-1",
"tableNames":"t1_$0-1"
}
}
}
}
dataNode配置存储节点,在分片算法无法使用的时候就扫描这些存储节点,需要注意的是在此处
dataNode中的生成表达式不支持groovy运算只支持$0-1语法生成
for (String target : targets) {
for (String schema : schemas) {
for (String table : tables) {
....生成存储节点
}
}
}