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;
}
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);
}
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);
}
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;
}
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;
}
Aggregations