Search in sources :

Example 6 with FieldPacket

use of io.mycat.net.mysql.FieldPacket in project Mycat-Server by MyCATApache.

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.packetId;
    String name = ManagerParseShow.getWhereParameter(stmt);
    for (RowDataPacket row : getRows(name, c.getCharset())) {
        row.packetId = ++packetId;
        buffer = row.write(buffer, c, true);
    }
    // write last eof
    EOFPacket lastEof = new EOFPacket();
    lastEof.packetId = ++packetId;
    buffer = lastEof.write(buffer, c, true);
    // post write
    c.write(buffer);
}
Also used : RowDataPacket(io.mycat.net.mysql.RowDataPacket) EOFPacket(io.mycat.net.mysql.EOFPacket) ByteBuffer(java.nio.ByteBuffer) FieldPacket(io.mycat.net.mysql.FieldPacket)

Example 7 with FieldPacket

use of io.mycat.net.mysql.FieldPacket in project Mycat-Server by MyCATApache.

the class ShowDirectMemory method showDirectMemoryTotal.

public static void showDirectMemoryTotal(ManagerConnection c) {
    ByteBuffer buffer = c.allocate();
    // write header
    buffer = totalHeader.write(buffer, c, true);
    // write fields
    for (FieldPacket field : totalFields) {
        buffer = field.write(buffer, c, true);
    }
    // write eof
    buffer = totalEof.write(buffer, c, true);
    // write rows
    byte packetId = totalEof.packetId;
    int useOffHeapForMerge = MycatServer.getInstance().getConfig().getSystem().getUseOffHeapForMerge();
    ConcurrentHashMap<Long, Long> networkbufferpool = MycatServer.getInstance().getBufferPool().getNetDirectMemoryUsage();
    RowDataPacket row = new RowDataPacket(TOTAL_FIELD_COUNT);
    long usedforMerge = 0;
    long usedforNetworkd = 0;
    try {
        /**
             * 通过-XX:MaxDirectMemorySize=2048m设置的值
             */
        row.add(JavaUtils.bytesToString2(Platform.getMaxDirectMemory()).getBytes(c.getCharset()));
        if (useOffHeapForMerge == 1) {
            /**
                 * 结果集合并时,总共消耗的DirectMemory内存
                 */
            ConcurrentHashMap<Long, Long> concurrentHashMap = MycatServer.getInstance().getMyCatMemory().getResultMergeMemoryManager().getDirectMemorUsage();
            for (Map.Entry<Long, Long> entry : concurrentHashMap.entrySet()) {
                usedforMerge += entry.getValue();
            }
        }
        /**
             * 网络packet处理,在buffer pool 已经使用DirectMemory内存
             */
        for (Map.Entry<Long, Long> entry : networkbufferpool.entrySet()) {
            usedforNetworkd += entry.getValue();
        }
        row.add(JavaUtils.bytesToString2(usedforMerge + usedforNetworkd).getBytes(c.getCharset()));
        long totalAvailable = 0;
        if (useOffHeapForMerge == 1) {
            /**
                 * 设置使用off-heap内存处理结果集时,防止客户把MaxDirectMemorySize设置到物理内存的极限。
                 * Mycat能使用的DirectMemory是MaxDirectMemorySize*DIRECT_SAFETY_FRACTION大小,
                 * DIRECT_SAFETY_FRACTION为安全系数,为OS,Heap预留空间,避免因大结果集造成系统物理内存被耗尽!
                 */
            totalAvailable = (long) (Platform.getMaxDirectMemory() * MyCatMemory.DIRECT_SAFETY_FRACTION);
        } else {
            totalAvailable = Platform.getMaxDirectMemory();
        }
        row.add(JavaUtils.bytesToString2(totalAvailable - usedforMerge - usedforNetworkd).getBytes(c.getCharset()));
        if (useOffHeapForMerge == 1) {
            /**
                 * 输出安全系统DIRECT_SAFETY_FRACTION
                 */
            row.add(("" + MyCatMemory.DIRECT_SAFETY_FRACTION).getBytes(c.getCharset()));
        } else {
            row.add(("1.0").getBytes(c.getCharset()));
        }
        long resevedForOs = 0;
        if (useOffHeapForMerge == 1) {
            /**
                 * 预留OS系统部分内存!!!
                 */
            resevedForOs = (long) ((1 - MyCatMemory.DIRECT_SAFETY_FRACTION) * (Platform.getMaxDirectMemory() - 2 * MycatServer.getInstance().getTotalNetWorkBufferSize()));
        }
        row.add(resevedForOs > 0 ? JavaUtils.bytesToString2(resevedForOs).getBytes(c.getCharset()) : "0".getBytes(c.getCharset()));
        row.packetId = ++packetId;
        buffer = row.write(buffer, c, true);
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    // write last eof
    EOFPacket lastEof = new EOFPacket();
    lastEof.packetId = ++packetId;
    buffer = lastEof.write(buffer, c, true);
    // write buffer
    c.write(buffer);
}
Also used : RowDataPacket(io.mycat.net.mysql.RowDataPacket) EOFPacket(io.mycat.net.mysql.EOFPacket) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ByteBuffer(java.nio.ByteBuffer) FieldPacket(io.mycat.net.mysql.FieldPacket) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Map(java.util.Map)

Example 8 with FieldPacket

use of io.mycat.net.mysql.FieldPacket in project Mycat-Server by MyCATApache.

the class ShowHeartbeatDetail 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.packetId;
    Pair<String, String> pair = ManagerParseHeartbeat.getPair(stmt);
    String name = pair.getValue();
    for (RowDataPacket row : getRows(name, c.getCharset())) {
        row.packetId = ++packetId;
        buffer = row.write(buffer, c, true);
    }
    // write last eof
    EOFPacket lastEof = new EOFPacket();
    lastEof.packetId = ++packetId;
    buffer = lastEof.write(buffer, c, true);
    // post write
    c.write(buffer);
}
Also used : RowDataPacket(io.mycat.net.mysql.RowDataPacket) EOFPacket(io.mycat.net.mysql.EOFPacket) ByteBuffer(java.nio.ByteBuffer) FieldPacket(io.mycat.net.mysql.FieldPacket)

Example 9 with FieldPacket

use of io.mycat.net.mysql.FieldPacket in project Mycat-Server by MyCATApache.

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.packetId;
    for (NIOProcessor process : MycatServer.getInstance().getProcessors()) {
        for (FrontendConnection front : process.getFrontends().values()) {
            if (!(front instanceof ServerConnection)) {
                continue;
            }
            ServerConnection sc = (ServerConnection) front;
            RowDataPacket row = getRow(sc, c.getCharset());
            if (row != null) {
                row.packetId = ++packetId;
                buffer = row.write(buffer, c, true);
            }
        }
    }
    // write last eof
    EOFPacket lastEof = new EOFPacket();
    lastEof.packetId = ++packetId;
    buffer = lastEof.write(buffer, c, true);
    // write buffer
    c.write(buffer);
}
Also used : FrontendConnection(io.mycat.net.FrontendConnection) RowDataPacket(io.mycat.net.mysql.RowDataPacket) EOFPacket(io.mycat.net.mysql.EOFPacket) ServerConnection(io.mycat.server.ServerConnection) NIOProcessor(io.mycat.net.NIOProcessor) ByteBuffer(java.nio.ByteBuffer) FieldPacket(io.mycat.net.mysql.FieldPacket)

Example 10 with FieldPacket

use of io.mycat.net.mysql.FieldPacket in project Mycat-Server by MyCATApache.

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.packetId;
    int i = 0;
    Map<String, UserStat> statMap = UserStatAnalyzer.getInstance().getUserStatMap();
    for (UserStat userStat : statMap.values()) {
        String user = userStat.getUser();
        ConcurrentHashMap<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());
                row.packetId = ++packetId;
                buffer = row.write(buffer, c, true);
            }
        }
    }
    // write last eof
    EOFPacket lastEof = new EOFPacket();
    lastEof.packetId = ++packetId;
    buffer = lastEof.write(buffer, c, true);
    // write buffer
    c.write(buffer);
}
Also used : SqlResultSet(io.mycat.statistic.stat.SqlResultSet) RowDataPacket(io.mycat.net.mysql.RowDataPacket) UserStat(io.mycat.statistic.stat.UserStat) EOFPacket(io.mycat.net.mysql.EOFPacket) ByteBuffer(java.nio.ByteBuffer) FieldPacket(io.mycat.net.mysql.FieldPacket)

Aggregations

FieldPacket (io.mycat.net.mysql.FieldPacket)84 ByteBuffer (java.nio.ByteBuffer)75 EOFPacket (io.mycat.net.mysql.EOFPacket)74 RowDataPacket (io.mycat.net.mysql.RowDataPacket)69 ResultSetHeaderPacket (io.mycat.net.mysql.ResultSetHeaderPacket)9 NIOProcessor (io.mycat.net.NIOProcessor)7 UserStat (io.mycat.statistic.stat.UserStat)6 ArrayList (java.util.ArrayList)5 Map (java.util.Map)5 SchemaConfig (io.mycat.config.model.SchemaConfig)4 MycatConfig (io.mycat.config.MycatConfig)3 FrontendConnection (io.mycat.net.FrontendConnection)3 BackendConnection (io.mycat.backend.BackendConnection)2 PhysicalDBNode (io.mycat.backend.datasource.PhysicalDBNode)2 UserConfig (io.mycat.config.model.UserConfig)2 ServerConnection (io.mycat.server.ServerConnection)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 HashMap (java.util.HashMap)2 List (java.util.List)2 TreeSet (java.util.TreeSet)2