Search in sources :

Example 1 with RouteResultsetNode

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

the class BaseHandlerBuilder method getTableSources.

protected RouteResultsetNode[] getTableSources(Set<String> dataNodes, String sql) {
    String randomDatenode = null;
    int index = (int) (System.currentTimeMillis() % dataNodes.size());
    int i = 0;
    for (String dataNode : dataNodes) {
        if (index == i) {
            randomDatenode = dataNode;
            break;
        }
        i++;
    }
    RouteResultsetNode rrss = new RouteResultsetNode(randomDatenode, ServerParse.SELECT, sql);
    return new RouteResultsetNode[] { rrss };
}
Also used : RouteResultsetNode(com.actiontech.dble.route.RouteResultsetNode)

Example 2 with RouteResultsetNode

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

the class JoinNodeHandlerBuilder method mergeBuild.

@Override
public void mergeBuild() {
    try {
        this.needWhereHandler = false;
        this.canPushDown = !node.existUnPushDownGroup();
        PushDownVisitor pdVisitor = new PushDownVisitor(node, true);
        MergeBuilder mergeBuilder = new MergeBuilder(session, node, needCommon, pdVisitor);
        String sql = null;
        if (node.getAst() != null && node.getParent() == null) {
            // it's root
            pdVisitor.visit();
            sql = pdVisitor.getSql().toString();
        }
        RouteResultsetNode[] rrssArray;
        // maybe some node is view
        if (sql == null) {
            rrssArray = mergeBuilder.construct().getNodes();
        } else {
            rrssArray = mergeBuilder.constructByStatement(sql, node.getAst()).getNodes();
        }
        this.needCommon = mergeBuilder.getNeedCommonFlag();
        buildMergeHandler(node, rrssArray);
    } catch (Exception e) {
        throw new MySQLOutPutException(ErrorCode.ER_QUERYHANDLER, "", "join node mergebuild exception!", e);
    }
}
Also used : RouteResultsetNode(com.actiontech.dble.route.RouteResultsetNode) PushDownVisitor(com.actiontech.dble.backend.mysql.nio.handler.builder.sqlvisitor.PushDownVisitor) ItemString(com.actiontech.dble.plan.common.item.ItemString) MySQLOutPutException(com.actiontech.dble.plan.common.exception.MySQLOutPutException) MySQLOutPutException(com.actiontech.dble.plan.common.exception.MySQLOutPutException)

Example 3 with RouteResultsetNode

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

the class NoNameNodeHandlerBuilder method buildOwn.

@Override
public void buildOwn() {
    PushDownVisitor visitor = new PushDownVisitor(node, true);
    visitor.visit();
    this.canPushDown = true;
    String sql = visitor.getSql().toString();
    String schema = session.getSource().getSchema();
    SchemaConfig schemaConfig = schemaConfigMap.get(schema);
    RouteResultsetNode[] rrss = getTableSources(schemaConfig.getAllDataNodes(), sql);
    hBuilder.checkRRSs(rrss);
    MultiNodeMergeHandler mh = new MultiNodeMergeHandler(getSequenceId(), rrss, session.getSource().isAutocommit() && !session.getSource().isTxStart(), session, null);
    addHandler(mh);
}
Also used : SchemaConfig(com.actiontech.dble.config.model.SchemaConfig) RouteResultsetNode(com.actiontech.dble.route.RouteResultsetNode) MultiNodeMergeHandler(com.actiontech.dble.backend.mysql.nio.handler.query.impl.MultiNodeMergeHandler) PushDownVisitor(com.actiontech.dble.backend.mysql.nio.handler.builder.sqlvisitor.PushDownVisitor)

Example 4 with RouteResultsetNode

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

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

the class MultiNodeMergeHandler method getRoutesSql.

private String getRoutesSql(RouteResultsetNode[] nodes) {
    StringBuilder sb = new StringBuilder();
    sb.append('{');
    Map<String, List<RouteResultsetNode>> sqlMap = new HashMap<>();
    for (RouteResultsetNode rrss : nodes) {
        String sql = rrss.getStatement();
        if (!sqlMap.containsKey(sql)) {
            List<RouteResultsetNode> rrssList = new ArrayList<>();
            rrssList.add(rrss);
            sqlMap.put(sql, rrssList);
        } else {
            List<RouteResultsetNode> rrssList = sqlMap.get(sql);
            rrssList.add(rrss);
        }
    }
    for (Map.Entry<String, List<RouteResultsetNode>> entry : sqlMap.entrySet()) {
        sb.append(entry.getKey()).append(entry.getValue()).append(';');
    }
    sb.append('}');
    return sb.toString();
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) RouteResultsetNode(com.actiontech.dble.route.RouteResultsetNode) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

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