use of com.actiontech.dble.route.function.AbstractPartitionAlgorithm in project dble by actiontech.
the class RouterUtil method routeWithPartition.
private static void routeWithPartition(Map<String, Set<String>> tablesRouteMap, String tableName, TableConfig tableConfig, Set<ColumnRoutePair> partitionValue) throws SQLNonTransientException {
for (ColumnRoutePair pair : partitionValue) {
AbstractPartitionAlgorithm algorithm = tableConfig.getRule().getRuleAlgorithm();
if (pair.colValue != null) {
if (NEED_REPLACE.equals(pair.colValue)) {
return;
}
Integer nodeIndex = algorithm.calculate(pair.colValue);
if (nodeIndex == null) {
String msg = "can't find any valid data node :" + tableConfig.getName() + " -> " + tableConfig.getPartitionColumn() + " -> " + pair.colValue;
LOGGER.info(msg);
throw new SQLNonTransientException(msg);
}
ArrayList<String> dataNodes = tableConfig.getDataNodes();
String node;
if (nodeIndex >= 0 && nodeIndex < dataNodes.size()) {
node = dataNodes.get(nodeIndex);
} else {
node = null;
String msg = "Can't find a valid data node for specified node index :" + tableConfig.getName() + " -> " + tableConfig.getPartitionColumn() + " -> " + pair.colValue + " -> " + "Index : " + nodeIndex;
LOGGER.info(msg);
throw new SQLNonTransientException(msg);
}
if (node != null) {
if (tablesRouteMap.get(tableName) == null) {
tablesRouteMap.put(tableName, new HashSet<String>());
}
tablesRouteMap.get(tableName).add(node);
}
}
if (pair.rangeValue != null) {
Integer[] nodeIndexes = algorithm.calculateRange(pair.rangeValue.getBeginValue().toString(), pair.rangeValue.getEndValue().toString());
ArrayList<String> dataNodes = tableConfig.getDataNodes();
String node;
for (Integer idx : nodeIndexes) {
if (idx >= 0 && idx < dataNodes.size()) {
node = dataNodes.get(idx);
} else {
String msg = "Can't find valid data node(s) for some of specified node indexes :" + tableConfig.getName() + " -> " + tableConfig.getPartitionColumn();
LOGGER.info(msg);
throw new SQLNonTransientException(msg);
}
if (node != null) {
if (tablesRouteMap.get(tableName) == null) {
tablesRouteMap.put(tableName, new HashSet<String>());
}
tablesRouteMap.get(tableName).add(node);
}
}
}
}
}
use of com.actiontech.dble.route.function.AbstractPartitionAlgorithm 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
}
}
Aggregations