Search in sources :

Example 6 with RouteResultsetNode

use of com.actiontech.dble.route.RouteResultsetNode 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 7 with RouteResultsetNode

use of com.actiontech.dble.route.RouteResultsetNode 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)

Example 8 with RouteResultsetNode

use of com.actiontech.dble.route.RouteResultsetNode in project dble by actiontech.

the class MySQLConnection method query.

/**
 * by wuzh ,execute a query and ignore transaction settings for performance
 */
public void query(String query) {
    RouteResultsetNode rrn = new RouteResultsetNode("default", ServerParse.SELECT, query);
    synAndDoExecute(null, rrn, this.charsetName, this.txIsolation, true, this.getUsrVariables(), this.getSysVariables());
}
Also used : RouteResultsetNode(com.actiontech.dble.route.RouteResultsetNode)

Example 9 with RouteResultsetNode

use of com.actiontech.dble.route.RouteResultsetNode in project dble by actiontech.

the class NormalAutoRollbackNodesHandler method rollback.

@Override
public void rollback() {
    if (errConnection != null && nodes.length == errConnection.size()) {
        for (BackendConnection conn : errConnection) {
            conn.quit();
        }
        errConnection.clear();
        session.getSource().write(sendData);
        return;
    }
    if (errConnection != null && errConnection.size() > 0) {
        for (RouteResultsetNode node : nodes) {
            final BackendConnection conn = session.getTarget(node);
            if (errConnection.contains(conn)) {
                session.getTargetMap().remove(node);
                conn.quit();
            }
        }
        errConnection.clear();
    }
    super.rollback();
}
Also used : BackendConnection(com.actiontech.dble.backend.BackendConnection) RouteResultsetNode(com.actiontech.dble.route.RouteResultsetNode)

Example 10 with RouteResultsetNode

use of com.actiontech.dble.route.RouteResultsetNode in project dble by actiontech.

the class XAAutoRollbackNodesHandler method rollback.

@Override
public void rollback() {
    if (errConnection != null && nodes.length == errConnection.size()) {
        for (BackendConnection conn : errConnection) {
            conn.quit();
        }
        errConnection.clear();
        session.getSource().write(sendData);
        return;
    }
    if (errConnection != null && errConnection.size() > 0) {
        for (RouteResultsetNode node : nodes) {
            final BackendConnection conn = session.getTarget(node);
            if (errConnection.contains(conn)) {
                session.getTargetMap().remove(node);
                conn.quit();
            }
        }
        errConnection.clear();
    }
    super.rollback();
}
Also used : BackendConnection(com.actiontech.dble.backend.BackendConnection) RouteResultsetNode(com.actiontech.dble.route.RouteResultsetNode)

Aggregations

RouteResultsetNode (com.actiontech.dble.route.RouteResultsetNode)48 BackendConnection (com.actiontech.dble.backend.BackendConnection)12 PhysicalDBNode (com.actiontech.dble.backend.datasource.PhysicalDBNode)9 RouteResultset (com.actiontech.dble.route.RouteResultset)8 TableConfig (com.actiontech.dble.config.model.TableConfig)6 SQLNonTransientException (java.sql.SQLNonTransientException)6 MySQLConnection (com.actiontech.dble.backend.mysql.nio.MySQLConnection)5 MySQLOutPutException (com.actiontech.dble.plan.common.exception.MySQLOutPutException)5 PushDownVisitor (com.actiontech.dble.backend.mysql.nio.handler.builder.sqlvisitor.PushDownVisitor)4 AbstractPartitionAlgorithm (com.actiontech.dble.route.function.AbstractPartitionAlgorithm)4 SQLExpr (com.alibaba.druid.sql.ast.SQLExpr)4 ServerConfig (com.actiontech.dble.config.ServerConfig)3 SchemaConfig (com.actiontech.dble.config.model.SchemaConfig)3 RouteCalculateUnit (com.actiontech.dble.route.parser.druid.RouteCalculateUnit)3 LoadData (com.actiontech.dble.sqlengine.mpp.LoadData)3 LayerCachePool (com.actiontech.dble.cache.LayerCachePool)2 DruidShardingParseInfo (com.actiontech.dble.route.parser.druid.DruidShardingParseInfo)2 SQLException (java.sql.SQLException)2 SQLSyntaxErrorException (java.sql.SQLSyntaxErrorException)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2