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);
}
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");
}
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);
}
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;
}
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;
}
}
Aggregations