Search in sources :

Example 1 with MySQLConnection

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

the class ResetConnHandler method okResponse.

@Override
public void okResponse(byte[] ok, BackendConnection conn) {
    MySQLConnection mysqlConn = (MySQLConnection) conn;
    mysqlConn.resetContextStatus();
    conn.release();
}
Also used : MySQLConnection(com.actiontech.dble.backend.mysql.nio.MySQLConnection)

Example 2 with MySQLConnection

use of com.actiontech.dble.backend.mysql.nio.MySQLConnection 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 3 with MySQLConnection

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

the class BaseSelectHandler method initConnection.

public MySQLConnection initConnection() throws Exception {
    if (session.closed()) {
        return null;
    }
    MySQLConnection exeConn = (MySQLConnection) session.getTarget(rrss);
    if (session.tryExistsCon(exeConn, rrss)) {
        return exeConn;
    } else {
        PhysicalDBNode dn = DbleServer.getInstance().getConfig().getDataNodes().get(rrss.getName());
        // autocommit is session.getSource().isAutocommit() && !session.getSource().isTxStart()
        final BackendConnection newConn = dn.getConnection(dn.getDatabase(), autocommit, autocommit);
        session.bindConnection(rrss, newConn);
        return (MySQLConnection) newConn;
    }
}
Also used : PhysicalDBNode(com.actiontech.dble.backend.datasource.PhysicalDBNode) BackendConnection(com.actiontech.dble.backend.BackendConnection) MySQLConnection(com.actiontech.dble.backend.mysql.nio.MySQLConnection)

Example 4 with MySQLConnection

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

the class MultiNodeMergeHandler method rowResponse.

@Override
public boolean rowResponse(byte[] row, RowDataPacket rowPacket, boolean isLeft, BackendConnection conn) {
    if (terminate.get() || noNeedRows)
        return true;
    if (isEasyMerge) {
        nextHandler.rowResponse(null, rowPacket, this.isLeft, conn);
    } else {
        MySQLConnection mySQLConn = (MySQLConnection) conn;
        BlockingQueue<HeapItem> queue = queues.get(mySQLConn);
        if (queue == null)
            return true;
        HeapItem item = new HeapItem(row, rowPacket, mySQLConn);
        try {
            queue.put(item);
        } catch (InterruptedException e) {
        // ignore error
        }
    }
    return false;
}
Also used : HeapItem(com.actiontech.dble.backend.mysql.nio.handler.util.HeapItem) MySQLConnection(com.actiontech.dble.backend.mysql.nio.MySQLConnection)

Example 5 with MySQLConnection

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

the class FetchStoreNodeOfChildTableHandler method execute.

public String execute(String schema, ArrayList<String> dataNodes) {
    String key = schema + ":" + sql;
    CachePool cache = DbleServer.getInstance().getCacheService().getCachePool("ER_SQL2PARENTID");
    if (cache != null) {
        String cacheResult = (String) cache.get(key);
        if (cacheResult != null) {
            return cacheResult;
        }
    }
    int totalCount = dataNodes.size();
    LOGGER.debug("find child node with sql:" + sql);
    for (String dn : dataNodes) {
        if (!LOGGER.isDebugEnabled()) {
            // no early return when debug
            if (dataNode != null) {
                LOGGER.debug(" found return ");
                return dataNode;
            }
        }
        PhysicalDBNode mysqlDN = DbleServer.getInstance().getConfig().getDataNodes().get(dn);
        try {
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("execute in data_node " + dn);
            }
            RouteResultsetNode node = new RouteResultsetNode(dn, ServerParse.SELECT, sql);
            // get child node from master
            node.setRunOnSlave(false);
            BackendConnection conn = session.getTarget(node);
            if (session.tryExistsCon(conn, node)) {
                if (session.closed()) {
                    session.clearResources(true);
                    return null;
                }
                conn.setResponseHandler(this);
                conn.setSession(session);
                ((MySQLConnection) conn).setComplexQuery(true);
                conn.execute(node, session.getSource(), isAutoCommit());
            } else {
                mysqlDN.getConnection(mysqlDN.getDatabase(), session.getSource().isTxStart(), session.getSource().isAutocommit(), node, this, node);
            }
        } catch (Exception e) {
            LOGGER.info("get connection err " + e);
        }
    }
    lock.lock();
    try {
        while (dataNode == null) {
            try {
                result.await(50, TimeUnit.MILLISECONDS);
            } catch (InterruptedException e) {
                break;
            }
            if (dataNode != null || finished.get() >= totalCount) {
                break;
            }
        }
    } finally {
        lock.unlock();
    }
    if (!LOGGER.isDebugEnabled()) {
        // no cached when debug
        if (dataNode != null && cache != null) {
            cache.putIfAbsent(key, dataNode);
        }
    }
    return dataNode;
}
Also used : PhysicalDBNode(com.actiontech.dble.backend.datasource.PhysicalDBNode) BackendConnection(com.actiontech.dble.backend.BackendConnection) RouteResultsetNode(com.actiontech.dble.route.RouteResultsetNode) CachePool(com.actiontech.dble.cache.CachePool) 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