use of io.mycat.backend.datasource.PhysicalDatasource 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.datasource.PhysicalDatasource in project Mycat-Server by MyCATApache.
the class ConfigTest method getPhysicalDBPool.
private PhysicalDBPool getPhysicalDBPool(DataHostConfig conf, ConfigLoader configLoader) {
String name = conf.getName();
String dbType = conf.getDbType();
String dbDriver = conf.getDbDriver();
PhysicalDatasource[] writeSources = createDataSource(conf, name, dbType, dbDriver, conf.getWriteHosts(), false);
Map<Integer, DBHostConfig[]> readHostsMap = conf.getReadHosts();
Map<Integer, PhysicalDatasource[]> readSourcesMap = new HashMap<Integer, PhysicalDatasource[]>(readHostsMap.size());
for (Map.Entry<Integer, DBHostConfig[]> entry : readHostsMap.entrySet()) {
PhysicalDatasource[] readSources = createDataSource(conf, name, dbType, dbDriver, entry.getValue(), true);
readSourcesMap.put(entry.getKey(), readSources);
}
PhysicalDBPool pool = new PhysicalDBPool(conf.getName(), conf, writeSources, readSourcesMap, conf.getBalance(), conf.getWriteType());
return pool;
}
use of io.mycat.backend.datasource.PhysicalDatasource in project Mycat-Server by MyCATApache.
the class PostgreSQLDetector method onResult.
@Override
public void onResult(SQLQueryResult<Map<String, String>> result) {
if (result.isSuccess()) {
int balance = heartbeat.getSource().getDbPool().getBalance();
PhysicalDatasource source = heartbeat.getSource();
Map<String, String> resultResult = result.getResult();
if (source.getHostConfig().isShowSlaveSql() && (source.getHostConfig().getSwitchType() == DataHostConfig.SYN_STATUS_SWITCH_DS || PhysicalDBPool.BALANCE_NONE != balance)) {
String Slave_IO_Running = resultResult != null ? resultResult.get("Slave_IO_Running") : null;
String Slave_SQL_Running = resultResult != null ? resultResult.get("Slave_SQL_Running") : null;
if (Slave_IO_Running != null && Slave_IO_Running.equals(Slave_SQL_Running) && Slave_SQL_Running.equals("Yes")) {
heartbeat.setDbSynStatus(DBHeartbeat.DB_SYN_NORMAL);
String Seconds_Behind_Master = resultResult.get("Seconds_Behind_Master");
if (null != Seconds_Behind_Master && !"".equals(Seconds_Behind_Master)) {
heartbeat.setSlaveBehindMaster(Integer.valueOf(Seconds_Behind_Master));
}
} else if (source.isSalveOrRead()) {
MySQLHeartbeat.LOGGER.warn("found MySQL master/slave Replication err !!! " + heartbeat.getSource().getConfig());
heartbeat.setDbSynStatus(DBHeartbeat.DB_SYN_ERROR);
}
}
heartbeat.setResult(PostgreSQLHeartbeat.OK_STATUS, this, null);
} else {
heartbeat.setResult(PostgreSQLHeartbeat.ERROR_STATUS, this, null);
}
lasstReveivedQryTime = System.currentTimeMillis();
}
use of io.mycat.backend.datasource.PhysicalDatasource 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.datasource.PhysicalDatasource in project Mycat-Server by MyCATApache.
the class MySQLDetector method onResult.
@Override
public void onResult(SQLQueryResult<Map<String, String>> result) {
if (result.isSuccess()) {
int balance = heartbeat.getSource().getDbPool().getBalance();
PhysicalDatasource source = heartbeat.getSource();
int switchType = source.getHostConfig().getSwitchType();
Map<String, String> resultResult = result.getResult();
if (resultResult != null && !resultResult.isEmpty() && switchType == DataHostConfig.SYN_STATUS_SWITCH_DS && source.getHostConfig().isShowSlaveSql()) {
String Slave_IO_Running = resultResult != null ? resultResult.get("Slave_IO_Running") : null;
String Slave_SQL_Running = resultResult != null ? resultResult.get("Slave_SQL_Running") : null;
if (Slave_IO_Running != null && Slave_IO_Running.equals(Slave_SQL_Running) && Slave_SQL_Running.equals("Yes")) {
heartbeat.setDbSynStatus(DBHeartbeat.DB_SYN_NORMAL);
String Seconds_Behind_Master = resultResult.get("Seconds_Behind_Master");
if (null != Seconds_Behind_Master && !"".equals(Seconds_Behind_Master)) {
int Behind_Master = Integer.parseInt(Seconds_Behind_Master);
if (Behind_Master > source.getHostConfig().getSlaveThreshold()) {
MySQLHeartbeat.LOGGER.warn("found MySQL master/slave Replication delay !!! " + heartbeat.getSource().getConfig() + ", binlog sync time delay: " + Behind_Master + "s");
}
heartbeat.setSlaveBehindMaster(Behind_Master);
}
} else if (source.isSalveOrRead()) {
// String Last_IO_Error = resultResult != null ? resultResult.get("Last_IO_Error") : null;
MySQLHeartbeat.LOGGER.warn("found MySQL master/slave Replication err !!! " + heartbeat.getSource().getConfig() + ", " + resultResult);
heartbeat.setDbSynStatus(DBHeartbeat.DB_SYN_ERROR);
}
heartbeat.getAsynRecorder().set(resultResult, switchType);
heartbeat.setResult(MySQLHeartbeat.OK_STATUS, this, null);
} else if (resultResult != null && !resultResult.isEmpty() && switchType == DataHostConfig.CLUSTER_STATUS_SWITCH_DS && source.getHostConfig().isShowClusterSql()) {
// String Variable_name = resultResult != null ? resultResult.get("Variable_name") : null;
// Primary
String wsrep_cluster_status = resultResult != null ? resultResult.get("wsrep_cluster_status") : null;
// ON
String wsrep_connected = resultResult != null ? resultResult.get("wsrep_connected") : null;
// ON
String wsrep_ready = resultResult != null ? resultResult.get("wsrep_ready") : null;
if ("ON".equals(wsrep_connected) && "ON".equals(wsrep_ready) && "Primary".equals(wsrep_cluster_status)) {
heartbeat.setDbSynStatus(DBHeartbeat.DB_SYN_NORMAL);
heartbeat.setResult(MySQLHeartbeat.OK_STATUS, this, null);
} else {
MySQLHeartbeat.LOGGER.warn("found MySQL cluster status err !!! " + heartbeat.getSource().getConfig() + " wsrep_cluster_status: " + wsrep_cluster_status + " wsrep_connected: " + wsrep_connected + " wsrep_ready: " + wsrep_ready);
heartbeat.setDbSynStatus(DBHeartbeat.DB_SYN_ERROR);
heartbeat.setResult(MySQLHeartbeat.ERROR_STATUS, this, null);
}
heartbeat.getAsynRecorder().set(resultResult, switchType);
} else {
heartbeat.setResult(MySQLHeartbeat.OK_STATUS, this, null);
}
// 监测数据库同步状态,在 switchType=-1或者1的情况下,也需要收集主从同步状态
heartbeat.getAsynRecorder().set(resultResult, switchType);
} else {
heartbeat.setResult(MySQLHeartbeat.ERROR_STATUS, this, null);
}
lasstReveivedQryTime = System.currentTimeMillis();
heartbeat.getRecorder().set((lasstReveivedQryTime - lastSendQryTime));
}
Aggregations