Search in sources :

Example 1 with BackendConnection

use of com.actiontech.dble.backend.BackendConnection in project dble by actiontech.

the class MultiNodeQueryHandler method execute.

public void execute() throws Exception {
    lock.lock();
    try {
        this.reset(rrs.getNodes().length);
        this.fieldsReturned = false;
        this.affectedRows = 0L;
        this.insertId = 0L;
    } finally {
        lock.unlock();
    }
    startTime = System.currentTimeMillis();
    LOGGER.debug("rrs.getRunOnSlave()-" + rrs.getRunOnSlave());
    StringBuilder sb = new StringBuilder();
    for (final RouteResultsetNode node : rrs.getNodes()) {
        if (node.isModifySQL()) {
            sb.append("[").append(node.getName()).append("]").append(node.getStatement()).append(";\n");
        }
    }
    if (sb.length() > 0) {
        TxnLogHelper.putTxnLog(session.getSource(), sb.toString());
    }
    for (final RouteResultsetNode node : rrs.getNodes()) {
        BackendConnection conn = session.getTarget(node);
        if (session.tryExistsCon(conn, node)) {
            node.setRunOnSlave(rrs.getRunOnSlave());
            innerExecute(conn, node);
        } else {
            // create new connection
            node.setRunOnSlave(rrs.getRunOnSlave());
            PhysicalDBNode dn = DbleServer.getInstance().getConfig().getDataNodes().get(node.getName());
            dn.getConnection(dn.getDatabase(), session.getSource().isTxStart(), sessionAutocommit, node, this, node);
        }
    }
    session.endDelive();
}
Also used : PhysicalDBNode(com.actiontech.dble.backend.datasource.PhysicalDBNode) BackendConnection(com.actiontech.dble.backend.BackendConnection) RouteResultsetNode(com.actiontech.dble.route.RouteResultsetNode)

Example 2 with BackendConnection

use of com.actiontech.dble.backend.BackendConnection in project dble by actiontech.

the class MultiNodeQueryHandler method handleDdl.

private void handleDdl() {
    if (rrs.getSqlType() != ServerParse.DDL || errConnection == null) {
        return;
    }
    StringBuilder s = new StringBuilder();
    s.append(rrs.toString());
    s.append(", failed={");
    for (int i = 0; i < errConnection.size(); i++) {
        BackendConnection conn = errConnection.get(i);
        s.append("\n ").append(FormatUtil.format(i + 1, 3));
        s.append(" -> ").append(conn.compactInfo());
    }
    s.append("\n}");
    LOGGER.warn(AlarmCode.CORE_DDL_WARN + s.toString());
}
Also used : BackendConnection(com.actiontech.dble.backend.BackendConnection)

Example 3 with BackendConnection

use of com.actiontech.dble.backend.BackendConnection 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 BackendConnection

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

Example 5 with BackendConnection

use of com.actiontech.dble.backend.BackendConnection in project dble by actiontech.

the class MultiNodeDdlHandler method execute.

public void execute() throws Exception {
    lock.lock();
    try {
        this.reset(rrs.getNodes().length);
    } finally {
        lock.unlock();
    }
    LOGGER.debug("rrs.getRunOnSlave()-" + rrs.getRunOnSlave());
    StringBuilder sb = new StringBuilder();
    for (final RouteResultsetNode node : rrs.getNodes()) {
        if (node.isModifySQL()) {
            sb.append("[").append(node.getName()).append("]").append(node.getStatement()).append(";\n");
        }
    }
    if (sb.length() > 0) {
        TxnLogHelper.putTxnLog(session.getSource(), sb.toString());
    }
    for (final RouteResultsetNode node : rrs.getNodes()) {
        BackendConnection conn = session.getTarget(node);
        if (session.tryExistsCon(conn, node)) {
            node.setRunOnSlave(rrs.getRunOnSlave());
            innerExecute(conn, node);
        } else {
            // create new connection
            node.setRunOnSlave(rrs.getRunOnSlave());
            PhysicalDBNode dn = DbleServer.getInstance().getConfig().getDataNodes().get(node.getName());
            dn.getConnection(dn.getDatabase(), true, sessionAutocommit, node, this, node);
        }
    }
}
Also used : PhysicalDBNode(com.actiontech.dble.backend.datasource.PhysicalDBNode) BackendConnection(com.actiontech.dble.backend.BackendConnection) RouteResultsetNode(com.actiontech.dble.route.RouteResultsetNode)

Aggregations

BackendConnection (com.actiontech.dble.backend.BackendConnection)29 RouteResultsetNode (com.actiontech.dble.route.RouteResultsetNode)12 MySQLConnection (com.actiontech.dble.backend.mysql.nio.MySQLConnection)8 PhysicalDBNode (com.actiontech.dble.backend.datasource.PhysicalDBNode)7 NIOProcessor (com.actiontech.dble.net.NIOProcessor)4 RowDataPacket (com.actiontech.dble.net.mysql.RowDataPacket)4 IOException (java.io.IOException)3 ServerConfig (com.actiontech.dble.config.ServerConfig)2 EOFPacket (com.actiontech.dble.net.mysql.EOFPacket)2 FieldPacket (com.actiontech.dble.net.mysql.FieldPacket)2 ServerConnection (com.actiontech.dble.server.ServerConnection)2 ByteBuffer (java.nio.ByteBuffer)2 Entry (java.util.Map.Entry)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 ConQueue (com.actiontech.dble.backend.ConQueue)1 PhysicalDBPool (com.actiontech.dble.backend.datasource.PhysicalDBPool)1 PhysicalDatasource (com.actiontech.dble.backend.datasource.PhysicalDatasource)1 GetConnectionHandler (com.actiontech.dble.backend.mysql.nio.handler.GetConnectionHandler)1 NewConnectionRespHandler (com.actiontech.dble.backend.mysql.nio.handler.NewConnectionRespHandler)1 ArrayMinHeap (com.actiontech.dble.backend.mysql.nio.handler.util.ArrayMinHeap)1