Search in sources :

Example 46 with RowDataPacket

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

the class ShowConnection 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 != null) {
                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 47 with RowDataPacket

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

the class ShowConnection method getRow.

private static RowDataPacket getRow(FrontendConnection c, String charset) {
    RowDataPacket row = new RowDataPacket(FIELD_COUNT);
    row.add(c.getProcessor().getName().getBytes());
    row.add(LongUtil.toBytes(c.getId()));
    row.add(StringUtil.encode(c.getHost(), charset));
    row.add(IntegerUtil.toBytes(c.getPort()));
    row.add(IntegerUtil.toBytes(c.getLocalPort()));
    row.add(StringUtil.encode(c.getSchema(), charset));
    row.add(StringUtil.encode(c.getCharset(), charset));
    row.add(LongUtil.toBytes(c.getNetInBytes()));
    row.add(LongUtil.toBytes(c.getNetOutBytes()));
    row.add(LongUtil.toBytes((TimeUtil.currentTimeMillis() - c.getStartupTime()) / 1000L));
    row.add(IntegerUtil.toBytes(c.getWriteAttempts()));
    ByteBuffer bb = c.getReadBuffer();
    row.add(IntegerUtil.toBytes(bb == null ? 0 : bb.capacity()));
    BufferQueue bq = c.getWriteQueue();
    row.add(IntegerUtil.toBytes(bq == null ? 0 : bq.size()));
    if (c instanceof ServerConnection) {
        ServerConnection sc = (ServerConnection) c;
        row.add(IntegerUtil.toBytes(sc.getSession().getTargetCount()));
    } else {
        row.add(null);
    }
    return row;
}
Also used : RowDataPacket(com.alibaba.cobar.net.mysql.RowDataPacket) ServerConnection(com.alibaba.cobar.server.ServerConnection) ByteBuffer(java.nio.ByteBuffer) BufferQueue(com.alibaba.cobar.net.buffer.BufferQueue)

Example 48 with RowDataPacket

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

the class ShowDataNode method execute.

public static void execute(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();
    Map<String, MySQLDataNode> dataNodes = conf.getDataNodes();
    List<String> keys = new ArrayList<String>();
    if (StringUtil.isEmpty(name)) {
        keys.addAll(dataNodes.keySet());
    } else {
        SchemaConfig sc = conf.getSchemas().get(name);
        if (null != sc) {
            keys.addAll(sc.getAllDataNodes());
        }
    }
    Collections.sort(keys, new Comparators<String>());
    for (String key : keys) {
        RowDataPacket row = getRow(dataNodes.get(key), 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) SchemaConfig(com.alibaba.cobar.config.model.SchemaConfig) RowDataPacket(com.alibaba.cobar.net.mysql.RowDataPacket) ArrayList(java.util.ArrayList) EOFPacket(com.alibaba.cobar.net.mysql.EOFPacket) CobarConfig(com.alibaba.cobar.CobarConfig) ByteBuffer(java.nio.ByteBuffer) FieldPacket(com.alibaba.cobar.net.mysql.FieldPacket)

Example 49 with RowDataPacket

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

the class ShowDataNode method getRow.

private static RowDataPacket getRow(MySQLDataNode node, String charset) {
    RowDataPacket row = new RowDataPacket(FIELD_COUNT);
    row.add(StringUtil.encode(node.getName(), charset));
    row.add(StringUtil.encode(node.getConfig().getDataSource(), charset));
    MySQLDataSource ds = node.getSource();
    if (ds != null) {
        row.add(IntegerUtil.toBytes(ds.getIndex()));
        row.add(ds.getConfig().getType().getBytes());
        row.add(IntegerUtil.toBytes(ds.getActiveCount()));
        row.add(IntegerUtil.toBytes(ds.getIdleCount()));
        row.add(IntegerUtil.toBytes(ds.size()));
    } else {
        row.add(null);
        row.add(null);
        row.add(null);
        row.add(null);
        row.add(null);
    }
    row.add(LongUtil.toBytes(node.getExecuteCount()));
    row.add(StringUtil.encode(nf.format(0), charset));
    row.add(StringUtil.encode(nf.format(0), charset));
    row.add(LongUtil.toBytes(0));
    long recoveryTime = node.getHeartbeatRecoveryTime() - TimeUtil.currentTimeMillis();
    row.add(LongUtil.toBytes(recoveryTime > 0 ? recoveryTime / 1000L : -1L));
    return row;
}
Also used : MySQLDataSource(com.alibaba.cobar.mysql.MySQLDataSource) RowDataPacket(com.alibaba.cobar.net.mysql.RowDataPacket)

Example 50 with RowDataPacket

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

the class ShowDataSource method execute.

public static void execute(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();
    Map<String, DataSourceConfig> dataSources = conf.getDataSources();
    List<String> keys = new ArrayList<String>();
    if (null != name) {
        MySQLDataNode dn = conf.getDataNodes().get(name);
        if (dn != null)
            for (MySQLDataSource ds : dn.getSources()) {
                if (ds != null) {
                    keys.add(ds.getName());
                }
            }
    } else {
        keys.addAll(dataSources.keySet());
    }
    Collections.sort(keys, new Comparators<String>());
    for (String key : keys) {
        RowDataPacket row = getRow(dataSources.get(key), 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) DataSourceConfig(com.alibaba.cobar.config.model.DataSourceConfig) RowDataPacket(com.alibaba.cobar.net.mysql.RowDataPacket) ArrayList(java.util.ArrayList) EOFPacket(com.alibaba.cobar.net.mysql.EOFPacket) CobarConfig(com.alibaba.cobar.CobarConfig) ByteBuffer(java.nio.ByteBuffer) MySQLDataSource(com.alibaba.cobar.mysql.MySQLDataSource) 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