Search in sources :

Example 46 with RowDataPacket

use of com.actiontech.dble.net.mysql.RowDataPacket in project dble by actiontech.

the class ShowDatasourceSyn method getRows.

private static List<RowDataPacket> getRows(String charset) {
    List<RowDataPacket> list = new LinkedList<>();
    ServerConfig conf = DbleServer.getInstance().getConfig();
    // host nodes
    Map<String, PhysicalDBPool> dataHosts = conf.getDataHosts();
    for (PhysicalDBPool pool : dataHosts.values()) {
        for (PhysicalDatasource ds : pool.getAllDataSources()) {
            DBHeartbeat hb = ds.getHeartbeat();
            DataSourceSyncRecorder record = hb.getAsyncRecorder();
            Map<String, String> states = record.getRecords();
            RowDataPacket row = new RowDataPacket(FIELD_COUNT);
            if (!states.isEmpty()) {
                row.add(StringUtil.encode(ds.getName(), charset));
                row.add(StringUtil.encode(ds.getConfig().getIp(), charset));
                row.add(LongUtil.toBytes(ds.getConfig().getPort()));
                row.add(StringUtil.encode(states.get("Master_Host"), charset));
                row.add(LongUtil.toBytes(Long.parseLong(states.get("Master_Port"))));
                row.add(StringUtil.encode(states.get("Master_User"), charset));
                String seconds = states.get("Seconds_Behind_Master");
                row.add(seconds == null ? null : LongUtil.toBytes(Long.parseLong(seconds)));
                row.add(StringUtil.encode(states.get("Slave_IO_Running"), charset));
                row.add(StringUtil.encode(states.get("Slave_SQL_Running"), charset));
                row.add(StringUtil.encode(states.get("Slave_IO_State"), charset));
                row.add(LongUtil.toBytes(Long.parseLong(states.get("Connect_Retry"))));
                row.add(StringUtil.encode(states.get("Last_IO_Error"), charset));
                list.add(row);
            }
        }
    }
    return list;
}
Also used : ServerConfig(com.actiontech.dble.config.ServerConfig) PhysicalDatasource(com.actiontech.dble.backend.datasource.PhysicalDatasource) DBHeartbeat(com.actiontech.dble.backend.heartbeat.DBHeartbeat) RowDataPacket(com.actiontech.dble.net.mysql.RowDataPacket) DataSourceSyncRecorder(com.actiontech.dble.statistic.DataSourceSyncRecorder) PhysicalDBPool(com.actiontech.dble.backend.datasource.PhysicalDBPool) LinkedList(java.util.LinkedList)

Example 47 with RowDataPacket

use of com.actiontech.dble.net.mysql.RowDataPacket in project dble by actiontech.

the class ShowDatasourceSyn method response.

public static void response(ManagerConnection c) {
    ByteBuffer buffer = c.allocate();
    // write header
    buffer = HEADER.write(buffer, c, true);
    // write fields
    for (FieldPacket field : FIELDS) {
        buffer = field.write(buffer, c, true);
    }
    // write eof
    buffer = EOF.write(buffer, c, true);
    // write rows
    byte packetId = EOF.getPacketId();
    for (RowDataPacket row : getRows(c.getCharset().getResults())) {
        row.setPacketId(++packetId);
        buffer = row.write(buffer, c, true);
    }
    // write last eof
    EOFPacket lastEof = new EOFPacket();
    lastEof.setPacketId(++packetId);
    buffer = lastEof.write(buffer, c, true);
    // post write
    c.write(buffer);
}
Also used : RowDataPacket(com.actiontech.dble.net.mysql.RowDataPacket) EOFPacket(com.actiontech.dble.net.mysql.EOFPacket) ByteBuffer(java.nio.ByteBuffer) FieldPacket(com.actiontech.dble.net.mysql.FieldPacket)

Example 48 with RowDataPacket

use of com.actiontech.dble.net.mysql.RowDataPacket in project dble by actiontech.

the class ShowDatasourceSynDetail method response.

public static void response(ManagerConnection c, String stmt) {
    ByteBuffer buffer = c.allocate();
    // write header
    buffer = HEADER.write(buffer, c, true);
    // write fields
    for (FieldPacket field : FIELDS) {
        buffer = field.write(buffer, c, true);
    }
    // write eof
    buffer = EOF.write(buffer, c, true);
    // write rows
    byte packetId = EOF.getPacketId();
    String name = ManagerParseShow.getWhereParameter(stmt);
    for (RowDataPacket row : getRows(name, c.getCharset().getResults())) {
        row.setPacketId(++packetId);
        buffer = row.write(buffer, c, true);
    }
    // write last eof
    EOFPacket lastEof = new EOFPacket();
    lastEof.setPacketId(++packetId);
    buffer = lastEof.write(buffer, c, true);
    // post write
    c.write(buffer);
}
Also used : RowDataPacket(com.actiontech.dble.net.mysql.RowDataPacket) EOFPacket(com.actiontech.dble.net.mysql.EOFPacket) ByteBuffer(java.nio.ByteBuffer) FieldPacket(com.actiontech.dble.net.mysql.FieldPacket)

Example 49 with RowDataPacket

use of com.actiontech.dble.net.mysql.RowDataPacket in project dble by actiontech.

the class ShowDirectMemory method showDirectMemoryDetail.

private static void showDirectMemoryDetail(ManagerConnection c) {
    ByteBuffer buffer = c.allocate();
    // write header
    buffer = DETAIL_HEADER.write(buffer, c, true);
    // write fields
    for (FieldPacket field : DETAIL_FIELDS) {
        buffer = field.write(buffer, c, true);
    }
    // write eof
    buffer = DETAIL_EOF.write(buffer, c, true);
    // write rows
    byte packetId = DETAIL_EOF.getPacketId();
    ConcurrentMap<Long, Long> networkBufferPool = DbleServer.getInstance().getBufferPool().getNetDirectMemoryUsage();
    for (Map.Entry<Long, Long> entry : networkBufferPool.entrySet()) {
        RowDataPacket row = new RowDataPacket(DETAIL_FIELD_COUNT);
        long value = entry.getValue();
        row.add(StringUtil.encode(String.valueOf(entry.getKey()), c.getCharset().getResults()));
        /* DIRECT_MEMORY belong to Buffer Pool */
        row.add(StringUtil.encode("NetWorkBufferPool", c.getCharset().getResults()));
        row.add(StringUtil.encode(value > 0 ? JavaUtils.bytesToString2(value) : "0", c.getCharset().getResults()));
        row.setPacketId(++packetId);
        buffer = row.write(buffer, c, true);
    }
    // write last eof
    EOFPacket lastEof = new EOFPacket();
    lastEof.setPacketId(++packetId);
    buffer = lastEof.write(buffer, c, true);
    // write buffer
    c.write(buffer);
}
Also used : RowDataPacket(com.actiontech.dble.net.mysql.RowDataPacket) EOFPacket(com.actiontech.dble.net.mysql.EOFPacket) ByteBuffer(java.nio.ByteBuffer) FieldPacket(com.actiontech.dble.net.mysql.FieldPacket) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map)

Example 50 with RowDataPacket

use of com.actiontech.dble.net.mysql.RowDataPacket in project dble by actiontech.

the class ShowDirectMemory method showDirectMemoryTotal.

private static void showDirectMemoryTotal(ManagerConnection c) {
    ByteBuffer buffer = c.allocate();
    // write header
    buffer = TOTAL_HEADER.write(buffer, c, true);
    // write fields
    for (FieldPacket field : TOTAL_FIELDS) {
        buffer = field.write(buffer, c, true);
    }
    // write eof
    buffer = TOTAL_EOF.write(buffer, c, true);
    ConcurrentMap<Long, Long> networkBufferPool = DbleServer.getInstance().getBufferPool().getNetDirectMemoryUsage();
    RowDataPacket row = new RowDataPacket(TOTAL_FIELD_COUNT);
    long usedForNetwork = 0;
    /* the value of -XX:MaxDirectMemorySize */
    long totalAvailable = Platform.getMaxDirectMemory();
    row.add(StringUtil.encode(JavaUtils.bytesToString2(totalAvailable), c.getCharset().getResults()));
    /* IO packet used in DirectMemory in buffer pool */
    for (Map.Entry<Long, Long> entry : networkBufferPool.entrySet()) {
        usedForNetwork += entry.getValue();
    }
    row.add(StringUtil.encode(JavaUtils.bytesToString2(usedForNetwork), c.getCharset().getResults()));
    row.add(StringUtil.encode(JavaUtils.bytesToString2(totalAvailable - usedForNetwork), c.getCharset().getResults()));
    // write rows
    byte packetId = TOTAL_EOF.getPacketId();
    row.setPacketId(++packetId);
    buffer = row.write(buffer, c, true);
    // write last eof
    EOFPacket lastEof = new EOFPacket();
    lastEof.setPacketId(++packetId);
    buffer = lastEof.write(buffer, c, true);
    // write buffer
    c.write(buffer);
}
Also used : RowDataPacket(com.actiontech.dble.net.mysql.RowDataPacket) EOFPacket(com.actiontech.dble.net.mysql.EOFPacket) ByteBuffer(java.nio.ByteBuffer) FieldPacket(com.actiontech.dble.net.mysql.FieldPacket) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map)

Aggregations

RowDataPacket (com.actiontech.dble.net.mysql.RowDataPacket)141 EOFPacket (com.actiontech.dble.net.mysql.EOFPacket)59 FieldPacket (com.actiontech.dble.net.mysql.FieldPacket)59 ByteBuffer (java.nio.ByteBuffer)59 ServerConfig (com.actiontech.dble.config.ServerConfig)8 NIOProcessor (com.actiontech.dble.net.NIOProcessor)8 Map (java.util.Map)8 PhysicalDBPool (com.actiontech.dble.backend.datasource.PhysicalDBPool)7 PhysicalDatasource (com.actiontech.dble.backend.datasource.PhysicalDatasource)7 MySQLConnection (com.actiontech.dble.backend.mysql.nio.MySQLConnection)7 LocalResult (com.actiontech.dble.backend.mysql.store.LocalResult)6 UnSortedLocalResult (com.actiontech.dble.backend.mysql.store.UnSortedLocalResult)6 DBHeartbeat (com.actiontech.dble.backend.heartbeat.DBHeartbeat)5 ItemSum (com.actiontech.dble.plan.common.item.function.sumfunc.ItemSum)5 UserStat (com.actiontech.dble.statistic.stat.UserStat)5 BackendConnection (com.actiontech.dble.backend.BackendConnection)4 SchemaConfig (com.actiontech.dble.config.model.SchemaConfig)4 FrontendConnection (com.actiontech.dble.net.FrontendConnection)4 ResultSetHeaderPacket (com.actiontech.dble.net.mysql.ResultSetHeaderPacket)4 LinkedList (java.util.LinkedList)4