Search in sources :

Example 26 with PhysicalDBNode

use of io.mycat.backend.datasource.PhysicalDBNode 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);
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : PhysicalDBNode(io.mycat.backend.datasource.PhysicalDBNode) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) PhysicalDBPool(io.mycat.backend.datasource.PhysicalDBPool) MycatConfig(io.mycat.config.MycatConfig) MySQLConsistencyChecker(io.mycat.backend.heartbeat.MySQLConsistencyChecker) PhysicalDatasource(io.mycat.backend.datasource.PhysicalDatasource) MySQLDataSource(io.mycat.backend.mysql.nio.MySQLDataSource) TableConfig(io.mycat.config.model.TableConfig)

Example 27 with PhysicalDBNode

use of io.mycat.backend.datasource.PhysicalDBNode in project Mycat-Server by MyCATApache.

the class SQLJob method run.

public void run() {
    try {
        if (ds == null) {
            RouteResultsetNode node = new RouteResultsetNode(dataNodeOrDatabase, ServerParse.SELECT, sql);
            // create new connection
            MycatConfig conf = MycatServer.getInstance().getConfig();
            PhysicalDBNode dn = conf.getDataNodes().get(node.getName());
            dn.getConnection(dn.getDatabase(), true, node, this, node);
        } else {
            ds.getConnection(dataNodeOrDatabase, true, this, null);
        }
    } catch (Exception e) {
        LOGGER.info("can't get connection for sql ,error:", e);
        doFinished(true, e.getMessage());
    }
}
Also used : PhysicalDBNode(io.mycat.backend.datasource.PhysicalDBNode) RouteResultsetNode(io.mycat.route.RouteResultsetNode) MycatConfig(io.mycat.config.MycatConfig)

Aggregations

PhysicalDBNode (io.mycat.backend.datasource.PhysicalDBNode)27 MycatConfig (io.mycat.config.MycatConfig)15 PhysicalDBPool (io.mycat.backend.datasource.PhysicalDBPool)13 PhysicalDatasource (io.mycat.backend.datasource.PhysicalDatasource)9 RouteResultsetNode (io.mycat.route.RouteResultsetNode)7 BackendConnection (io.mycat.backend.BackendConnection)6 SchemaConfig (io.mycat.config.model.SchemaConfig)6 DBHostConfig (io.mycat.config.model.DBHostConfig)4 TableConfig (io.mycat.config.model.TableConfig)4 IOException (java.io.IOException)4 Connection (java.sql.Connection)4 HashMap (java.util.HashMap)4 MycatCluster (io.mycat.config.MycatCluster)3 FirewallConfig (io.mycat.config.model.FirewallConfig)3 UserConfig (io.mycat.config.model.UserConfig)3 ConfigException (io.mycat.config.util.ConfigException)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 MySQLConsistencyChecker (io.mycat.backend.heartbeat.MySQLConsistencyChecker)2 MySQLDataSource (io.mycat.backend.mysql.nio.MySQLDataSource)2