Search in sources :

Example 1 with OkPacket

use of com.alibaba.cobar.net.mysql.OkPacket in project cobar by alibaba.

the class SingleNodeHandler method okResponse.

@Override
public void okResponse(byte[] data, MySQLConnection conn) {
    boolean executeResponse = false;
    try {
        executeResponse = conn.syncAndExcute();
    } catch (UnsupportedEncodingException e) {
        executeException(conn);
    }
    if (executeResponse) {
        conn.setRunning(false);
        ServerConnection source = session.getSource();
        if (source.isAutocommit()) {
            session.clearConnections();
        }
        endRunning();
        OkPacket ok = new OkPacket();
        ok.read(data);
        source.setLastInsertId(ok.insertId);
        buffer = source.writeToBuffer(data, buffer);
        source.write(buffer);
    }
}
Also used : OkPacket(com.alibaba.cobar.net.mysql.OkPacket) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ServerConnection(com.alibaba.cobar.server.ServerConnection)

Example 2 with OkPacket

use of com.alibaba.cobar.net.mysql.OkPacket in project cobar by alibaba.

the class SingleNodeExecutor method setLastInsertId.

private void setLastInsertId(BinaryPacket bin, ServerConnection sc) {
    OkPacket ok = new OkPacket();
    ok.read(bin);
    if (ok.insertId > 0) {
        sc.setLastInsertId(ok.insertId);
    }
}
Also used : OkPacket(com.alibaba.cobar.net.mysql.OkPacket)

Example 3 with OkPacket

use of com.alibaba.cobar.net.mysql.OkPacket in project cobar by alibaba.

the class KillHandler method getOkPacket.

private static OkPacket getOkPacket() {
    OkPacket packet = new OkPacket();
    packet.packetId = 1;
    packet.affectedRows = 0;
    packet.serverStatus = 2;
    return packet;
}
Also used : OkPacket(com.alibaba.cobar.net.mysql.OkPacket)

Example 4 with OkPacket

use of com.alibaba.cobar.net.mysql.OkPacket in project cobar by alibaba.

the class BlockingSession method cancel.

@Override
public void cancel(FrontendConnection sponsor) {
    // TODO terminate session
    source.writeErrMessage(ErrorCode.ER_QUERY_INTERRUPTED, "Query execution was interrupted");
    if (sponsor != null) {
        OkPacket packet = new OkPacket();
        packet.packetId = 1;
        packet.affectedRows = 0;
        packet.serverStatus = 2;
        packet.write(sponsor);
    }
}
Also used : OkPacket(com.alibaba.cobar.net.mysql.OkPacket)

Example 5 with OkPacket

use of com.alibaba.cobar.net.mysql.OkPacket in project cobar by alibaba.

the class KillConnection method response.

public static void response(String stmt, int offset, ManagerConnection mc) {
    int count = 0;
    List<FrontendConnection> list = getList(stmt, offset, mc);
    if (list != null)
        for (NIOConnection c : list) {
            StringBuilder s = new StringBuilder();
            logger.warn(s.append(c).append("killed by manager").toString());
            c.close();
            count++;
        }
    OkPacket packet = new OkPacket();
    packet.packetId = 1;
    packet.affectedRows = count;
    packet.serverStatus = 2;
    packet.write(mc);
}
Also used : FrontendConnection(com.alibaba.cobar.net.FrontendConnection) OkPacket(com.alibaba.cobar.net.mysql.OkPacket) NIOConnection(com.alibaba.cobar.net.NIOConnection)

Aggregations

OkPacket (com.alibaba.cobar.net.mysql.OkPacket)15 ServerConnection (com.alibaba.cobar.server.ServerConnection)3 ReentrantLock (java.util.concurrent.locks.ReentrantLock)3 MySQLDataNode (com.alibaba.cobar.mysql.MySQLDataNode)2 IOException (java.io.IOException)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 MySQLChannel (com.alibaba.cobar.mysql.bio.MySQLChannel)1 FrontendConnection (com.alibaba.cobar.net.FrontendConnection)1 NIOConnection (com.alibaba.cobar.net.NIOConnection)1 BinaryPacket (com.alibaba.cobar.net.mysql.BinaryPacket)1 ErrorPacket (com.alibaba.cobar.net.mysql.ErrorPacket)1 FieldPacket (com.alibaba.cobar.net.mysql.FieldPacket)1 HeartbeatPacket (com.alibaba.cobar.net.mysql.HeartbeatPacket)1 MySQLPacket (com.alibaba.cobar.net.mysql.MySQLPacket)1 RouteResultsetNode (com.alibaba.cobar.route.RouteResultsetNode)1 LinkedList (java.util.LinkedList)1