Search in sources :

Example 46 with EOFPacket

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

the class ShowDataNode method execute.

public static void execute(ManagerConnection c, String name) {
    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;
    MycatConfig conf = MycatServer.getInstance().getConfig();
    Map<String, PhysicalDBNode> dataNodes = conf.getDataNodes();
    List<String> keys = new ArrayList<String>();
    if (StringUtil.isEmpty(name)) {
        keys.addAll(dataNodes.keySet());
    } else {
        SchemaConfig sc = conf.getSchemas().get(name);
        if (null != sc) {
            keys.addAll(sc.getAllDataNodes());
        }
    }
    Collections.sort(keys, new Comparators<String>());
    for (String key : keys) {
        RowDataPacket row = getRow(dataNodes.get(key), 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 : PhysicalDBNode(io.mycat.backend.datasource.PhysicalDBNode) SchemaConfig(io.mycat.config.model.SchemaConfig) RowDataPacket(io.mycat.net.mysql.RowDataPacket) ArrayList(java.util.ArrayList) EOFPacket(io.mycat.net.mysql.EOFPacket) MycatConfig(io.mycat.config.MycatConfig) ByteBuffer(java.nio.ByteBuffer) FieldPacket(io.mycat.net.mysql.FieldPacket)

Example 47 with EOFPacket

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

the class ShowBackendOld 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);
    byte packetId = eof.packetId;
    String charset = c.getCharset();
    for (BackendConnection bc : NIOProcessor.backends_old) {
        if (bc != null) {
            RowDataPacket row = getRow(bc, charset);
            row.packetId = ++packetId;
            buffer = row.write(buffer, c, true);
        }
    }
    EOFPacket lastEof = new EOFPacket();
    lastEof.packetId = ++packetId;
    buffer = lastEof.write(buffer, c, true);
    c.write(buffer);
}
Also used : BackendConnection(io.mycat.backend.BackendConnection) RowDataPacket(io.mycat.net.mysql.RowDataPacket) EOFPacket(io.mycat.net.mysql.EOFPacket) ByteBuffer(java.nio.ByteBuffer) FieldPacket(io.mycat.net.mysql.FieldPacket)

Example 48 with EOFPacket

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

the class ShowDatasourceCluster 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;
    for (RowDataPacket row : getRows(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 49 with EOFPacket

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

the class ShowDirectMemory method showDirectMemoryDetail.

public static void showDirectMemoryDetail(ManagerConnection c) {
    ByteBuffer buffer = c.allocate();
    // write header
    buffer = detailHeader.write(buffer, c, true);
    // write fields
    for (FieldPacket field : detailFields) {
        buffer = field.write(buffer, c, true);
    }
    // write eof
    buffer = detailEof.write(buffer, c, true);
    // write rows
    byte packetId = detailEof.packetId;
    int useOffHeapForMerge = MycatServer.getInstance().getConfig().getSystem().getUseOffHeapForMerge();
    ConcurrentHashMap<Long, Long> networkbufferpool = MycatServer.getInstance().getBufferPool().getNetDirectMemoryUsage();
    try {
        if (useOffHeapForMerge == 1) {
            ConcurrentHashMap<Long, Long> concurrentHashMap = MycatServer.getInstance().getMyCatMemory().getResultMergeMemoryManager().getDirectMemorUsage();
            for (Long key : concurrentHashMap.keySet()) {
                RowDataPacket row = new RowDataPacket(DETAILl_FIELD_COUNT);
                Long value = concurrentHashMap.get(key);
                row.add(String.valueOf(key).getBytes(c.getCharset()));
                /**
                     * 该DIRECTMEMORY内存被结果集处理使用了
                     */
                row.add("MergeMemoryPool".getBytes(c.getCharset()));
                row.add(value > 0 ? JavaUtils.bytesToString2(value).getBytes(c.getCharset()) : "0".getBytes(c.getCharset()));
                row.packetId = ++packetId;
                buffer = row.write(buffer, c, true);
            }
        }
        for (Long key : networkbufferpool.keySet()) {
            RowDataPacket row = new RowDataPacket(DETAILl_FIELD_COUNT);
            Long value = networkbufferpool.get(key);
            row.add(String.valueOf(key).getBytes(c.getCharset()));
            /**
                 * 该DIRECTMEMORY内存属于Buffer Pool管理的!
                 */
            row.add("NetWorkBufferPool".getBytes(c.getCharset()));
            row.add(value > 0 ? JavaUtils.bytesToString2(value).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)

Example 50 with EOFPacket

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

the class ShowHeartbeat 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.packetId;
    for (RowDataPacket row : getRows()) {
        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)

Aggregations

EOFPacket (io.mycat.net.mysql.EOFPacket)78 ByteBuffer (java.nio.ByteBuffer)77 FieldPacket (io.mycat.net.mysql.FieldPacket)74 RowDataPacket (io.mycat.net.mysql.RowDataPacket)69 ResultSetHeaderPacket (io.mycat.net.mysql.ResultSetHeaderPacket)10 NIOProcessor (io.mycat.net.NIOProcessor)7 UserStat (io.mycat.statistic.stat.UserStat)6 ServerConnection (io.mycat.server.ServerConnection)5 Map (java.util.Map)5 SchemaConfig (io.mycat.config.model.SchemaConfig)4 ArrayList (java.util.ArrayList)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 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 HashMap (java.util.HashMap)2 List (java.util.List)2 TreeSet (java.util.TreeSet)2