Search in sources :

Example 51 with RowDataPacket

use of io.mycat.net.mysql.RowDataPacket in project Mycat_plus by coderczp.

the class SequenceVal method rowResponse.

@Override
public void rowResponse(byte[] row, BackendConnection conn) {
    RowDataPacket rowDataPkg = new RowDataPacket(1);
    rowDataPkg.read(row);
    byte[] columnData = rowDataPkg.fieldValues.get(0);
    String columnVal = new String(columnData);
    SequenceVal seqVal = (SequenceVal) conn.getAttachment();
    if (IncrSequenceMySQLHandler.errSeqResult.equals(columnVal)) {
        seqVal.dbretVal = IncrSequenceMySQLHandler.errSeqResult;
        LOGGER.warn(" sequnce sql returned err value ,sequence:" + seqVal.seqName + " " + columnVal + " sql:" + seqVal.sql);
    } else {
        seqVal.dbretVal = columnVal;
    }
}
Also used : RowDataPacket(io.mycat.net.mysql.RowDataPacket)

Example 52 with RowDataPacket

use of io.mycat.net.mysql.RowDataPacket in project Mycat_plus by coderczp.

the class MysqlInformationSchemaHandler method querySessionVariables.

/**
 * @param c
 * @param charset
 */
private static void querySessionVariables(ServerConnection c, String charset) {
    int field_count = 2;
    FieldPacket[] fields = new FieldPacket[field_count];
    fields[0] = PacketUtil.getField("VARIABLE_NAME", Fields.FIELD_TYPE_VAR_STRING);
    fields[1] = PacketUtil.getField("VARIABLE_VALUE", Fields.FIELD_TYPE_VAR_STRING);
    RowDataPacket[] rows = new RowDataPacket[1];
    RowDataPacket row = new RowDataPacket(field_count);
    row.add(StringUtil.encode("TIME_ZONE", charset));
    row.add(StringUtil.encode("system ", charset));
    rows[0] = row;
    Result rs = new Result();
    rs.fields = fields;
    rs.rows = rows;
    doWrite(rs, c);
}
Also used : RowDataPacket(io.mycat.net.mysql.RowDataPacket) FieldPacket(io.mycat.net.mysql.FieldPacket)

Example 53 with RowDataPacket

use of io.mycat.net.mysql.RowDataPacket in project Mycat_plus by coderczp.

the class MysqlInformationSchemaHandler method queryCollations.

/**
 * @param c
 * @param charset
 */
private static void queryCollations(ServerConnection c, String charset) {
    int field_count = 6;
    FieldPacket[] fields = new FieldPacket[field_count];
    fields[0] = PacketUtil.getField("COLLATION_NAME", Fields.FIELD_TYPE_VAR_STRING);
    fields[1] = PacketUtil.getField("CHARACTER_SET_NAME", Fields.FIELD_TYPE_VAR_STRING);
    fields[2] = PacketUtil.getField("ID", Fields.FIELD_TYPE_VAR_STRING);
    fields[3] = PacketUtil.getField("IS_DEFAULT", Fields.FIELD_TYPE_VAR_STRING);
    fields[4] = PacketUtil.getField("IS_COMPILED", Fields.FIELD_TYPE_VAR_STRING);
    fields[5] = PacketUtil.getField("SORTLEN", Fields.FIELD_TYPE_VAR_STRING);
    RowDataPacket[] rows = new RowDataPacket[1];
    RowDataPacket row = new RowDataPacket(field_count);
    row.add(StringUtil.encode("utf8_bin", charset));
    row.add(StringUtil.encode("utf8 ", charset));
    row.add(StringUtil.encode("196", charset));
    row.add(StringUtil.encode("", charset));
    row.add(StringUtil.encode("YES ", charset));
    row.add(StringUtil.encode("8", charset));
    rows[0] = row;
    Result rs = new Result();
    rs.fields = fields;
    rs.rows = rows;
    doWrite(rs, c);
}
Also used : RowDataPacket(io.mycat.net.mysql.RowDataPacket) FieldPacket(io.mycat.net.mysql.FieldPacket)

Example 54 with RowDataPacket

use of io.mycat.net.mysql.RowDataPacket in project Mycat_plus by coderczp.

the class ShowCache method getRow.

private static RowDataPacket getRow(String poolName, CacheStatic cacheStatic, String charset) {
    RowDataPacket row = new RowDataPacket(FIELD_COUNT);
    row.add(StringUtil.encode(poolName, charset));
    // max size
    row.add(LongUtil.toBytes(cacheStatic.getMaxSize()));
    row.add(LongUtil.toBytes(cacheStatic.getItemSize()));
    row.add(LongUtil.toBytes(cacheStatic.getAccessTimes()));
    row.add(LongUtil.toBytes(cacheStatic.getHitTimes()));
    row.add(LongUtil.toBytes(cacheStatic.getPutTimes()));
    row.add(LongUtil.toBytes(cacheStatic.getLastAccesTime()));
    row.add(LongUtil.toBytes(cacheStatic.getLastPutTime()));
    return row;
}
Also used : RowDataPacket(io.mycat.net.mysql.RowDataPacket)

Example 55 with RowDataPacket

use of io.mycat.net.mysql.RowDataPacket in project Mycat_plus by coderczp.

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.packetId;
    CacheService cacheService = MycatServer.getInstance().getCacheService();
    for (Map.Entry<String, CachePool> entry : cacheService.getAllCachePools().entrySet()) {
        String cacheName = entry.getKey();
        CachePool cachePool = entry.getValue();
        if (cachePool instanceof LayerCachePool) {
            for (Map.Entry<String, CacheStatic> staticsEntry : ((LayerCachePool) cachePool).getAllCacheStatic().entrySet()) {
                RowDataPacket row = getRow(cacheName + '.' + staticsEntry.getKey(), staticsEntry.getValue(), c.getCharset());
                row.packetId = ++packetId;
                buffer = row.write(buffer, c, true);
            }
        } else {
            RowDataPacket row = getRow(cacheName, cachePool.getCacheStatic(), 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 : RowDataPacket(io.mycat.net.mysql.RowDataPacket) EOFPacket(io.mycat.net.mysql.EOFPacket) ByteBuffer(java.nio.ByteBuffer) LayerCachePool(io.mycat.cache.LayerCachePool) CachePool(io.mycat.cache.CachePool) CacheStatic(io.mycat.cache.CacheStatic) LayerCachePool(io.mycat.cache.LayerCachePool) FieldPacket(io.mycat.net.mysql.FieldPacket) Map(java.util.Map) CacheService(io.mycat.cache.CacheService)

Aggregations

RowDataPacket (io.mycat.net.mysql.RowDataPacket)269 FieldPacket (io.mycat.net.mysql.FieldPacket)143 ByteBuffer (java.nio.ByteBuffer)140 EOFPacket (io.mycat.net.mysql.EOFPacket)137 MycatConfig (io.mycat.config.MycatConfig)20 LinkedList (java.util.LinkedList)16 PhysicalDatasource (io.mycat.backend.datasource.PhysicalDatasource)14 NIOProcessor (io.mycat.net.NIOProcessor)14 SchemaConfig (io.mycat.config.model.SchemaConfig)13 ResultSetHeaderPacket (io.mycat.net.mysql.ResultSetHeaderPacket)13 PhysicalDBPool (io.mycat.backend.datasource.PhysicalDBPool)12 UserStat (io.mycat.statistic.stat.UserStat)12 IOException (java.io.IOException)12 Map (java.util.Map)12 DBHeartbeat (io.mycat.backend.heartbeat.DBHeartbeat)10 ServerConnection (io.mycat.server.ServerConnection)10 BinaryRowDataPacket (io.mycat.net.mysql.BinaryRowDataPacket)8 File (java.io.File)8 DataSourceSyncRecorder (io.mycat.statistic.DataSourceSyncRecorder)6 BufferedReader (java.io.BufferedReader)6