Search in sources :

Example 1 with EOFPacket

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

the class ShowServerLog method handle.

public static void handle(String stmt, ManagerConnection c) {
    Map<String, String> condPairMap = getCondPair(stmt);
    if (condPairMap == null) {
        c.writeErrMessage(ErrorCode.ER_YES, "Unsupported statement");
        return;
    }
    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();
    PackageBufINf bufInf;
    if (condPairMap.isEmpty()) {
        bufInf = showLogSum(c, buffer, packetId);
    } else {
        String logFile = condPairMap.get("file");
        if (logFile == null) {
            logFile = DEFAULT_LOGFILE;
        }
        String limitStr = condPairMap.get("limit");
        limitStr = (limitStr != null) ? limitStr : "0," + 100000;
        String[] limitArry = limitStr.split("\\s|,");
        int start = Integer.parseInt(limitArry[0]);
        int page = Integer.parseInt(limitArry[1]);
        int end = start + page;
        String key = condPairMap.get("key");
        String regex = condPairMap.get("regex");
        bufInf = showLogRange(c, buffer, packetId, key, regex, start, end, logFile);
    }
    packetId = bufInf.getPacketId();
    buffer = bufInf.getBuffer();
    EOFPacket lastEof = new EOFPacket();
    lastEof.setPacketId(++packetId);
    buffer = lastEof.write(buffer, c, true);
    // write buffer
    c.write(buffer);
}
Also used : EOFPacket(com.actiontech.dble.net.mysql.EOFPacket) ByteBuffer(java.nio.ByteBuffer) FieldPacket(com.actiontech.dble.net.mysql.FieldPacket)

Example 2 with EOFPacket

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

the class ShowSQL 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();
    Map<String, UserStat> statMap = UserStatAnalyzer.getInstance().getUserStatMap();
    for (UserStat userStat : statMap.values()) {
        String user = userStat.getUser();
        List<UserSqlLastStat.SqlLast> queries = userStat.getSqlLastStat().getQueries();
        int i = 1;
        for (UserSqlLastStat.SqlLast sqlLast : queries) {
            if (sqlLast != null) {
                RowDataPacket row = getRow(user, sqlLast, i, c.getCharset().getResults());
                row.setPacketId(++packetId);
                i++;
                buffer = row.write(buffer, c, true);
            }
        }
        if (isClear) {
            userStat.getSqlLastStat().clear();
        }
    }
    // 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) UserSqlLastStat(com.actiontech.dble.statistic.stat.UserSqlLastStat) FieldPacket(com.actiontech.dble.net.mysql.FieldPacket)

Example 3 with EOFPacket

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

the class ShowSQLCondition 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();
    String key = QueryConditionAnalyzer.getInstance().getKey();
    List<Map.Entry<Object, AtomicLong>> list = QueryConditionAnalyzer.getInstance().getValues();
    if (list != null) {
        int size = list.size();
        long total = 0L;
        for (int i = 0; i < size; i++) {
            Map.Entry<Object, AtomicLong> entry = list.get(i);
            Object value = entry.getKey();
            Long count = entry.getValue().get();
            total += count;
            RowDataPacket row = getRow(i, key, value.toString(), count, c.getCharset().getResults());
            row.setPacketId(++packetId);
            buffer = row.write(buffer, c, true);
        }
        RowDataPacket vkRow = getRow(size + 1, key + ".valuekey", "size", size, c.getCharset().getResults());
        vkRow.setPacketId(++packetId);
        buffer = vkRow.write(buffer, c, true);
        RowDataPacket vcRow = getRow(size + 2, key + ".valuecount", "total", total, c.getCharset().getResults());
        vcRow.setPacketId(++packetId);
        buffer = vcRow.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) AtomicLong(java.util.concurrent.atomic.AtomicLong) AtomicLong(java.util.concurrent.atomic.AtomicLong) FieldPacket(com.actiontech.dble.net.mysql.FieldPacket) Map(java.util.Map)

Example 4 with EOFPacket

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

the class ShowSQLHigh 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();
    Map<String, UserStat> statMap = UserStatAnalyzer.getInstance().getUserStatMap();
    for (UserStat userStat : statMap.values()) {
        String user = userStat.getUser();
        List<SqlFrequency> list = userStat.getSqlHigh().getSqlFrequency(isClear);
        if (list != null) {
            int i = 1;
            for (SqlFrequency sqlFrequency : list) {
                if (sqlFrequency != null) {
                    RowDataPacket row = getRow(i, user, sqlFrequency.getSql(), sqlFrequency.getCount(), sqlFrequency.getAvgTime(), sqlFrequency.getMaxTime(), sqlFrequency.getMinTime(), sqlFrequency.getExecuteTime(), sqlFrequency.getLastTime(), c.getCharset().getResults());
                    row.setPacketId(++packetId);
                    buffer = row.write(buffer, c, true);
                    i++;
                }
            }
        }
    }
    // write last eof
    EOFPacket lastEof = new EOFPacket();
    lastEof.setPacketId(++packetId);
    buffer = lastEof.write(buffer, c, true);
    // write buffer
    c.write(buffer);
}
Also used : SqlFrequency(com.actiontech.dble.statistic.stat.SqlFrequency) 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 5 with EOFPacket

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

the class ShowSQLLarge 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();
    Map<String, UserStat> statMap = UserStatAnalyzer.getInstance().getUserStatMap();
    for (UserStat userStat : statMap.values()) {
        String user = userStat.getUser();
        List<UserSqlLargeStat.SqlLarge> queries = userStat.getSqlLargeRowStat().getQueries();
        for (UserSqlLargeStat.SqlLarge sql : queries) {
            if (sql != null) {
                RowDataPacket row = getRow(user, sql, c.getCharset().getResults());
                row.setPacketId(++packetId);
                buffer = row.write(buffer, c, true);
            }
        }
        if (isClear) {
            userStat.getSqlLargeRowStat().clear();
        }
    }
    // 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) UserSqlLargeStat(com.actiontech.dble.statistic.stat.UserSqlLargeStat)

Aggregations

EOFPacket (com.actiontech.dble.net.mysql.EOFPacket)66 FieldPacket (com.actiontech.dble.net.mysql.FieldPacket)65 ByteBuffer (java.nio.ByteBuffer)63 RowDataPacket (com.actiontech.dble.net.mysql.RowDataPacket)59 Map (java.util.Map)8 NIOProcessor (com.actiontech.dble.net.NIOProcessor)6 ResultSetHeaderPacket (com.actiontech.dble.net.mysql.ResultSetHeaderPacket)6 UserStat (com.actiontech.dble.statistic.stat.UserStat)6 SchemaConfig (com.actiontech.dble.config.model.SchemaConfig)4 ServerConfig (com.actiontech.dble.config.ServerConfig)3 FrontendConnection (com.actiontech.dble.net.FrontendConnection)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 PackageBufINf (com.actiontech.dble.manager.handler.PackageBufINf)2 TreeSet (java.util.TreeSet)2 ConcurrentMap (java.util.concurrent.ConcurrentMap)2 Matcher (java.util.regex.Matcher)2 PhysicalDBPool (com.actiontech.dble.backend.datasource.PhysicalDBPool)1