Search in sources :

Example 76 with RowDataPacket

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

the class SelectLastInsertId method response.

public static void response(ServerConnection c, String stmt, int aliasIndex) {
    String alias = ParseUtil.parseAlias(stmt, aliasIndex);
    if (alias == null) {
        alias = ORG_NAME;
    }
    ByteBuffer buffer = c.allocate();
    // write header
    buffer = HEADER.write(buffer, c, true);
    // write fields
    byte packetId = HEADER.getPacketId();
    FieldPacket field = PacketUtil.getField(alias, ORG_NAME, Fields.FIELD_TYPE_LONGLONG);
    field.setPacketId(++packetId);
    buffer = field.write(buffer, c, true);
    // write eof
    EOFPacket eof = new EOFPacket();
    eof.setPacketId(++packetId);
    buffer = eof.write(buffer, c, true);
    // write rows
    RowDataPacket row = new RowDataPacket(FIELD_COUNT);
    row.add(LongUtil.toBytes(c.getLastInsertId()));
    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 : 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 77 with RowDataPacket

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

the class SelectTxReadOnly method response.

public static void response(ServerConnection 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.getPacketId();
    RowDataPacket row = new RowDataPacket(FIELD_COUNT);
    int result = c.isReadOnly() ? 1 : 0;
    row.add(LongUtil.toBytes(result));
    row.setPacketId(++packetId);
    buffer = row.write(buffer, c, true);
    EOFPacket lastEof = new EOFPacket();
    lastEof.setPacketId(++packetId);
    buffer = lastEof.write(buffer, c, true);
    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 78 with RowDataPacket

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

the class SelectVariables method execute.

public static void execute(ServerConnection c, String sql) {
    String subSql = sql.substring(sql.indexOf("SELECT") + 6);
    List<String> splitVar = Splitter.on(",").omitEmptyStrings().trimResults().splitToList(subSql);
    splitVar = convert(splitVar);
    int fieldCount = splitVar.size();
    ResultSetHeaderPacket header = PacketUtil.getHeader(fieldCount);
    FieldPacket[] fields = new FieldPacket[fieldCount];
    int i = 0;
    byte packetId = 0;
    header.setPacketId(++packetId);
    for (String s : splitVar) {
        fields[i] = PacketUtil.getField(s, Fields.FIELD_TYPE_VAR_STRING);
        fields[i++].setPacketId(++packetId);
    }
    ByteBuffer buffer = c.allocate();
    // write header
    buffer = header.write(buffer, c, true);
    // write fields
    for (FieldPacket field : fields) {
        buffer = field.write(buffer, c, true);
    }
    EOFPacket eof = new EOFPacket();
    eof.setPacketId(++packetId);
    // write eof
    buffer = eof.write(buffer, c, true);
    // write rows
    // byte packetId = eof.packetId;
    RowDataPacket row = new RowDataPacket(fieldCount);
    for (String s : splitVar) {
        String value = VARIABLES.get(s) == null ? "" : VARIABLES.get(s);
        row.add(value.getBytes());
    }
    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 : ResultSetHeaderPacket(com.actiontech.dble.net.mysql.ResultSetHeaderPacket) RowDataPacket(com.actiontech.dble.net.mysql.RowDataPacket) EOFPacket(com.actiontech.dble.net.mysql.EOFPacket) FieldPacket(com.actiontech.dble.net.mysql.FieldPacket) ByteBuffer(java.nio.ByteBuffer)

Example 79 with RowDataPacket

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

the class FetchMySQLSequenceHandler method rowResponse.

@Override
public boolean rowResponse(byte[] row, RowDataPacket rowPacket, boolean isLeft, BackendConnection conn) {
    RowDataPacket rowDataPkg = new RowDataPacket(1);
    rowDataPkg.read(row);
    byte[] columnData = rowDataPkg.fieldValues.get(0);
    String columnVal = new String(columnData);
    SequenceVal seqVal = (SequenceVal) conn.getAttachment();
    if (IncrSequenceMySQLHandler.ERR_SEQ_RESULT.equals(columnVal)) {
        seqVal.dbretVal = IncrSequenceMySQLHandler.ERR_SEQ_RESULT;
        LOGGER.warn(AlarmCode.CORE_SEQUENCE_WARN + " sequnce sql returned err value ,sequence:" + seqVal.seqName + " " + columnVal + " sql:" + seqVal.sql);
    } else {
        seqVal.dbretVal = columnVal;
    }
    return false;
}
Also used : RowDataPacket(com.actiontech.dble.net.mysql.RowDataPacket)

Example 80 with RowDataPacket

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

the class JoinHandler method addRowToDeque.

private void addRowToDeque(RowDataPacket row, int columnCount, FairLinkedBlockingDeque<LocalResult> deque, RowDataComparator cmp) throws InterruptedException {
    LocalResult localResult = deque.peekLast();
    if (localResult != null) {
        RowDataPacket lastRow = localResult.getLastRow();
        if (lastRow.getFieldCount() == 0) {
            // eof may added in terminateThread
            return;
        } else if (row.getFieldCount() > 0 && cmp.compare(lastRow, row) == 0) {
            localResult.add(row);
            return;
        } else {
            localResult.done();
        }
    }
    LocalResult newLocalResult = new UnSortedLocalResult(columnCount, pool, this.charset).setMemSizeController(session.getJoinBufferMC());
    newLocalResult.add(row);
    if (row.getFieldCount() == 0)
        newLocalResult.done();
    deque.putLast(newLocalResult);
}
Also used : LocalResult(com.actiontech.dble.backend.mysql.store.LocalResult) UnSortedLocalResult(com.actiontech.dble.backend.mysql.store.UnSortedLocalResult) RowDataPacket(com.actiontech.dble.net.mysql.RowDataPacket) UnSortedLocalResult(com.actiontech.dble.backend.mysql.store.UnSortedLocalResult)

Aggregations

RowDataPacket (com.actiontech.dble.net.mysql.RowDataPacket)141 EOFPacket (com.actiontech.dble.net.mysql.EOFPacket)59 FieldPacket (com.actiontech.dble.net.mysql.FieldPacket)59 ByteBuffer (java.nio.ByteBuffer)59 ServerConfig (com.actiontech.dble.config.ServerConfig)8 NIOProcessor (com.actiontech.dble.net.NIOProcessor)8 Map (java.util.Map)8 PhysicalDBPool (com.actiontech.dble.backend.datasource.PhysicalDBPool)7 PhysicalDatasource (com.actiontech.dble.backend.datasource.PhysicalDatasource)7 MySQLConnection (com.actiontech.dble.backend.mysql.nio.MySQLConnection)7 LocalResult (com.actiontech.dble.backend.mysql.store.LocalResult)6 UnSortedLocalResult (com.actiontech.dble.backend.mysql.store.UnSortedLocalResult)6 DBHeartbeat (com.actiontech.dble.backend.heartbeat.DBHeartbeat)5 ItemSum (com.actiontech.dble.plan.common.item.function.sumfunc.ItemSum)5 UserStat (com.actiontech.dble.statistic.stat.UserStat)5 BackendConnection (com.actiontech.dble.backend.BackendConnection)4 SchemaConfig (com.actiontech.dble.config.model.SchemaConfig)4 FrontendConnection (com.actiontech.dble.net.FrontendConnection)4 ResultSetHeaderPacket (com.actiontech.dble.net.mysql.ResultSetHeaderPacket)4 LinkedList (java.util.LinkedList)4