Search in sources :

Example 1 with MySQLDataSource

use of com.actiontech.dble.backend.mysql.nio.MySQLDataSource 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 2 with MySQLDataSource

use of com.actiontech.dble.backend.mysql.nio.MySQLDataSource in project dble by actiontech.

the class ConfigTest method createDataSource.

private PhysicalDatasource[] createDataSource(DataHostConfig conf, String hostName, 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 3 with MySQLDataSource

use of com.actiontech.dble.backend.mysql.nio.MySQLDataSource in project dble by actiontech.

the class GlobalTableUtil method consistencyCheck.

public static void consistencyCheck() {
    ServerConfig config = DbleServer.getInstance().getConfig();
    for (TableConfig table : globalTableMap.values()) {
        Map<String, ArrayList<PhysicalDBNode>> executedMap = new HashMap<>();
        // <table name="travelrecord" dataNode="dn1,dn2,dn3"
        for (String nodeName : table.getDataNodes()) {
            Map<String, PhysicalDBNode> map = config.getDataNodes();
            for (PhysicalDBNode dbNode : map.values()) {
                // <dataNode name="dn1" dataHost="localhost1" database="db1" />
                if (nodeName.equals(dbNode.getName())) {
                    // dn1,dn2,dn3
                    PhysicalDBPool pool = dbNode.getDbPool();
                    Collection<PhysicalDatasource> allDS = pool.getAllDataSources();
                    for (PhysicalDatasource pds : allDS) {
                        if (pds instanceof MySQLDataSource) {
                            ArrayList<PhysicalDBNode> nodes = executedMap.get(pds.getName());
                            if (nodes == null) {
                                nodes = new ArrayList<>();
                            }
                            nodes.add(dbNode);
                            executedMap.put(pds.getName(), nodes);
                        }
                    }
                }
            }
        }
        for (Map.Entry<String, ArrayList<PhysicalDBNode>> entry : executedMap.entrySet()) {
            ArrayList<PhysicalDBNode> nodes = entry.getValue();
            String[] schemas = new String[nodes.size()];
            for (int index = 0; index < nodes.size(); index++) {
                schemas[index] = StringUtil.removeBackQuote(nodes.get(index).getDatabase());
            }
            Collection<PhysicalDatasource> allDS = nodes.get(0).getDbPool().getAllDataSources();
            for (PhysicalDatasource pds : allDS) {
                if (pds instanceof MySQLDataSource && entry.getKey().equals(pds.getName())) {
                    MySQLDataSource mds = (MySQLDataSource) pds;
                    MySQLConsistencyChecker checker = new MySQLConsistencyChecker(mds, schemas, table.getName());
                    isInnerColumnCheckFinished = 0;
                    checker.checkInnerColumnExist();
                    while (isInnerColumnCheckFinished <= 0) {
                        LOGGER.debug("isInnerColumnCheckFinished:" + isInnerColumnCheckFinished);
                        try {
                            TimeUnit.SECONDS.sleep(1);
                        } catch (InterruptedException e) {
                            LOGGER.info(e.getMessage());
                        }
                    }
                    LOGGER.debug("isInnerColumnCheckFinished:" + isInnerColumnCheckFinished);
                    // check another measure
                    checker = new MySQLConsistencyChecker(mds, schemas, table.getName());
                    isColumnCountCheckFinished = 0;
                    checker.checkRecordCount();
                    while (isColumnCountCheckFinished <= 0) {
                        LOGGER.debug("isColumnCountCheckFinished:" + isColumnCountCheckFinished);
                        try {
                            TimeUnit.SECONDS.sleep(1);
                        } catch (InterruptedException e) {
                            LOGGER.info(e.getMessage());
                        }
                    }
                    LOGGER.debug("isColumnCountCheckFinished:" + isColumnCountCheckFinished);
                    checker = new MySQLConsistencyChecker(mds, schemas, table.getName());
                    checker.checkMaxTimeStamp();
                }
            }
        }
    }
}
Also used : PhysicalDBNode(com.actiontech.dble.backend.datasource.PhysicalDBNode) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) PhysicalDBPool(com.actiontech.dble.backend.datasource.PhysicalDBPool) ServerConfig(com.actiontech.dble.config.ServerConfig) MySQLConsistencyChecker(com.actiontech.dble.backend.heartbeat.MySQLConsistencyChecker) PhysicalDatasource(com.actiontech.dble.backend.datasource.PhysicalDatasource) MySQLDataSource(com.actiontech.dble.backend.mysql.nio.MySQLDataSource) TableConfig(com.actiontech.dble.config.model.TableConfig) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 4 with MySQLDataSource

use of com.actiontech.dble.backend.mysql.nio.MySQLDataSource in project dble by actiontech.

the class MySQLDetector method heartbeat.

public void heartbeat() {
    lastSendQryTime = System.currentTimeMillis();
    MySQLDataSource ds = heartbeat.getSource();
    String databaseName = ds.getDbPool().getSchemas()[0];
    String[] fetchCols = {};
    if (heartbeat.getSource().getHostConfig().isShowSlaveSql()) {
        fetchCols = MYSQL_SLAVE_STATUS_COLS;
    }
    if (heartbeat.getSource().getHostConfig().isShowClusterSql()) {
        fetchCols = MYSQL_CLUSTER_STATUS_COLS;
    }
    OneRawSQLQueryResultHandler resultHandler = new OneRawSQLQueryResultHandler(fetchCols, this);
    sqlJob = new SQLJob(heartbeat.getHeartbeatSQL(), databaseName, resultHandler, ds);
    sqlJob.run();
}
Also used : OneRawSQLQueryResultHandler(com.actiontech.dble.sqlengine.OneRawSQLQueryResultHandler) SQLJob(com.actiontech.dble.sqlengine.SQLJob) MySQLDataSource(com.actiontech.dble.backend.mysql.nio.MySQLDataSource)

Aggregations

MySQLDataSource (com.actiontech.dble.backend.mysql.nio.MySQLDataSource)4 PhysicalDatasource (com.actiontech.dble.backend.datasource.PhysicalDatasource)3 PhysicalDBNode (com.actiontech.dble.backend.datasource.PhysicalDBNode)1 PhysicalDBPool (com.actiontech.dble.backend.datasource.PhysicalDBPool)1 MySQLConsistencyChecker (com.actiontech.dble.backend.heartbeat.MySQLConsistencyChecker)1 ServerConfig (com.actiontech.dble.config.ServerConfig)1 TableConfig (com.actiontech.dble.config.model.TableConfig)1 OneRawSQLQueryResultHandler (com.actiontech.dble.sqlengine.OneRawSQLQueryResultHandler)1 SQLJob (com.actiontech.dble.sqlengine.SQLJob)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1