文章详情

短信预约-IT技能 免费直播动态提醒

请输入下面的图形验证码

提交验证

短信预约提醒成功

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

2024-04-02 19:55

关注

#在客户端查询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 
阅读原文内容投诉

免责声明:

① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。

② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341

软考中级精品资料免费领

  • 历年真题答案解析
  • 备考技巧名师总结
  • 高频考点精准押题
  • 2024年上半年信息系统项目管理师第二批次真题及答案解析(完整版)

    难度     813人已做
    查看
  • 【考后总结】2024年5月26日信息系统项目管理师第2批次考情分析

    难度     354人已做
    查看
  • 【考后总结】2024年5月25日信息系统项目管理师第1批次考情分析

    难度     318人已做
    查看
  • 2024年上半年软考高项第一、二批次真题考点汇总(完整版)

    难度     435人已做
    查看
  • 2024年上半年系统架构设计师考试综合知识真题

    难度     224人已做
    查看

相关文章

发现更多好内容

猜你喜欢

AI推送时光机
位置:首页-资讯-数据库
咦!没有更多了?去看看其它编程学习网 内容吧
首页课程
资料下载
问答资讯