Search in sources :

Example 21 with RouteResultsetNode

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

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

the class FetchMySQLSequenceHandler method execute.

public void execute(SequenceVal seqVal) {
    ServerConfig conf = DbleServer.getInstance().getConfig();
    PhysicalDBNode mysqlDN = conf.getDataNodes().get(seqVal.dataNode);
    try {
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("execute in data node " + seqVal.dataNode + " for fetch sequence sql " + seqVal.sql);
        }
        // change Select mode to Update mode. Make sure the query send to the write host
        mysqlDN.getConnection(mysqlDN.getDatabase(), true, true, new RouteResultsetNode(seqVal.dataNode, ServerParse.UPDATE, seqVal.sql), this, seqVal);
    } catch (Exception e) {
        LOGGER.info("get connection err " + e);
    }
}
Also used : PhysicalDBNode(com.actiontech.dble.backend.datasource.PhysicalDBNode) ServerConfig(com.actiontech.dble.config.ServerConfig) RouteResultsetNode(com.actiontech.dble.route.RouteResultsetNode)

Example 23 with RouteResultsetNode

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

the class DruidSelectParser method tryRouteSingleTable.

private void tryRouteSingleTable(SchemaConfig schema, RouteResultset rrs, LayerCachePool cachePool) throws SQLException {
    if (rrs.isFinishedRoute()) {
        return;
    }
    SortedSet<RouteResultsetNode> nodeSet = new TreeSet<>();
    String table = ctx.getTables().get(0);
    if (RouterUtil.isNoSharding(schema, table)) {
        RouterUtil.routeToSingleNode(rrs, schema.getDataNode());
        return;
    }
    for (RouteCalculateUnit unit : ctx.getRouteCalculateUnits()) {
        RouteResultset rrsTmp = RouterUtil.tryRouteForOneTable(schema, unit, table, rrs, true, cachePool);
        if (rrsTmp != null && rrsTmp.getNodes() != null) {
            Collections.addAll(nodeSet, rrsTmp.getNodes());
            if (rrsTmp.isGlobalTable()) {
                break;
            }
        }
    }
    if (nodeSet.size() == 0) {
        String msg = " find no Route:" + rrs.getStatement();
        LOGGER.info(msg);
        throw new SQLNonTransientException(msg);
    }
    RouteResultsetNode[] nodes = new RouteResultsetNode[nodeSet.size()];
    int i = 0;
    for (RouteResultsetNode aNodeSet : nodeSet) {
        nodes[i] = aNodeSet;
        i++;
    }
    rrs.setNodes(nodes);
    rrs.setFinishedRoute(true);
}
Also used : RouteCalculateUnit(com.actiontech.dble.route.parser.druid.RouteCalculateUnit) SQLNonTransientException(java.sql.SQLNonTransientException) RouteResultsetNode(com.actiontech.dble.route.RouteResultsetNode) RouteResultset(com.actiontech.dble.route.RouteResultset)

Example 24 with RouteResultsetNode

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

the class AbstractCommitNodesHandler method commit.

@Override
public void commit() {
    final int initCount = session.getTargetCount();
    lock.lock();
    try {
        reset(initCount);
    } finally {
        lock.unlock();
    }
    int position = 0;
    // then the XA transaction will be not killed, if killed ,then we will not commit
    if (session.getXaState() != null && session.getXaState() == TxState.TX_ENDED_STATE) {
        if (!session.cancelableStatusSet(NonBlockingSession.CANCEL_STATUS_COMMITTING)) {
            return;
        }
    }
    try {
        sendFinishedFlag = false;
        for (RouteResultsetNode rrn : session.getTargetKeys()) {
            final BackendConnection conn = session.getTarget(rrn);
            conn.setResponseHandler(this);
            if (!executeCommit((MySQLConnection) conn, position++)) {
                break;
            }
        }
    } finally {
        lockForErrorHandle.lock();
        try {
            sendFinishedFlag = true;
            sendFinished.signalAll();
        } finally {
            lockForErrorHandle.unlock();
        }
    }
}
Also used : BackendConnection(com.actiontech.dble.backend.BackendConnection) RouteResultsetNode(com.actiontech.dble.route.RouteResultsetNode) MySQLConnection(com.actiontech.dble.backend.mysql.nio.MySQLConnection)

Example 25 with RouteResultsetNode

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

the class NormalRollbackNodesHandler method rollback.

public void rollback() {
    final int initCount = session.getTargetCount();
    lock.lock();
    try {
        reset(initCount);
    } finally {
        lock.unlock();
    }
    int position = 0;
    for (final RouteResultsetNode node : session.getTargetKeys()) {
        final BackendConnection conn = session.getTarget(node);
        if (conn.isClosed()) {
            lock.lock();
            try {
                nodeCount--;
            } finally {
                lock.unlock();
            }
            continue;
        }
        position++;
        conn.setResponseHandler(this);
        conn.rollback();
    }
    if (position == 0) {
        if (sendData == null) {
            sendData = OkPacket.OK;
        }
        cleanAndFeedback();
    }
}
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