Search in sources :

Example 1 with DataNodeConfig

use of io.mycat.config.model.DataNodeConfig in project Mycat_plus by coderczp.

the class XMLSchemaLoader method getDataNodeDbTypeMap.

private Set<String> getDataNodeDbTypeMap(String dataNode) {
    Set<String> dbTypes = new HashSet<>();
    String[] dataNodeArr = SplitUtil.split(dataNode, ',', '$', '-');
    for (String node : dataNodeArr) {
        DataNodeConfig datanode = dataNodes.get(node);
        DataHostConfig datahost = dataHosts.get(datanode.getDataHost());
        dbTypes.add(datahost.getDbType());
    }
    return dbTypes;
}
Also used : DataHostConfig(io.mycat.config.model.DataHostConfig) DataNodeConfig(io.mycat.config.model.DataNodeConfig)

Example 2 with DataNodeConfig

use of io.mycat.config.model.DataNodeConfig in project Mycat_plus by coderczp.

the class XMLSchemaLoader method createDataNode.

private void createDataNode(String dnName, String database, String host) {
    DataNodeConfig conf = new DataNodeConfig(dnName, database, host);
    if (dataNodes.containsKey(conf.getName())) {
        throw new ConfigException("dataNode " + conf.getName() + " duplicated!");
    }
    if (!dataHosts.containsKey(host)) {
        throw new ConfigException("dataNode " + dnName + " reference dataHost:" + host + " not exists!");
    }
    dataHosts.get(host).addDataNode(conf.getName());
    dataNodes.put(conf.getName(), conf);
}
Also used : ConfigException(io.mycat.config.util.ConfigException) DataNodeConfig(io.mycat.config.model.DataNodeConfig)

Example 3 with DataNodeConfig

use of io.mycat.config.model.DataNodeConfig in project Mycat_plus by coderczp.

the class XMLSchemaLoader method distributeDataNodes.

/**
 * distribute datanodes in multi hosts,means ,dn1 (host1),dn100
 * (host2),dn300(host3),dn2(host1),dn101(host2),dn301(host3)...etc
 *	将每个host上的datanode按照host重新排列。比如上面的例子host1拥有dn1,dn2,host2拥有dn100,dn101,host3拥有dn300,dn301,
 * 按照host重新排列: 0->dn1 (host1),1->dn100(host2),2->dn300(host3),3->dn2(host1),4->dn101(host2),5->dn301(host3)
 *
 * @param theDataNodes
 */
private void distributeDataNodes(ArrayList<String> theDataNodes) {
    Map<String, ArrayList<String>> newDataNodeMap = new HashMap<String, ArrayList<String>>(dataHosts.size());
    for (String dn : theDataNodes) {
        DataNodeConfig dnConf = dataNodes.get(dn);
        String host = dnConf.getDataHost();
        ArrayList<String> hostDns = newDataNodeMap.get(host);
        hostDns = (hostDns == null) ? new ArrayList<String>() : hostDns;
        hostDns.add(dn);
        newDataNodeMap.put(host, hostDns);
    }
    ArrayList<String> result = new ArrayList<String>(theDataNodes.size());
    boolean hasData = true;
    while (hasData) {
        hasData = false;
        for (ArrayList<String> dns : newDataNodeMap.values()) {
            if (!dns.isEmpty()) {
                result.add(dns.remove(0));
                hasData = true;
            }
        }
    }
    theDataNodes.clear();
    theDataNodes.addAll(result);
}
Also used : DataNodeConfig(io.mycat.config.model.DataNodeConfig)

Example 4 with DataNodeConfig

use of io.mycat.config.model.DataNodeConfig in project Mycat_plus by coderczp.

the class ConfigInitializer method initDataNodes.

private Map<String, PhysicalDBNode> initDataNodes(ConfigLoader configLoader) {
    Map<String, DataNodeConfig> nodeConfs = configLoader.getDataNodes();
    Map<String, PhysicalDBNode> nodes = new HashMap<String, PhysicalDBNode>(nodeConfs.size());
    for (DataNodeConfig conf : nodeConfs.values()) {
        PhysicalDBPool pool = this.dataHosts.get(conf.getDataHost());
        if (pool == null) {
            throw new ConfigException("dataHost not exists " + conf.getDataHost());
        }
        PhysicalDBNode dataNode = new PhysicalDBNode(conf.getName(), conf.getDatabase(), pool);
        nodes.put(dataNode.getName(), dataNode);
    }
    return nodes;
}
Also used : PhysicalDBNode(io.mycat.backend.datasource.PhysicalDBNode) HashMap(java.util.HashMap) PhysicalDBPool(io.mycat.backend.datasource.PhysicalDBPool) ConfigException(io.mycat.config.util.ConfigException) DataNodeConfig(io.mycat.config.model.DataNodeConfig)

Example 5 with DataNodeConfig

use of io.mycat.config.model.DataNodeConfig in project Mycat_plus by coderczp.

the class ConfigComparer method getDataNodes.

// 获取拆分表对应节点列表,具体到实例地址、库
private List<DataNode> getDataNodes(TableConfig tableConfig, Map<String, DataNodeConfig> dnConfig, Map<String, DataHostConfig> dhConfig) {
    List<DataNode> dataNodes = new ArrayList<DataNode>();
    // TO-DO
    ArrayList<String> dataNodeNames = tableConfig.getDataNodes();
    int i = 0;
    for (String name : dataNodeNames) {
        DataNodeConfig config = dnConfig.get(name);
        String db = config.getDatabase();
        String dataHost = config.getDataHost();
        DataHostConfig dh = dhConfig.get(dataHost);
        String dbType = dh.getDbType();
        DBHostConfig[] writeHosts = dh.getWriteHosts();
        DBHostConfig currentWriteHost;
        if (isAwaysUseMaster) {
            currentWriteHost = writeHosts[0];
        } else {
            // 迁移数据发生在当前切换后的数据源
            currentWriteHost = writeHosts[Integer.valueOf(dnIndexProps.getProperty(dh.getName()))];
        }
        DataNode dn = new DataNode(name, currentWriteHost.getIp(), currentWriteHost.getPort(), currentWriteHost.getUser(), currentWriteHost.getPassword(), db, dbType, i++);
        dataNodes.add(dn);
    }
    return dataNodes;
}
Also used : DBHostConfig(io.mycat.config.model.DBHostConfig) ArrayList(java.util.ArrayList) DataHostConfig(io.mycat.config.model.DataHostConfig) DataNodeConfig(io.mycat.config.model.DataNodeConfig)

Aggregations

DataNodeConfig (io.mycat.config.model.DataNodeConfig)14 DataHostConfig (io.mycat.config.model.DataHostConfig)8 ConfigException (io.mycat.config.util.ConfigException)6 PhysicalDBNode (io.mycat.backend.datasource.PhysicalDBNode)2 PhysicalDBPool (io.mycat.backend.datasource.PhysicalDBPool)2 DBHostConfig (io.mycat.config.model.DBHostConfig)2 SchemaConfig (io.mycat.config.model.SchemaConfig)2 TableConfig (io.mycat.config.model.TableConfig)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Element (org.w3c.dom.Element)2 NodeList (org.w3c.dom.NodeList)2