Search in sources :

Example 11 with FieldPacket

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

the class ShowSQLSumUser method execute.

public static void execute(ManagerConnection c, boolean isClear) {
    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();
    int i = 0;
    Map<String, UserStat> statMap = UserStatAnalyzer.getInstance().getUserStatMap();
    for (UserStat userStat : statMap.values()) {
        i++;
        RowDataPacket row = getRow(userStat, i, c.getCharset().getResults());
        row.setPacketId(++packetId);
        buffer = row.write(buffer, c, true);
    }
    if (isClear) {
        UserStatAnalyzer.getInstance().reset();
    }
    // 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) UserStat(com.actiontech.dble.statistic.stat.UserStat) EOFPacket(com.actiontech.dble.net.mysql.EOFPacket) ByteBuffer(java.nio.ByteBuffer) FieldPacket(com.actiontech.dble.net.mysql.FieldPacket)

Example 12 with FieldPacket

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

the class ShowSession method execute.

public static void execute(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 (NIOProcessor process : DbleServer.getInstance().getFrontProcessors()) {
        for (FrontendConnection front : process.getFrontends().values()) {
            if (!(front instanceof ServerConnection)) {
                continue;
            }
            ServerConnection sc = (ServerConnection) front;
            RowDataPacket row = getRow(sc, c.getCharset().getResults());
            if (row != null) {
                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 : FrontendConnection(com.actiontech.dble.net.FrontendConnection) RowDataPacket(com.actiontech.dble.net.mysql.RowDataPacket) EOFPacket(com.actiontech.dble.net.mysql.EOFPacket) ServerConnection(com.actiontech.dble.server.ServerConnection) NIOProcessor(com.actiontech.dble.net.NIOProcessor) ByteBuffer(java.nio.ByteBuffer) FieldPacket(com.actiontech.dble.net.mysql.FieldPacket)

Example 13 with FieldPacket

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

the class ShowSqlResultSet method execute.

public static void execute(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();
    int i = 0;
    Map<String, UserStat> statMap = UserStatAnalyzer.getInstance().getUserStatMap();
    for (UserStat userStat : statMap.values()) {
        String user = userStat.getUser();
        ConcurrentMap<String, SqlResultSet> map = userStat.getSqlResultSizeRecorder().getSqlResultSet();
        if (map != null) {
            for (SqlResultSet sqlResultSet : map.values()) {
                RowDataPacket row = getRow(++i, user, sqlResultSet.getSql(), sqlResultSet.getCount(), sqlResultSet.getResultSetSize(), 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 : SqlResultSet(com.actiontech.dble.statistic.stat.SqlResultSet) RowDataPacket(com.actiontech.dble.net.mysql.RowDataPacket) UserStat(com.actiontech.dble.statistic.stat.UserStat) EOFPacket(com.actiontech.dble.net.mysql.EOFPacket) ByteBuffer(java.nio.ByteBuffer) FieldPacket(com.actiontech.dble.net.mysql.FieldPacket)

Example 14 with FieldPacket

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

the class ShowSysLog method execute.

public static void execute(ManagerConnection c, int numLines) {
    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 filename = SystemConfig.getHomePath() + File.separator + "logs" + File.separator + ShowServerLog.DEFAULT_LOGFILE;
    String[] lines = getLinesByLogFile(filename, numLines);
    boolean linesIsEmpty = true;
    for (String line : lines) {
        if (line != null) {
            RowDataPacket row = new RowDataPacket(FIELD_COUNT);
            row.add(StringUtil.encode(line.substring(0, 19), c.getCharset().getResults()));
            row.add(StringUtil.encode(line.substring(19, line.length()), c.getCharset().getResults()));
            row.setPacketId(++packetId);
            buffer = row.write(buffer, c, true);
            linesIsEmpty = false;
        }
    }
    if (linesIsEmpty) {
        RowDataPacket row = new RowDataPacket(FIELD_COUNT);
        row.add(StringUtil.encode("NULL", c.getCharset().getResults()));
        row.add(StringUtil.encode("NULL", 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)

Example 15 with FieldPacket

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

the class ShowBackendStat method execute.

public static void execute(ManagerConnection c) {
    ByteBuffer buffer = c.allocate();
    buffer = HEADER.write(buffer, c, true);
    for (FieldPacket field : FIELDS) {
        buffer = field.write(buffer, c, true);
    }
    buffer = EOF.write(buffer, c, true);
    HashMap<String, BackendStat> infos = stat();
    byte packetId = EOF.getPacketId();
    for (Map.Entry<String, BackendStat> entry : infos.entrySet()) {
        RowDataPacket row = getRow(entry.getValue(), c.getCharset().getResults());
        row.setPacketId(++packetId);
        buffer = row.write(buffer, c, true);
    }
    EOFPacket lastEof = new EOFPacket();
    lastEof.setPacketId(++packetId);
    buffer = lastEof.write(buffer, c, true);
    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) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

FieldPacket (com.actiontech.dble.net.mysql.FieldPacket)81 EOFPacket (com.actiontech.dble.net.mysql.EOFPacket)65 ByteBuffer (java.nio.ByteBuffer)64 RowDataPacket (com.actiontech.dble.net.mysql.RowDataPacket)59 ArrayList (java.util.ArrayList)9 Map (java.util.Map)8 NIOProcessor (com.actiontech.dble.net.NIOProcessor)6 ResultSetHeaderPacket (com.actiontech.dble.net.mysql.ResultSetHeaderPacket)6 Item (com.actiontech.dble.plan.common.item.Item)6 UserStat (com.actiontech.dble.statistic.stat.UserStat)6 SchemaConfig (com.actiontech.dble.config.model.SchemaConfig)4 PackageBufINf (com.actiontech.dble.manager.handler.PackageBufINf)4 RowDataComparator (com.actiontech.dble.backend.mysql.nio.handler.util.RowDataComparator)3 ServerConfig (com.actiontech.dble.config.ServerConfig)3 FrontendConnection (com.actiontech.dble.net.FrontendConnection)3 Field (com.actiontech.dble.plan.common.field.Field)3 BackendConnection (com.actiontech.dble.backend.BackendConnection)2 PhysicalDBNode (com.actiontech.dble.backend.datasource.PhysicalDBNode)2 TableConfig (com.actiontech.dble.config.model.TableConfig)2 UserConfig (com.actiontech.dble.config.model.UserConfig)2