Search in sources :

Example 26 with MySQLConnection

use of com.actiontech.dble.backend.mysql.nio.MySQLConnection in project dble by actiontech.

the class SetTestJob method okResponse.

@Override
public void okResponse(byte[] ok, BackendConnection conn) {
    doFinished(false);
    sc.write(ok);
    ResetConnHandler handler = new ResetConnHandler();
    conn.setResponseHandler(handler);
    ((MySQLConnection) conn).setComplexQuery(true);
    MySQLConnection connection = (MySQLConnection) conn;
    connection.write(connection.writeToBuffer(ResetConnectionPacket.RESET, connection.allocate()));
}
Also used : ResetConnHandler(com.actiontech.dble.backend.mysql.nio.handler.ResetConnHandler) MySQLConnection(com.actiontech.dble.backend.mysql.nio.MySQLConnection)

Example 27 with MySQLConnection

use of com.actiontech.dble.backend.mysql.nio.MySQLConnection in project dble by actiontech.

the class DirectGroupByHandler method ownThreadJob.

@Override
protected void ownThreadJob(Object... objects) {
    MySQLConnection conn = (MySQLConnection) objects[0];
    recordElapsedTime("local group by thread is start:");
    try {
        int eofCount = 0;
        for (; ; ) {
            RowDataPacket row = outQueue.take();
            if (row.getFieldCount() == 0) {
                eofCount++;
                if (eofCount == bucketSize)
                    break;
                else
                    continue;
            }
            groupLocalResult.add(row);
        }
        recordElapsedTime("local group by thread is end:");
        groupLocalResult.done();
        recordElapsedTime("local group by thread is done for read:");
        if (!hasFirstRow.get()) {
            if (HandlerTool.needSendNoRow(this.groupBys))
                sendNoRowGroupRowPacket(conn);
        } else {
            sendGroupRowPacket(conn);
        }
        nextHandler.rowEofResponse(null, this.isLeft, conn);
    } catch (Exception e) {
        String msg = "group by thread is error," + e.getLocalizedMessage();
        LOGGER.info(msg, e);
        session.onQueryError(msg.getBytes());
    }
}
Also used : RowDataPacket(com.actiontech.dble.net.mysql.RowDataPacket) MySQLConnection(com.actiontech.dble.backend.mysql.nio.MySQLConnection)

Example 28 with MySQLConnection

use of com.actiontech.dble.backend.mysql.nio.MySQLConnection in project dble by actiontech.

the class BaseSelectHandler method errorResponse.

@Override
public void errorResponse(byte[] err, BackendConnection conn) {
    ((MySQLConnection) conn).setRunning(false);
    ErrorPacket errPacket = new ErrorPacket();
    errPacket.read(err);
    String errMsg;
    try {
        errMsg = new String(errPacket.getMessage(), CharsetUtil.getJavaCharset(conn.getCharset().getResults()));
    } catch (UnsupportedEncodingException e) {
        errMsg = "UnsupportedEncodingException:" + conn.getCharset();
    }
    LOGGER.info(conn.toString() + errMsg);
    if (terminate.get())
        return;
    session.onQueryError(errMsg.getBytes());
}
Also used : ErrorPacket(com.actiontech.dble.net.mysql.ErrorPacket) UnsupportedEncodingException(java.io.UnsupportedEncodingException) MySQLConnection(com.actiontech.dble.backend.mysql.nio.MySQLConnection)

Example 29 with MySQLConnection

use of com.actiontech.dble.backend.mysql.nio.MySQLConnection in project dble by actiontech.

the class MultiNodeMergeHandler method terminateThread.

@Override
protected void terminateThread() throws Exception {
    for (Entry<MySQLConnection, BlockingQueue<HeapItem>> entry : this.queues.entrySet()) {
        // add EOF to signal atoMerge thread
        entry.getValue().clear();
        entry.getValue().put(new HeapItem(null, null, entry.getKey()));
    }
    recycleConn();
}
Also used : BlockingQueue(java.util.concurrent.BlockingQueue) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) HeapItem(com.actiontech.dble.backend.mysql.nio.handler.util.HeapItem) MySQLConnection(com.actiontech.dble.backend.mysql.nio.MySQLConnection)

Example 30 with MySQLConnection

use of com.actiontech.dble.backend.mysql.nio.MySQLConnection in project dble by actiontech.

the class MultiNodeMergeHandler method ownThreadJob.

@Override
protected void ownThreadJob(Object... objects) {
    try {
        ArrayMinHeap<HeapItem> heap = new ArrayMinHeap<>(new Comparator<HeapItem>() {

            @Override
            public int compare(HeapItem o1, HeapItem o2) {
                RowDataPacket row1 = o1.getRowPacket();
                RowDataPacket row2 = o2.getRowPacket();
                if (row1 == null || row2 == null) {
                    if (row1 == row2)
                        return 0;
                    if (row1 == null)
                        return -1;
                    return 1;
                }
                return rowComparator.compare(row1, row2);
            }
        });
        // init heap
        for (Map.Entry<MySQLConnection, BlockingQueue<HeapItem>> entry : queues.entrySet()) {
            HeapItem firstItem = entry.getValue().take();
            heap.add(firstItem);
        }
        while (!heap.isEmpty()) {
            if (terminate.get())
                return;
            HeapItem top = heap.peak();
            if (top.isNullItem()) {
                heap.poll();
            } else {
                BlockingQueue<HeapItem> topItemQueue = queues.get(top.getIndex());
                HeapItem item = topItemQueue.take();
                heap.replaceTop(item);
                if (nextHandler.rowResponse(top.getRowData(), top.getRowPacket(), this.isLeft, top.getIndex())) {
                    noNeedRows = true;
                    while (!heap.isEmpty()) {
                        HeapItem itemToDiscard = heap.poll();
                        if (!itemToDiscard.isNullItem()) {
                            BlockingQueue<HeapItem> discardQueue = queues.get(itemToDiscard.getIndex());
                            while (true) {
                                if (discardQueue.take().isNullItem() || terminate.get()) {
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        }
        if (LOGGER.isInfoEnabled()) {
            String executeQueries = getRoutesSql(route);
            LOGGER.info(executeQueries + " heap send eof: ");
        }
        nextHandler.rowEofResponse(null, this.isLeft, queues.keySet().iterator().next());
    } catch (Exception e) {
        String msg = "Merge thread error, " + e.getLocalizedMessage();
        LOGGER.info(msg, e);
        session.onQueryError(msg.getBytes());
    }
}
Also used : BlockingQueue(java.util.concurrent.BlockingQueue) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) HeapItem(com.actiontech.dble.backend.mysql.nio.handler.util.HeapItem) ArrayMinHeap(com.actiontech.dble.backend.mysql.nio.handler.util.ArrayMinHeap) RowDataPacket(com.actiontech.dble.net.mysql.RowDataPacket) MySQLOutPutException(com.actiontech.dble.plan.common.exception.MySQLOutPutException) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) MySQLConnection(com.actiontech.dble.backend.mysql.nio.MySQLConnection)

Aggregations

MySQLConnection (com.actiontech.dble.backend.mysql.nio.MySQLConnection)34 BackendConnection (com.actiontech.dble.backend.BackendConnection)8 RowDataPacket (com.actiontech.dble.net.mysql.RowDataPacket)7 RouteResultsetNode (com.actiontech.dble.route.RouteResultsetNode)5 HeapItem (com.actiontech.dble.backend.mysql.nio.handler.util.HeapItem)4 NIOProcessor (com.actiontech.dble.net.NIOProcessor)4 PhysicalDBNode (com.actiontech.dble.backend.datasource.PhysicalDBNode)3 ErrorPacket (com.actiontech.dble.net.mysql.ErrorPacket)3 TwoTableComparator (com.actiontech.dble.backend.mysql.nio.handler.util.TwoTableComparator)2 LocalResult (com.actiontech.dble.backend.mysql.store.LocalResult)2 UnSortedLocalResult (com.actiontech.dble.backend.mysql.store.UnSortedLocalResult)2 MySQLOutPutException (com.actiontech.dble.plan.common.exception.MySQLOutPutException)2 Entry (java.util.Map.Entry)2 BlockingQueue (java.util.concurrent.BlockingQueue)2 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)2 PhysicalDBPool (com.actiontech.dble.backend.datasource.PhysicalDBPool)1 PhysicalDatasource (com.actiontech.dble.backend.datasource.PhysicalDatasource)1 ResetConnHandler (com.actiontech.dble.backend.mysql.nio.handler.ResetConnHandler)1 ArrayMinHeap (com.actiontech.dble.backend.mysql.nio.handler.util.ArrayMinHeap)1 TxState (com.actiontech.dble.backend.mysql.xa.TxState)1