Search in sources :

Example 81 with RowDataPacket

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

the class NotInHandler method ownThreadJob.

@Override
protected void ownThreadJob(Object... objects) {
    MySQLConnection conn = (MySQLConnection) objects[0];
    LocalResult leftLocal = null, rightLocal = null;
    try {
        Comparator<RowDataPacket> notInComparator = new TwoTableComparator(leftFieldPackets, rightFieldPackets, leftOrders, rightOrders, this.isAllPushDown(), this.type());
        leftLocal = takeFirst(leftQueue);
        rightLocal = takeFirst(rightQueue);
        while (true) {
            RowDataPacket leftRow = leftLocal.getLastRow();
            RowDataPacket rightRow = rightLocal.getLastRow();
            if (leftRow.getFieldCount() == 0) {
                break;
            }
            if (rightRow.getFieldCount() == 0) {
                sendLeft(leftLocal, conn);
                leftLocal.close();
                leftLocal = takeFirst(leftQueue);
                continue;
            }
            int rs = notInComparator.compare(leftRow, rightRow);
            if (rs < 0) {
                sendLeft(leftLocal, conn);
                leftLocal.close();
                leftLocal = takeFirst(leftQueue);
                continue;
            } else if (rs > 0) {
                rightLocal.close();
                rightLocal = takeFirst(rightQueue);
            } else {
                // because not in, if equal left should move to next value
                leftLocal.close();
                rightLocal.close();
                leftLocal = takeFirst(leftQueue);
                rightLocal = takeFirst(rightQueue);
            }
        }
        nextHandler.rowEofResponse(null, isLeft, conn);
        HandlerTool.terminateHandlerTree(this);
    } catch (Exception e) {
        String msg = "notIn 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 82 with RowDataPacket

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

the class NotInHandler 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) {
            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)

Example 83 with RowDataPacket

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

the class AllAnySubQueryHandler method rowResponse.

@Override
public boolean rowResponse(byte[] rowNull, RowDataPacket rowPacket, boolean isLeft, BackendConnection conn) {
    lock.lock();
    try {
        if (terminate.get()) {
            return true;
        }
        RowDataPacket row = rowPacket;
        if (row == null) {
            row = new RowDataPacket(this.fieldPackets.size());
            row.read(rowNull);
        }
        sourceField.setPtr(row.getValue(0));
        Item value = itemSubQuery.getFiled().getResultItem();
        if (itemSubQuery.getValue().size() == 0) {
            itemSubQuery.getValue().add(value);
            tmpRow = row;
        } else if (itemSubQuery.getValue().size() == 1) {
            handleNewRow(row, value);
        } else {
        // ignore row
        }
    } finally {
        lock.unlock();
    }
    return false;
}
Also used : Item(com.actiontech.dble.plan.common.item.Item) RowDataPacket(com.actiontech.dble.net.mysql.RowDataPacket)

Example 84 with RowDataPacket

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

the class InSubQueryHandler method rowResponse.

@Override
public boolean rowResponse(byte[] rowNull, RowDataPacket rowPacket, boolean isLeft, BackendConnection conn) {
    lock.lock();
    try {
        if (terminate.get()) {
            return true;
        }
        if (++rowCount > maxPartSize * maxConnSize) {
            String errMessage = "sub query too much rows!";
            LOGGER.info(errMessage);
            genErrorPackage(ErrorCode.ER_UNKNOWN_ERROR, errMessage);
            conn.close(errMessage);
            try {
                tempDoneCallBack.call();
            } catch (Exception callback) {
                LOGGER.info("callback exception!", callback);
            }
            return true;
        }
        RowDataPacket row = rowPacket;
        if (row == null) {
            row = new RowDataPacket(this.fieldPackets.size());
            row.read(rowNull);
        }
        sourceField.setPtr(row.getValue(0));
        Item value = itemSubQuery.getFiled().getResultItem();
        if (value != null) {
            itemSubQuery.getValue().add(value);
        }
    } finally {
        lock.unlock();
    }
    return false;
}
Also used : Item(com.actiontech.dble.plan.common.item.Item) RowDataPacket(com.actiontech.dble.net.mysql.RowDataPacket) ItemString(com.actiontech.dble.plan.common.item.ItemString)

Example 85 with RowDataPacket

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

the class DistinctResultDiskBuffer method addToHeap.

/**
 * if heap already contains row, no add into heap
 *
 * @param tape
 */
protected void addToHeap(ResultDiskTape tape) {
    while (true) {
        RowDataPacket row = tape.nextRow();
        if (row == null)
            return;
        else {
            TapeItem tapeItem = new TapeItem(row, tape);
            TapeItem oldItem = heap.find(tapeItem);
            if (oldItem == null) {
                heap.add(tapeItem);
                return;
            } else {
                onFoundRow(oldItem.row, row);
            }
        }
    }
}
Also used : 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