use of io.mycat.backend.mysql.nio.MySQLDataSource in project Mycat-Server by MyCATApache.
the class ConfigInitializer method createDataSource.
private PhysicalDatasource[] createDataSource(DataHostConfig conf, String hostName, String dbType, String dbDriver, DBHostConfig[] nodes, boolean isRead) {
PhysicalDatasource[] dataSources = new PhysicalDatasource[nodes.length];
if (dbType.equals("mysql") && dbDriver.equals("native")) {
for (int i = 0; i < nodes.length; i++) {
//设置最大idle时间,默认为30分钟
nodes[i].setIdleTimeout(system.getIdleTimeout());
MySQLDataSource ds = new MySQLDataSource(nodes[i], conf, isRead);
dataSources[i] = ds;
}
} else if (dbDriver.equals("jdbc")) {
for (int i = 0; i < nodes.length; i++) {
nodes[i].setIdleTimeout(system.getIdleTimeout());
JDBCDatasource ds = new JDBCDatasource(nodes[i], conf, isRead);
dataSources[i] = ds;
}
} else if ("postgresql".equalsIgnoreCase(dbType) && dbDriver.equalsIgnoreCase("native")) {
for (int i = 0; i < nodes.length; i++) {
nodes[i].setIdleTimeout(system.getIdleTimeout());
PostgreSQLDataSource ds = new PostgreSQLDataSource(nodes[i], conf, isRead);
dataSources[i] = ds;
}
} else {
throw new ConfigException("not supported yet !" + hostName);
}
return dataSources;
}
use of io.mycat.backend.mysql.nio.MySQLDataSource in project Mycat-Server by MyCATApache.
the class GlobalTableUtil method reGetColumnsForTable.
/**
* 重新获得table 的列list
* @param tableName
*/
private static void reGetColumnsForTable(String tableName) {
MycatConfig config = MycatServer.getInstance().getConfig();
if (globalTableMap != null && globalTableMap.get(tableName.toUpperCase()) != null) {
TableConfig tableConfig = globalTableMap.get(tableName.toUpperCase());
if (// consistencyCheck 在运行中
tableConfig == null || isInnerColumnCheckFinished != 1)
return;
String nodeName = tableConfig.getDataNodes().get(0);
Map<String, PhysicalDBNode> map = config.getDataNodes();
for (String k2 : map.keySet()) {
PhysicalDBNode dBnode = map.get(k2);
if (nodeName.equals(dBnode.getName())) {
PhysicalDBPool pool = dBnode.getDbPool();
List<PhysicalDatasource> dsList = (List<PhysicalDatasource>) pool.genAllDataSources();
for (PhysicalDatasource ds : dsList) {
if (ds instanceof MySQLDataSource) {
MySQLDataSource mds = (MySQLDataSource) dsList.get(0);
MySQLConsistencyChecker checker = new MySQLConsistencyChecker(mds, tableConfig.getName());
checker.checkInnerColumnExist();
// 运行一次就行了,不需要像consistencyCheck那样每个db都运行一次
return;
}
}
}
}
}
}
use of io.mycat.backend.mysql.nio.MySQLDataSource in project Mycat-Server by MyCATApache.
the class ConfigTest method createDataSource.
private PhysicalDatasource[] createDataSource(DataHostConfig conf, String hostName, String dbType, String dbDriver, DBHostConfig[] nodes, boolean isRead) {
PhysicalDatasource[] dataSources = new PhysicalDatasource[nodes.length];
if (dbType.equals("mysql") && dbDriver.equals("native")) {
for (int i = 0; i < nodes.length; i++) {
nodes[i].setIdleTimeout(system.getIdleTimeout());
MySQLDataSource ds = new MySQLDataSource(nodes[i], conf, isRead);
dataSources[i] = ds;
}
} else if (dbDriver.equals("jdbc")) {
for (int i = 0; i < nodes.length; i++) {
nodes[i].setIdleTimeout(system.getIdleTimeout());
JDBCDatasource ds = new JDBCDatasource(nodes[i], conf, isRead);
dataSources[i] = ds;
}
} else {
throw new ConfigException("not supported yet !" + hostName);
}
return dataSources;
}
use of io.mycat.backend.mysql.nio.MySQLDataSource in project Mycat-Server by MyCATApache.
the class MySQLDetector method heartbeat.
public void heartbeat() {
lastSendQryTime = System.currentTimeMillis();
MySQLDataSource ds = heartbeat.getSource();
String databaseName = ds.getDbPool().getSchemas()[0];
String[] fetchColms = {};
if (heartbeat.getSource().getHostConfig().isShowSlaveSql()) {
fetchColms = MYSQL_SLAVE_STAUTS_COLMS;
}
if (heartbeat.getSource().getHostConfig().isShowClusterSql()) {
fetchColms = MYSQL_CLUSTER_STAUTS_COLMS;
}
OneRawSQLQueryResultHandler resultHandler = new OneRawSQLQueryResultHandler(fetchColms, this);
sqlJob = new SQLJob(heartbeat.getHeartbeatSQL(), databaseName, resultHandler, ds);
sqlJob.run();
}
use of io.mycat.backend.mysql.nio.MySQLDataSource in project Mycat-Server by MyCATApache.
the class GlobalTableUtil method consistencyCheck.
public static void consistencyCheck() {
MycatConfig config = MycatServer.getInstance().getConfig();
for (String key : globalTableMap.keySet()) {
TableConfig table = globalTableMap.get(key);
// <table name="travelrecord" dataNode="dn1,dn2,dn3"
List<String> dataNodeList = table.getDataNodes();
// 记录本次已经执行的datanode
// 多个 datanode 对应到同一个 PhysicalDatasource 只执行一次
Map<String, String> executedMap = new HashMap<>();
for (String nodeName : dataNodeList) {
Map<String, PhysicalDBNode> map = config.getDataNodes();
for (String k2 : map.keySet()) {
// <dataNode name="dn1" dataHost="localhost1" database="db1" />
PhysicalDBNode dBnode = map.get(k2);
if (nodeName.equals(dBnode.getName())) {
// dn1,dn2,dn3
PhysicalDBPool pool = dBnode.getDbPool();
Collection<PhysicalDatasource> allDS = pool.genAllDataSources();
for (PhysicalDatasource pds : allDS) {
if (pds instanceof MySQLDataSource) {
MySQLDataSource mds = (MySQLDataSource) pds;
if (executedMap.get(pds.getName()) == null) {
MySQLConsistencyChecker checker = new MySQLConsistencyChecker(mds, table.getName());
isInnerColumnCheckFinished = 0;
checker.checkInnerColumnExist();
while (isInnerColumnCheckFinished <= 0) {
LOGGER.debug("isInnerColumnCheckFinished:" + isInnerColumnCheckFinished);
try {
TimeUnit.SECONDS.sleep(1);
} catch (InterruptedException e) {
LOGGER.warn(e.getMessage());
}
}
LOGGER.debug("isInnerColumnCheckFinished:" + isInnerColumnCheckFinished);
// 一种 check 完成之后,再进行另一种 check
checker = new MySQLConsistencyChecker(mds, table.getName());
isColumnCountCheckFinished = 0;
checker.checkRecordCout();
while (isColumnCountCheckFinished <= 0) {
LOGGER.debug("isColumnCountCheckFinished:" + isColumnCountCheckFinished);
try {
TimeUnit.SECONDS.sleep(1);
} catch (InterruptedException e) {
LOGGER.warn(e.getMessage());
}
}
LOGGER.debug("isColumnCountCheckFinished:" + isColumnCountCheckFinished);
checker = new MySQLConsistencyChecker(mds, table.getName());
checker.checkMaxTimeStamp();
executedMap.put(pds.getName(), nodeName);
}
}
}
}
}
}
}
}
Aggregations