Search in sources :

Example 1 with RowDataPacket

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

the class MultiNodeSelectHandler method rowResponse.

@Override
public boolean rowResponse(final byte[] row, RowDataPacket rowPacketNull, boolean isLeft, BackendConnection conn) {
    if (errorResponse.get() || noNeedRows) {
        return true;
    }
    BlockingQueue<HeapItem> queue = queues.get(conn);
    if (queue == null)
        return true;
    RowDataPacket rp = new RowDataPacket(fieldCount);
    rp.read(row);
    HeapItem item = new HeapItem(row, rp, (MySQLConnection) conn);
    try {
        queue.put(item);
    } catch (InterruptedException e) {
        LOGGER.info("rowResponse error", e);
    }
    return false;
}
Also used : HeapItem(com.actiontech.dble.backend.mysql.nio.handler.util.HeapItem) RowDataPacket(com.actiontech.dble.net.mysql.RowDataPacket)

Example 2 with RowDataPacket

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

the class ShowVariablesHandler method rowResponse.

@Override
public boolean rowResponse(byte[] row, RowDataPacket rowPacket, boolean isLeft, BackendConnection conn) {
    String charset = session.getSource().getCharset().getResults();
    RowDataPacket rowDataPacket = new RowDataPacket(2);
    /* Fixme: the accurate statistics of netOutBytes.
         *
         * We read net packet, but don't do Stat here. So the statistical magnitude -- netOutBytes is not exact.
         * Of course, we can do that.
         * But it is tiresome: re-implement the function of method rowResponse that have been implemented in super class.
         */
    rowDataPacket.read(row);
    String varName = StringUtil.decode(rowDataPacket.fieldValues.get(0), charset);
    if (shadowVars.containsKey(varName)) {
        rowDataPacket.setValue(1, StringUtil.encode(shadowVars.get(varName), charset));
        super.rowResponse(rowDataPacket.toBytes(), rowPacket, isLeft, conn);
    } else {
        super.rowResponse(row, rowPacket, isLeft, conn);
    }
    return false;
}
Also used : RowDataPacket(com.actiontech.dble.net.mysql.RowDataPacket)

Example 3 with RowDataPacket

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

the class JoinHandler method rowEofResponse.

@Override
public void rowEofResponse(byte[] data, boolean isLeft, BackendConnection conn) {
    logger.debug("roweof");
    if (terminate.get()) {
        return;
    }
    RowDataPacket eofRow = new RowDataPacket(0);
    try {
        if (isLeft) {
            logger.debug("row eof left");
            addRowToDeque(eofRow, leftFieldPackets.size(), leftQueue, leftComparator);
        } else {
            logger.debug("row eof right");
            addRowToDeque(eofRow, rightFieldPackets.size(), rightQueue, rightComparator);
        }
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}
Also used : RowDataPacket(com.actiontech.dble.net.mysql.RowDataPacket)

Example 4 with RowDataPacket

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

the class JoinHandler method ownThreadJob.

@Override
protected void ownThreadJob(Object... objects) {
    MySQLConnection conn = (MySQLConnection) objects[0];
    LocalResult leftLocal = null, rightLocal = null;
    try {
        Comparator<RowDataPacket> joinComparator = new TwoTableComparator(leftFieldPackets, rightFieldPackets, leftOrders, rightOrders, this.isAllPushDown(), this.type());
        // logger.debug("merge Join start");
        leftLocal = takeFirst(leftQueue);
        rightLocal = takeFirst(rightQueue);
        while (true) {
            if (terminate.get())
                return;
            RowDataPacket leftRow = leftLocal.getLastRow();
            RowDataPacket rightRow = rightLocal.getLastRow();
            if (leftRow.getFieldCount() == 0) {
                break;
            }
            if (rightRow.getFieldCount() == 0) {
                if (isLeftJoin) {
                    if (connectLeftAndNull(leftLocal, conn))
                        break;
                    leftLocal = takeFirst(leftQueue);
                    continue;
                } else {
                    break;
                }
            }
            int rs = joinComparator.compare(leftRow, rightRow);
            if (rs < 0) {
                if (isLeftJoin) {
                    if (connectLeftAndNull(leftLocal, conn))
                        break;
                    leftLocal = takeFirst(leftQueue);
                    continue;
                } else {
                    leftLocal.close();
                    leftLocal = takeFirst(leftQueue);
                }
            } else if (rs > 0) {
                rightLocal.close();
                rightLocal = takeFirst(rightQueue);
            } else {
                if (connectLeftAndRight(leftLocal, rightLocal, conn))
                    break;
                leftLocal = takeFirst(leftQueue);
                rightLocal = takeFirst(rightQueue);
            }
        }
        nextHandler.rowEofResponse(null, isLeft, conn);
        HandlerTool.terminateHandlerTree(this);
    } catch (Exception e) {
        String msg = "join thread error, " + e.getLocalizedMessage();
        logger.info(msg, e);
        session.onQueryError(msg.getBytes());
    } finally {
        if (leftLocal != null)
            leftLocal.close();
        if (rightLocal != null)
            rightLocal.close();
    }
}
Also used : LocalResult(com.actiontech.dble.backend.mysql.store.LocalResult) UnSortedLocalResult(com.actiontech.dble.backend.mysql.store.UnSortedLocalResult) TwoTableComparator(com.actiontech.dble.backend.mysql.nio.handler.util.TwoTableComparator) RowDataPacket(com.actiontech.dble.net.mysql.RowDataPacket) MySQLConnection(com.actiontech.dble.backend.mysql.nio.MySQLConnection)

Example 5 with RowDataPacket

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

the class JoinHandler method takeFirst.

private LocalResult takeFirst(FairLinkedBlockingDeque<LocalResult> deque) throws InterruptedException {
    /**
     * it must be in single thread
     */
    deque.waitUtilCount(1);
    LocalResult result = deque.peekFirst();
    RowDataPacket lastRow = result.getLastRow();
    if (lastRow.getFieldCount() == 0)
        return deque.takeFirst();
    else {
        deque.waitUtilCount(2);
        return deque.takeFirst();
    }
}
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)

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