Search in sources :

Example 6 with ErrorPacket

use of io.mycat.net.mysql.ErrorPacket in project Mycat-Server by MyCATApache.

the class MySQLConnectionAuthenticator method handle.

@Override
public void handle(byte[] data) {
    try {
        switch(data[4]) {
            case OkPacket.FIELD_COUNT:
                HandshakePacket packet = source.getHandshake();
                if (packet == null) {
                    processHandShakePacket(data);
                    // 发送认证数据包
                    source.authenticate();
                    break;
                }
                // 处理认证结果
                source.setHandler(new MySQLConnectionHandler(source));
                source.setAuthenticated(true);
                boolean clientCompress = Capabilities.CLIENT_COMPRESS == (Capabilities.CLIENT_COMPRESS & packet.serverCapabilities);
                boolean usingCompress = MycatServer.getInstance().getConfig().getSystem().getUseCompression() == 1;
                if (clientCompress && usingCompress) {
                    source.setSupportCompress(true);
                }
                if (listener != null) {
                    listener.connectionAcquired(source);
                }
                break;
            case ErrorPacket.FIELD_COUNT:
                ErrorPacket err = new ErrorPacket();
                err.read(data);
                String errMsg = new String(err.message);
                LOGGER.warn("can't connect to mysql server ,errmsg:" + errMsg + " " + source);
                //source.close(errMsg);
                throw new ConnectionException(err.errno, errMsg);
            case EOFPacket.FIELD_COUNT:
                auth323(data[3]);
                break;
            default:
                packet = source.getHandshake();
                if (packet == null) {
                    processHandShakePacket(data);
                    // 发送认证数据包
                    source.authenticate();
                    break;
                } else {
                    throw new RuntimeException("Unknown Packet!");
                }
        }
    } catch (RuntimeException e) {
        if (listener != null) {
            listener.connectionError(e, source);
            return;
        }
        throw e;
    }
}
Also used : HandshakePacket(io.mycat.net.mysql.HandshakePacket) ErrorPacket(io.mycat.net.mysql.ErrorPacket) ConnectionException(io.mycat.net.ConnectionException)

Example 7 with ErrorPacket

use of io.mycat.net.mysql.ErrorPacket in project Mycat-Server by MyCATApache.

the class SingleNodeHandler method connectionClose.

@Override
public void connectionClose(BackendConnection conn, String reason) {
    ErrorPacket err = new ErrorPacket();
    err.packetId = ++packetId;
    err.errno = ErrorCode.ER_ERROR_ON_CLOSE;
    err.message = StringUtil.encode(reason, session.getSource().getCharset());
    this.backConnectionErr(err, conn);
}
Also used : ErrorPacket(io.mycat.net.mysql.ErrorPacket)

Example 8 with ErrorPacket

use of io.mycat.net.mysql.ErrorPacket in project Mycat-Server by MyCATApache.

the class FetchStoreNodeOfChildTableHandler method errorResponse.

@Override
public void errorResponse(byte[] data, BackendConnection conn) {
    finished.incrementAndGet();
    ErrorPacket err = new ErrorPacket();
    err.read(data);
    LOGGER.warn("errorResponse " + err.errno + " " + new String(err.message));
    conn.release();
}
Also used : ErrorPacket(io.mycat.net.mysql.ErrorPacket)

Example 9 with ErrorPacket

use of io.mycat.net.mysql.ErrorPacket in project Mycat-Server by MyCATApache.

the class KillConnectionHandler method errorResponse.

@Override
public void errorResponse(byte[] data, BackendConnection conn) {
    ErrorPacket err = new ErrorPacket();
    err.read(data);
    String msg = null;
    try {
        msg = new String(err.message, conn.getCharset());
    } catch (UnsupportedEncodingException e) {
        msg = new String(err.message);
    }
    LOGGER.warn("kill backend connection " + killee + " failed: " + msg + " con:" + conn);
    conn.release();
    killee.close("exception:" + msg);
}
Also used : ErrorPacket(io.mycat.net.mysql.ErrorPacket) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 10 with ErrorPacket

use of io.mycat.net.mysql.ErrorPacket in project Mycat-Server by MyCATApache.

the class CommitCommand method errorResponse.

@Override
public void errorResponse(NonBlockingSession session, byte[] err, int total, int failed) {
    ErrorPacket errPkg = new ErrorPacket();
    errPkg.read(err);
    String errInfo = "total " + total + " failed " + failed + " detail:" + new String(errPkg.message);
    session.getSource().setTxInterrupt(errInfo);
    errPkg.write(session.getSource());
}
Also used : ErrorPacket(io.mycat.net.mysql.ErrorPacket)

Aggregations

ErrorPacket (io.mycat.net.mysql.ErrorPacket)21 IOException (java.io.IOException)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 HandshakePacket (io.mycat.net.mysql.HandshakePacket)2 ConnectionException (io.mycat.net.ConnectionException)1 AuthPacket (io.mycat.net.mysql.AuthPacket)1 BinaryPacket (io.mycat.net.mysql.BinaryPacket)1 HeartbeatPacket (io.mycat.net.mysql.HeartbeatPacket)1 OkPacket (io.mycat.net.mysql.OkPacket)1 Reply323Packet (io.mycat.net.mysql.Reply323Packet)1 ServerConnection (io.mycat.server.ServerConnection)1 BufferedInputStream (java.io.BufferedInputStream)1 BufferedOutputStream (java.io.BufferedOutputStream)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 Socket (java.net.Socket)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1