use of com.actiontech.dble.config.util.ConfigException in project dble by actiontech.
the class XMLSchemaLoader method checkRuleSuitTable.
/**
* shard table datanode(2) < function count(3) and check failed
*/
private void checkRuleSuitTable(TableConfig tableConf) {
AbstractPartitionAlgorithm function = tableConf.getRule().getRuleAlgorithm();
int suitValue = function.suitableFor(tableConf);
if (suitValue < 0) {
throw new ConfigException("Illegal table conf : table [ " + tableConf.getName() + " ] rule function [ " + tableConf.getRule().getFunctionName() + " ] partition size : " + tableConf.getRule().getRuleAlgorithm().getPartitionNum() + " > table datanode size : " + tableConf.getDataNodes().size() + ", please make sure table datanode size = function partition size");
} else if (suitValue > 0) {
LOGGER.info("table conf : table [ {} ] rule function [ {} ] partition size : {} < table datanode size : {} , this cause some datanode to be redundant", new String[] { tableConf.getName(), tableConf.getRule().getFunctionName(), String.valueOf(tableConf.getRule().getRuleAlgorithm().getPartitionNum()), String.valueOf(tableConf.getDataNodes().size()) });
} else {
// table data node size == rule function partition size
}
}
use of com.actiontech.dble.config.util.ConfigException in project dble by actiontech.
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");
if (lowerCaseNames) {
name = name.toLowerCase();
}
String dataNode = schemaElement.getAttribute("dataNode");
String sqlMaxLimitStr = schemaElement.getAttribute("sqlMaxLimit");
int sqlMaxLimit = -1;
// sql result size limit
if (sqlMaxLimitStr != null && !sqlMaxLimitStr.isEmpty()) {
sqlMaxLimit = Integer.parseInt(sqlMaxLimitStr);
}
// check and add dataNode
if (dataNode != null && !dataNode.isEmpty()) {
List<String> dataNodeLst = new ArrayList<>(1);
dataNodeLst.add(dataNode);
checkDataNodeExists(dataNodeLst);
} else {
dataNode = null;
}
// load tables from schema
Map<String, TableConfig> tables = loadTables(schemaElement, lowerCaseNames);
if (schemas.containsKey(name)) {
throw new ConfigException("schema " + name + " duplicated!");
}
// if schema has no default dataNode,it must contains at least one table
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);
mergeFuncNodeERMap(schemaConfig);
mergeFkERMap(schemaConfig);
schemas.put(name, schemaConfig);
}
makeAllErRelations();
}
use of com.actiontech.dble.config.util.ConfigException in project dble by actiontech.
the class XMLSchemaLoader method load.
private void load(String dtdFile, String xmlFile) {
InputStream dtd = null;
InputStream xml = null;
try {
dtd = ResourceUtil.getResourceAsStream(dtdFile);
xml = ResourceUtil.getResourceAsStream(xmlFile);
Element root = ConfigUtil.getDocument(dtd, xml).getDocumentElement();
loadDataHosts(root);
loadDataNodes(root);
loadSchemas(root);
} catch (ConfigException e) {
throw e;
} catch (Exception e) {
throw new ConfigException(e);
} finally {
if (dtd != null) {
try {
dtd.close();
} catch (IOException e) {
// ignore error
}
}
if (xml != null) {
try {
xml.close();
} catch (IOException e) {
// ignore error
}
}
}
}
Aggregations