Search in sources :

Example 1 with RowDataPacket

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

the class MyCATSequnceProcessor method outRawData.

private void outRawData(ServerConnection sc, String value) {
    byte packetId = 0;
    int fieldCount = 1;
    ByteBuffer byteBuf = sc.allocate();
    ResultSetHeaderPacket headerPkg = new ResultSetHeaderPacket();
    headerPkg.fieldCount = fieldCount;
    headerPkg.packetId = ++packetId;
    byteBuf = headerPkg.write(byteBuf, sc, true);
    FieldPacket fieldPkg = new FieldPacket();
    fieldPkg.packetId = ++packetId;
    fieldPkg.name = StringUtil.encode("SEQUNCE", sc.getCharset());
    byteBuf = fieldPkg.write(byteBuf, sc, true);
    EOFPacket eofPckg = new EOFPacket();
    eofPckg.packetId = ++packetId;
    byteBuf = eofPckg.write(byteBuf, sc, true);
    RowDataPacket rowDataPkg = new RowDataPacket(fieldCount);
    rowDataPkg.packetId = ++packetId;
    rowDataPkg.add(StringUtil.encode(value, sc.getCharset()));
    byteBuf = rowDataPkg.write(byteBuf, sc, true);
    // write last eof
    EOFPacket lastEof = new EOFPacket();
    lastEof.packetId = ++packetId;
    byteBuf = lastEof.write(byteBuf, sc, true);
    // write buffer
    sc.write(byteBuf);
}
Also used : ResultSetHeaderPacket(io.mycat.net.mysql.ResultSetHeaderPacket) RowDataPacket(io.mycat.net.mysql.RowDataPacket) EOFPacket(io.mycat.net.mysql.EOFPacket) ByteBuffer(java.nio.ByteBuffer) FieldPacket(io.mycat.net.mysql.FieldPacket)

Example 2 with RowDataPacket

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

the class MaxHeap method heapify.

private void heapify(int i, int size) {
    int max = 0;
    // ==size/2
    int mid = size >> 1;
    while (i <= mid) {
        max = i;
        int left = i << 1;
        int right = left + 1;
        if (left < size && cmp.compare(data.get(left), data.get(i)) > 0) {
            max = left;
        }
        if (right < size && cmp.compare(data.get(right), data.get(max)) > 0) {
            max = right;
        }
        if (i == max) {
            break;
        }
        if (i != max) {
            RowDataPacket tmp = data.get(i);
            data.set(i, data.get(max));
            data.set(max, tmp);
            i = max;
        }
    }
}
Also used : RowDataPacket(io.mycat.net.mysql.RowDataPacket)

Example 3 with RowDataPacket

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

the class PackageBufINf method showLogSum.

private static PackageBufINf showLogSum(ManagerConnection c, ByteBuffer buffer, byte packetId) {
    PackageBufINf bufINf = new PackageBufINf();
    File[] logFiles = new File(SystemConfig.getHomePath(), "logs").listFiles();
    String fileNames = "";
    for (File f : logFiles) {
        if (f.isFile()) {
            fileNames += "  " + f.getName();
        }
    }
    File file = getLogFile(DEFAULT_LOGFILE);
    BufferedReader br = null;
    int totalLines = 0;
    CircularArrayList<String> queue = new CircularArrayList<String>(50);
    try {
        br = new BufferedReader(new FileReader(file));
        String line = null;
        while ((line = br.readLine()) != null) {
            totalLines++;
            if (queue.size() == queue.capacity()) {
                queue.remove(0);
            }
            queue.add(line);
        }
        RowDataPacket row = new RowDataPacket(FIELD_COUNT);
        row.add(StringUtil.encode("files in log dir:" + totalLines + fileNames, c.getCharset()));
        row.packetId = ++packetId;
        buffer = row.write(buffer, c, true);
        row = new RowDataPacket(FIELD_COUNT);
        row.add(StringUtil.encode("Total lines " + totalLines + " ,tail " + queue.size() + " line is following:", c.getCharset()));
        row.packetId = ++packetId;
        buffer = row.write(buffer, c, true);
        int size = queue.size() - 1;
        for (int i = size; i >= 0; i--) {
            String data = queue.get(i);
            row = new RowDataPacket(FIELD_COUNT);
            row.add(StringUtil.encode(data, c.getCharset()));
            row.packetId = ++packetId;
            buffer = row.write(buffer, c, true);
        }
        bufINf.buffer = buffer;
        bufINf.packetId = packetId;
        return bufINf;
    } catch (Exception e) {
        LOGGER.error("showLogSumError", e);
        RowDataPacket row = new RowDataPacket(FIELD_COUNT);
        row.add(StringUtil.encode(e.toString(), c.getCharset()));
        row.packetId = ++packetId;
        buffer = row.write(buffer, c, true);
        bufINf.buffer = buffer;
    } finally {
        if (br != null) {
            try {
                br.close();
            } catch (IOException e) {
                LOGGER.error("showLogSumError", e);
            }
        }
    }
    bufINf.packetId = packetId;
    return bufINf;
}
Also used : RowDataPacket(io.mycat.net.mysql.RowDataPacket) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) CircularArrayList(io.mycat.util.CircularArrayList) IOException(java.io.IOException) File(java.io.File) IOException(java.io.IOException)

Example 4 with RowDataPacket

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

the class SelectSessionAutoIncrement 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;
    RowDataPacket row = new RowDataPacket(FIELD_COUNT);
    row.packetId = ++packetId;
    row.add(LongUtil.toBytes(1));
    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 5 with RowDataPacket

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

the class SelectVersionComment 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;
    RowDataPacket row = new RowDataPacket(FIELD_COUNT);
    row.add(VERSION_COMMENT);
    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

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