use of com.alibaba.cobar.server.ServerConnection in project cobar by alibaba.
the class DefaultCommitExecutor method handleException.
private void handleException(Channel mc, BlockingSession session, Exception e) {
isFail.set(true);
if (decrementCountBy(1)) {
try {
session.clear();
ServerConnection sc = session.getSource();
getLogger().warn(new StringBuilder().append(sc).append(mc).append(getErrorMessage()).toString(), e);
String msg = e.getMessage();
sc.writeErrMessage(ErrorCode.ER_YES, msg == null ? e.getClass().getSimpleName() : msg);
} catch (Exception e2) {
getLogger().warn("exception happens in failure notification: " + session.getSource(), e2);
}
}
}
use of com.alibaba.cobar.server.ServerConnection in project cobar by alibaba.
the class ShowConnection method getRow.
private static RowDataPacket getRow(FrontendConnection c, String charset) {
RowDataPacket row = new RowDataPacket(FIELD_COUNT);
row.add(c.getProcessor().getName().getBytes());
row.add(LongUtil.toBytes(c.getId()));
row.add(StringUtil.encode(c.getHost(), charset));
row.add(IntegerUtil.toBytes(c.getPort()));
row.add(IntegerUtil.toBytes(c.getLocalPort()));
row.add(StringUtil.encode(c.getSchema(), charset));
row.add(StringUtil.encode(c.getCharset(), charset));
row.add(LongUtil.toBytes(c.getNetInBytes()));
row.add(LongUtil.toBytes(c.getNetOutBytes()));
row.add(LongUtil.toBytes((TimeUtil.currentTimeMillis() - c.getStartupTime()) / 1000L));
row.add(IntegerUtil.toBytes(c.getWriteAttempts()));
ByteBuffer bb = c.getReadBuffer();
row.add(IntegerUtil.toBytes(bb == null ? 0 : bb.capacity()));
BufferQueue bq = c.getWriteQueue();
row.add(IntegerUtil.toBytes(bq == null ? 0 : bq.size()));
if (c instanceof ServerConnection) {
ServerConnection sc = (ServerConnection) c;
row.add(IntegerUtil.toBytes(sc.getSession().getTargetCount()));
} else {
row.add(null);
}
return row;
}
use of com.alibaba.cobar.server.ServerConnection in project cobar by alibaba.
the class SingleNodeHandler method executeException.
private void executeException(MySQLConnection c) {
c.setRunning(false);
endRunning();
session.clearConnections();
ErrorPacket err = new ErrorPacket();
err.packetId = ++packetId;
err.errno = ErrorCode.ER_YES;
err.message = StringUtil.encode("unknown backend charset: " + c.getCharset(), session.getSource().getCharset());
ServerConnection source = session.getSource();
source.write(err.write(buffer, source));
}
use of com.alibaba.cobar.server.ServerConnection in project cobar by alibaba.
the class SingleNodeHandler method rowEofResponse.
@Override
public void rowEofResponse(byte[] eof, MySQLConnection conn) {
ServerConnection source = session.getSource();
conn.setRunning(false);
conn.recordSql(source.getHost(), source.getSchema(), route.getStatement());
if (source.isAutocommit()) {
session.clearConnections();
}
endRunning();
buffer = source.writeToBuffer(eof, buffer);
source.write(buffer);
}
use of com.alibaba.cobar.server.ServerConnection in project cobar by alibaba.
the class MultiNodeExecutor method notifyFailure.
/**
* 通知,执行异常
*
* @throws nothing never throws any exception
*/
private void notifyFailure(BlockingSession ss) {
try {
// 清理
ss.clear();
ServerConnection sc = ss.getSource();
sc.setTxInterrupt();
// 通知
ErrorPacket err = new ErrorPacket();
// ERROR_PACKET
err.packetId = ++packetId;
err.errno = errno;
err.message = StringUtil.encode(errMessage, sc.getCharset());
sc.write(err.write(buffer, sc));
} catch (Exception e) {
LOGGER.warn("exception happens in failure notification: " + ss.getSource(), e);
}
}
Aggregations