Search in sources :

Example 11 with MySQLConnection

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

the class ShowBackendOld method getRow.

private static RowDataPacket getRow(BackendConnection c, String charset) {
    RowDataPacket row = new RowDataPacket(FIELD_COUNT);
    row.add(LongUtil.toBytes(c.getId()));
    long threadId = 0;
    if (c instanceof MySQLConnection) {
        threadId = ((MySQLConnection) c).getThreadId();
    }
    row.add(LongUtil.toBytes(threadId));
    row.add(StringUtil.encode(c.getHost(), charset));
    row.add(IntegerUtil.toBytes(c.getPort()));
    row.add(IntegerUtil.toBytes(c.getLocalPort()));
    row.add(LongUtil.toBytes(c.getNetInBytes()));
    row.add(LongUtil.toBytes(c.getNetOutBytes()));
    row.add(LongUtil.toBytes((TimeUtil.currentTimeMillis() - c.getStartupTime()) / 1000L));
    row.add(LongUtil.toBytes(c.getLastTime()));
    boolean isBorrowed = c.isBorrowed();
    row.add(isBorrowed ? "true".getBytes() : "false".getBytes());
    return row;
}
Also used : RowDataPacket(com.actiontech.dble.net.mysql.RowDataPacket) MySQLConnection(com.actiontech.dble.backend.mysql.nio.MySQLConnection)

Example 12 with MySQLConnection

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

the class ConMap method clearConnections.

public void clearConnections(String reason, PhysicalDatasource dataSource) {
    for (NIOProcessor processor : DbleServer.getInstance().getBackendProcessors()) {
        ConcurrentMap<Long, BackendConnection> map = processor.getBackends();
        Iterator<Entry<Long, BackendConnection>> iterator = map.entrySet().iterator();
        while (iterator.hasNext()) {
            Entry<Long, BackendConnection> entry = iterator.next();
            BackendConnection con = entry.getValue();
            if (con instanceof MySQLConnection) {
                if (((MySQLConnection) con).getPool() == dataSource) {
                    con.close(reason);
                    iterator.remove();
                }
            }
        }
    }
    items.clear();
}
Also used : Entry(java.util.Map.Entry) NIOProcessor(com.actiontech.dble.net.NIOProcessor) MySQLConnection(com.actiontech.dble.backend.mysql.nio.MySQLConnection)

Example 13 with MySQLConnection

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

the class NIOProcessor method backendCheck.

private void backendCheck() {
    long sqlTimeout = DbleServer.getInstance().getConfig().getSystem().getSqlExecuteTimeout() * 1000L;
    Iterator<Entry<Long, BackendConnection>> it = backends.entrySet().iterator();
    while (it.hasNext()) {
        BackendConnection c = it.next().getValue();
        // remove empty
        if (c == null) {
            it.remove();
            continue;
        }
        // Active/IDLE/PREPARED XA backends will not be checked
        if (c instanceof MySQLConnection) {
            MySQLConnection m = (MySQLConnection) c;
            if (m.isClosedOrQuit()) {
                it.remove();
                continue;
            }
            if (m.getXaStatus() != null && m.getXaStatus() != TxState.TX_INITIALIZE_STATE) {
                continue;
            }
        }
        // close the conn which executeTimeOut
        if (!c.isDDL() && c.isBorrowed() && c.getLastTime() < TimeUtil.currentTimeMillis() - sqlTimeout) {
            LOGGER.info("found backend connection SQL timeout ,close it " + c);
            c.close("sql timeout");
        }
        // clean closed conn or check time out
        if (c.isClosed()) {
            it.remove();
        } else {
            // very important ,for some data maybe not sent
            if (c instanceof AbstractConnection) {
                checkConSendQueue((AbstractConnection) c);
            }
            c.idleCheck();
        }
    }
}
Also used : Entry(java.util.Map.Entry) BackendConnection(com.actiontech.dble.backend.BackendConnection) MySQLConnection(com.actiontech.dble.backend.mysql.nio.MySQLConnection)

Example 14 with MySQLConnection

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

the class NonBlockingSession method freshConn.

public MySQLConnection freshConn(MySQLConnection errConn, ResponseHandler queryHandler) {
    for (final RouteResultsetNode node : this.getTargetKeys()) {
        final MySQLConnection mysqlCon = (MySQLConnection) this.getTarget(node);
        if (errConn.equals(mysqlCon)) {
            ServerConfig conf = DbleServer.getInstance().getConfig();
            PhysicalDBNode dn = conf.getDataNodes().get(node.getName());
            try {
                MySQLConnection newConn = (MySQLConnection) dn.getConnection(dn.getDatabase(), errConn.isAutocommit(), false);
                newConn.setXaStatus(errConn.getXaStatus());
                if (!newConn.setResponseHandler(queryHandler)) {
                    return errConn;
                }
                this.bindConnection(node, newConn);
                return newConn;
            } catch (Exception e) {
                return errConn;
            }
        }
    }
    return errConn;
}
Also used : PhysicalDBNode(com.actiontech.dble.backend.datasource.PhysicalDBNode) ServerConfig(com.actiontech.dble.config.ServerConfig) RouteResultsetNode(com.actiontech.dble.route.RouteResultsetNode) SQLSyntaxErrorException(java.sql.SQLSyntaxErrorException) MySQLOutPutException(com.actiontech.dble.plan.common.exception.MySQLOutPutException) MySQLConnection(com.actiontech.dble.backend.mysql.nio.MySQLConnection)

Example 15 with MySQLConnection

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

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