use of com.actiontech.dble.backend.datasource.PhysicalDatasource in project dble by actiontech.
the class MySQLDetector method onResult.
@Override
public void onResult(SQLQueryResult<Map<String, String>> result) {
if (result.isSuccess()) {
PhysicalDatasource source = heartbeat.getSource();
int switchType = source.getHostConfig().getSwitchType();
Map<String, String> resultResult = result.getResult();
if (switchType == DataHostConfig.SYN_STATUS_SWITCH_DS && source.getHostConfig().isShowSlaveSql()) {
setStatusBySlave(source, switchType, resultResult);
} else if (switchType == DataHostConfig.CLUSTER_STATUS_SWITCH_DS && source.getHostConfig().isShowClusterSql()) {
setStatusByCluster(switchType, resultResult);
} else {
heartbeat.setResult(MySQLHeartbeat.OK_STATUS, null);
// monitor sync status,even switchType=-1 or 1
heartbeat.getAsyncRecorder().set(resultResult, switchType);
}
} else {
heartbeat.setResult(MySQLHeartbeat.ERROR_STATUS, null);
}
lastReceivedQryTime = System.currentTimeMillis();
heartbeat.getRecorder().set((lastReceivedQryTime - lastSendQryTime));
}
use of com.actiontech.dble.backend.datasource.PhysicalDatasource in project dble by actiontech.
the class ServerConfig method addedDatasource.
private boolean addedDatasource(Map<String, PhysicalDBPool> newDataHosts, DsDiff diff) {
for (PhysicalDBPool npool : newDataHosts.values()) {
PhysicalDBPool opool = dataHosts.get(npool.getHostName());
if (opool == null) {
LOGGER.warn(AlarmCode.CORE_GENERAL_WARN + "reload -add- failed, use old datasources ");
return true;
}
Map<Integer, PhysicalDatasource[]> ndss = npool.getReadSources();
Map<Integer, PhysicalDatasource[]> odss = opool.getReadSources();
Map<Integer, ArrayList<PhysicalDatasource>> iadd = new HashMap<>(2);
boolean haveOne = false;
for (Map.Entry<Integer, PhysicalDatasource[]> nentry : ndss.entrySet()) {
boolean doadd = false;
ArrayList<PhysicalDatasource> add = new ArrayList<>();
for (PhysicalDatasource nds : nentry.getValue()) {
boolean isExist = false;
for (Map.Entry<Integer, PhysicalDatasource[]> oentry : odss.entrySet()) {
for (PhysicalDatasource ods : oentry.getValue()) {
if (nds.getName().equals(ods.getName())) {
isExist = true;
break;
}
}
if (isExist) {
break;
}
}
if (!isExist) {
add.add(nds);
doadd = true;
}
}
if (doadd) {
iadd.put(nentry.getKey(), add);
haveOne = true;
}
}
if (haveOne) {
diff.added.put(opool, iadd);
}
}
return false;
}
use of com.actiontech.dble.backend.datasource.PhysicalDatasource in project dble by actiontech.
the class ServerConfig method dsdiff.
private DsDiff dsdiff(Map<String, PhysicalDBPool> newDataHosts) {
DsDiff diff = new DsDiff();
// deleted datasource
for (PhysicalDBPool opool : dataHosts.values()) {
PhysicalDBPool npool = newDataHosts.get(opool.getHostName());
if (npool == null) {
LOGGER.info("reload -delete- failed, use old datasources ");
return null;
}
Map<Integer, PhysicalDatasource[]> odss = opool.getReadSources();
Map<Integer, PhysicalDatasource[]> ndss = npool.getReadSources();
Map<Integer, ArrayList<PhysicalDatasource>> idel = new HashMap<>(2);
boolean haveOne = false;
for (Map.Entry<Integer, PhysicalDatasource[]> oentry : odss.entrySet()) {
boolean doadd = false;
ArrayList<PhysicalDatasource> del = new ArrayList<>();
for (PhysicalDatasource ods : oentry.getValue()) {
boolean dodel = true;
for (Map.Entry<Integer, PhysicalDatasource[]> nentry : ndss.entrySet()) {
for (PhysicalDatasource nds : nentry.getValue()) {
if (ods.getName().equals(nds.getName())) {
dodel = false;
break;
}
}
if (!dodel) {
break;
}
}
if (dodel) {
del.add(ods);
doadd = true;
}
}
if (doadd) {
idel.put(oentry.getKey(), del);
haveOne = true;
}
}
if (haveOne) {
diff.deled.put(opool, idel);
}
}
// added datasource
if (addedDatasource(newDataHosts, diff))
return null;
return diff;
}
use of com.actiontech.dble.backend.datasource.PhysicalDatasource in project dble by actiontech.
the class ConfigInitializer method createDataSource.
private PhysicalDatasource[] createDataSource(DataHostConfig conf, DBHostConfig[] nodes, boolean isRead) {
PhysicalDatasource[] dataSources = new PhysicalDatasource[nodes.length];
for (int i = 0; i < nodes.length; i++) {
nodes[i].setIdleTimeout(system.getIdleTimeout());
MySQLDataSource ds = new MySQLDataSource(nodes[i], conf, isRead);
dataSources[i] = ds;
}
return dataSources;
}
use of com.actiontech.dble.backend.datasource.PhysicalDatasource in project dble by actiontech.
the class SelectHandler method handle.
public static void handle(String stmt, ManagerConnection c, int offset) {
switch(ManagerParseSelect.parse(stmt, offset)) {
case VERSION_COMMENT:
SelectVersionComment.response(c);
break;
case SESSION_TX_READ_ONLY:
SelectSessionTxReadOnly.execute(c);
break;
case MAX_ALLOWED_PACKET:
SelectMaxAllowedPacket.execute(c);
break;
default:
if (isSupportSelect(stmt)) {
Iterator<PhysicalDBPool> iterator = DbleServer.getInstance().getConfig().getDataHosts().values().iterator();
if (iterator.hasNext()) {
PhysicalDBPool pool = iterator.next();
final PhysicalDatasource source = pool.getSource();
TransformSQLJob sqlJob = new TransformSQLJob(stmt, pool.getSchemas()[0], source, c);
sqlJob.run();
} else {
c.writeErrMessage(ErrorCode.ER_YES, "no valid data host");
}
} else {
c.writeErrMessage(ErrorCode.ER_YES, "Unsupported statement");
}
}
}
Aggregations