Search in sources :

Example 51 with EOFPacket

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

the class ShowSQLSlow 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<SQLRecord> keyList = userStat.getSqlRecorder().getRecords();
        for (SQLRecord key : keyList) {
            if (key != null) {
                RowDataPacket row = getRow(user, key, c.getCharset().getResults());
                row.setPacketId(++packetId);
                buffer = row.write(buffer, c, true);
            }
        }
        if (isClear) {
            userStat.clearSqlSlow();
        }
    }
    // 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) SQLRecord(com.actiontech.dble.statistic.SQLRecord) ByteBuffer(java.nio.ByteBuffer) FieldPacket(com.actiontech.dble.net.mysql.FieldPacket)

Example 52 with EOFPacket

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

the class ShowSQLSumTable 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, TableStat> statMap = TableStatAnalyzer.getInstance().getTableStatMap();
        for (TableStat tableStat : statMap.values()) {
            i++;
           RowDataPacket row = getRow(tableStat,i, c.getCharset());//getRow(sqlStat,sql, c.getCharset());
           row.packetId = ++packetId;
           buffer = row.write(buffer, c,true);
        }
        */
    List<TableStat> list = TableStatAnalyzer.getInstance().getTableStats(isClear);
    if (list != null) {
        int i = 1;
        for (TableStat tableStat : list) {
            if (tableStat != null) {
                RowDataPacket row = getRow(tableStat, i, c.getCharset().getResults());
                i++;
                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) TableStat(com.actiontech.dble.statistic.stat.TableStat) ByteBuffer(java.nio.ByteBuffer) FieldPacket(com.actiontech.dble.net.mysql.FieldPacket)

Example 53 with EOFPacket

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

the class ShowServer 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();
    RowDataPacket row = getRow(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 54 with EOFPacket

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

the class ConfFileHandler method handle.

public static void handle(String stmt, 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 theStmt = stmt.toUpperCase().trim();
    PackageBufINf bufInf;
    if (theStmt.equals("FILE @@LIST")) {
        bufInf = listConfigFiles(c, buffer, packetId);
    } else if (theStmt.startsWith("FILE @@SHOW")) {
        int index = stmt.lastIndexOf(' ');
        String fileName = stmt.substring(index + 1);
        bufInf = showConfigFile(c, buffer, packetId, fileName);
    } else if (theStmt.startsWith(UPLOAD_CMD)) {
        int index = stmt.indexOf(' ', UPLOAD_CMD.length());
        int index2 = stmt.indexOf(' ', index + 1);
        if (index <= 0 || index2 <= 0 || index + 1 > stmt.length() || index2 + 1 > stmt.length()) {
            bufInf = showInfo(c, buffer, packetId, "Invald param ,usage  ");
        }
        String fileName = stmt.substring(index + 1, index2);
        String content = stmt.substring(index2 + 1).trim();
        bufInf = upLoadConfigFile(c, buffer, packetId, fileName, content);
    } else {
        bufInf = showInfo(c, buffer, packetId, "Invald command ");
    }
    packetId = bufInf.getPacketId();
    buffer = bufInf.getBuffer();
    // write last eof
    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 55 with EOFPacket

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

the class Explain2Handler method showError.

private static void showError(String stmt, ServerConnection c, String msg) {
    ByteBuffer buffer = c.allocate();
    // write header
    ResultSetHeaderPacket header = PacketUtil.getHeader(FIELD_COUNT);
    byte packetId = header.getPacketId();
    buffer = header.write(buffer, c, true);
    // write fields
    for (FieldPacket field : FIELDS) {
        field.setPacketId(++packetId);
        buffer = field.write(buffer, c, true);
    }
    // write eof
    EOFPacket eof = new EOFPacket();
    eof.setPacketId(++packetId);
    buffer = eof.write(buffer, c, true);
    RowDataPacket row = new RowDataPacket(FIELD_COUNT);
    row.add(StringUtil.encode(stmt, c.getCharset().getResults()));
    row.add(StringUtil.encode(msg, 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 : ResultSetHeaderPacket(com.actiontech.dble.net.mysql.ResultSetHeaderPacket) 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)

Aggregations

EOFPacket (com.actiontech.dble.net.mysql.EOFPacket)67 FieldPacket (com.actiontech.dble.net.mysql.FieldPacket)66 ByteBuffer (java.nio.ByteBuffer)64 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 PreparedOkPacket (com.actiontech.dble.net.mysql.PreparedOkPacket)2 TreeSet (java.util.TreeSet)2 ConcurrentMap (java.util.concurrent.ConcurrentMap)2 Matcher (java.util.regex.Matcher)2