文章目录
  1. 1. MyCAT select 日志分析
  2. 2. 动态加载schema.xml
  3. 3. MyCAT 字符集

MyCAT 的日志还是相对比较简明的,看系统细节的话需要打开debug级别的 log,修改log4j.xml

1
2
3
4
5
<root>
<level value="debug" />
<appender-ref ref="FILE" />
<!--<appender-ref ref="FILE" />-->
</root>

然后启动 MyCAT 就可以看到详细的日志了,日志默认路径在logs/mycat.log。启用之前,设置 Mysql 的字符集为 utf81,即修改/etc/mysql/my.cnf,在[mysqld]后添加character-set-server=utf8。

MyCAT select 日志分析

运行简单的查询 sql,如下,

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
mysql> explain select * from travelrecord;
+-----------+--------------------------------------+
| DATA_NODE | SQL |
+-----------+--------------------------------------+
| dn1 | SELECT * FROM travelrecord LIMIT 100 |
| dn2 | SELECT * FROM travelrecord LIMIT 100 |
| dn3 | SELECT * FROM travelrecord LIMIT 100 |
+-----------+--------------------------------------+
3 rows in set (0.25 sec)
mysql> select * from travelrecord;
+---------+---------+------------+------+------+
| id | user_id | traveldate | fee | days |
+---------+---------+------------+------+------+
| 1000000 | abc | 2016-01-02 | 100 | 3 |
| 7000000 | abc | 2016-01-02 | 100 | 3 |
+---------+---------+------------+------+------+
2 rows in set (0.09 sec)

对应的 debug 日志比较长,以下只列出了执行 select 的日志,explain 的日志没有列出,如下,

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
01/23 15:33:33.441 INFO [$_NIOREACTOR-0-RW] (FrontendAuthenticator.java:193) -ServerConnection [id=1, schema=TESTDB, host=192.168.2.201, user=test,txIsolation=3, autocommit=true, schema=TESTDB]'test' login success
01/23 15:33:33.443 DEBUG [$_NIOREACTOR-0-RW] (ServerQueryHandler.java:56) -ServerConnection [id=1, schema=TESTDB, host=192.168.2.201, user=test,txIsolation=3, autocommit=true, schema=TESTDB]show databases
01/23 15:33:33.458 DEBUG [$_NIOREACTOR-0-RW] (ServerQueryHandler.java:56) -ServerConnection [id=1, schema=TESTDB, host=192.168.2.201, user=test,txIsolation=3, autocommit=true, schema=TESTDB]show tables
01/23 15:33:33.465 DEBUG [$_NIOREACTOR-0-RW] (ServerQueryHandler.java:56) -ServerConnection [id=1, schema=TESTDB, host=192.168.2.201, user=test,txIsolation=3, autocommit=true, schema=TESTDB]select * from travelrecord
01/23 15:33:33.469 DEBUG [$_NIOREACTOR-0-RW] (EnchachePool.java:76) -SQLRouteCache miss cache ,key:TESTDBselect * from travelrecord
01/23 15:33:33.589 DEBUG [$_NIOREACTOR-0-RW] (EnchachePool.java:59) -SQLRouteCache add cache ,key:TESTDBselect * from travelrecord value:select * from travelrecord, route={
1 -> dn1{SELECT *
FROM travelrecord
LIMIT 100}
2 -> dn2{SELECT *
FROM travelrecord
LIMIT 100}
3 -> dn3{SELECT *
FROM travelrecord
LIMIT 100}
}
01/23 15:33:33.589 DEBUG [$_NIOREACTOR-0-RW] (NonBlockingSession.java:113) -ServerConnection [id=1, schema=TESTDB, host=192.168.2.201, user=test,txIsolation=3, autocommit=true, schema=TESTDB]select * from travelrecord, route={
1 -> dn1{SELECT *
FROM travelrecord
LIMIT 100}
2 -> dn2{SELECT *
FROM travelrecord
LIMIT 100}
3 -> dn3{SELECT *
FROM travelrecord
LIMIT 100}
} rrs
01/23 15:33:33.593 DEBUG [$_NIOREACTOR-0-RW] (MultiNodeQueryHandler.java:82) -execute mutinode query select * from travelrecord
01/23 15:33:33.595 DEBUG [$_NIOREACTOR-0-RW] (MultiNodeQueryHandler.java:97) -has data merge logic
01/23 15:33:33.595 DEBUG [$_NIOREACTOR-0-RW] (PhysicalDBPool.java:452) -select read source hostS1 for dataHost:localhost1
01/23 15:33:33.595 DEBUG [$_NIOREACTOR-0-RW] (MySQLConnection.java:445) -con need syn ,total syn cmd 1 commands SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ;schema change:false con:MySQLConnection [id=2, lastTime=1453534413595, user=root, schema=db1, old shema=db1, borrowed=true, fromSlaveDB=false, threadId=17, charset=utf8, txIsolation=0, autocommit=true, attachment=dn1{SELECT *
FROM travelrecord
LIMIT 100}, respHandler=org.opencloudb.mysql.nio.handler.MultiNodeQueryHandler@17b029c7, host=workstation, port=3316, statusSync=null, writeQueue=0, modifiedSQLExecuted=false]
01/23 15:33:33.596 DEBUG [$_NIOREACTOR-0-RW] (PhysicalDBPool.java:452) -select read source hostS1 for dataHost:localhost1
01/23 15:33:33.597 DEBUG [$_NIOREACTOR-0-RW] (MySQLConnection.java:445) -con need syn ,total syn cmd 1 commands SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ;schema change:false con:MySQLConnection [id=4, lastTime=1453534413597, user=root, schema=db2, old shema=db2, borrowed=true, fromSlaveDB=false, threadId=16, charset=utf8, txIsolation=0, autocommit=true, attachment=dn2{SELECT *
FROM travelrecord
LIMIT 100}, respHandler=org.opencloudb.mysql.nio.handler.MultiNodeQueryHandler@17b029c7, host=workstation, port=3316, statusSync=null, writeQueue=0, modifiedSQLExecuted=false]
01/23 15:33:33.597 DEBUG [$_NIOREACTOR-0-RW] (PhysicalDBPool.java:452) -select read source hostS1 for dataHost:localhost1
01/23 15:33:33.597 DEBUG [$_NIOREACTOR-0-RW] (MySQLConnection.java:445) -con need syn ,total syn cmd 1 commands SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ;schema change:false con:MySQLConnection [id=5, lastTime=1453534413597, user=root, schema=db3, old shema=db3, borrowed=true, fromSlaveDB=false, threadId=12, charset=utf8, txIsolation=0, autocommit=true, attachment=dn3{SELECT *
FROM travelrecord
LIMIT 100}, respHandler=org.opencloudb.mysql.nio.handler.MultiNodeQueryHandler@17b029c7, host=workstation, port=3316, statusSync=null, writeQueue=0, modifiedSQLExecuted=false]
01/23 15:33:33.597 DEBUG [$_NIOREACTOR-2-RW] (MultiNodeQueryHandler.java:171) -received ok response ,executeResponse:false from MySQLConnection [id=2, lastTime=1453534413593, user=root, schema=db1, old shema=db1, borrowed=true, fromSlaveDB=false, threadId=17, charset=utf8, txIsolation=3, autocommit=true, attachment=dn1{SELECT *
FROM travelrecord
LIMIT 100}, respHandler=org.opencloudb.mysql.nio.handler.MultiNodeQueryHandler@17b029c7, host=workstation, port=3316, statusSync=org.opencloudb.mysql.nio.MySQLConnection$StatusSync@3f164fd2, writeQueue=0, modifiedSQLExecuted=false]
01/23 15:33:33.598 DEBUG [$_NIOREACTOR-1-RW] (MultiNodeQueryHandler.java:171) -received ok response ,executeResponse:false from MySQLConnection [id=5, lastTime=1453534413593, user=root, schema=db3, old shema=db3, borrowed=true, fromSlaveDB=false, threadId=12, charset=utf8, txIsolation=3, autocommit=true, attachment=dn3{SELECT *
FROM travelrecord
LIMIT 100}, respHandler=org.opencloudb.mysql.nio.handler.MultiNodeQueryHandler@17b029c7, host=workstation, port=3316, statusSync=org.opencloudb.mysql.nio.MySQLConnection$StatusSync@94bf31, writeQueue=0, modifiedSQLExecuted=false]
01/23 15:33:33.599 DEBUG [$_NIOREACTOR-1-RW] (MultiNodeQueryHandler.java:241) -on row end reseponse MySQLConnection [id=5, lastTime=1453534413593, user=root, schema=db3, old shema=db3, borrowed=true, fromSlaveDB=false, threadId=12, charset=utf8, txIsolation=3, autocommit=true, attachment=dn3{SELECT *
FROM travelrecord
LIMIT 100}, respHandler=org.opencloudb.mysql.nio.handler.MultiNodeQueryHandler@17b029c7, host=workstation, port=3316, statusSync=org.opencloudb.mysql.nio.MySQLConnection$StatusSync@94bf31, writeQueue=0, modifiedSQLExecuted=false]
01/23 15:33:33.598 DEBUG [$_NIOREACTOR-0-RW] (MultiNodeQueryHandler.java:171) -received ok response ,executeResponse:false from MySQLConnection [id=4, lastTime=1453534413593, user=root, schema=db2, old shema=db2, borrowed=true, fromSlaveDB=false, threadId=16, charset=utf8, txIsolation=3, autocommit=true, attachment=dn2{SELECT *
FROM travelrecord
LIMIT 100}, respHandler=org.opencloudb.mysql.nio.handler.MultiNodeQueryHandler@17b029c7, host=workstation, port=3316, statusSync=org.opencloudb.mysql.nio.MySQLConnection$StatusSync@41a599fc, writeQueue=0, modifiedSQLExecuted=false]
01/23 15:33:33.600 DEBUG [$_NIOREACTOR-1-RW] (NonBlockingSession.java:229) -release connection MySQLConnection [id=5, lastTime=1453534413593, user=root, schema=db3, old shema=db3, borrowed=true, fromSlaveDB=false, threadId=12, charset=utf8, txIsolation=3, autocommit=true, attachment=dn3{SELECT *
FROM travelrecord
LIMIT 100}, respHandler=org.opencloudb.mysql.nio.handler.MultiNodeQueryHandler@17b029c7, host=workstation, port=3316, statusSync=org.opencloudb.mysql.nio.MySQLConnection$StatusSync@94bf31, writeQueue=0, modifiedSQLExecuted=false]
01/23 15:33:33.603 DEBUG [$_NIOREACTOR-1-RW] (PhysicalDatasource.java:403) -release channel MySQLConnection [id=5, lastTime=1453534413593, user=root, schema=db3, old shema=db3, borrowed=true, fromSlaveDB=false, threadId=12, charset=utf8, txIsolation=3, autocommit=true, attachment=null, respHandler=null, host=workstation, port=3316, statusSync=null, writeQueue=0, modifiedSQLExecuted=false]
01/23 15:33:33.600 DEBUG [$_NIOREACTOR-2-RW] (DataMergeService.java:94) -field metadata inf:[DAYS=ColMeta [colIndex=4, colType=3], USER_ID=ColMeta [colIndex=1, colType=253], ID=ColMeta [colIndex=0, colType=8], TRAVELDATE=ColMeta [colIndex=2, colType=10], FEE=ColMeta [colIndex=3, colType=246]]
01/23 15:33:33.605 DEBUG [$_NIOREACTOR-2-RW] (MultiNodeQueryHandler.java:241) -on row end reseponse MySQLConnection [id=2, lastTime=1453534413593, user=root, schema=db1, old shema=db1, borrowed=true, fromSlaveDB=false, threadId=17, charset=utf8, txIsolation=3, autocommit=true, attachment=dn1{SELECT *
FROM travelrecord
LIMIT 100}, respHandler=org.opencloudb.mysql.nio.handler.MultiNodeQueryHandler@17b029c7, host=workstation, port=3316, statusSync=org.opencloudb.mysql.nio.MySQLConnection$StatusSync@3f164fd2, writeQueue=0, modifiedSQLExecuted=false]
01/23 15:33:33.605 DEBUG [$_NIOREACTOR-2-RW] (NonBlockingSession.java:229) -release connection MySQLConnection [id=2, lastTime=1453534413593, user=root, schema=db1, old shema=db1, borrowed=true, fromSlaveDB=false, threadId=17, charset=utf8, txIsolation=3, autocommit=true, attachment=dn1{SELECT *
FROM travelrecord
LIMIT 100}, respHandler=org.opencloudb.mysql.nio.handler.MultiNodeQueryHandler@17b029c7, host=workstation, port=3316, statusSync=org.opencloudb.mysql.nio.MySQLConnection$StatusSync@3f164fd2, writeQueue=0, modifiedSQLExecuted=false]
01/23 15:33:33.605 DEBUG [$_NIOREACTOR-2-RW] (PhysicalDatasource.java:403) -release channel MySQLConnection [id=2, lastTime=1453534413593, user=root, schema=db1, old shema=db1, borrowed=true, fromSlaveDB=false, threadId=17, charset=utf8, txIsolation=3, autocommit=true, attachment=null, respHandler=null, host=workstation, port=3316, statusSync=null, writeQueue=0, modifiedSQLExecuted=false]
01/23 15:33:33.607 DEBUG [$_NIOREACTOR-0-RW] (MultiNodeQueryHandler.java:241) -on row end reseponse MySQLConnection [id=4, lastTime=1453534413593, user=root, schema=db2, old shema=db2, borrowed=true, fromSlaveDB=false, threadId=16, charset=utf8, txIsolation=3, autocommit=true, attachment=dn2{SELECT *
FROM travelrecord
LIMIT 100}, respHandler=org.opencloudb.mysql.nio.handler.MultiNodeQueryHandler@17b029c7, host=workstation, port=3316, statusSync=org.opencloudb.mysql.nio.MySQLConnection$StatusSync@41a599fc, writeQueue=0, modifiedSQLExecuted=false]
01/23 15:33:33.610 DEBUG [$_NIOREACTOR-0-RW] (NonBlockingSession.java:229) -release connection MySQLConnection [id=4, lastTime=1453534413593, user=root, schema=db2, old shema=db2, borrowed=true, fromSlaveDB=false, threadId=16, charset=utf8, txIsolation=3, autocommit=true, attachment=dn2{SELECT *
FROM travelrecord
LIMIT 100}, respHandler=org.opencloudb.mysql.nio.handler.MultiNodeQueryHandler@17b029c7, host=workstation, port=3316, statusSync=org.opencloudb.mysql.nio.MySQLConnection$StatusSync@41a599fc, writeQueue=0, modifiedSQLExecuted=false]
01/23 15:33:33.610 DEBUG [$_NIOREACTOR-0-RW] (PhysicalDatasource.java:403) -release channel MySQLConnection [id=4, lastTime=1453534413593, user=root, schema=db2, old shema=db2, borrowed=true, fromSlaveDB=false, threadId=16, charset=utf8, txIsolation=3, autocommit=true, attachment=null, respHandler=null, host=workstation, port=3316, statusSync=null, writeQueue=0, modifiedSQLExecuted=false]
01/23 15:33:33.611 DEBUG [BusinessExecutor5] (DataMergeService.java:296) -prepare mpp merge result for select * from travelrecord

以上日志中,执行过程如下,

  1. MyCAT 先收到 sql,然后去路径 cache 中查找是否已经有解析好的路径,但是没有找到,因此提示SQLRouteCache miss cache,于是解析该 sql,并将路径保存,提示SQLRouteCache add cache
  2. 接下来,使用NonBlockingSession.java,即非阻塞会话来获取连接, 还有提示,使用MultiNodeQueryHandler,多节点查询,过程中需要数据合并,即has data merge logic
  3. 然后,找到了读的数据源,提示select read source hostS1 for dataHost:localhost1,并提示获取连接成功,执行同步命令,-con need syn ,total syn cmd 1 commands,之后发送查询sql,因为 travelrecord 表在 db1、db2、db3 共有3个分片,因此,以上日志在这3个分片上各出现了一次;
  4. 然后,收到返回结果并调用回调函数,on row end reseponse,等数据接收完成还会提示received ok response,同样,也是收到3个分片上各一次;
  5. 执行完后,会释放 MyCAT 会话和 Mysql 连接,release connection MySQLConnectionrelease channel MySQLConnection
  6. 收到的结果还需要显示列名,因此,上述执行过程中会提示,field metadata inf
  7. 等收到3个分片的所有数据后,进行数据合并,prepare mpp merge result

以上就是 MyCAT 上执行 sql 的基本步骤。

动态加载schema.xml

MyCAT 的schema.xml是可以动态加载(reload)的。假定新增一个分片表 T_VOTE (ID,PROVINCE),PROVINCE 列用hash分片。首先需要修改rule.xml

1
2
3
4
5
6
<tableRule name="sharding-by-stringhash">
<rule>
<columns>province</columns>
<algorithm>murmur</algorithm>
</rule>
</tableRule>

其中,murmur是一致性 hash 方法。在schema.xml中增加,

1
<table name="t_vote" primaryKey="ID" dataNode="dn1,dn2,dn3" rule="sharding-by-stringhash" />

修改完文件后,使用管理端,端口9066,登陆MyCAT,用以下命令可以重新加载配置文件,

1
2
3
mysql> reload @@config;
Query OK, 1 row affected (0.13 sec)
Reload config success

加载完成之后,可以发现用户端,即端口8066,上已经可以看到新增的 T_VOTE 表,

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
mysql> show tables;
+------------------+
| Tables in TESTDB |
+------------------+
| company |
| customer |
| customer_addr |
| employee |
| goods |
| hotnews |
| orders |
| order_items |
| travelrecord |
| t_vote |
+------------------+
10 rows in set (0.00 sec)

查看这段时间内的日志,如下,

1
2
3
4
5
6
7
8
9
01/23 16:43:14.003 DEBUG [$_NIOREACTOR-3-RW] (ManagerQueryHandler.java:65) -[thread=$_NIOREACTOR-3-RW,class=ManagerConnection,id=7,host=192.168.2.201,port=9066,schema=TESTDB]reload @@config
01/23 16:43:14.048 INFO [BusinessExecutor7] (CacheService.java:187) -clear all cache pool
01/23 16:43:14.048 INFO [BusinessExecutor7] (EnchachePool.java:85) -clear cache ER_SQL2PARENTID
01/23 16:43:14.124 INFO [BusinessExecutor7] (EnchachePool.java:85) -clear cache SQLRouteCache
01/23 16:43:14.125 INFO [BusinessExecutor7] (DefaultLayedCachePool.java:100) -clear cache
01/23 16:43:14.126 INFO [BusinessExecutor7] (EnchachePool.java:85) -clear cache TableID2DataNodeCache.TESTDB_ORDERS
01/23 16:43:14.128 WARN [BusinessExecutor6] (ReloadConfig.java:166) -send ok package to client [thread=BusinessExecutor6,class=ManagerConnection,id=7,host=192.168.2.201,port=9066,schema=TESTDB]
01/23 16:43:17.674 DEBUG [Timer0] (ConnectionHeartBeatHandler.java:52) -do heartbeat for con MySQLConnection [id=6, lastTime=1453538597657, user=root, schema=db2, old shema=db2, borrowed=true, fromSlaveDB=false, threadId=15, charset=utf8, txIsolation=3, autocommit=true, attachment=null, respHandler=null, host=workstation, port=3316, statusSync=null, writeQueue=0, modifiedSQLExecuted=false]
01/23 16:43:17.675 DEBUG [Timer0] (ConnectionHeartBeatHandler.java:52) -do heartbeat for con MySQLConnection [id=4, lastTime=1453538597657, user=root, schema=db2, old shema=db2, borrowed=true, fromSlaveDB=false, threadId=16, charset=utf8, txIsolation=3, autocommit=true, attachment=null, respHandler=null, host=workstation, port=3316, statusSync=null, writeQueue=0, modifiedSQLExecuted=false]

可以发现,重新加载的过程中,清理了一些 cache,并重新建立了心跳。

MyCAT 字符集

以上的实验中,MyCAT 的字符集和 Mysql 客户端的字符集都是采用 utf8,修改 Mysql 客户端的字符集为 latin1,即修改客户端所在机器的/etc/mysql/my.cnf,在[client]后添加default-character-set=latin1。再次执行相同的查询select * from travelrecord;,日志如下,

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
01/23 17:30:17.877 DEBUG [$_NIOREACTOR-2-RW] (EnchachePool.java:70) -SQLRouteCache hit cache ,key:TESTDBselect * from travelrecord
01/23 17:30:17.877 DEBUG [$_NIOREACTOR-2-RW] (NonBlockingSession.java:113) -ServerConnection [id=4, schema=TESTDB, host=192.168.2.201, user=test,txIsolation=3, autocommit=true, schema=TESTDB]select * from travelrecord, route={
1 -> dn1{SELECT *
FROM travelrecord
LIMIT 100}
2 -> dn2{SELECT *
FROM travelrecord
LIMIT 100}
3 -> dn3{SELECT *
FROM travelrecord
LIMIT 100}
} rrs
01/23 17:30:17.877 DEBUG [$_NIOREACTOR-2-RW] (MultiNodeQueryHandler.java:82) -execute mutinode query select * from travelrecord
01/23 17:30:17.877 DEBUG [$_NIOREACTOR-2-RW] (MultiNodeQueryHandler.java:97) -has data merge logic
01/23 17:30:17.877 DEBUG [$_NIOREACTOR-2-RW] (PhysicalDBPool.java:452) -select read source hostS1 for dataHost:localhost1
01/23 17:30:17.878 DEBUG [$_NIOREACTOR-2-RW] (PhysicalDBPool.java:452) -select read source hostS1 for dataHost:localhost1
01/23 17:30:17.878 DEBUG [$_NIOREACTOR-2-RW] (MySQLConnection.java:445) -con need syn ,total syn cmd 2 commands SET names latin1;SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ;schema change:false con:MySQLConnection [id=100, lastTime=1453541417878, user=root, schema=db2, old shema=db2, borrowed=true, fromSlaveDB=false, threadId=5, charset=latin1, txIsolation=0, autocommit=true, attachment=dn2{SELECT *
FROM travelrecord
LIMIT 100}, respHandler=org.opencloudb.mysql.nio.handler.MultiNodeQueryHandler@41d3a141, host=workstation, port=3316, statusSync=null, writeQueue=0, modifiedSQLExecuted=false]
01/23 17:30:17.878 DEBUG [$_NIOREACTOR-2-RW] (PhysicalDBPool.java:452) -select read source hostS1 for dataHost:localhost1
01/23 17:30:17.879 DEBUG [$_NIOREACTOR-2-RW] (MySQLConnection.java:445) -con need syn ,total syn cmd 2 commands SET names latin1;SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ;schema change:false con:MySQLConnection [id=99, lastTime=1453541417878, user=root, schema=db3, old shema=db3, borrowed=true, fromSlaveDB=false, threadId=2, charset=latin1, txIsolation=0, autocommit=true, attachment=dn3{SELECT *
FROM travelrecord
LIMIT 100}, respHandler=org.opencloudb.mysql.nio.handler.MultiNodeQueryHandler@41d3a141, host=workstation, port=3316, statusSync=null, writeQueue=0, modifiedSQLExecuted=false]
01/23 17:30:17.879 DEBUG [$_NIOREACTOR-1-RW] (MultiNodeQueryHandler.java:171) -received ok response ,executeResponse:false from MySQLConnection [id=99, lastTime=1453541417860, user=root, schema=db3, old shema=db3, borrowed=true, fromSlaveDB=false, threadId=2, charset=latin1, txIsolation=0, autocommit=true, attachment=dn3{SELECT *
FROM travelrecord
LIMIT 100}, respHandler=org.opencloudb.mysql.nio.handler.MultiNodeQueryHandler@41d3a141, host=workstation, port=3316, statusSync=org.opencloudb.mysql.nio.MySQLConnection$StatusSync@12bc7f96, writeQueue=0, modifiedSQLExecuted=false]
01/23 17:30:17.879 DEBUG [$_NIOREACTOR-2-RW] (MultiNodeQueryHandler.java:171) -received ok response ,executeResponse:false from MySQLConnection [id=100, lastTime=1453541417860, user=root, schema=db2, old shema=db2, borrowed=true, fromSlaveDB=false, threadId=5, charset=latin1, txIsolation=0, autocommit=true, attachment=dn2{SELECT *
FROM travelrecord
LIMIT 100}, respHandler=org.opencloudb.mysql.nio.handler.MultiNodeQueryHandler@41d3a141, host=workstation, port=3316, statusSync=org.opencloudb.mysql.nio.MySQLConnection$StatusSync@327030f, writeQueue=0, modifiedSQLExecuted=false]
01/23 17:30:17.880 DEBUG [$_NIOREACTOR-1-RW] (MultiNodeQueryHandler.java:171) -received ok response ,executeResponse:false from MySQLConnection [id=99, lastTime=1453541417860, user=root, schema=db3, old shema=db3, borrowed=true, fromSlaveDB=false, threadId=2, charset=latin1, txIsolation=3, autocommit=true, attachment=dn3{SELECT *
FROM travelrecord
LIMIT 100}, respHandler=org.opencloudb.mysql.nio.handler.MultiNodeQueryHandler@41d3a141, host=workstation, port=3316, statusSync=org.opencloudb.mysql.nio.MySQLConnection$StatusSync@12bc7f96, writeQueue=0, modifiedSQLExecuted=false]
01/23 17:30:17.880 DEBUG [$_NIOREACTOR-2-RW] (MultiNodeQueryHandler.java:171) -received ok response ,executeResponse:false from MySQLConnection [id=100, lastTime=1453541417860, user=root, schema=db2, old shema=db2, borrowed=true, fromSlaveDB=false, threadId=5, charset=latin1, txIsolation=3, autocommit=true, attachment=dn2{SELECT *
FROM travelrecord
LIMIT 100}, respHandler=org.opencloudb.mysql.nio.handler.MultiNodeQueryHandler@41d3a141, host=workstation, port=3316, statusSync=org.opencloudb.mysql.nio.MySQLConnection$StatusSync@327030f, writeQueue=0, modifiedSQLExecuted=false]
01/23 17:30:17.886 DEBUG [$_NIOREACTOR-1-RW] (DataMergeService.java:94) -field metadata inf:[DAYS=ColMeta [colIndex=4, colType=3], USER_ID=ColMeta [colIndex=1, colType=253], ID=ColMeta [colIndex=0, colType=8], TRAVELDATE=ColMeta [colIndex=2, colType=10], FEE=ColMeta [colIndex=3, colType=246]]
01/23 17:30:17.887 DEBUG [$_NIOREACTOR-1-RW] (MultiNodeQueryHandler.java:241) -on row end reseponse MySQLConnection [id=99, lastTime=1453541417860, user=root, schema=db3, old shema=db3, borrowed=true, fromSlaveDB=false, threadId=2, charset=latin1, txIsolation=3, autocommit=true, attachment=dn3{SELECT *
FROM travelrecord
LIMIT 100}, respHandler=org.opencloudb.mysql.nio.handler.MultiNodeQueryHandler@41d3a141, host=workstation, port=3316, statusSync=org.opencloudb.mysql.nio.MySQLConnection$StatusSync@12bc7f96, writeQueue=0, modifiedSQLExecuted=false]
01/23 17:30:17.887 DEBUG [$_NIOREACTOR-1-RW] (NonBlockingSession.java:229) -release connection MySQLConnection [id=99, lastTime=1453541417860, user=root, schema=db3, old shema=db3, borrowed=true, fromSlaveDB=false, threadId=2, charset=latin1, txIsolation=3, autocommit=true, attachment=dn3{SELECT *
FROM travelrecord
LIMIT 100}, respHandler=org.opencloudb.mysql.nio.handler.MultiNodeQueryHandler@41d3a141, host=workstation, port=3316, statusSync=org.opencloudb.mysql.nio.MySQLConnection$StatusSync@12bc7f96, writeQueue=0, modifiedSQLExecuted=false]
01/23 17:30:17.888 DEBUG [$_NIOREACTOR-1-RW] (PhysicalDatasource.java:403) -release channel MySQLConnection [id=99, lastTime=1453541417860, user=root, schema=db3, old shema=db3, borrowed=true, fromSlaveDB=false, threadId=2, charset=latin1, txIsolation=3, autocommit=true, attachment=null, respHandler=null, host=workstation, port=3316, statusSync=null, writeQueue=0, modifiedSQLExecuted=false]
01/23 17:30:17.888 DEBUG [$_NIOREACTOR-3-RW] (MultiNodeQueryHandler.java:241) -on row end reseponse MySQLConnection [id=101, lastTime=1453541417860, user=root, schema=db1, old shema=db1, borrowed=true, fromSlaveDB=false, threadId=3, charset=latin1, txIsolation=3, autocommit=true, attachment=dn1{SELECT *
FROM travelrecord
LIMIT 100}, respHandler=org.opencloudb.mysql.nio.handler.MultiNodeQueryHandler@41d3a141, host=workstation, port=3316, statusSync=null, writeQueue=0, modifiedSQLExecuted=false]
01/23 17:30:17.888 DEBUG [$_NIOREACTOR-2-RW] (MultiNodeQueryHandler.java:241) -on row end reseponse MySQLConnection [id=100, lastTime=1453541417860, user=root, schema=db2, old shema=db2, borrowed=true, fromSlaveDB=false, threadId=5, charset=latin1, txIsolation=3, autocommit=true, attachment=dn2{SELECT *
FROM travelrecord
LIMIT 100}, respHandler=org.opencloudb.mysql.nio.handler.MultiNodeQueryHandler@41d3a141, host=workstation, port=3316, statusSync=org.opencloudb.mysql.nio.MySQLConnection$StatusSync@327030f, writeQueue=0, modifiedSQLExecuted=false]
01/23 17:30:17.889 DEBUG [$_NIOREACTOR-2-RW] (NonBlockingSession.java:229) -release connection MySQLConnection [id=100, lastTime=1453541417860, user=root, schema=db2, old shema=db2, borrowed=true, fromSlaveDB=false, threadId=5, charset=latin1, txIsolation=3, autocommit=true, attachment=dn2{SELECT *
FROM travelrecord
LIMIT 100}, respHandler=org.opencloudb.mysql.nio.handler.MultiNodeQueryHandler@41d3a141, host=workstation, port=3316, statusSync=org.opencloudb.mysql.nio.MySQLConnection$StatusSync@327030f, writeQueue=0, modifiedSQLExecuted=false]
01/23 17:30:17.889 DEBUG [$_NIOREACTOR-2-RW] (PhysicalDatasource.java:403) -release channel MySQLConnection [id=100, lastTime=1453541417860, user=root, schema=db2, old shema=db2, borrowed=true, fromSlaveDB=false, threadId=5, charset=latin1, txIsolation=3, autocommit=true, attachment=null, respHandler=null, host=workstation, port=3316, statusSync=null, writeQueue=0, modifiedSQLExecuted=false]
01/23 17:30:17.889 DEBUG [$_NIOREACTOR-3-RW] (NonBlockingSession.java:229) -release connection MySQLConnection [id=101, lastTime=1453541417860, user=root, schema=db1, old shema=db1, borrowed=true, fromSlaveDB=false, threadId=3, charset=latin1, txIsolation=3, autocommit=true, attachment=dn1{SELECT *
FROM travelrecord
LIMIT 100}, respHandler=org.opencloudb.mysql.nio.handler.MultiNodeQueryHandler@41d3a141, host=workstation, port=3316, statusSync=null, writeQueue=0, modifiedSQLExecuted=false]
01/23 17:30:17.890 DEBUG [$_NIOREACTOR-3-RW] (PhysicalDatasource.java:403) -release channel MySQLConnection [id=101, lastTime=1453541417860, user=root, schema=db1, old shema=db1, borrowed=true, fromSlaveDB=false, threadId=3, charset=latin1, txIsolation=3, autocommit=true, attachment=null, respHandler=null, host=workstation, port=3316, statusSync=null, writeQueue=0, modifiedSQLExecuted=false]
01/23 17:30:17.891 DEBUG [BusinessExecutor3] (DataMergeService.java:296) -prepare mpp merge result for select * from travelrecord
01/23 17:30:17.892 DEBUG [BusinessExecutor3] (MultiNodeQueryHandler.java:324) -last packet id:10

可以发现,日志差异并不大,只是所有原先是charset=utf8的地方换成了charset=latin1,还有一处重要的变化是执行同步命令con need syn ,total syn cmd 2 commands,多了一个命令SET names latin1用于设置字符集。不过这样做是有问题的,客户端与服务器端的字符集不同,会导致乱码。例如,有中文的情况,如下图,

文章目录
  1. 1. MyCAT select 日志分析
  2. 2. 动态加载schema.xml
  3. 3. MyCAT 字符集

欢迎来到Valleylord的博客!

本博的文章尽量原创。