Search in sources :

Example 1 with PhysicalDatasource

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));
}
Also used : PhysicalDatasource(com.actiontech.dble.backend.datasource.PhysicalDatasource)

Example 2 with PhysicalDatasource

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;
}
Also used : PhysicalDatasource(com.actiontech.dble.backend.datasource.PhysicalDatasource) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) PhysicalDBPool(com.actiontech.dble.backend.datasource.PhysicalDBPool) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with PhysicalDatasource

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;
}
Also used : PhysicalDatasource(com.actiontech.dble.backend.datasource.PhysicalDatasource) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) PhysicalDBPool(com.actiontech.dble.backend.datasource.PhysicalDBPool) HashMap(java.util.HashMap) Map(java.util.Map)

Example 4 with PhysicalDatasource

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;
}
Also used : PhysicalDatasource(com.actiontech.dble.backend.datasource.PhysicalDatasource) MySQLDataSource(com.actiontech.dble.backend.mysql.nio.MySQLDataSource)

Example 5 with PhysicalDatasource

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");
            }
    }
}
Also used : PhysicalDatasource(com.actiontech.dble.backend.datasource.PhysicalDatasource) PhysicalDBPool(com.actiontech.dble.backend.datasource.PhysicalDBPool) TransformSQLJob(com.actiontech.dble.sqlengine.TransformSQLJob)

Aggregations

PhysicalDatasource (com.actiontech.dble.backend.datasource.PhysicalDatasource)19 PhysicalDBPool (com.actiontech.dble.backend.datasource.PhysicalDBPool)16 ServerConfig (com.actiontech.dble.config.ServerConfig)7 RowDataPacket (com.actiontech.dble.net.mysql.RowDataPacket)7 DBHeartbeat (com.actiontech.dble.backend.heartbeat.DBHeartbeat)5 LinkedList (java.util.LinkedList)4 Map (java.util.Map)4 PhysicalDBNode (com.actiontech.dble.backend.datasource.PhysicalDBNode)3 MySQLDataSource (com.actiontech.dble.backend.mysql.nio.MySQLDataSource)3 DataSourceSyncRecorder (com.actiontech.dble.statistic.DataSourceSyncRecorder)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 SimpleDateFormat (java.text.SimpleDateFormat)2 BackendConnection (com.actiontech.dble.backend.BackendConnection)1 MySQLConsistencyChecker (com.actiontech.dble.backend.heartbeat.MySQLConsistencyChecker)1 MySQLConnection (com.actiontech.dble.backend.mysql.nio.MySQLConnection)1 TableConfig (com.actiontech.dble.config.model.TableConfig)1 ConfigException (com.actiontech.dble.config.util.ConfigException)1 NIOProcessor (com.actiontech.dble.net.NIOProcessor)1 EOFPacket (com.actiontech.dble.net.mysql.EOFPacket)1