Search in sources :

Example 26 with SystemConfig

use of io.mycat.config.model.SystemConfig in project Mycat-Server by MyCATApache.

the class HintDBTypeTest method testHint.

/**
     * 测试注解
     *
     * @throws Exception
     */
@Test
public void testHint() throws Exception {
    SchemaConfig schema = schemaMap.get("TESTDB");
    //使用注解(新注解,/*!mycat*/),runOnSlave=false 强制走主节点
    String sql = "/*!mycat:db_type=master*/select * from employee where sharding_id=1";
    CacheService cacheService = new CacheService();
    RouteService routerService = new RouteService(cacheService);
    RouteResultset rrs = routerService.route(new SystemConfig(), schema, ServerParse.SELECT, sql, "UTF-8", null);
    Assert.assertTrue(!rrs.getRunOnSlave());
    //使用注解(新注解,/*#mycat*/),runOnSlave=false 强制走主节点
    sql = "/*#mycat:db_type=master*/select * from employee where sharding_id=1";
    rrs = routerService.route(new SystemConfig(), schema, ServerParse.SELECT, sql, "UTF-8", null);
    Assert.assertTrue(!rrs.getRunOnSlave());
    //使用注解(新注解,/*mycat*/),runOnSlave=false 强制走主节点
    sql = "/*mycat:db_type=master*/select * from employee where sharding_id=1";
    rrs = routerService.route(new SystemConfig(), schema, ServerParse.SELECT, sql, "UTF-8", null);
    Assert.assertTrue(!rrs.getRunOnSlave());
    //不使用注解,runOnSlave=null, 根据读写分离策略走主从库
    sql = "select * from employee where sharding_id=1";
    rrs = routerService.route(new SystemConfig(), schema, ServerParse.SELECT, sql, "UTF-8", null);
    Assert.assertTrue(rrs.getRunOnSlave() == null);
}
Also used : SystemConfig(io.mycat.config.model.SystemConfig) SchemaConfig(io.mycat.config.model.SchemaConfig) CacheService(io.mycat.cache.CacheService) Test(org.junit.Test)

Example 27 with SystemConfig

use of io.mycat.config.model.SystemConfig in project Mycat-Server by MyCATApache.

the class FileSystemRepository method init.

@Override
public void init() {
    //        ConfigProperties configProperties = Configuration.getConfigProperties();
    //        String baseDir = configProperties.getLogBaseDir();
    //        String baseName = configProperties.getLogBaseName();
    MycatConfig mycatconfig = MycatServer.getInstance().getConfig();
    SystemConfig systemConfig = mycatconfig.getSystem();
    String baseDir = systemConfig.getXARecoveryLogBaseDir();
    String baseName = systemConfig.getXARecoveryLogBaseName();
    logger.debug("baseDir " + baseDir);
    logger.debug("baseName " + baseName);
    //Judge whether exist the basedir
    createBaseDir(baseDir);
    file = new VersionedFile(baseDir, baseName, ".log");
}
Also used : SystemConfig(io.mycat.config.model.SystemConfig) MycatConfig(io.mycat.config.MycatConfig)

Example 28 with SystemConfig

use of io.mycat.config.model.SystemConfig in project Mycat-Server by MyCATApache.

the class ShowSysParam method execute.

public static void execute(ManagerConnection c) {
    ByteBuffer buffer = c.allocate();
    // write header
    buffer = header.write(buffer, c, true);
    // write fields
    for (FieldPacket field : fields) {
        buffer = field.write(buffer, c, true);
    }
    // write eof
    buffer = eof.write(buffer, c, true);
    // write rows
    byte packetId = eof.packetId;
    SystemConfig sysConfig = MycatServer.getInstance().getConfig().getSystem();
    List<String> paramValues = new ArrayList<String>();
    paramValues.add(sysConfig.getProcessors() + "");
    paramValues.add(sysConfig.getBufferPoolChunkSize() + "B");
    paramValues.add(sysConfig.getBufferPoolPageSize() + "B");
    paramValues.add(sysConfig.getProcessorBufferLocalPercent() + "");
    paramValues.add(sysConfig.getProcessorExecutor() + "");
    paramValues.add(sysConfig.getSequnceHandlerType() == 1 ? "数据库方式" : "本地文件方式");
    paramValues.add(sysConfig.getPacketHeaderSize() + "B");
    paramValues.add(sysConfig.getMaxPacketSize() / 1024 / 1024 + "M");
    paramValues.add(sysConfig.getIdleTimeout() / 1000 / 60 + "分钟");
    paramValues.add(sysConfig.getCharset() + "");
    paramValues.add(ISOLATIONS[sysConfig.getTxIsolation()]);
    paramValues.add(sysConfig.getSqlExecuteTimeout() + "秒");
    paramValues.add(sysConfig.getProcessorCheckPeriod() / 1000 + "秒");
    paramValues.add(sysConfig.getDataNodeIdleCheckPeriod() / 1000 + "秒");
    paramValues.add(sysConfig.getDataNodeHeartbeatPeriod() / 1000 + "秒");
    paramValues.add(sysConfig.getBindIp() + "");
    paramValues.add(sysConfig.getServerPort() + "");
    paramValues.add(sysConfig.getManagerPort() + "");
    for (int i = 0; i < PARAMNAMES.length; i++) {
        RowDataPacket row = new RowDataPacket(FIELD_COUNT);
        row.add(StringUtil.encode(PARAMNAMES[i], c.getCharset()));
        row.add(StringUtil.encode(paramValues.get(i), c.getCharset()));
        row.add(StringUtil.encode(PARAM_DESCRIPTION[i], c.getCharset()));
        row.packetId = ++packetId;
        buffer = row.write(buffer, c, true);
    }
    // write last eof
    EOFPacket lastEof = new EOFPacket();
    lastEof.packetId = ++packetId;
    buffer = lastEof.write(buffer, c, true);
    // write buffer
    c.write(buffer);
}
Also used : SystemConfig(io.mycat.config.model.SystemConfig) RowDataPacket(io.mycat.net.mysql.RowDataPacket) ArrayList(java.util.ArrayList) EOFPacket(io.mycat.net.mysql.EOFPacket) ByteBuffer(java.nio.ByteBuffer) FieldPacket(io.mycat.net.mysql.FieldPacket)

Example 29 with SystemConfig

use of io.mycat.config.model.SystemConfig in project Mycat-Server by MyCATApache.

the class RouteStrategyFactory method init.

public static void init() {
    SystemConfig config = MycatServer.getInstance().getConfig().getSystem();
    String defaultSqlParser = config.getDefaultSqlParser();
    defaultSqlParser = defaultSqlParser == null ? "" : defaultSqlParser;
    //修改为ConcurrentHashMap,避免并发问题
    strategyMap.putIfAbsent("druidparser", new DruidMycatRouteStrategy());
    defaultStrategy = strategyMap.get(defaultSqlParser);
    if (defaultStrategy == null) {
        defaultStrategy = strategyMap.get("druidparser");
        defaultSqlParser = "druidparser";
    }
    config.setDefaultSqlParser(defaultSqlParser);
    isInit = true;
}
Also used : SystemConfig(io.mycat.config.model.SystemConfig) DruidMycatRouteStrategy(io.mycat.route.impl.DruidMycatRouteStrategy)

Example 30 with SystemConfig

use of io.mycat.config.model.SystemConfig in project Mycat-Server by MyCATApache.

the class ExplainHandler method getRouteResultset.

private static RouteResultset getRouteResultset(ServerConnection c, String stmt) {
    String db = c.getSchema();
    int sqlType = ServerParse.parse(stmt) & 0xff;
    if (db == null) {
        db = SchemaUtil.detectDefaultDb(stmt, sqlType);
        if (db == null) {
            c.writeErrMessage(ErrorCode.ER_NO_DB_ERROR, "No database selected");
            return null;
        }
    }
    SchemaConfig schema = MycatServer.getInstance().getConfig().getSchemas().get(db);
    if (schema == null) {
        c.writeErrMessage(ErrorCode.ER_BAD_DB_ERROR, "Unknown database '" + db + "'");
        return null;
    }
    try {
        if (ServerParse.INSERT == sqlType && isMycatSeq(stmt, schema)) {
            c.writeErrMessage(ErrorCode.ER_PARSE_ERROR, "insert sql using mycat seq,you must provide primaryKey value for explain");
            return null;
        }
        SystemConfig system = MycatServer.getInstance().getConfig().getSystem();
        return MycatServer.getInstance().getRouterservice().route(system, schema, sqlType, stmt, c.getCharset(), c);
    } catch (Exception e) {
        StringBuilder s = new StringBuilder();
        logger.warn(s.append(c).append(stmt).toString() + " error:" + e);
        String msg = e.getMessage();
        c.writeErrMessage(ErrorCode.ER_PARSE_ERROR, msg == null ? e.getClass().getSimpleName() : msg);
        return null;
    }
}
Also used : SystemConfig(io.mycat.config.model.SystemConfig) SchemaConfig(io.mycat.config.model.SchemaConfig)

Aggregations

SystemConfig (io.mycat.config.model.SystemConfig)59 SchemaConfig (io.mycat.config.model.SchemaConfig)54 RouteResultset (io.mycat.route.RouteResultset)32 Test (org.junit.Test)29 RouteResultsetNode (io.mycat.route.RouteResultsetNode)7 CacheService (io.mycat.cache.CacheService)5 SQLNonTransientException (java.sql.SQLNonTransientException)5 NoSuchElementException (java.util.NoSuchElementException)5 RouteService (io.mycat.route.RouteService)4 ArrayList (java.util.ArrayList)4 SQLStatement (com.alibaba.druid.sql.ast.SQLStatement)3 MySqlStatementParser (com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser)3 TableConfig (io.mycat.config.model.TableConfig)3 PhysicalDBPool (io.mycat.backend.datasource.PhysicalDBPool)1 DirectByteBufferPool (io.mycat.buffer.DirectByteBufferPool)1 MycatConfig (io.mycat.config.MycatConfig)1 ManagerConnectionFactory (io.mycat.manager.ManagerConnectionFactory)1 MyCatMemory (io.mycat.memory.MyCatMemory)1 AIOAcceptor (io.mycat.net.AIOAcceptor)1 AIOConnector (io.mycat.net.AIOConnector)1