Search in sources :

Example 6 with LocalResult

use of com.actiontech.dble.backend.mysql.store.LocalResult in project dble by actiontech.

the class JoinHandler method addEndRowToDeque.

/**
 * only for terminate.
 *
 * @param row
 * @param columnCount
 * @param deque
 * @throws InterruptedException
 */
private void addEndRowToDeque(RowDataPacket row, int columnCount, FairLinkedBlockingDeque<LocalResult> deque) throws InterruptedException {
    LocalResult newLocalResult = new UnSortedLocalResult(columnCount, pool, this.charset).setMemSizeController(session.getJoinBufferMC());
    newLocalResult.add(row);
    newLocalResult.done();
    LocalResult localResult = deque.addOrReplaceLast(newLocalResult);
    if (localResult != null)
        localResult.close();
}
Also used : LocalResult(com.actiontech.dble.backend.mysql.store.LocalResult) UnSortedLocalResult(com.actiontech.dble.backend.mysql.store.UnSortedLocalResult) UnSortedLocalResult(com.actiontech.dble.backend.mysql.store.UnSortedLocalResult)

Example 7 with LocalResult

use of com.actiontech.dble.backend.mysql.store.LocalResult 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)

Example 8 with LocalResult

use of com.actiontech.dble.backend.mysql.store.LocalResult 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 9 with LocalResult

use of com.actiontech.dble.backend.mysql.store.LocalResult 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 10 with LocalResult

use of com.actiontech.dble.backend.mysql.store.LocalResult in project dble by actiontech.

the class NotInHandler method clearDeque.

private void clearDeque(FairLinkedBlockingDeque<LocalResult> deque) {
    if (deque == null)
        return;
    LocalResult local = deque.poll();
    while (local != null) {
        local.close();
        local = deque.poll();
    }
}
Also used : LocalResult(com.actiontech.dble.backend.mysql.store.LocalResult) UnSortedLocalResult(com.actiontech.dble.backend.mysql.store.UnSortedLocalResult)

Aggregations

LocalResult (com.actiontech.dble.backend.mysql.store.LocalResult)10 UnSortedLocalResult (com.actiontech.dble.backend.mysql.store.UnSortedLocalResult)10 RowDataPacket (com.actiontech.dble.net.mysql.RowDataPacket)6 MySQLConnection (com.actiontech.dble.backend.mysql.nio.MySQLConnection)2 TwoTableComparator (com.actiontech.dble.backend.mysql.nio.handler.util.TwoTableComparator)2