Search in sources :

Example 1 with BackendAIOConnection

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

the class LoadDataUtil method requestFileDataResponse.

public static void requestFileDataResponse(byte[] data, BackendConnection conn) {
    byte packId = data[3];
    BackendAIOConnection backendAIOConnection = (BackendAIOConnection) conn;
    RouteResultsetNode rrn = (RouteResultsetNode) conn.getAttachment();
    LoadData loadData = rrn.getLoadData();
    List<String> loadDataData = loadData.getData();
    try {
        if (loadDataData != null && loadDataData.size() > 0) {
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            for (int i = 0, loadDataDataSize = loadDataData.size(); i < loadDataDataSize; i++) {
                String line = loadDataData.get(i);
                String s = (i == loadDataDataSize - 1) ? line : line + loadData.getLineTerminatedBy();
                byte[] bytes = s.getBytes(loadData.getCharset());
                bos.write(bytes);
            }
            packId = writeToBackConnection(packId, new ByteArrayInputStream(bos.toByteArray()), backendAIOConnection);
        } else {
            //从文件读取
            packId = writeToBackConnection(packId, new BufferedInputStream(new FileInputStream(loadData.getFileName())), backendAIOConnection);
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    } finally {
        //结束必须发空包
        byte[] empty = new byte[] { 0, 0, 0, 3 };
        empty[3] = ++packId;
        backendAIOConnection.write(empty);
    }
}
Also used : LoadData(io.mycat.sqlengine.mpp.LoadData) BackendAIOConnection(io.mycat.net.BackendAIOConnection) RouteResultsetNode(io.mycat.route.RouteResultsetNode)

Example 2 with BackendAIOConnection

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

the class ShowBackend method getRow.

private static RowDataPacket getRow(BackendConnection c, String charset) {
    RowDataPacket row = new RowDataPacket(FIELD_COUNT);
    if (c instanceof BackendAIOConnection) {
        row.add(((BackendAIOConnection) c).getProcessor().getName().getBytes());
    } else if (c instanceof JDBCConnection) {
        row.add(((JDBCConnection) c).getProcessor().getName().getBytes());
    } else {
        row.add("N/A".getBytes());
    }
    row.add(LongUtil.toBytes(c.getId()));
    long threadId = 0;
    if (c instanceof MySQLConnection) {
        threadId = ((MySQLConnection) c).getThreadId();
    }
    row.add(LongUtil.toBytes(threadId));
    row.add(StringUtil.encode(c.getHost(), charset));
    row.add(IntegerUtil.toBytes(c.getPort()));
    row.add(IntegerUtil.toBytes(c.getLocalPort()));
    row.add(LongUtil.toBytes(c.getNetInBytes()));
    row.add(LongUtil.toBytes(c.getNetOutBytes()));
    row.add(LongUtil.toBytes((TimeUtil.currentTimeMillis() - c.getStartupTime()) / 1000L));
    row.add(c.isClosed() ? "true".getBytes() : "false".getBytes());
    // boolean isRunning = c.isRunning();
    // row.add(isRunning ? "true".getBytes() : "false".getBytes());
    boolean isBorrowed = c.isBorrowed();
    row.add(isBorrowed ? "true".getBytes() : "false".getBytes());
    int writeQueueSize = 0;
    String schema = "";
    String charsetInf = "";
    String txLevel = "";
    String txAutommit = "";
    if (c instanceof MySQLConnection) {
        MySQLConnection mysqlC = (MySQLConnection) c;
        writeQueueSize = mysqlC.getWriteQueue().size();
        schema = mysqlC.getSchema();
        charsetInf = mysqlC.getCharset() + ":" + mysqlC.getCharsetIndex();
        txLevel = mysqlC.getTxIsolation() + "";
        txAutommit = mysqlC.isAutocommit() + "";
    }
    row.add(IntegerUtil.toBytes(writeQueueSize));
    row.add(schema.getBytes());
    row.add(charsetInf.getBytes());
    row.add(txLevel.getBytes());
    row.add(txAutommit.getBytes());
    return row;
}
Also used : RowDataPacket(io.mycat.net.mysql.RowDataPacket) BackendAIOConnection(io.mycat.net.BackendAIOConnection) JDBCConnection(io.mycat.backend.jdbc.JDBCConnection) MySQLConnection(io.mycat.backend.mysql.nio.MySQLConnection)

Aggregations

BackendAIOConnection (io.mycat.net.BackendAIOConnection)2 JDBCConnection (io.mycat.backend.jdbc.JDBCConnection)1 MySQLConnection (io.mycat.backend.mysql.nio.MySQLConnection)1 RowDataPacket (io.mycat.net.mysql.RowDataPacket)1 RouteResultsetNode (io.mycat.route.RouteResultsetNode)1 LoadData (io.mycat.sqlengine.mpp.LoadData)1