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);
}
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());
}
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());
}
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));
}
}
}
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");
}
}
}
Aggregations