MyCATApache / Mycat-Server

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

Laravel的Eloquent模型绑定导致的Mycat-server异常 #1725

Open yiranzai opened 6 years ago

yiranzai commented 6 years ago

Mycat所在服务器为CentOS 7.4 1708 64位 Mycat-server版本为1.6

亲测在Laravel中,原生sql的各项操作没问题。 Eloquent模型的操作会报错,检查mycat日志 如下

2017-12-07 20:22:55.299  INFO [$_NIOREACTOR-0-RW] (io.mycat.net.handler.FrontendAuthenticator.success(FrontendAuthenticator.java:194)) - ServerConnection [id=1, schema=shop, host=59.41.64.2, user=proxy,txIsolation=3, autocommit=true, schema=shop]'proxy' login success
2017-12-07 20:22:55.346  WARN [$_NIOREACTOR-0-RW] (io.mycat.server.handler.SetHandler.handle(SetHandler.java:159)) - ServerConnection [id=1, schema=shop, host=59.41.64.2, user=proxy,txIsolation=3, autocommit=true, schema=shop]set session sql_mode='ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION' is not recoginized and ignored
2017-12-07 20:22:55.546  WARN [$_NIOREACTOR-0-RW] (io.mycat.net.NIOReactor$RW.run(NIOReactor.java:107)) - caught err:
java.lang.IndexOutOfBoundsException: No group 2
    at java.util.regex.Matcher.start(Matcher.java:375) ~[?:1.8.0_20]
    at java.util.regex.Matcher.appendReplacement(Matcher.java:880) ~[?:1.8.0_20]
    at java.util.regex.Matcher.replaceFirst(Matcher.java:1004) ~[?:1.8.0_20]
    at java.lang.String.replaceFirst(String.java:2165) ~[?:1.8.0_20]
    at io.mycat.server.handler.ServerPrepareHandler.prepareStmtBindValue(ServerPrepareHandler.java:222) ~[Mycat-server-1.6-RELEASE.jar:?]
    at io.mycat.server.handler.ServerPrepareHandler.execute(ServerPrepareHandler.java:135) ~[Mycat-server-1.6-RELEASE.jar:?]
    at io.mycat.net.FrontendConnection.stmtExecute(FrontendConnection.java:386) ~[Mycat-server-1.6-RELEASE.jar:?]
    at io.mycat.net.handler.FrontendCommandHandler.handle(FrontendCommandHandler.java:99) ~[Mycat-server-1.6-RELEASE.jar:?]
    at io.mycat.net.FrontendConnection.rawHandle(FrontendConnection.java:478) ~[Mycat-server-1.6-RELEASE.jar:?]
    at io.mycat.net.FrontendConnection.handle(FrontendConnection.java:460) ~[Mycat-server-1.6-RELEASE.jar:?]
    at io.mycat.net.AbstractConnection.onReadData(AbstractConnection.java:321) ~[Mycat-server-1.6-RELEASE.jar:?]
    at io.mycat.net.NIOSocketWR.asynRead(NIOSocketWR.java:190) ~[Mycat-server-1.6-RELEASE.jar:?]
    at io.mycat.net.AbstractConnection.asynRead(AbstractConnection.java:273) ~[Mycat-server-1.6-RELEASE.jar:?]
    at io.mycat.net.NIOReactor$RW.run(NIOReactor.java:102) ~[Mycat-server-1.6-RELEASE.jar:?]
    at java.lang.Thread.run(Thread.java:745) [?:1.8.0_20]
2017-12-07 20:22:55.546  INFO [$_NIOREACTOR-0-RW] (io.mycat.net.AbstractConnection.close(AbstractConnection.java:508)) - close connection,reason:program err:java.lang.IndexOutOfBoundsException: No group 2 ,ServerConnection [id=1, schema=shop, host=59.41.64.2, user=proxy,txIsolation=3, autocommit=true, schema=shop]
2017-12-07 20:22:55.579  INFO [$_NIOREACTOR-0-RW] (io.mycat.net.handler.FrontendAuthenticator.success(FrontendAuthenticator.java:194)) - ServerConnection [id=2, schema=shop, host=59.41.64.2, user=proxy,txIsolation=3, autocommit=true, schema=shop]'proxy' login success
2017-12-07 20:22:55.618  WARN [$_NIOREACTOR-0-RW] (io.mycat.server.handler.SetHandler.handle(SetHandler.java:159)) - ServerConnection [id=2, schema=shop, host=59.41.64.2, user=proxy,txIsolation=3, autocommit=true, schema=shop]set session sql_mode='ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION' is not recoginized and ignored
2017-12-07 20:22:55.635  WARN [$_NIOREACTOR-0-RW] (io.mycat.net.NIOReactor$RW.run(NIOReactor.java:107)) - caught err:
java.lang.IndexOutOfBoundsException: No group 2
    at java.util.regex.Matcher.start(Matcher.java:375) ~[?:1.8.0_20]
    at java.util.regex.Matcher.appendReplacement(Matcher.java:880) ~[?:1.8.0_20]
    at java.util.regex.Matcher.replaceFirst(Matcher.java:1004) ~[?:1.8.0_20]
    at java.lang.String.replaceFirst(String.java:2165) ~[?:1.8.0_20]
    at io.mycat.server.handler.ServerPrepareHandler.prepareStmtBindValue(ServerPrepareHandler.java:222) ~[Mycat-server-1.6-RELEASE.jar:?]
    at io.mycat.server.handler.ServerPrepareHandler.execute(ServerPrepareHandler.java:135) ~[Mycat-server-1.6-RELEASE.jar:?]
    at io.mycat.net.FrontendConnection.stmtExecute(FrontendConnection.java:386) ~[Mycat-server-1.6-RELEASE.jar:?]
    at io.mycat.net.handler.FrontendCommandHandler.handle(FrontendCommandHandler.java:99) ~[Mycat-server-1.6-RELEASE.jar:?]
    at io.mycat.net.FrontendConnection.rawHandle(FrontendConnection.java:478) ~[Mycat-server-1.6-RELEASE.jar:?]
    at io.mycat.net.FrontendConnection.handle(FrontendConnection.java:460) ~[Mycat-server-1.6-RELEASE.jar:?]
    at io.mycat.net.AbstractConnection.onReadData(AbstractConnection.java:321) ~[Mycat-server-1.6-RELEASE.jar:?]
    at io.mycat.net.NIOSocketWR.asynRead(NIOSocketWR.java:190) ~[Mycat-server-1.6-RELEASE.jar:?]
    at io.mycat.net.AbstractConnection.asynRead(AbstractConnection.java:273) ~[Mycat-server-1.6-RELEASE.jar:?]
    at io.mycat.net.NIOReactor$RW.run(NIOReactor.java:102) ~[Mycat-server-1.6-RELEASE.jar:?]
    at java.lang.Thread.run(Thread.java:745) [?:1.8.0_20]
2017-12-07 20:22:55.635  INFO [$_NIOREACTOR-0-RW] (io.mycat.net.AbstractConnection.close(AbstractConnection.java:508)) - close connection,reason:program err:java.lang.IndexOutOfBoundsException: No group 2 ,ServerConnection [id=2, schema=shop, host=59.41.64.2, user=proxy,txIsolation=3, autocommit=true, schema=shop]
ZzzCrazyPig commented 6 years ago

@yiranzai 你取的版本可能之前的预处理逻辑处理占位符有问题,按目前最新代码来看,应该没有这个报错,你可以取最新的1.6.x的代码试试

yiranzai commented 6 years ago

@ZzzCrazyPig 老哥,非常感谢,这个问题困扰了我很多天。 在Mycat群里问没人搭理我,我是做PHP的又不懂Java。 用Xdebug分析Eloquent,又有好几万行log出来。 再次表示感谢!

ZzzCrazyPig commented 6 years ago

@yiranzai 不用客气,这个坑还是我埋下的= =。高版本也有高版本的风险,没有办法保证没有其他BUG,mycat对预处理的支持还没那么完善。如果真考虑上mycat,开发语言是php的话,你还是得多测试一下预处理相关的逻辑有没有问题,毕竟我所知道的PHP框架,很多都是用了mysql预处理sql接口。我本身做Java开发,Java使用jdbc驱动连mycat几乎是不走预处理的(都是走jdbc本地预处理,非server端预处理)

yiranzai commented 6 years ago

@ZzzCrazyPig 我是小菜鸟,还没毕业。 毕设是要求负载均衡主从复制读写分离,尝试过Mysql-proxy,很容易挂。Mysql-router读写端口不一个,才知道了Mycat。 看来要先去看看预处理了。 总之谢大佬点拨 笔芯