Search in sources :

Example 11 with RowDataPacket

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

the class ShowSlow method schema.

public static void schema(ManagerConnection c, String name) {
    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;
    CobarConfig conf = CobarServer.getInstance().getConfig();
    SchemaConfig schema = conf.getSchemas().get(name);
    if (schema != null) {
        SQLRecorder recorder = new SQLRecorder(conf.getSystem().getSqlRecordCount());
        Map<String, MySQLDataNode> dataNodes = conf.getDataNodes();
        for (String n : schema.getAllDataNodes()) {
            MySQLDataNode dn = dataNodes.get(n);
            MySQLDataSource ds = null;
            if (dn != null && (ds = dn.getSource()) != null) {
                for (SQLRecord r : ds.getSqlRecorder().getRecords()) {
                    if (r != null && recorder.check(r.executeTime)) {
                        recorder.add(r);
                    }
                }
            }
        }
        SQLRecord[] records = recorder.getRecords();
        for (int i = records.length - 1; i >= 0; i--) {
            if (records[i] != null) {
                RowDataPacket row = getRow(records[i], 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 : MySQLDataNode(com.alibaba.cobar.mysql.MySQLDataNode) SchemaConfig(com.alibaba.cobar.config.model.SchemaConfig) SQLRecorder(com.alibaba.cobar.statistic.SQLRecorder) RowDataPacket(com.alibaba.cobar.net.mysql.RowDataPacket) EOFPacket(com.alibaba.cobar.net.mysql.EOFPacket) CobarConfig(com.alibaba.cobar.CobarConfig) SQLRecord(com.alibaba.cobar.statistic.SQLRecord) ByteBuffer(java.nio.ByteBuffer) MySQLDataSource(com.alibaba.cobar.mysql.MySQLDataSource) FieldPacket(com.alibaba.cobar.net.mysql.FieldPacket)

Example 12 with RowDataPacket

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

the class ShowThreadPool method getRow.

private static RowDataPacket getRow(NameableExecutor exec, String charset) {
    RowDataPacket row = new RowDataPacket(FIELD_COUNT);
    row.add(StringUtil.encode(exec.getName(), charset));
    row.add(IntegerUtil.toBytes(exec.getPoolSize()));
    row.add(IntegerUtil.toBytes(exec.getActiveCount()));
    row.add(IntegerUtil.toBytes(exec.getQueue().size()));
    row.add(LongUtil.toBytes(exec.getCompletedTaskCount()));
    row.add(LongUtil.toBytes(exec.getTaskCount()));
    return row;
}
Also used : RowDataPacket(com.alibaba.cobar.net.mysql.RowDataPacket)

Example 13 with RowDataPacket

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

the class ShowDatabase 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;
    Map<String, SchemaConfig> schemas = CobarServer.getInstance().getConfig().getSchemas();
    for (String name : new TreeSet<String>(schemas.keySet())) {
        RowDataPacket row = new RowDataPacket(FIELD_COUNT);
        row.add(StringUtil.encode(name, 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 : SchemaConfig(com.alibaba.cobar.config.model.SchemaConfig) TreeSet(java.util.TreeSet) 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 RowDataPacket

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

the class ShowHeartbeat method response.

public static void response(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 (RowDataPacket row : getRows()) {
        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 15 with RowDataPacket

use of com.alibaba.cobar.net.mysql.RowDataPacket 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)

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