Search in sources :

Example 46 with FieldPacket

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

the class SelectVariables method execute.

public static void execute(ServerConnection c, String sql) {
    String subSql = sql.substring(sql.indexOf("SELECT") + 6);
    List<String> splitVar = Splitter.on(",").omitEmptyStrings().trimResults().splitToList(subSql);
    splitVar = convert(splitVar);
    int fieldCount = splitVar.size();
    ResultSetHeaderPacket header = PacketUtil.getHeader(fieldCount);
    FieldPacket[] fields = new FieldPacket[fieldCount];
    int i = 0;
    byte packetId = 0;
    header.setPacketId(++packetId);
    for (String s : splitVar) {
        fields[i] = PacketUtil.getField(s, Fields.FIELD_TYPE_VAR_STRING);
        fields[i++].setPacketId(++packetId);
    }
    ByteBuffer buffer = c.allocate();
    // write header
    buffer = header.write(buffer, c, true);
    // write fields
    for (FieldPacket field : fields) {
        buffer = field.write(buffer, c, true);
    }
    EOFPacket eof = new EOFPacket();
    eof.setPacketId(++packetId);
    // write eof
    buffer = eof.write(buffer, c, true);
    // write rows
    // byte packetId = eof.packetId;
    RowDataPacket row = new RowDataPacket(fieldCount);
    for (String s : splitVar) {
        String value = VARIABLES.get(s) == null ? "" : VARIABLES.get(s);
        row.add(value.getBytes());
    }
    row.setPacketId(++packetId);
    buffer = row.write(buffer, c, true);
    // write lastEof
    EOFPacket lastEof = new EOFPacket();
    lastEof.setPacketId(++packetId);
    buffer = lastEof.write(buffer, c, true);
    // write buffer
    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) FieldPacket(com.actiontech.dble.net.mysql.FieldPacket) ByteBuffer(java.nio.ByteBuffer)

Example 47 with FieldPacket

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

the class ShowBinlogStatus method writeResponse.

private static void writeResponse(ManagerConnection c) {
    if (errMsg == null) {
        ByteBuffer buffer = c.allocate();
        buffer = HEADER.write(buffer, c, true);
        for (FieldPacket field : FIELDS_PACKET) {
            buffer = field.write(buffer, c, true);
        }
        buffer = EOF.write(buffer, c, true);
        byte packetId = EOF.getPacketId();
        for (RowDataPacket row : rows) {
            row.setPacketId(++packetId);
            buffer = row.write(buffer, c, true);
        }
        rows.clear();
        EOFPacket lastEof = new EOFPacket();
        lastEof.setPacketId(++packetId);
        buffer = lastEof.write(buffer, c, true);
        c.write(buffer);
    } else {
        c.writeErrMessage(ErrorCode.ER_UNKNOWN_ERROR, errMsg);
        errMsg = null;
    }
}
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 48 with FieldPacket

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

the class ShowCache 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();
    CacheService cacheService = DbleServer.getInstance().getCacheService();
    for (Map.Entry<String, CachePool> entry : cacheService.getAllCachePools().entrySet()) {
        String cacheName = entry.getKey();
        CachePool cachePool = entry.getValue();
        if (cachePool != null) {
            if (cachePool instanceof LayerCachePool) {
                for (Map.Entry<String, CacheStatic> staticsEntry : ((LayerCachePool) cachePool).getAllCacheStatic().entrySet()) {
                    RowDataPacket row = getRow(cacheName + '.' + staticsEntry.getKey(), staticsEntry.getValue(), c.getCharset().getResults());
                    row.setPacketId(++packetId);
                    buffer = row.write(buffer, c, true);
                }
            } else {
                RowDataPacket row = getRow(cacheName, cachePool.getCacheStatic(), 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) CachePool(com.actiontech.dble.cache.CachePool) LayerCachePool(com.actiontech.dble.cache.LayerCachePool) CacheStatic(com.actiontech.dble.cache.CacheStatic) LayerCachePool(com.actiontech.dble.cache.LayerCachePool) FieldPacket(com.actiontech.dble.net.mysql.FieldPacket) Map(java.util.Map) CacheService(com.actiontech.dble.cache.CacheService)

Example 49 with FieldPacket

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

the class ShowCommand 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 p : DbleServer.getInstance().getFrontProcessors()) {
        RowDataPacket row = getRow(p);
        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) NIOProcessor(com.actiontech.dble.net.NIOProcessor) ByteBuffer(java.nio.ByteBuffer) FieldPacket(com.actiontech.dble.net.mysql.FieldPacket)

Example 50 with FieldPacket

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

the class ShowConnectionCount 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();
    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)

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