Mycat之String msg = "can't find table define in schema "+ tableName + " schema:" + schema.getName();
错误位置如下:RouterUtil 类中的tryRouteForTables方法
1、正常情况可以查询数据
2017-03-01 20:13:19,812 [WARN ][$_NIOREACTOR-2-RW] ServerConnection [id=4, schema=TESTDB, host=127.0.0.1, user=root,txIsolation=3, autocommit=true, schema=TESTDB]SELECT address as address FROM `t_gaojs` err:java.sql.SQLNonTransientException: can't find table define in schema ADDRESS schema:TESTDB java.sql.SQLNonTransientException: can't find table define in schema ADDRESS schema:TESTDB
at io.mycat.route.util.RouterUtil.tryRouteForTables(RouterUtil.java:1002)
at io.mycat.route.parser.druid.impl.DruidSelectParser.tryRoute(DruidSelectParser.java:412)
at io.mycat.route.parser.druid.impl.DruidSelectParser.changeSql(DruidSelectParser.java:287)
at io.mycat.route.parser.druid.impl.DefaultDruidParser.parser(DefaultDruidParser.java:67)
找到报错原因 ---》 表名字解析错误
RouterUtil 类中的tryRouteForTables方法
/**
* 多表路由
*/
public static RouteResultset tryRouteForTables(SchemaConfig schema, DruidShardingParseInfo ctx,
RouteCalculateUnit routeUnit, RouteResultset rrs, boolean isSelect,
LayerCachePool cachePool)
throws SQLNonTransientException {
List
if(schema.isNoSharding()||(tables.size() >= 1&&isNoSharding(schema,tables.get(0)))) {
return routeToSingleNode(rrs, schema.getDataNode(), ctx.getSql());
}
//只有一个表的
if(tables.size() == 1) {
return RouterUtil.tryRouteForOneTable(schema, ctx, routeUnit,
tables.get(0), rrs, isSelect, cachePool);
}
Set
//每个表对应的路由映射
Map
//分库解析信息不为空
Map
if(tablesAndConditions != null && tablesAndConditions.size() > 0) {
//为分库表找路由
RouterUtil.findRouteWithcConditionsForTables(schema, rrs, tablesAndConditions,
tablesRouteMap, ctx.getSql(), cachePool, isSelect);
if(rrs.isFinishedRoute()) {
return rrs;
}
}
//为全局表和单库表找路由
for(String tableName : tables) {
TableConfig tableConfig = schema.getTables().get(tableName.toUpperCase());
if(tableConfig == null) {
String msg = "can't find table define in schema "+ tableName + " schema:" + schema.getName();
LOGGER.warn(msg);
throw new SQLNonTransientException(msg);
}
if(tableConfig.isGlobalTable()) {//全局表
if(tablesRouteMap.get(tableName) == null) {
tablesRouteMap.put(tableName, new HashSet
}
tablesRouteMap.get(tableName).addAll(tableConfig.getDataNodes());
} else if(tablesRouteMap.get(tableName) == null) { //余下的表都是单库表
tablesRouteMap.put(tableName, new HashSet
tablesRouteMap.get(tableName).addAll(tableConfig.getDataNodes());
}
}
//此处省略如下代码
}