Search in sources :

Example 61 with RowDataPacket

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

the class SelectUser method response.

public static void response(ServerConnection c) {
    if (MycatServer.getInstance().isOnline()) {
        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;
        RowDataPacket row = new RowDataPacket(FIELD_COUNT);
        row.add(getUser(c));
        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);
    } else {
        error.write(c);
    }
}
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 62 with RowDataPacket

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

the class ShowCobarCluster method getRows.

private static List<RowDataPacket> getRows(ServerConnection c) {
    List<RowDataPacket> rows = new LinkedList<RowDataPacket>();
    MycatConfig config = MycatServer.getInstance().getConfig();
    MycatCluster cluster = config.getCluster();
    Map<String, SchemaConfig> schemas = config.getSchemas();
    SchemaConfig schema = (c.getSchema() == null) ? null : schemas.get(c.getSchema());
    // 如果没有指定schema或者schema为null,则使用全部集群。
    if (schema == null) {
        Map<String, MycatNode> nodes = cluster.getNodes();
        for (MycatNode n : nodes.values()) {
            if (n != null && n.isOnline()) {
                rows.add(getRow(n, c.getCharset()));
            }
        }
    } else {
        Map<String, MycatNode> nodes = cluster.getNodes();
        for (MycatNode n : nodes.values()) {
            if (n != null && n.isOnline()) {
                rows.add(getRow(n, c.getCharset()));
            }
        }
    }
    if (rows.size() == 0) {
        alarm.error(Alarms.CLUSTER_EMPTY + c.toString());
    }
    return rows;
}
Also used : SchemaConfig(io.mycat.config.model.SchemaConfig) MycatNode(io.mycat.config.MycatNode) RowDataPacket(io.mycat.net.mysql.RowDataPacket) MycatCluster(io.mycat.config.MycatCluster) MycatConfig(io.mycat.config.MycatConfig) LinkedList(java.util.LinkedList)

Example 63 with RowDataPacket

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

the class ShowMyCATCluster method response.

public static void response(ServerConnection c) {
    ByteBuffer buffer = c.allocate();
    // write header
    buffer = header.write(buffer, c, true);
    // write field
    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)) {
        row.packetId = ++packetId;
        buffer = row.write(buffer, c, true);
    }
    // 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 64 with RowDataPacket

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

the class ShowMyCATCluster method getRow.

private static RowDataPacket getRow(MycatNode node, String charset) {
    MycatNodeConfig conf = node.getConfig();
    RowDataPacket row = new RowDataPacket(FIELD_COUNT);
    row.add(StringUtil.encode(conf.getHost(), charset));
    row.add(IntegerUtil.toBytes(conf.getWeight()));
    return row;
}
Also used : MycatNodeConfig(io.mycat.config.model.MycatNodeConfig) RowDataPacket(io.mycat.net.mysql.RowDataPacket)

Example 65 with RowDataPacket

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

the class ShareRowOutPutDataHandler method getRow.

// 不是主键,获取join左边的的记录
private byte[] getRow(Map<String, byte[]> batchRowsCopy, String value, int index) {
    for (Map.Entry<String, byte[]> e : batchRowsCopy.entrySet()) {
        String key = e.getKey();
        RowDataPacket rowDataPkg = ResultSetUtil.parseRowData(e.getValue(), afields);
        byte[] columnValue = rowDataPkg.fieldValues.get(index);
        if (columnValue == null)
            continue;
        String id = ByteUtil.getString(columnValue);
        if (id.equals(value)) {
            return batchRowsCopy.remove(key);
        }
    }
    return null;
}
Also used : RowDataPacket(io.mycat.net.mysql.RowDataPacket) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

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