Search in sources :

Example 16 with FieldPacket

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

the class ShowCommandCount 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)

Example 17 with FieldPacket

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

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.getPacketId();
    NIOProcessor[] processors = DbleServer.getInstance().getFrontProcessors();
    for (NIOProcessor p : processors) {
        for (FrontendConnection fc : p.getFrontends().values()) {
            if (fc != null) {
                RowDataPacket row = getRow(fc, 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 : FrontendConnection(com.actiontech.dble.net.FrontendConnection) 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 18 with FieldPacket

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

the class ShowConnectionSQL 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()) {
        for (FrontendConnection fc : p.getFrontends().values()) {
            if (!fc.isClosed()) {
                RowDataPacket row = getRow(fc, 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 : FrontendConnection(com.actiontech.dble.net.FrontendConnection) 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 19 with FieldPacket

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

the class ShowDataNode method execute.

public static void execute(ManagerConnection c, String name) {
    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();
    ServerConfig conf = DbleServer.getInstance().getConfig();
    Map<String, PhysicalDBNode> dataNodes = conf.getDataNodes();
    List<String> keys = new ArrayList<>();
    if (StringUtil.isEmpty(name)) {
        keys.addAll(dataNodes.keySet());
    } else {
        SchemaConfig sc = conf.getSchemas().get(name);
        if (null != sc) {
            keys.addAll(sc.getAllDataNodes());
        }
    }
    Collections.sort(keys, new Comparator<String>() {

        @Override
        public int compare(String o1, String o2) {
            Pair<String, Integer> p1 = PairUtil.splitIndex(o1, '[', ']');
            Pair<String, Integer> p2 = PairUtil.splitIndex(o2, '[', ']');
            if (p1.getKey().compareTo(p2.getKey()) == 0) {
                return p1.getValue() - p2.getValue();
            } else {
                return p1.getKey().compareTo(p2.getKey());
            }
        }
    });
    for (String key : keys) {
        RowDataPacket row = getRow(dataNodes.get(key), c.getCharset().getResults());
        if (row != null) {
            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);
    // post write
    c.write(buffer);
}
Also used : PhysicalDBNode(com.actiontech.dble.backend.datasource.PhysicalDBNode) SchemaConfig(com.actiontech.dble.config.model.SchemaConfig) RowDataPacket(com.actiontech.dble.net.mysql.RowDataPacket) EOFPacket(com.actiontech.dble.net.mysql.EOFPacket) ByteBuffer(java.nio.ByteBuffer) ServerConfig(com.actiontech.dble.config.ServerConfig) FieldPacket(com.actiontech.dble.net.mysql.FieldPacket) Pair(com.actiontech.dble.route.parser.util.Pair)

Example 20 with FieldPacket

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

the class ShowDatabase 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();
    Map<String, SchemaConfig> schemas = DbleServer.getInstance().getConfig().getSchemas();
    for (String name : new TreeSet<>(schemas.keySet())) {
        RowDataPacket row = new RowDataPacket(FIELD_COUNT);
        row.add(StringUtil.encode(name, c.getCharset().getResults()));
        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 : SchemaConfig(com.actiontech.dble.config.model.SchemaConfig) TreeSet(java.util.TreeSet) 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