`
gaojingsong
  • 浏览: 1155741 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
文章分类
社区版块
存档分类
最新评论

Mycat源码解读--错误之【find no Route】

阅读更多

 Mycat之find no Route:SELECT * FROM `db1`.`t_gaojs` LIMIT 0

 错误原因竟然是:DruidSelectParser类中的tryRoute方法

1、后台报错,前台竟然可以查询出数据

2017-03-01 20:37:59,312 [WARN ][$_NIOREACTOR-3-RW] ServerConnection [id=1, schema=TESTDB, host=127.0.0.1, user=root,txIsolation=3, autocommit=true, schema=TESTDB]SELECT * FROM `db1`.`t_gaojs` LIMIT 0 err:java.sql.SQLNonTransientException:  find no Route:SELECT * FROM `db1`.`t_gaojs` LIMIT 0 java.sql.SQLNonTransientException:  find no Route:SELECT * FROM `db1`.`t_gaojs` LIMIT 0

at io.mycat.route.parser.druid.impl.DruidSelectParser.tryRoute(DruidSelectParser.java:437)


 错误原因竟然是:DruidSelectParser类中的tryRoute方法

 

           private void tryRoute(SchemaConfig schema, RouteResultset rrs,

                    LayerCachePool cachePool) throws SQLNonTransientException {

                if(rrs.isFinishedRoute())

              {

                    return;//避免重复路由

               }

 

         //无表的select语句直接路由带任一节点

        if((ctx.getTables() == null || ctx.getTables().size() == 0)

                   &&(ctx.getTableAliasMap()==null||ctx.getTableAliasMap().isEmpty())) {

                              rrs = RouterUtil.routeToSingleNode(rrs, schema.getRandomDataNode(), ctx.getSql());

                      rrs.setFinishedRoute(true);

                     return;

          }

            //RouterUtil.tryRouteForTables(schema, ctx, rrs, true, cachePool);

         SortedSet<RouteResultsetNode> nodeSet = new TreeSet<RouteResultsetNode>();

          boolean isAllGlobalTable = RouterUtil.isAllGlobalTable(ctx, schema);

          for (RouteCalculateUnit unit : ctx.getRouteCalculateUnits()) {

                 RouteResultset rrsTmp = RouterUtil.tryRouteForTables(schema, ctx, unit, rrs, true, cachePool);

             if (rrsTmp != null&&rrsTmp.getNodes()!=null) {

                   for (RouteResultsetNode node : rrsTmp.getNodes()) {

                  nodeSet.add(node);

               }

          }

           if(isAllGlobalTable) {//都是全局表时只计算一遍路由

                 break;

          }

      }

 

        if(nodeSet.size() == 0) {

 

            Collection<String> stringCollection= ctx.getTableAliasMap().values() ;

            for (String table : stringCollection)

            {

                if(table!=null&&table.toLowerCase().contains("information_schema."))

                {

                    rrs = RouterUtil.routeToSingleNode(rrs, schema.getRandomDataNode(), ctx.getSql());

                    rrs.setFinishedRoute(true);

                    return;

                }

            }

                String msg = " find no Route:" + ctx.getSql();

              LOGGER.warn(msg);

              throw new SQLNonTransientException(msg);

            }

 

         RouteResultsetNode[] nodes = new RouteResultsetNode[nodeSet.size()];

        int i = 0;

       for (Iterator<RouteResultsetNode> iterator = nodeSet.iterator(); iterator.hasNext();) {

            nodes[i] = (RouteResultsetNode) iterator.next();

            i++;

        }

       rrs.setNodes(nodes);

      rrs.setFinishedRoute(true);

   }

 


 

  • 大小: 82.2 KB
  • 大小: 44 KB
  • 大小: 97.6 KB
  • 大小: 87.9 KB
  • 大小: 101.1 KB
  • 大小: 110.3 KB
0
0
分享到:
评论
1 楼 shuang1qiang 2017-03-15  
大神怎么解决呢

相关推荐

Global site tag (gtag.js) - Google Analytics