Search in sources :

Example 66 with RowDataPacket

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

the class ShareRowOutPutDataHandler method onRowData.

@Override
public boolean onRowData(String dataNode, byte[] rowData) {
    RowDataPacket rowDataPkgold = ResultSetUtil.parseRowData(rowData, bfields);
    // 拷贝一份batchRows
    Map<String, byte[]> batchRowsCopy = new ConcurrentHashMap<String, byte[]>();
    batchRowsCopy.putAll(arows);
    // 获取Id字段,
    String id = ByteUtil.getString(rowDataPkgold.fieldValues.get(joinR));
    // 查找ID对应的A表的记录
    // arows.remove(id);
    byte[] arow = getRow(batchRowsCopy, id, joinL);
    // byte[] arow = getRow(id,joinL);//arows.remove(id);
    while (arow != null) {
        // ctx.getAllFields());
        RowDataPacket rowDataPkg = ResultSetUtil.parseRowData(arow, afields);
        for (int i = 1; i < rowDataPkgold.fieldCount; i++) {
            // 设置b.name 字段
            byte[] bname = rowDataPkgold.fieldValues.get(i);
            rowDataPkg.add(bname);
            rowDataPkg.addFieldCount(1);
        }
        // RowData(rowDataPkg);
        // huangyiming add
        MiddlerResultHandler middlerResultHandler = session.getMiddlerResultHandler();
        if (null == middlerResultHandler) {
            ctx.writeRow(rowDataPkg);
        } else {
            if (middlerResultHandler instanceof MiddlerQueryResultHandler) {
                // if(middlerResultHandler.getDataType().equalsIgnoreCase("string")){
                byte[] columnData = rowDataPkg.fieldValues.get(0);
                if (columnData != null && columnData.length > 0) {
                    String rowValue = new String(columnData);
                    middlerResultHandler.add(rowValue);
                }
            // }
            }
        }
        arow = getRow(batchRowsCopy, id, joinL);
    // arow = getRow(id,joinL);
    }
    return false;
}
Also used : RowDataPacket(io.mycat.net.mysql.RowDataPacket) MiddlerResultHandler(io.mycat.backend.mysql.nio.handler.MiddlerResultHandler) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) MiddlerQueryResultHandler(io.mycat.backend.mysql.nio.handler.MiddlerQueryResultHandler)

Example 67 with RowDataPacket

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

the class SelectSessionTxReadOnly 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(0));
    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 68 with RowDataPacket

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

the class ShowBackend 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 (NIOProcessor p : MycatServer.getInstance().getProcessors()) {
        for (BackendConnection bc : p.getBackends().values()) {
            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) NIOProcessor(io.mycat.net.NIOProcessor) ByteBuffer(java.nio.ByteBuffer) FieldPacket(io.mycat.net.mysql.FieldPacket)

Example 69 with RowDataPacket

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

the class ShowConnection 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;
    String charset = c.getCharset();
    NIOProcessor[] processors = MycatServer.getInstance().getProcessors();
    for (NIOProcessor p : processors) {
        for (FrontendConnection fc : p.getFrontends().values()) {
            if (fc != null) {
                RowDataPacket row = getRow(fc, charset);
                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) NIOProcessor(io.mycat.net.NIOProcessor) ByteBuffer(java.nio.ByteBuffer) FieldPacket(io.mycat.net.mysql.FieldPacket)

Example 70 with RowDataPacket

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

the class ShowDataNode method getRow.

private static RowDataPacket getRow(PhysicalDBNode node, String charset) {
    RowDataPacket row = new RowDataPacket(FIELD_COUNT);
    row.add(StringUtil.encode(node.getName(), charset));
    row.add(StringUtil.encode(node.getDbPool().getHostName() + '/' + node.getDatabase(), charset));
    PhysicalDBPool pool = node.getDbPool();
    PhysicalDatasource ds = pool.getSource();
    if (ds != null) {
        int active = ds.getActiveCountForSchema(node.getDatabase());
        int idle = ds.getIdleCountForSchema(node.getDatabase());
        row.add(IntegerUtil.toBytes(pool.getActivedIndex()));
        row.add(StringUtil.encode(ds.getConfig().getDbType(), charset));
        row.add(IntegerUtil.toBytes(active));
        row.add(IntegerUtil.toBytes(idle));
        row.add(IntegerUtil.toBytes(ds.getSize()));
    } else {
        row.add(null);
        row.add(null);
        row.add(null);
        row.add(null);
        row.add(null);
    }
    row.add(LongUtil.toBytes(ds.getExecuteCountForSchema(node.getDatabase())));
    row.add(StringUtil.encode(nf.format(0), charset));
    row.add(StringUtil.encode(nf.format(0), charset));
    row.add(LongUtil.toBytes(0));
    long recoveryTime = pool.getSource().getHeartbeatRecoveryTime() - TimeUtil.currentTimeMillis();
    row.add(LongUtil.toBytes(recoveryTime > 0 ? recoveryTime / 1000L : -1L));
    return row;
}
Also used : PhysicalDatasource(io.mycat.backend.datasource.PhysicalDatasource) RowDataPacket(io.mycat.net.mysql.RowDataPacket) PhysicalDBPool(io.mycat.backend.datasource.PhysicalDBPool)

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