Search in sources :

Example 51 with RowDataPacket

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

the class SelectSessionAutoIncrement 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 = new RowDataPacket(FIELD_COUNT);
    row.packetId = ++packetId;
    row.add(LongUtil.toBytes(1));
    buffer = row.write(buffer, c);
    // write last eof
    EOFPacket lastEof = new EOFPacket();
    lastEof.packetId = ++packetId;
    buffer = lastEof.write(buffer, c);
    // post write
    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 52 with RowDataPacket

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

the class SelectVersionComment 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 = new RowDataPacket(FIELD_COUNT);
    row.add(VERSION_COMMENT);
    row.packetId = ++packetId;
    buffer = row.write(buffer, c);
    // write last eof
    EOFPacket lastEof = new EOFPacket();
    lastEof.packetId = ++packetId;
    buffer = lastEof.write(buffer, c);
    // post write
    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 53 with RowDataPacket

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

the class ShowBackend method execute.

public static void execute(ManagerConnection c) {
    ByteBuffer buffer = c.allocate();
    buffer = header.write(buffer, c);
    for (FieldPacket field : fields) {
        buffer = field.write(buffer, c);
    }
    buffer = eof.write(buffer, c);
    byte packetId = eof.packetId;
    String charset = c.getCharset();
    for (NIOProcessor p : CobarServer.getInstance().getProcessors()) {
        for (BackendConnection bc : p.getBackends().values()) {
            if (bc != null) {
                RowDataPacket row = getRow(bc, charset);
                row.packetId = ++packetId;
                buffer = row.write(buffer, c);
            }
        }
    }
    EOFPacket lastEof = new EOFPacket();
    lastEof.packetId = ++packetId;
    buffer = lastEof.write(buffer, c);
    c.write(buffer);
}
Also used : BackendConnection(com.alibaba.cobar.net.BackendConnection) 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 54 with RowDataPacket

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

the class ShowDataSources method getRow.

private static RowDataPacket getRow(MySQLDataNode node, String charset) {
    RowDataPacket row = new RowDataPacket(FIELD_COUNT);
    row.add(StringUtil.encode(node.getName(), charset));
    MySQLDataSource ds = node.getSource();
    if (ds != null) {
        DataSourceConfig dsc = ds.getConfig();
        row.add(StringUtil.encode(dsc.getType(), charset));
        row.add(StringUtil.encode(dsc.getHost(), charset));
        row.add(IntegerUtil.toBytes(dsc.getPort()));
        row.add(StringUtil.encode(dsc.getDatabase(), charset));
    } else {
        row.add(null);
        row.add(null);
        row.add(null);
        row.add(null);
    }
    return row;
}
Also used : MySQLDataSource(com.alibaba.cobar.mysql.MySQLDataSource) DataSourceConfig(com.alibaba.cobar.config.model.DataSourceConfig) RowDataPacket(com.alibaba.cobar.net.mysql.RowDataPacket)

Example 55 with RowDataPacket

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

the class ShowDataSources method response.

public static void response(ServerConnection c) {
    ByteBuffer buffer = c.allocate();
    // write header
    buffer = header.write(buffer, c);
    // write field
    for (FieldPacket field : fields) {
        buffer = field.write(buffer, c);
    }
    // write eof
    buffer = eof.write(buffer, c);
    // write rows
    byte packetId = eof.packetId;
    Map<String, MySQLDataNode> nodes = CobarServer.getInstance().getConfig().getDataNodes();
    for (MySQLDataNode node : nodes.values()) {
        RowDataPacket row = getRow(node, 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);
    // post write
    c.write(buffer);
}
Also used : MySQLDataNode(com.alibaba.cobar.mysql.MySQLDataNode) 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)

Aggregations

RowDataPacket (com.alibaba.cobar.net.mysql.RowDataPacket)61 ByteBuffer (java.nio.ByteBuffer)38 EOFPacket (com.alibaba.cobar.net.mysql.EOFPacket)37 FieldPacket (com.alibaba.cobar.net.mysql.FieldPacket)37 CobarConfig (com.alibaba.cobar.CobarConfig)7 MySQLDataNode (com.alibaba.cobar.mysql.MySQLDataNode)6 NIOProcessor (com.alibaba.cobar.net.NIOProcessor)6 MySQLDataSource (com.alibaba.cobar.mysql.MySQLDataSource)5 SchemaConfig (com.alibaba.cobar.config.model.SchemaConfig)4 SQLRecord (com.alibaba.cobar.statistic.SQLRecord)3 ArrayList (java.util.ArrayList)3 CobarNode (com.alibaba.cobar.CobarNode)2 DataSourceConfig (com.alibaba.cobar.config.model.DataSourceConfig)2 CobarHeartbeat (com.alibaba.cobar.heartbeat.CobarHeartbeat)2 MySQLHeartbeat (com.alibaba.cobar.heartbeat.MySQLHeartbeat)2 FrontendConnection (com.alibaba.cobar.net.FrontendConnection)2 ResultSetHeaderPacket (com.alibaba.cobar.net.mysql.ResultSetHeaderPacket)2 LinkedList (java.util.LinkedList)2 TreeSet (java.util.TreeSet)2 CobarCluster (com.alibaba.cobar.CobarCluster)1