Mycat源码解读--错误之【can't find table define in schema 】

在Mycat中遇到'can't find table define in schema'错误,主要出现在RouterUtil的tryRouteForTables方法。当尝试通过别名查询时,Mycat无法正确解析表名,导致数据路由失败。错误详细信息显示在ServerConnection的日志警告中,指出表定义在指定的schema中不存在。问题根源在于RouterUtil类的tryRouteForTables方法中的表名字解析错误。解决方案是确保表配置正确,并在schema中定义。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Mycat之String msg = "can't find table define in schema "+ tableName + " schema:" + schema.getName();

错误位置如下:RouterUtil 类中的tryRouteForTables方法

1、正常情况可以查询数据


 2、别名查询出现错误


 Mycat 怎么就通过不了呢


 

 

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<String> tables = ctx.getTables();

 

          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<String> retNodesSet = new HashSet<String>();

         //每个表对应的路由映射

         Map<String,Set<String>> tablesRouteMap = new HashMap<String,Set<String>>();

 

        //分库解析信息不为空

          Map<String, Map<String, Set<ColumnRoutePair>>> tablesAndConditions =                       routeUnit.getTablesAndConditions();

       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<String>());

              }

           tablesRouteMap.get(tableName).addAll(tableConfig.getDataNodes());

     } else if(tablesRouteMap.get(tableName) == null) { //余下的表都是单库表

             tablesRouteMap.put(tableName, new HashSet<String>());

            tablesRouteMap.get(tableName).addAll(tableConfig.getDataNodes());

       }

}

             //此处省略如下代码

               

}

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值