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
转载于:https://blog.51cto.com/2143754/2120168
Mycat读写分离以及拆库拆表综合实验3:通过日志分析mycat路由过程相关推荐
- Mycat 读写分离、主从切换、分库分表的操作记录
Mycat 读写分离.主从切换.分库分表的操作记录 系统开发中,数据库是非常重要的一个点.除了程序的本身的优化,如:SQL语句优化.代码优化,数据库的处理本身优化也是非常重要的.主从.热备.分表分库等 ...
- Mycat 读写分离实战
Mycat读写分离实战 一.主从复制搭建 1.实验环境 搭建一主一从的部署架构,master(主库)运行在阿里云服务器 47.108.136.201,slave(从库)运行在 IP 地址为 12.16 ...
- Mycat读写分离、主从切换、分库分表的操作记录 https://www.cnblogs.com/kevingrace/p/9365840.html
[此篇文章写得不错] 系统开发中,数据库是非常重要的一个点.除了程序的本身的优化,如:SQL语句优化.代码优化,数据库的处理本身优化也是非常重要的.主从.热备.分表分库等都是系统发展迟早会遇到的技术问 ...
- MyCAT读写分离分库分表
MyCAT读写分离及分库分表 第1章 MyCAT分布式系统解决方案 1.1 分布式系统介绍: 分布式系统特性: 1. 透明性: a) 分布式系统对用户来说是透明的,一个分布式系统在用户面前的表现就像一 ...
- MyCat 读写分离与分库分表
一.Mycat 简介 Mycat 是一个开源的数据库中间件,可以解决分布式数据库环境下的大多数问题,如读写分离.分库分表等,除此之外,它还具备以下特性: 支持 MySQL.Oracle.DB2.SQL ...
- 应用 | 同学,该学MyCat实际应用案例与MyCat读写分离了
Hi!我是小小,一个双鱼座的佛系程序猿,今日的blog将会写关于MyCat最后一点学习内容,读写分离,与MyCat实际应用案例和一个小小的例子. MyCat 读写分离 MyCat的读写分离是建立在My ...
- mysql主从和mycat读写分离的安装及验证
目录 一.背景介绍 二.安装mysql数据库(主从机器都需要先这样安装) 三.主从机配置 1.主服务器进行如下操作 2.从服务器进行如下操作 四.代理服务器安装和配置mycat读写分离 五.主从复制. ...
- Mycat读写分离的简单实现
文章目录 1.Mycat读写分离的配置 1.1.Mycat是什么 1.2.Mycat能干什么 1.2.1.数据库的读写分离 1.2.1.1.数据库读写分离图解 1.2.2.数据库分库分表 1.2.2. ...
- MySQL数据库mycat读写分离
mycat读写分离 Mycat的读写分离是建立在Mysq的主从复制的基础上的 修改配置文件 schema.xml <?xml version="1.0"?> <! ...
- mysql高级技术之mycat读写分离技术实践
1,课程回顾 2,本章重点 mysql 主从原理,好处mycat 概念,读写分离好处,读写分离的实现 3,具体内容 3.1 mysql 主从 3.1.1 linux下mysql安装 以mysql5.6 ...
最新文章
- xgboost不能解决哪些问题?为什么?进而说明树模型有哪些缺陷?那种模型能够树模型的这种缺陷?
- 打羽毛球如何提高手腕的爆发力
- CCS中给工程加入C66x CSL库和头文件
- 日志 查看匹配内容的前后几行
- SAP Spartacus 自定义Popover指令,如何实现弹出对话框自动关闭功能
- root cause of error messagw for a mixed usage of 01 and 03
- c语言中文件读写面试题,在C ++中有效读取非常大的文本文件
- Java读源代码学设计模式:适配器Adapter
- 【Python】Python简介和Python解释器
- ai合成迪丽热巴下海_丽热巴被富家哥求婚,男方坚持示爱九个月,当众下跪赠女方豪车...
- Android 中的Activity的静态变量问题
- js 数组的属性及其常用的方法
- 燃料电池电池超级电容复合能量管理策略simulink仿真模型
- 在服务器上搭建ftp站点
- 模拟测试数据的生成方法
- 在线支付功能的设计及其实现
- SecureCRT Home End键
- Jmeter(五)bayboy录制时弹窗“当前页面的脚本发生错误”解决办法
- 中国记账软件行业现状规模与应用前景预测报告(2022-2027)
- [圣诞大礼]Macintosh苹果机精品游戏合集