Search in sources :

Example 11 with FieldPacket

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

the class ShowParser method execute.

public static void execute(ManagerConnection c) {
    ByteBuffer buffer = c.allocate();
    // write header
    buffer = header.write(buffer, c);
    // write fields
    for (FieldPacket field : fields) {
        buffer = field.write(buffer, c);
    }
    // write eof
    buffer = eof.write(buffer, c);
    // write rows
    byte packetId = eof.packetId;
    for (int i = 0; i < 1; i++) {
        RowDataPacket row = getRow(c.getCharset());
        row.packetId = ++packetId;
        buffer = row.write(buffer, c);
    }
    // write last eof
    EOFPacket lastEof = new EOFPacket();
    lastEof.packetId = ++packetId;
    buffer = lastEof.write(buffer, c);
    // write buffer
    c.write(buffer);
}
Also used : RowDataPacket(com.alibaba.cobar.net.mysql.RowDataPacket) EOFPacket(com.alibaba.cobar.net.mysql.EOFPacket) ByteBuffer(java.nio.ByteBuffer) FieldPacket(com.alibaba.cobar.net.mysql.FieldPacket)

Example 12 with FieldPacket

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

the class ShowProcessor method execute.

public static void execute(ManagerConnection c) {
    ByteBuffer buffer = c.allocate();
    // write header
    buffer = header.write(buffer, c);
    // write fields
    for (FieldPacket field : fields) {
        buffer = field.write(buffer, c);
    }
    // write eof
    buffer = eof.write(buffer, c);
    // write rows
    byte packetId = eof.packetId;
    for (NIOProcessor p : CobarServer.getInstance().getProcessors()) {
        RowDataPacket row = getRow(p, c.getCharset());
        row.packetId = ++packetId;
        buffer = row.write(buffer, c);
    }
    // write last eof
    EOFPacket lastEof = new EOFPacket();
    lastEof.packetId = ++packetId;
    buffer = lastEof.write(buffer, c);
    // write buffer
    c.write(buffer);
}
Also used : RowDataPacket(com.alibaba.cobar.net.mysql.RowDataPacket) EOFPacket(com.alibaba.cobar.net.mysql.EOFPacket) NIOProcessor(com.alibaba.cobar.net.NIOProcessor) ByteBuffer(java.nio.ByteBuffer) FieldPacket(com.alibaba.cobar.net.mysql.FieldPacket)

Example 13 with FieldPacket

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

the class ShowCollation method execute.

public static void execute(ManagerConnection c) {
    ByteBuffer buffer = c.allocate();
    // write header
    buffer = header.write(buffer, c);
    // write fields
    for (FieldPacket field : fields) {
        buffer = field.write(buffer, c);
    }
    // write eof
    buffer = eof.write(buffer, c);
    // write rows
    byte packetId = eof.packetId;
    RowDataPacket row = getRow(c.getCharset());
    row.packetId = ++packetId;
    buffer = row.write(buffer, c);
    // write lastEof
    EOFPacket lastEof = new EOFPacket();
    lastEof.packetId = ++packetId;
    buffer = lastEof.write(buffer, c);
    // write buffer
    c.write(buffer);
}
Also used : RowDataPacket(com.alibaba.cobar.net.mysql.RowDataPacket) EOFPacket(com.alibaba.cobar.net.mysql.EOFPacket) ByteBuffer(java.nio.ByteBuffer) FieldPacket(com.alibaba.cobar.net.mysql.FieldPacket)

Example 14 with FieldPacket

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

the class ShowConnectionSQL method execute.

public static void execute(ManagerConnection c) {
    ByteBuffer buffer = c.allocate();
    // write header
    buffer = header.write(buffer, c);
    // write fields
    for (FieldPacket field : fields) {
        buffer = field.write(buffer, c);
    }
    // write eof
    buffer = eof.write(buffer, c);
    // write rows
    byte packetId = eof.packetId;
    String charset = c.getCharset();
    for (NIOProcessor p : CobarServer.getInstance().getProcessors()) {
        for (FrontendConnection fc : p.getFrontends().values()) {
            if (!fc.isClosed()) {
                RowDataPacket row = getRow(fc, charset);
                row.packetId = ++packetId;
                buffer = row.write(buffer, c);
            }
        }
    }
    // write last eof
    EOFPacket lastEof = new EOFPacket();
    lastEof.packetId = ++packetId;
    buffer = lastEof.write(buffer, c);
    // write buffer
    c.write(buffer);
}
Also used : FrontendConnection(com.alibaba.cobar.net.FrontendConnection) RowDataPacket(com.alibaba.cobar.net.mysql.RowDataPacket) EOFPacket(com.alibaba.cobar.net.mysql.EOFPacket) NIOProcessor(com.alibaba.cobar.net.NIOProcessor) ByteBuffer(java.nio.ByteBuffer) FieldPacket(com.alibaba.cobar.net.mysql.FieldPacket)

Example 15 with FieldPacket

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

the class SingleNodeExecutor method handleResultSet.

/**
     * 处理结果集数据
     */
private void handleResultSet(RouteResultsetNode rrn, BlockingSession ss, MySQLChannel mc, BinaryPacket bin, int flag) throws IOException {
    final ServerConnection sc = ss.getSource();
    // HEADER
    bin.packetId = ++packetId;
    List<MySQLPacket> headerList = new LinkedList<MySQLPacket>();
    headerList.add(bin);
    for (; ; ) {
        bin = mc.receive();
        switch(bin.data[0]) {
            case ErrorPacket.FIELD_COUNT:
                {
                    LOGGER.warn(mc.getErrLog(rrn.getStatement(), mc.getErrMessage(bin), sc));
                    mc.setRunning(false);
                    if (mc.isAutocommit()) {
                        ss.clear();
                    }
                    endRunning();
                    // ERROR_PACKET
                    bin.packetId = ++packetId;
                    sc.write(bin.write(sc.allocate(), sc));
                    return;
                }
            case EOFPacket.FIELD_COUNT:
                {
                    // FIELD_EOF
                    bin.packetId = ++packetId;
                    ByteBuffer bb = sc.allocate();
                    for (MySQLPacket packet : headerList) {
                        bb = packet.write(bb, sc);
                    }
                    bb = bin.write(bb, sc);
                    headerList = null;
                    handleRowData(rrn, ss, mc, bb, packetId);
                    return;
                }
            default:
                // FIELDS
                bin.packetId = ++packetId;
                switch(flag) {
                    case RouteResultset.REWRITE_FIELD:
                        StringBuilder fieldName = new StringBuilder();
                        fieldName.append("Tables_in_").append(ss.getSource().getSchema());
                        FieldPacket field = PacketUtil.getField(bin, fieldName.toString());
                        headerList.add(field);
                        break;
                    default:
                        headerList.add(bin);
                }
        }
    }
}
Also used : MySQLPacket(com.alibaba.cobar.net.mysql.MySQLPacket) ServerConnection(com.alibaba.cobar.server.ServerConnection) ByteBuffer(java.nio.ByteBuffer) FieldPacket(com.alibaba.cobar.net.mysql.FieldPacket) LinkedList(java.util.LinkedList)

Aggregations

FieldPacket (com.alibaba.cobar.net.mysql.FieldPacket)43 ByteBuffer (java.nio.ByteBuffer)40 EOFPacket (com.alibaba.cobar.net.mysql.EOFPacket)38 RowDataPacket (com.alibaba.cobar.net.mysql.RowDataPacket)37 NIOProcessor (com.alibaba.cobar.net.NIOProcessor)6 CobarConfig (com.alibaba.cobar.CobarConfig)5 MySQLDataNode (com.alibaba.cobar.mysql.MySQLDataNode)5 SchemaConfig (com.alibaba.cobar.config.model.SchemaConfig)3 MySQLDataSource (com.alibaba.cobar.mysql.MySQLDataSource)3 SQLRecord (com.alibaba.cobar.statistic.SQLRecord)3 FrontendConnection (com.alibaba.cobar.net.FrontendConnection)2 MySQLPacket (com.alibaba.cobar.net.mysql.MySQLPacket)2 ResultSetHeaderPacket (com.alibaba.cobar.net.mysql.ResultSetHeaderPacket)2 ServerConnection (com.alibaba.cobar.server.ServerConnection)2 ArrayList (java.util.ArrayList)2 LinkedList (java.util.LinkedList)2 TreeSet (java.util.TreeSet)2 DataSourceConfig (com.alibaba.cobar.config.model.DataSourceConfig)1 UserConfig (com.alibaba.cobar.config.model.UserConfig)1 MySQLChannel (com.alibaba.cobar.mysql.bio.MySQLChannel)1