use of io.mycat.server.ServerConnection in project Mycat_plus by coderczp.
the class SingleNodeHandler method backConnectionErr.
private void backConnectionErr(ErrorPacket errPkg, BackendConnection conn) {
endRunning();
ServerConnection source = session.getSource();
String errUser = source.getUser();
String errHost = source.getHost();
int errPort = source.getLocalPort();
String errmgs = " errno:" + errPkg.errno + " " + new String(errPkg.message);
LOGGER.warn("execute sql err :" + errmgs + " con:" + conn + " frontend host:" + errHost + "/" + errPort + "/" + errUser);
session.releaseConnectionIfSafe(conn, LOGGER.isDebugEnabled(), false);
source.setTxInterrupt(errmgs);
/**
* TODO: 修复全版本BUG
*
* BUG复现:
* 1、MysqlClient: SELECT 9223372036854775807 + 1;
* 2、MyCatServer: ERROR 1690 (22003): BIGINT value is out of range in '(9223372036854775807 + 1)'
* 3、MysqlClient: ERROR 2013 (HY000): Lost connection to MySQL server during query
*
* Fixed后
* 1、MysqlClient: SELECT 9223372036854775807 + 1;
* 2、MyCatServer: ERROR 1690 (22003): BIGINT value is out of range in '(9223372036854775807 + 1)'
* 3、MysqlClient: ERROR 1690 (22003): BIGINT value is out of range in '(9223372036854775807 + 1)'
*/
// 由于 pakcetId != 1 造成的问题
errPkg.packetId = 1;
errPkg.write(source);
recycleResources();
}
use of io.mycat.server.ServerConnection in project Mycat_plus by coderczp.
the class SingleNodeHandler method rowEofResponse.
/**
* select
*
* 行结束标志返回时触发,将EOF标志写入缓冲区,最后调用source.write(buffer)将缓冲区放入前端连接的写缓冲队列中,等待NIOSocketWR将其发送给应用
*/
@Override
public void rowEofResponse(byte[] eof, BackendConnection conn) {
this.netOutBytes += eof.length;
ServerConnection source = session.getSource();
conn.recordSql(source.getHost(), source.getSchema(), node.getStatement());
// 判断是调用存储过程的话不能在这里释放链接
if (!rrs.isCallStatement() || (rrs.isCallStatement() && rrs.getProcedure().isResultSimpleValue())) {
session.releaseConnectionIfSafe(conn, LOGGER.isDebugEnabled(), false);
endRunning();
}
eof[3] = ++packetId;
buffer = source.writeToBuffer(eof, allocBuffer());
int resultSize = source.getWriteQueue().size() * MycatServer.getInstance().getConfig().getSystem().getBufferPoolPageSize();
resultSize = resultSize + buffer.position();
MiddlerResultHandler middlerResultHandler = session.getMiddlerResultHandler();
if (middlerResultHandler != null) {
middlerResultHandler.secondEexcute();
} else {
source.write(buffer);
}
source.setExecuteSql(null);
// TODO: add by zhuam
// 查询结果派发
QueryResult queryResult = new QueryResult(session.getSource().getUser(), rrs.getSqlType(), rrs.getStatement(), affectedRows, netInBytes, netOutBytes, startTime, System.currentTimeMillis(), resultSize);
QueryResultDispatcher.dispatchQuery(queryResult);
}
use of io.mycat.server.ServerConnection in project Mycat_plus by coderczp.
the class SingleNodeHandler method execute.
public void execute() throws Exception {
startTime = System.currentTimeMillis();
ServerConnection sc = session.getSource();
this.isRunning = true;
this.packetId = 0;
final BackendConnection conn = session.getTarget(node);
LOGGER.debug("rrs.getRunOnSlave() " + rrs.getRunOnSlave());
// 实现 master/slave注解
node.setRunOnSlave(rrs.getRunOnSlave());
LOGGER.debug("node.getRunOnSlave() " + node.getRunOnSlave());
if (session.tryExistsCon(conn, node)) {
_execute(conn);
} else {
// create new connection
MycatConfig conf = MycatServer.getInstance().getConfig();
LOGGER.debug("node.getRunOnSlave() " + node.getRunOnSlave());
// 实现 master/slave注解
node.setRunOnSlave(rrs.getRunOnSlave());
LOGGER.debug("node.getRunOnSlave() " + node.getRunOnSlave());
PhysicalDBNode dn = conf.getDataNodes().get(node.getName());
dn.getConnection(dn.getDatabase(), sc.isAutocommit(), node, this, node);
}
}
use of io.mycat.server.ServerConnection in project Mycat_plus by coderczp.
the class SingleNodeHandler method connectionError.
@Override
public void connectionError(Throwable e, BackendConnection conn) {
endRunning();
ErrorPacket err = new ErrorPacket();
err.packetId = ++packetId;
err.errno = ErrorCode.ER_NEW_ABORTING_CONNECTION;
err.message = StringUtil.encode(e.getMessage(), session.getSource().getCharset());
ServerConnection source = session.getSource();
source.write(err.write(allocBuffer(), source, true));
}
use of io.mycat.server.ServerConnection in project Mycat_plus by coderczp.
the class ShowSession method execute.
public static void execute(ManagerConnection c) {
ByteBuffer buffer = c.allocate();
// write header
buffer = header.write(buffer, c, true);
// write fields
for (FieldPacket field : fields) {
buffer = field.write(buffer, c, true);
}
// write eof
buffer = eof.write(buffer, c, true);
// write rows
byte packetId = eof.packetId;
for (NIOProcessor process : MycatServer.getInstance().getProcessors()) {
for (FrontendConnection front : process.getFrontends().values()) {
if (!(front instanceof ServerConnection)) {
continue;
}
ServerConnection sc = (ServerConnection) front;
RowDataPacket row = getRow(sc, c.getCharset());
if (row != null) {
row.packetId = ++packetId;
buffer = row.write(buffer, c, true);
}
}
}
// write last eof
EOFPacket lastEof = new EOFPacket();
lastEof.packetId = ++packetId;
buffer = lastEof.write(buffer, c, true);
// write buffer
c.write(buffer);
}
Aggregations