Search in sources :

Example 31 with MySQLConnection

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

the class MultiNodeMergeHandler method execute.

public void execute() throws Exception {
    synchronized (exeHandlers) {
        if (terminate.get())
            return;
        for (BaseSelectHandler exeHandler : exeHandlers) {
            MySQLConnection exeConn = exeHandler.initConnection();
            if (exeConn != null) {
                exeConn.setComplexQuery(true);
                queues.put(exeConn, new LinkedBlockingQueue<HeapItem>(queueSize));
                exeHandler.execute(exeConn);
            }
        }
    }
}
Also used : HeapItem(com.actiontech.dble.backend.mysql.nio.handler.util.HeapItem) MySQLConnection(com.actiontech.dble.backend.mysql.nio.MySQLConnection)

Example 32 with MySQLConnection

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

the class OrderByHandler method ownThreadJob.

@Override
protected void ownThreadJob(Object... objects) {
    MySQLConnection conn = (MySQLConnection) objects[0];
    recordElapsedTime("order write start :");
    try {
        while (true) {
            if (terminate.get()) {
                return;
            }
            RowDataPacket row = null;
            try {
                row = queue.take();
            } catch (InterruptedException e) {
            // ignore error
            }
            if (row.getFieldCount() == 0) {
                break;
            }
            localResult.add(row);
        }
        recordElapsedTime("order write end :");
        localResult.done();
        recordElapsedTime("order read start :");
        while (true) {
            if (terminate.get()) {
                return;
            }
            RowDataPacket row = localResult.next();
            if (row == null) {
                break;
            }
            if (nextHandler.rowResponse(null, row, this.isLeft, conn))
                break;
        }
        recordElapsedTime("order read end:");
        nextHandler.rowEofResponse(null, this.isLeft, conn);
    } catch (Exception e) {
        String msg = "OrderBy thread 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 33 with MySQLConnection

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

the class ConnectionHeartBeatHandler method doHeartBeat.

public void doHeartBeat(BackendConnection conn) {
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("do heartbeat for con " + conn);
    }
    lock.lock();
    try {
        conn.setResponseHandler(this);
        MySQLConnection mCon = (MySQLConnection) conn;
        mCon.write(mCon.writeToBuffer(PingPacket.PING, mCon.allocate()));
        long validateTime = 2;
        if (!condition.await(validateTime, TimeUnit.SECONDS)) {
            // if the thread be waked up by timer than close the connection
            conn.close("heartbeat timeout ");
        }
    } catch (Exception e) {
        executeException(conn, e);
    } finally {
        lock.unlock();
    }
}
Also used : MySQLConnection(com.actiontech.dble.backend.mysql.nio.MySQLConnection)

Example 34 with MySQLConnection

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

the class KillConnectionHandler method connectionAcquired.

@Override
public void connectionAcquired(BackendConnection conn) {
    conn.setResponseHandler(this);
    conn.setSession(session);
    CommandPacket packet = new CommandPacket();
    packet.setPacketId(0);
    packet.setCommand(MySQLPacket.COM_QUERY);
    packet.setArg(("KILL " + toKilled.getThreadId()).getBytes());
    MySQLConnection mysqlCon = (MySQLConnection) conn;
    packet.write(mysqlCon);
}
Also used : 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