Search in sources :

Example 86 with SystemConfig

use of io.mycat.config.model.SystemConfig in project Mycat_plus by coderczp.

the class PartitionByRangeModTest method testRange.

@Test
public void testRange() throws SQLNonTransientException {
    String sql = "select * from offer  where id between 2000000  and 4000001     order by id desc limit 100";
    SchemaConfig schema = schemaMap.get("TESTDB");
    RouteResultset rrs = routeStrategy.route(new SystemConfig(), schema, -1, sql, null, null, cachePool);
    Assert.assertEquals(10, rrs.getNodes().length);
    sql = "select * from offer  where id between 9  and 2000     order by id desc limit 100";
    rrs = routeStrategy.route(new SystemConfig(), schema, -1, sql, null, null, cachePool);
    Assert.assertEquals(5, rrs.getNodes().length);
    sql = "select * from offer  where id between 4000001  and 6005001     order by id desc limit 100";
    rrs = routeStrategy.route(new SystemConfig(), schema, -1, sql, null, null, cachePool);
    Assert.assertEquals(8, rrs.getNodes().length);
}
Also used : SystemConfig(io.mycat.config.model.SystemConfig) SchemaConfig(io.mycat.config.model.SchemaConfig) RouteResultset(io.mycat.route.RouteResultset) Test(org.junit.Test)

Example 87 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 88 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 89 with SystemConfig

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

the class DruidMysqlCreateTableTest method testInsert.

// @Test
public void testInsert() throws SQLNonTransientException {
    SchemaConfig schema = schemaMap.get("mysqldb");
    RouteResultset rrs = routeStrategy.route(new SystemConfig(), schema, -1, "insert into autoslot (id,sid) values(1,2) ", null, null, cachePool);
    Assert.assertEquals(1, rrs.getNodes().length);
    Assert.assertTrue(isInsertHasSlot(rrs.getStatement()));
}
Also used : SystemConfig(io.mycat.config.model.SystemConfig) SchemaConfig(io.mycat.config.model.SchemaConfig)

Example 90 with SystemConfig

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

the class DruidMysqlRouteStrategyTest method testIgnoreSchema.

public void testIgnoreSchema() throws Exception {
    SchemaConfig schema = schemaMap.get("ignoreSchemaTest");
    String sql = "select * from offer where offer_id=1";
    RouteResultset rrs = routeStrategy.route(new SystemConfig(), schema, 1, sql, null, null, cachePool);
    Assert.assertEquals(false, rrs.isCacheAble());
    Assert.assertEquals("cndb_dn", rrs.getNodes()[0].getName());
    Assert.assertEquals(sql, rrs.getNodes()[0].getStatement());
    sql = "select * from ignoreSchemaTest.offer1 where ignoreSchemaTest.offer1.offer_id=1";
    rrs = routeStrategy.route(new SystemConfig(), schema, 1, sql, null, null, cachePool);
    Assert.assertEquals(false, rrs.isCacheAble());
    Assert.assertEquals("select * from offer1 where offer1.offer_id=1", rrs.getNodes()[0].getStatement());
    sql = "select * from ignoreSchemaTest2.offer where ignoreSchemaTest2.offer.offer_id=1";
    rrs = routeStrategy.route(new SystemConfig(), schema, 1, sql, null, null, cachePool);
    Assert.assertEquals(false, rrs.isCacheAble());
    Assert.assertEquals(sql, rrs.getNodes()[0].getStatement(), sql);
    sql = "select * from ignoreSchemaTest2.offer a,offer b  where ignoreSchemaTest2.offer.offer_id=1";
    rrs = routeStrategy.route(new SystemConfig(), schema, 1, sql, null, null, cachePool);
    Assert.assertEquals(false, rrs.isCacheAble());
    Assert.assertEquals("select * from ignoreSchemaTest2.offer a,offer b  where ignoreSchemaTest2.offer.offer_id=1", rrs.getNodes()[0].getStatement());
}
Also used : SystemConfig(io.mycat.config.model.SystemConfig) SchemaConfig(io.mycat.config.model.SchemaConfig) RouteResultset(io.mycat.route.RouteResultset)

Aggregations

SystemConfig (io.mycat.config.model.SystemConfig)120 SchemaConfig (io.mycat.config.model.SchemaConfig)110 RouteResultset (io.mycat.route.RouteResultset)64 Test (org.junit.Test)60 RouteResultsetNode (io.mycat.route.RouteResultsetNode)14 CacheService (io.mycat.cache.CacheService)10 SQLNonTransientException (java.sql.SQLNonTransientException)10 NoSuchElementException (java.util.NoSuchElementException)10 RouteService (io.mycat.route.RouteService)8 ArrayList (java.util.ArrayList)8 SQLStatement (com.alibaba.druid.sql.ast.SQLStatement)6 MySqlStatementParser (com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser)6 TableConfig (io.mycat.config.model.TableConfig)6 PhysicalDBPool (io.mycat.backend.datasource.PhysicalDBPool)2 DirectByteBufferPool (io.mycat.buffer.DirectByteBufferPool)2 NettyBufferPool (io.mycat.buffer.NettyBufferPool)2 MycatConfig (io.mycat.config.MycatConfig)2 ManagerConnectionFactory (io.mycat.manager.ManagerConnectionFactory)2 MyCatMemory (io.mycat.memory.MyCatMemory)2 AIOAcceptor (io.mycat.net.AIOAcceptor)2