use of com.actiontech.dble.route.RouteResultset in project dble by actiontech.
the class ShowTables method parserAndExecuteShowTables.
private static void parserAndExecuteShowTables(ServerConnection c, String originSql, String node, ShowCreateStmtInfo info) throws Exception {
RouteResultset rrs = new RouteResultset(originSql, ServerParse.SHOW);
if (info.getSchema() != null) {
StringBuilder sql = new StringBuilder();
sql.append("SHOW ");
if (info.isFull()) {
sql.append("FULL ");
}
sql.append("TABLES ");
if (info.getCond() != null) {
sql.append(info.getCond());
}
rrs.setStatement(sql.toString());
}
RouterUtil.routeToSingleNode(rrs, node);
ShowTablesHandler showTablesHandler = new ShowTablesHandler(rrs, c.getSession2(), info);
showTablesHandler.execute();
}
use of com.actiontech.dble.route.RouteResultset in project dble by actiontech.
the class HintMasterDBHandler method route.
@Override
public RouteResultset route(SchemaConfig schema, int sqlType, String realSQL, ServerConnection sc, LayerCachePool cachePool, String hintSQLValue, int hintSqlType, Map hintMap) throws SQLException {
RouteResultset rrs = RouteStrategyFactory.getRouteStrategy().route(schema, sqlType, realSQL, sc, cachePool);
// master
LOGGER.debug("schema.rrs(): " + rrs);
Boolean isRouteToMaster = null;
// slave
LOGGER.debug("hintSQLValue:::::::::" + hintSQLValue);
if (hintSQLValue != null && !hintSQLValue.trim().equals("")) {
if (hintSQLValue.trim().equalsIgnoreCase("master")) {
isRouteToMaster = true;
}
if (hintSQLValue.trim().equalsIgnoreCase("slave")) {
if (sqlType == ServerParse.DELETE || sqlType == ServerParse.INSERT || sqlType == ServerParse.REPLACE || sqlType == ServerParse.UPDATE || sqlType == ServerParse.DDL) {
LOGGER.info("should not use hint 'db_type' to route 'delete', 'insert', 'replace', 'update', 'ddl' to a slave db.");
isRouteToMaster = null;
} else {
isRouteToMaster = false;
}
}
}
if (isRouteToMaster == null) {
LOGGER.info(" sql hint 'db_type' error, ignore this hint.");
return rrs;
}
if (isRouteToMaster) {
rrs.setRunOnSlave(false);
}
if (!isRouteToMaster) {
rrs.setRunOnSlave(true);
}
LOGGER.debug("rrs.getRunOnSlave():" + rrs.getRunOnSlave());
return rrs;
}
use of com.actiontech.dble.route.RouteResultset in project dble by actiontech.
the class HintDataNodeHandler method route.
@Override
public RouteResultset route(SchemaConfig schema, int sqlType, String realSQL, ServerConnection sc, LayerCachePool cachePool, String hintSQLValue, int hintSqlType, Map hintMap) throws SQLNonTransientException {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("route datanode sql hint from " + realSQL);
}
RouteResultset rrs = new RouteResultset(realSQL, sqlType);
PhysicalDBNode dataNode = DbleServer.getInstance().getConfig().getDataNodes().get(hintSQLValue);
if (dataNode != null) {
rrs = RouterUtil.routeToSingleNode(rrs, dataNode.getName());
} else {
String msg = "can't find hint datanode:" + hintSQLValue;
LOGGER.info(msg);
throw new SQLNonTransientException(msg);
}
return rrs;
}
use of com.actiontech.dble.route.RouteResultset in project dble by actiontech.
the class ServerConnection method routeSystemInfoAndExecuteSQL.
public void routeSystemInfoAndExecuteSQL(String stmt, SchemaUtil.SchemaInfo schemaInfo, int sqlType) {
ServerConfig conf = DbleServer.getInstance().getConfig();
UserConfig user = conf.getUsers().get(this.getUser());
if (user == null || !user.getSchemas().contains(schemaInfo.getSchema())) {
writeErrMessage("42000", "Access denied for user '" + this.getUser() + "' to database '" + schemaInfo.getSchema() + "'", ErrorCode.ER_DBACCESS_DENIED_ERROR);
return;
}
RouteResultset rrs = new RouteResultset(stmt, sqlType);
try {
if (RouterUtil.isNoSharding(schemaInfo.getSchemaConfig(), schemaInfo.getTable())) {
RouterUtil.routeToSingleNode(rrs, schemaInfo.getSchemaConfig().getDataNode());
} else {
TableConfig tc = schemaInfo.getSchemaConfig().getTables().get(schemaInfo.getTable());
if (tc == null) {
String msg = "Table '" + schemaInfo.getSchema() + "." + schemaInfo.getTable() + "' doesn't exist";
writeErrMessage("42S02", msg, ErrorCode.ER_NO_SUCH_TABLE);
return;
}
RouterUtil.routeToRandomNode(rrs, schemaInfo.getSchemaConfig(), schemaInfo.getTable());
}
session.execute(rrs);
} catch (Exception e) {
executeException(e, stmt);
}
}
use of com.actiontech.dble.route.RouteResultset 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);
}
Aggregations