Search in sources :

Example 31 with SchemaConfig

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);
}
Also used : SchemaConfig(com.actiontech.dble.config.model.SchemaConfig) Test(org.junit.Test)

Example 32 with SchemaConfig

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;
}
Also used : SchemaConfig(com.actiontech.dble.config.model.SchemaConfig) TableNode(com.actiontech.dble.plan.node.TableNode)

Example 33 with SchemaConfig

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);
    }
}
Also used : SchemaConfig(com.actiontech.dble.config.model.SchemaConfig)

Example 34 with SchemaConfig

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);
    }
}
Also used : SchemaConfig(com.actiontech.dble.config.model.SchemaConfig)

Example 35 with SchemaConfig

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);
    }
}
Also used : ServerConfig(com.actiontech.dble.config.ServerConfig) SchemaConfig(com.actiontech.dble.config.model.SchemaConfig) UserConfig(com.actiontech.dble.config.model.UserConfig)

Aggregations

SchemaConfig (com.actiontech.dble.config.model.SchemaConfig)70 TableConfig (com.actiontech.dble.config.model.TableConfig)16 SQLNonTransientException (java.sql.SQLNonTransientException)16 Test (org.junit.Test)15 RouteResultset (com.actiontech.dble.route.RouteResultset)6 PhysicalDBNode (com.actiontech.dble.backend.datasource.PhysicalDBNode)5 ServerConfig (com.actiontech.dble.config.ServerConfig)5 UserConfig (com.actiontech.dble.config.model.UserConfig)5 SQLStatement (com.alibaba.druid.sql.ast.SQLStatement)5 MySqlStatementParser (com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser)5 CacheService (com.actiontech.dble.cache.CacheService)4 EOFPacket (com.actiontech.dble.net.mysql.EOFPacket)4 FieldPacket (com.actiontech.dble.net.mysql.FieldPacket)4 RowDataPacket (com.actiontech.dble.net.mysql.RowDataPacket)4 StringPtr (com.actiontech.dble.plan.common.ptr.StringPtr)4 ByteBuffer (java.nio.ByteBuffer)4 ArrayList (java.util.ArrayList)4 PhysicalDBPool (com.actiontech.dble.backend.datasource.PhysicalDBPool)3 ERTable (com.actiontech.dble.config.model.ERTable)3 FirewallConfig (com.actiontech.dble.config.model.FirewallConfig)3