Search in sources :

Example 16 with ServerConnection

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);
        }
    }
}
Also used : ServerConnection(com.alibaba.cobar.server.ServerConnection) IOException(java.io.IOException) UnknownPacketException(com.alibaba.cobar.exception.UnknownPacketException)

Example 17 with ServerConnection

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;
}
Also used : RowDataPacket(com.alibaba.cobar.net.mysql.RowDataPacket) ServerConnection(com.alibaba.cobar.server.ServerConnection) ByteBuffer(java.nio.ByteBuffer) BufferQueue(com.alibaba.cobar.net.buffer.BufferQueue)

Example 18 with ServerConnection

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));
}
Also used : ErrorPacket(com.alibaba.cobar.net.mysql.ErrorPacket) ServerConnection(com.alibaba.cobar.server.ServerConnection)

Example 19 with ServerConnection

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);
}
Also used : ServerConnection(com.alibaba.cobar.server.ServerConnection)

Example 20 with ServerConnection

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);
    }
}
Also used : ErrorPacket(com.alibaba.cobar.net.mysql.ErrorPacket) ServerConnection(com.alibaba.cobar.server.ServerConnection) UnknownDataNodeException(com.alibaba.cobar.exception.UnknownDataNodeException) IOException(java.io.IOException)

Aggregations

ServerConnection (com.alibaba.cobar.server.ServerConnection)29 IOException (java.io.IOException)16 BinaryPacket (com.alibaba.cobar.net.mysql.BinaryPacket)6 UnknownDataNodeException (com.alibaba.cobar.exception.UnknownDataNodeException)5 MySQLChannel (com.alibaba.cobar.mysql.bio.MySQLChannel)5 ByteBuffer (java.nio.ByteBuffer)5 UnknownPacketException (com.alibaba.cobar.exception.UnknownPacketException)4 ErrorPacket (com.alibaba.cobar.net.mysql.ErrorPacket)4 Channel (com.alibaba.cobar.mysql.bio.Channel)3 OkPacket (com.alibaba.cobar.net.mysql.OkPacket)3 RouteResultsetNode (com.alibaba.cobar.route.RouteResultsetNode)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 ReentrantLock (java.util.concurrent.locks.ReentrantLock)3 CobarConfig (com.alibaba.cobar.CobarConfig)2 MySQLDataNode (com.alibaba.cobar.mysql.MySQLDataNode)2 FieldPacket (com.alibaba.cobar.net.mysql.FieldPacket)2 MySQLPacket (com.alibaba.cobar.net.mysql.MySQLPacket)2 LinkedList (java.util.LinkedList)2 FrontendConnection (com.alibaba.cobar.net.FrontendConnection)1 NIOProcessor (com.alibaba.cobar.net.NIOProcessor)1