Skip to content

[配置]schema

jamie12221 edited this page Nov 29, 2020 · 1 revision

schema配置

{库名}.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两个集群作为存储节点

分片表配置-hash型自动分片算法
{
  "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) { 
            ....生成存储节点
        }
    }
}
Clone this wiki locally