Mycat读写分离以及拆库拆表综合实验3:通过日志分析mycat路由过程

#在客户端查询t1表中id=1的值

网站建设哪家好,找创新互联公司!专注于网页设计、网站建设、微信开发、微信小程序定制开发、集团企业网站建设等服务项目。为回馈新老客户创新互联还提供了新市免费建站欢迎大家使用!

我们在之前的schma.cnf中定义了t1在是一张全局表,且位于名称为MySQL的分片节点(datanode)上,因此当mycat拦截到客户端SQL语句之后,分析t1位于mysql分片节点上,直接发放该分片节点的readhost上

mysql > select * from t1 where id=1;

2018-05-25 10:16:16.906 DEBUG [$_NIOREACTOR-1-RW] (io.mycat.backend.mysql.nio.MySQLConnection.synAndDoExecute(MySQLConnection.java:451)) - con need syn ,total syn cmd 1 commands SET names utf8;schema change:false con:MySQLConnection [id=29, lastTime=1527214576906, user=mycat, schema=yuyang, old shema=yuyang, borrowed=true, fromSlaveDB=true, threadId=20, charset=utf8, txIsolation=3, autocommit=true, attachment=MySQL{SELECT *
FROM t1
WHERE id = 1
LIMIT 100}, respHandler=SingleNodeHandler [node=MySQL{SELECT *
FROM t1
WHERE id = 1
LIMIT 100}, packetId=0], host=192.168.31.117, port=3306, statusSync=null, writeQueue=0, modifiedSQLExecuted=false]
2018-05-25 10:16:16.907 DEBUG [$_NIOREACTOR-1-RW] (io.mycat.server.NonBlockingSession.releaseConnection(NonBlockingSession.java:378)) - release connection MySQLConnection [id=29, lastTime=1527214576902, user=mycat, schema=yuyang, old shema=yuyang, borrowed=true, fromSlaveDB=true, threadId=20, charset=utf8, txIsolation=3, autocommit=true, attachment=MySQL{SELECT *
FROM t1
WHERE id = 1
LIMIT 100}, respHandler=SingleNodeHandler [node=MySQL{SELECT *
FROM t1
WHERE id = 1
LIMIT 100}, packetId=8], host=192.168.31.117, port=3306, statusSync=io.mycat.backend.mysql.nio.MySQLConnection$StatusSync@40563af9, writeQueue=0, modifiedSQLExecuted=false]
2018-05-25 10:16:16.907 DEBUG [$_NIOREACTOR-1-RW] (io.mycat.backend.datasource.PhysicalDatasource.releaseChannel(PhysicalDatasource.java:595)) - release channel MySQLConnection [id=29, lastTime=1527214576902, user=mycat, schema=yuyang, old shema=yuyang, borrowed=true, fromSlaveDB=true, threadId=20, charset=utf8, txIsolation=3, autocommit=true, attachment=null, respHandler=null, host=192.168.31.117, port=3306, statusSync=null, writeQueue=0, modifiedSQLExecuted=false]

t2同理,只不过发往名为mysql_galera的分片节点上

mysql > select * from t2 where id=3;
2018-05-25 10:44:00.504 DEBUG [$_NIOREACTOR-1-RW] (io.mycat.backend.mysql.nio.MySQLConnection.synAndDoExecute(MySQLConnection.java:451)) - con need syn ,total syn cmd 1 commands SET names utf8;schema change:false con:MySQLConnection [id=44, lastTime=1527216240504, user=mycat, schema=yuyang, old shema=yuyang, borrowed=true, fromSlaveDB=true, threadId=42, charset=utf8, txIsolation=3, autocommit=true, attachment=MySQL_galera{SELECT *
FROM t2
WHERE id = 3
LIMIT 100}, respHandler=SingleNodeHandler [node=MySQL_galera{SELECT *
FROM t2
WHERE id = 3
LIMIT 100}, packetId=0], host=192.168.31.123, port=3306, statusSync=null, writeQueue=0, modifiedSQLExecuted=false]
2018-05-25 10:44:00.506 DEBUG [$_NIOREACTOR-1-RW] (io.mycat.server.NonBlockingSession.releaseConnection(NonBlockingSession.java:378)) - release connection MySQLConnection [id=44, lastTime=1527216240502, user=mycat, schema=yuyang, old shema=yuyang, borrowed=true, fromSlaveDB=true, threadId=42, charset=utf8, txIsolation=3, autocommit=true, attachment=MySQL_galera{SELECT *
FROM t2
WHERE id = 3
LIMIT 100}, respHandler=SingleNodeHandler [node=MySQL_galera{SELECT *
FROM t2
WHERE id = 3
LIMIT 100}, packetId=8], host=192.168.31.123, port=3306, statusSync=io.mycat.backend.mysql.nio.MySQLConnection$StatusSync@786ee29, writeQueue=0, modifiedSQLExecuted=false]
2018-05-25 10:44:00.506 DEBUG [$_NIOREACTOR-1-RW] (io.mycat.backend.datasource.PhysicalDatasource.releaseChannel(PhysicalDatasource.java:595)) - release channel MySQLConnection [id=44, lastTime=1527216240502, user=mycat, schema=yuyang, old shema=yuyang, borrowed=true, fromSlaveDB=true, threadId=42, charset=utf8, txIsolation=3, autocommit=true, attachment=null, respHandler=null, host=192.168.31.123, port=3306, statusSync=null, writeQueue=0, modifiedSQLExecuted=false]

接下来我们分析一下t3的转发逻辑,在schma.cnf中我们定义t3分别位于mysql与mysql_galera两个分片节点上,且分片规则为id%1024后值为0-512则在mysql_galera上,513-1024则在mysql上,搞清楚了定义的分片位置与规则,下面来分析一下转发过程
首先,当mtcat拦截到SQL语句之后,发现t3存在分片规则,提取分片字段,匹配分片函数(也就是规则),得到了分片列表,把SQL语句发送到对应的分片节点上去执行

以select id from t3 where id=512 这里的查找id=512,按照分片函数,512放在名为mysql的分片节点上,然后把SQL发往该节点执行。

mysql > select id from t3 where id=512;
2018-05-25 10:46:01.027 DEBUG [$_NIOREACTOR-1-RW] (io.mycat.server.NonBlockingSession.execute(NonBlockingSession.java:126)) - ServerConnection [id=10, schema=mycat01, host=192.168.31.124, user=root,txIsolation=3, autocommit=true, schema=mycat01]select * from t3 where id=512, route={
   1 -> MySQL{select * from t3 where id=512}
} rrs 

mysql > select id from t3 where id=1088;
2018-05-25 10:50:20.308 DEBUG [$_NIOREACTOR-1-RW] (io.mycat.server.NonBlockingSession.execute(NonBlockingSession.java:126)) - ServerConnection [id=10, schema=mycat01, host=192.168.31.124, user=root,txIsolation=3, autocommit=true, schema=mycat01]select * from t3 where id=1088, route={
   1 -> MySQL_galera{select * from t3 where id=1088}
} rrs 

网站栏目:Mycat读写分离以及拆库拆表综合实验3:通过日志分析mycat路由过程
网页网址:https://www.cdcxhl.com/article32/pdicpc.html

成都网站建设公司_创新互联,为您提供域名注册企业网站制作自适应网站网站收录动态网站网页设计公司

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

外贸网站建设