alibaba / cobar

a proxy for sharding databases and tables
Apache License 2.0
3.21k stars 1.22k forks source link

After add feature : utf8mb4 #54

Closed ghost closed 8 years ago

ghost commented 9 years ago

git diff --name-status master v1.2.7

M       README.md
D       doc/Cobar1.0.6-1.2.0_performance_data.xlsx
D       doc/Cobar1.2.0_performanc_report.docx
D       doc/Cobar_data_migration.2011.03.ppt
D       doc/Cobar_datasource_heartbeat - Alibaba Open Sesame.pdf
D       doc/Cobar_rule - Alibaba Open Sesame.pdf
M       server/assembly/bin/startup.bat
M       server/src/main/net/com/alibaba/cobar/net/FrontendConnection.java
M       server/src/main/server/com/alibaba/cobar/heartbeat/CobarDetectorAuthenticator.java
M       server/src/main/server/com/alibaba/cobar/heartbeat/MySQLDetectorAuthenticator.java
M       server/src/main/server/com/alibaba/cobar/mysql/CharsetUtil.java
M       server/src/main/server/com/alibaba/cobar/mysql/bio/MySQLChannel.java
M       server/src/main/server/com/alibaba/cobar/mysql/nio/MySQLConnection.java
M       server/src/main/server/com/alibaba/cobar/mysql/nio/MySQLConnectionAuthenticator.java

Then do some stuff for code review, I find server/src/main/net/com/alibaba/cobar/net/FrontendConnection.java

image

It means

197: get Index from the map of DBCharsetIndex 201: set the index of DBCharset to this.charsetIndex // my question is : FrontendConnection.java the property is this.charsetIndex. "v1.2.7 this.charsetIndex" retrieves from the map of CharsetUtil.CHARSET_TO_INDEX. But CharsetUtil of new version, shows two maps: CHARSET_TO_INDEX + DB_CHARSET_TO_INDEX.

server/src/main/server/com/alibaba/cobar/mysql/nio/MySQLConnectionAuthenticator.java from Line56 is more wired.

                // 设置字符集编码
                int charsetIndex = (packet.serverCharsetIndex & 0xff);
                String charset = CharsetUtil.getDbCharset(charsetIndex);
                if (charset != null) {
                    source.setCharsetIndex(charsetIndex);
                    source.setCharset(CharsetUtil.getCharset(charsetIndex));
                    source.setDbCharset(charset);

                } 

Handling "Index" is not clear so that it will make some errors probably. You can not ensure the indexes be the same from two maps(CHARSET_TO_INDEX + DB_CHARSET_TO_INDEX) .