Search in sources :

Example 26 with RowDataPacket

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

the class SelectVersionComment method response.

public static void response(ServerConnection 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 27 with RowDataPacket

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

the class ShowCobarCluster method getRows.

private static List<RowDataPacket> getRows(ServerConnection c) {
    List<RowDataPacket> rows = new LinkedList<RowDataPacket>();
    CobarConfig config = CobarServer.getInstance().getConfig();
    CobarCluster cluster = config.getCluster();
    Map<String, SchemaConfig> schemas = config.getSchemas();
    SchemaConfig schema = (c.getSchema() == null) ? null : schemas.get(c.getSchema());
    // 如果没有指定schema或者schema为null,则使用全部集群。
    if (schema == null) {
        Map<String, CobarNode> nodes = cluster.getNodes();
        for (CobarNode n : nodes.values()) {
            if (n != null && n.isOnline()) {
                rows.add(getRow(n, c.getCharset()));
            }
        }
    } else {
        String group = (schema.getGroup() == null) ? "default" : schema.getGroup();
        List<String> nodeList = cluster.getGroups().get(group);
        if (nodeList != null && nodeList.size() > 0) {
            Map<String, CobarNode> nodes = cluster.getNodes();
            for (String id : nodeList) {
                CobarNode n = nodes.get(id);
                if (n != null && n.isOnline()) {
                    rows.add(getRow(n, c.getCharset()));
                }
            }
        }
        // 如果schema对应的group或者默认group都没有有效的节点,则使用全部集群。
        if (rows.size() == 0) {
            Map<String, CobarNode> nodes = cluster.getNodes();
            for (CobarNode n : nodes.values()) {
                if (n != null && n.isOnline()) {
                    rows.add(getRow(n, c.getCharset()));
                }
            }
        }
    }
    if (rows.size() == 0) {
        alarm.error(Alarms.CLUSTER_EMPTY + c.toString());
    }
    return rows;
}
Also used : SchemaConfig(com.alibaba.cobar.config.model.SchemaConfig) CobarNode(com.alibaba.cobar.CobarNode) RowDataPacket(com.alibaba.cobar.net.mysql.RowDataPacket) CobarConfig(com.alibaba.cobar.CobarConfig) LinkedList(java.util.LinkedList) CobarCluster(com.alibaba.cobar.CobarCluster)

Example 28 with RowDataPacket

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

the class ExplainHandler method handle.

public static void handle(String stmt, ServerConnection c, int offset) {
    stmt = stmt.substring(offset);
    RouteResultset rrs = getRouteResultset(c, stmt);
    if (rrs == null)
        return;
    ByteBuffer buffer = c.allocate();
    // write header
    ResultSetHeaderPacket header = PacketUtil.getHeader(FIELD_COUNT);
    byte packetId = header.packetId;
    buffer = header.write(buffer, c);
    // write fields
    for (FieldPacket field : fields) {
        field.packetId = ++packetId;
        buffer = field.write(buffer, c);
    }
    // write eof
    EOFPacket eof = new EOFPacket();
    eof.packetId = ++packetId;
    buffer = eof.write(buffer, c);
    // write rows
    RouteResultsetNode[] rrsn = (rrs != null) ? rrs.getNodes() : EMPTY_ARRAY;
    for (RouteResultsetNode node : rrsn) {
        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 : ResultSetHeaderPacket(com.alibaba.cobar.net.mysql.ResultSetHeaderPacket) RouteResultsetNode(com.alibaba.cobar.route.RouteResultsetNode) 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) RouteResultset(com.alibaba.cobar.route.RouteResultset)

Example 29 with RowDataPacket

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

the class ExplainHandler method getRow.

private static RowDataPacket getRow(RouteResultsetNode node, String charset) {
    RowDataPacket row = new RowDataPacket(FIELD_COUNT);
    row.add(StringUtil.encode(node.getName(), charset));
    row.add(StringUtil.encode(node.getStatement(), charset));
    return row;
}
Also used : RowDataPacket(com.alibaba.cobar.net.mysql.RowDataPacket)

Example 30 with RowDataPacket

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

the class ShowThreadPool 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;
    List<NameableExecutor> executors = getExecutors();
    for (NameableExecutor exec : executors) {
        if (exec != null) {
            RowDataPacket row = getRow(exec, 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 : NameableExecutor(com.alibaba.cobar.util.NameableExecutor) 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