use of com.actiontech.dble.config.model.SchemaConfig in project dble by actiontech.
the class DruidMysqlSqlParserTest method testLockTableSql.
@Test
public void testLockTableSql() throws SQLException {
String sql = "lock tables goods write";
SchemaConfig schema = schemaMap.get("TESTDB");
RouteResultset rrs = routeStrategy.route(schema, ServerParse.LOCK, sql, null, cachePool);
Assert.assertEquals(3, rrs.getNodes().length);
}
use of com.actiontech.dble.config.model.SchemaConfig in project dble by actiontech.
the class MyOptimizer method checkGlobalTable.
/**
* existShardTable
*
* @param node
* @return return 1 if it's all no name table or all global table node;
* return -1 if all the table is not global table,need not global optimizer;
* return 0 for other ,may need to global optimizer ;
*/
public static int checkGlobalTable(PlanNode node, Set<String> resultDataNodes) {
if (node.isSubQuery()) {
return 0;
}
Set<String> dataNodes = null;
boolean isAllGlobal = true;
boolean isContainGlobal = false;
for (TableNode tn : node.getReferedTableNodes()) {
if (tn.getUnGlobalTableCount() == 0) {
isContainGlobal = true;
if (isAllGlobal) {
if (dataNodes == null) {
dataNodes = new HashSet<>();
dataNodes.addAll(tn.getNoshardNode());
} else {
dataNodes.retainAll(tn.getNoshardNode());
}
} else {
return 0;
}
} else {
isAllGlobal = false;
if (isContainGlobal) {
return 0;
}
}
}
if (isAllGlobal) {
if (dataNodes == null) {
// all nonamenode
String db = SchemaUtil.getRandomDb();
SchemaConfig schemaConfig = DbleServer.getInstance().getConfig().getSchemas().get(db);
node.setNoshardNode(schemaConfig.getAllDataNodes());
resultDataNodes.addAll(schemaConfig.getAllDataNodes());
return 1;
} else if (dataNodes.size() > 0) {
// all global table
node.setNoshardNode(dataNodes);
resultDataNodes.addAll(dataNodes);
String sql = node.getSql();
for (TableNode tn : node.getReferedTableNodes()) {
sql = RouterUtil.removeSchema(sql, tn.getSchema());
}
node.setSql(sql);
return 1;
} else {
return 0;
}
}
return -1;
}
use of com.actiontech.dble.config.model.SchemaConfig in project dble by actiontech.
the class NoShardingSpace method testDefaultSpace.
public void testDefaultSpace() throws SQLException {
SchemaConfig schema = this.schema;
String stmt = "insert into offer (member_id, gmt_create) values ('1','2001-09-13 20:20:33')";
for (int i = 0; i < total; i++) {
RouteStrategyFactory.getRouteStrategy().route(schema, -1, stmt, null, cachePool);
}
}
use of com.actiontech.dble.config.model.SchemaConfig in project dble by actiontech.
the class ShardingMultiTableSpace method testTableSpace.
/**
* @throws SQLNonTransientException
*/
public void testTableSpace() throws SQLException {
SchemaConfig schema = getSchema();
String sql = "select id,member_id,gmt_create from offer where member_id in ('1','22','333','1124','4525')";
for (int i = 0; i < total; i++) {
RouteStrategyFactory.getRouteStrategy().route(schema, -1, sql, null, cachePool);
}
}
use of com.actiontech.dble.config.model.SchemaConfig in project dble by actiontech.
the class ShowTables method response.
public static void response(ServerConnection c, String stmt) {
ShowCreateStmtInfo info;
try {
info = new ShowCreateStmtInfo(stmt);
} catch (Exception e) {
c.writeErrMessage(ErrorCode.ER_PARSE_ERROR, e.toString());
return;
}
String showSchema = info.getSchema();
if (showSchema != null && DbleServer.getInstance().getSystemVariables().isLowerCaseTableNames()) {
showSchema = showSchema.toLowerCase();
}
String cSchema = showSchema == null ? c.getSchema() : showSchema;
if (cSchema == null) {
c.writeErrMessage("3D000", "No database selected", ErrorCode.ER_NO_DB_ERROR);
return;
}
SchemaConfig schema = DbleServer.getInstance().getConfig().getSchemas().get(cSchema);
if (schema == null) {
c.writeErrMessage("42000", "Unknown database '" + cSchema + "'", ErrorCode.ER_BAD_DB_ERROR);
return;
}
ServerConfig conf = DbleServer.getInstance().getConfig();
UserConfig user = conf.getUsers().get(c.getUser());
if (user == null || !user.getSchemas().contains(cSchema)) {
c.writeErrMessage("42000", "Access denied for user '" + c.getUser() + "' to database '" + cSchema + "'", ErrorCode.ER_DBACCESS_DENIED_ERROR);
return;
}
// if schema has default node ,show tables will send to backend
String node = schema.getDataNode();
if (!Strings.isNullOrEmpty(node)) {
try {
parserAndExecuteShowTables(c, stmt, node, info);
} catch (Exception e) {
c.writeErrMessage(ErrorCode.ER_PARSE_ERROR, e.toString());
}
} else {
responseDirect(c, cSchema, info);
}
}
Aggregations