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 };
}
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);
}
}
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);
}
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();
}
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();
}
Aggregations