alibaba / cobar

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

MySQLChannel 中 读取握手数据包出错 #23

Closed evenX86 closed 10 years ago

evenX86 commented 10 years ago

在CharseUtil中报错:

    //这里报了异常:java.lang.ArrayIndexOutOfBoundsException
    public static final String getCharset(int index) {
        try{
            return INDEX_TO_CHARSET[index];
        }catch (Exception e){

            e.printStackTrace();
            return null;
        }
    }

然后找到MySQLChannel中

  private MySQLChannel handshake() throws IOException {
        // 读取握手数据包
        BinaryPacket initPacket = new BinaryPacket();
        initPacket.read(in);
        HandshakePacket hsp = new HandshakePacket();
        hsp.read(initPacket);

        // 设置通道参数
        this.threadId = hsp.threadId;
        int ci = hsp.serverCharsetIndex & 0xff;
        LOGGER.error("ci有问题:==============" + ci + hsp.serverCharsetIndex);
        if ((charset = CharsetUtil.getCharset(ci)) != null) {
            this.charsetIndex = ci;
        } else {
            throw new UnknownCharsetException("charset:" + ci);
        }

这里在cobar运行后hsp.serverCharsetIndex=-64,所以后面就报异常了。 这样造成的结果是数据节点不能初始化,但是cobar能够启动,并且能访问到数据库,数据表就无法访问了