use of io.mycat.config.model.DataNodeConfig in project Mycat-Server by MyCATApache.
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-Server by MyCATApache.
the class XMLSchemaLoader method getDbType.
private Set<String> getDbType(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-Server by MyCATApache.
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 XMLSchemaLoader method loadSchemas.
private void loadSchemas(Element root) {
NodeList list = root.getElementsByTagName("schema");
for (int i = 0, n = list.getLength(); i < n; i++) {
Element schemaElement = (Element) list.item(i);
// 读取各个属性
String name = schemaElement.getAttribute("name");
String dataNode = schemaElement.getAttribute("dataNode");
String checkSQLSchemaStr = schemaElement.getAttribute("checkSQLschema");
String sqlMaxLimitStr = schemaElement.getAttribute("sqlMaxLimit");
int sqlMaxLimit = -1;
// 读取sql返回结果集限制
if (sqlMaxLimitStr != null && !sqlMaxLimitStr.isEmpty()) {
sqlMaxLimit = Integer.parseInt(sqlMaxLimitStr);
}
// check dataNode already exists or not,看schema标签中是否有datanode
String defaultDbType = null;
// 校验检查并添加dataNode
if (dataNode != null && !dataNode.isEmpty()) {
List<String> dataNodeLst = new ArrayList<String>(1);
dataNodeLst.add(dataNode);
checkDataNodeExists(dataNodeLst);
String dataHost = dataNodes.get(dataNode).getDataHost();
defaultDbType = dataHosts.get(dataHost).getDbType();
} else {
dataNode = null;
}
// 加载schema下所有tables
Map<String, TableConfig> tables = loadTables(schemaElement);
// 判断schema是否重复
if (schemas.containsKey(name)) {
throw new ConfigException("schema " + name + " duplicated!");
}
// 设置了table的不需要设置dataNode属性,没有设置table的必须设置dataNode属性
if (dataNode == null && tables.size() == 0) {
throw new ConfigException("schema " + name + " didn't config tables,so you must set dataNode property!");
}
SchemaConfig schemaConfig = new SchemaConfig(name, dataNode, tables, sqlMaxLimit, "true".equalsIgnoreCase(checkSQLSchemaStr));
// 设定DB类型,这对之后的sql语句路由解析有帮助
if (defaultDbType != null) {
schemaConfig.setDefaultDataNodeDbType(defaultDbType);
if (!"mysql".equalsIgnoreCase(defaultDbType)) {
schemaConfig.setNeedSupportMultiDBType(true);
}
}
// 判断是否有不是mysql的数据库类型,方便解析判断是否启用多数据库分页语法解析
for (TableConfig tableConfig : tables.values()) {
if (isHasMultiDbType(tableConfig)) {
schemaConfig.setNeedSupportMultiDBType(true);
break;
}
}
// 记录每种dataNode的DB类型
Map<String, String> dataNodeDbTypeMap = new HashMap<>();
for (String dataNodeName : dataNodes.keySet()) {
DataNodeConfig dataNodeConfig = dataNodes.get(dataNodeName);
String dataHost = dataNodeConfig.getDataHost();
DataHostConfig dataHostConfig = dataHosts.get(dataHost);
if (dataHostConfig != null) {
String dbType = dataHostConfig.getDbType();
dataNodeDbTypeMap.put(dataNodeName, dbType);
}
}
schemaConfig.setDataNodeDbTypeMap(dataNodeDbTypeMap);
schemas.put(name, schemaConfig);
}
}
use of io.mycat.config.model.DataNodeConfig in project Mycat_plus by coderczp.
the class XMLSchemaLoader method getDbType.
private Set<String> getDbType(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;
}
Aggregations