Search in sources :

Example 21 with ErrorPacket

use of com.alibaba.cobar.net.mysql.ErrorPacket in project cobar by alibaba.

the class MultiNodeQueryHandler method errorResponse.

@Override
public void errorResponse(byte[] data, MySQLConnection conn) {
    ErrorPacket err = new ErrorPacket();
    err.read(data);
    backendConnError(conn, err);
}
Also used : ErrorPacket(com.alibaba.cobar.net.mysql.ErrorPacket)

Example 22 with ErrorPacket

use of com.alibaba.cobar.net.mysql.ErrorPacket in project cobar by alibaba.

the class MultiNodeHandler method notifyError.

protected void notifyError(byte errPacketId) {
    recycleResources();
    ErrorPacket err;
    session.clearConnections();
    session.getSource().setTxInterrupt();
    err = error;
    if (err == null) {
        err = new ErrorPacket();
        err.packetId = errPacketId;
        err.errno = ErrorCode.ER_YES;
        err.message = StringUtil.encode("unknown error", session.getSource().getCharset());
    }
    err.packetId = errPacketId;
    err.write(session.getSource());
}
Also used : ErrorPacket(com.alibaba.cobar.net.mysql.ErrorPacket)

Example 23 with ErrorPacket

use of com.alibaba.cobar.net.mysql.ErrorPacket in project cobar by alibaba.

the class MultiNodeHandler method notifyError.

protected void notifyError() {
    recycleResources();
    byte errPacketId = ++packetId;
    ErrorPacket err;
    session.clearConnections();
    session.getSource().setTxInterrupt();
    err = error;
    if (err == null) {
        err = new ErrorPacket();
        err.packetId = errPacketId;
        err.errno = ErrorCode.ER_YES;
        err.message = StringUtil.encode("unknown error", session.getSource().getCharset());
    }
    err.packetId = errPacketId;
    err.write(session.getSource());
}
Also used : ErrorPacket(com.alibaba.cobar.net.mysql.ErrorPacket)

Example 24 with ErrorPacket

use of com.alibaba.cobar.net.mysql.ErrorPacket in project cobar by alibaba.

the class Heartbeat method response.

public static void response(ServerConnection c, byte[] data) {
    HeartbeatPacket hp = new HeartbeatPacket();
    hp.read(data);
    if (CobarServer.getInstance().isOnline()) {
        OkPacket ok = new OkPacket();
        ok.packetId = 1;
        ok.affectedRows = hp.id;
        ok.serverStatus = 2;
        ok.write(c);
        if (HEARTBEAT.isInfoEnabled()) {
            HEARTBEAT.info(responseMessage("OK", c, hp.id));
        }
    } else {
        ErrorPacket error = new ErrorPacket();
        error.packetId = 1;
        error.errno = ErrorCode.ER_SERVER_SHUTDOWN;
        error.message = String.valueOf(hp.id).getBytes();
        error.write(c);
        if (HEARTBEAT.isInfoEnabled()) {
            HEARTBEAT.info(responseMessage("ERROR", c, hp.id));
        }
    }
}
Also used : OkPacket(com.alibaba.cobar.net.mysql.OkPacket) ErrorPacket(com.alibaba.cobar.net.mysql.ErrorPacket) HeartbeatPacket(com.alibaba.cobar.net.mysql.HeartbeatPacket)

Example 25 with ErrorPacket

use of com.alibaba.cobar.net.mysql.ErrorPacket in project cobar by alibaba.

the class MySQLDetectorAuthenticator method handle.

@Override
public void handle(byte[] data) {
    MySQLDetector source = this.source;
    HandshakePacket hsp = source.getHandshake();
    if (hsp == null) {
        // 设置握手数据包
        hsp = new HandshakePacket();
        hsp.read(data);
        source.setHandshake(hsp);
        // 设置字符集编码
        int charsetIndex = (hsp.serverCharsetIndex & 0xff);
        String charset = CharsetUtil.getDbCharset(charsetIndex);
        if (charset != null) {
            source.setCharsetIndex(charsetIndex);
        } else {
            throw new RuntimeException("Unknown charsetIndex:" + charsetIndex);
        }
        // 发送认证数据包
        source.authenticate();
    } else {
        switch(data[4]) {
            case OkPacket.FIELD_COUNT:
                source.setHandler(new MySQLDetectorHandler(source));
                source.setAuthenticated(true);
                // 成功后发起心跳。
                source.heartbeat();
                break;
            case ErrorPacket.FIELD_COUNT:
                ErrorPacket err = new ErrorPacket();
                err.read(data);
                throw new RuntimeException(new String(err.message));
            case EOFPacket.FIELD_COUNT:
                auth323(data[3], hsp.seed);
                break;
            default:
                throw new RuntimeException("Unknown packet");
        }
    }
}
Also used : HandshakePacket(com.alibaba.cobar.net.mysql.HandshakePacket) ErrorPacket(com.alibaba.cobar.net.mysql.ErrorPacket)

Aggregations

ErrorPacket (com.alibaba.cobar.net.mysql.ErrorPacket)26 ErrorPacketException (com.alibaba.cobar.exception.ErrorPacketException)6 UnknownPacketException (com.alibaba.cobar.exception.UnknownPacketException)6 BinaryPacket (com.alibaba.cobar.net.mysql.BinaryPacket)6 CommandPacket (com.alibaba.cobar.net.mysql.CommandPacket)4 HandshakePacket (com.alibaba.cobar.net.mysql.HandshakePacket)4 ServerConnection (com.alibaba.cobar.server.ServerConnection)4 HeartbeatException (com.alibaba.cobar.exception.HeartbeatException)2 UnknownCharsetException (com.alibaba.cobar.exception.UnknownCharsetException)1 UnknownDataNodeException (com.alibaba.cobar.exception.UnknownDataNodeException)1 HeartbeatPacket (com.alibaba.cobar.net.mysql.HeartbeatPacket)1 OkPacket (com.alibaba.cobar.net.mysql.OkPacket)1 Reply323Packet (com.alibaba.cobar.net.mysql.Reply323Packet)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1