MyCATApache / Mycat-Server

GNU General Public License v2.0
9.51k stars 3.85k forks source link

mycat 配置了读写分离,但是仍然从主库中读取 #1635

Open budingts opened 7 years ago

budingts commented 7 years ago

2017-08-29 15:52:41,449 [DEBUG][$_NIOREACTOR-3-RW] ServerConnection [id=41, schema=TESTDB, host=127.0.0.1, user=root,txIsolation=3, autocommit=false, schema=TESTDB]select

            user_id, user_email

            from t_users  (io.mycat.server.ServerQueryHandler:ServerQueryHandler.java:57)

2017-08-29 15:52:41,449 [DEBUG][$_NIOREACTOR-3-RW] SQLRouteCache hit cache ,key:TESTDBselect

            user_id, user_email

            from t_users  (io.mycat.cache.impl.EnchachePool:EnchachePool.java:71)

2017-08-29 15:52:41,449 [DEBUG][$_NIOREACTOR-3-RW] ServerConnection [id=41, schema=TESTDB, host=127.0.0.1, user=root,txIsolation=3, autocommit=false, schema=TESTDB]select

            user_id, user_email

            from t_users, route={

1 -> dn1{SELECT user_id, user_email FROM t_users LIMIT 100} } rrs (io.mycat.server.NonBlockingSession:NonBlockingSession.java:110) 2017-08-29 15:52:41,450 [DEBUG][$_NIOREACTOR-3-RW] rrs.getRunOnSlave() null (io.mycat.backend.mysql.nio.handler.SingleNodeHandler:SingleNodeHandler.java:166) 2017-08-29 15:52:41,450 [DEBUG][$_NIOREACTOR-3-RW] node.getRunOnSlave() null (io.mycat.backend.mysql.nio.handler.SingleNodeHandler:SingleNodeHandler.java:168) 2017-08-29 15:52:41,450 [DEBUG][$_NIOREACTOR-3-RW] node.getRunOnSlave() null (io.mycat.backend.mysql.nio.handler.SingleNodeHandler:SingleNodeHandler.java:177) 2017-08-29 15:52:41,450 [DEBUG][$_NIOREACTOR-3-RW] node.getRunOnSlave() null (io.mycat.backend.mysql.nio.handler.SingleNodeHandler:SingleNodeHandler.java:179) 2017-08-29 15:52:41,450 [DEBUG][$_NIOREACTOR-3-RW] rrs.getRunOnSlave() null (io.mycat.backend.datasource.PhysicalDBNode:PhysicalDBNode.java:96) 2017-08-29 15:52:41,450 [DEBUG][$_NIOREACTOR-3-RW] rrs.getRunOnSlave() null (io.mycat.backend.datasource.PhysicalDBNode:PhysicalDBNode.java:127) 2017-08-29 15:52:41,450 [DEBUG][$_NIOREACTOR-3-RW] release connection MySQLConnection [id=22, lastTime=1503993161429, user=root, schema=weibo_simple, old shema=weibo_simple, borrowed=true, fromSlaveDB=false, threadId=9, charset=utf8, txIsolation=3, autocommit=true, attachment=dn1{SELECT user_id, user_email

yanjunli commented 7 years ago

autocommit=false 这是在事务中的查询。需要加注解才行。

budingts commented 7 years ago

哪里加注解?

budingts commented 7 years ago

找到原因了 @yanjunli ,谢谢了,我在数据源配置的时候配置了 defaultAutoCommit 配置成false了,改成true就行

<!-- Druid集连接池,首先spring配置DataSource -->
<bean id="druidDataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">
    <property name="driverClassName" value="${jdbc.driverClassName}" />

     <!-- 基本属性 url、user、password -->  
    <property name="url" value="${jdbc.url}" />
    <property name="username" value="${jdbc.username}" />
    <property name="password" value="${jdbc.password}" />
    <!--initialSize: 初始化连接-->
    <property name="initialSize" value="${jdbc.initialSize}"/>
    <!--minIdle: 最小空闲连接-->
    <property name="minIdle" value="${jdbc.minIdle}"/>
    <!--maxActive: 最大连接数量-->
    <property name="maxActive" value="${jdbc.maxActive}"/>
     <!--removeAbandoned: 对泄漏的连接,是否自动回收超时连接-->
    <property name="removeAbandoned" value="true"/>
    <!--removeAbandonedTimeout: 超时时间(以秒数为单位)-->
    <property name="removeAbandonedTimeout" value="${jdbc.removeAbandonedTimeout}"/>
    <!--maxWait: 超时等待时间以毫秒为单位 6000毫秒/1000等于60秒-->
    <property name="maxWait" value="${jdbc.maxWait}"/>
   <property name="defaultAutoCommit">
        <value>true</value>
    </property>
    <property name="validationQuery" value="select 1"/>

    <!-- 打开PSCache,并且指定每个连接上PSCache的大小 -->  
    <!-- 如果用Oracle,则把poolPreparedStatements配置为true,mysql可以配置为false。分库分表较多的数据库,建议配置为false -->  
    <property name="poolPreparedStatements" value="true" />
    <property name="maxOpenPreparedStatements" value="${jdbc.maxOpenPreparedStatements}" />

     <!-- 配置监控统计拦截的filters,去掉后监控界面sql无法统计 --> 
     <!--<property name="filters" value="stat"/>-->
     <!-- 慢日志查询  缺省为3秒  修改为10秒 10000 -->  
    <!-- <property name="connectionProperties" value="druid.stat.slowSqlMillis=5000" />   -->

</bean>
zhangxinyuan1 commented 6 years ago

@budingts defaultAutoCommit 配置成false了,改成true就行 改成了true 还是不行

mousycoder commented 5 years ago

+1

Fxdemon commented 5 years ago

+事物 自动走写

shawn9527 commented 5 years ago

哪里有区分是不是加了事务,我也是这种情况,谢谢?

shawnzhao@126.com

发件人: Fx_demon 发送时间: 2019-01-03 16:09 收件人: MyCATApache/Mycat-Server 抄送: Subscribed 主题: Re: [MyCATApache/Mycat-Server] mycat 配置了读写分离,但是仍然从主库中读取 (#1635) +事物 自动走写 — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

Fxdemon commented 5 years ago

在自己的应用端 添加事物注解或手动开启事物 提交事物

shawn9527 commented 5 years ago

师兄好, 那我是默认配置,没有手动开启的, 我的情况是读写分离,当读的时候前面3000个读请求可以负载均衡的分发到各个读节点,3000以后就只有一个读节点接受读请求,其他读节点不动了,像是死了一样?有遇到这种情况吗?谢谢

shawnzhao@126.com

发件人: Fx_demon 发送时间: 2019-01-03 17:49 收件人: MyCATApache/Mycat-Server 抄送: zhaoxiaolong; Comment 主题: Re: [MyCATApache/Mycat-Server] mycat 配置了读写分离,但是仍然从主库中读取 (#1635) 在自己的应用端 添加事物注解或手动开启事物 提交事物 — You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.