apache/shardingsphere · error · DataNodeGenerateException
2
2
Error message
Can not find data source in sharding rule, invalid actual data node '%s'.
What it means
DataNodeGenerateException ('Can not find data source in sharding rule, invalid actual data node') is thrown by ShardingTable.generateDataNodes while building the actual data nodes for a sharding table rule. Each configured actual data node string is parsed into (dataSource, tableName); if the parsed data source name is not in the rule's known data source names (dataSourceNames), the node is rejected. It is a configuration-load-time validation of data node expressions.
Source
Thrown at features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rule/ShardingTable.java:202
int index = 0;
for (String each : dataSourceNames) {
DataNode dataNode = new DataNode(each, (String) null, logicTable);
result.add(dataNode);
dataNodeIndexMap.put(dataNode, index);
actualDataSourceNames.add(each);
addActualTable(dataNode.getDataSourceName(), dataNode.getTableName());
index++;
}
return result;
}
private List<DataNode> generateDataNodes(final Collection<String> actualDataNodes, final Collection<String> dataSourceNames) {
List<DataNode> result = new ArrayList<>(actualDataNodes.size());
int index = 0;
for (String each : actualDataNodes) {
DataNode dataNode = new DataNode(each);
if (!dataSourceNames.contains(dataNode.getDataSourceName())) {
throw new DataNodeGenerateException(each);
}
result.add(dataNode);
dataNodeIndexMap.put(dataNode, index);
actualDataSourceNames.add(dataNode.getDataSourceName());
addActualTable(dataNode.getDataSourceName(), dataNode.getTableName());
index++;
}
return result;
}
/**
* Get data node groups.
*
* @return data node groups, key is data source name, values are data nodes belong to this data source
*/
public Map<String, List<DataNode>> getDataNodeGroups() {
return DataNodeUtils.getDataNodeGroups(actualDataNodes);
}View on GitHub (pinned to e952770a21)
Solutions
- Register the missing data source first (REGISTER STORAGE UNIT / add to dataSources) before creating or altering the sharding rule.
- Fix the actualDataNodes expression to reference only configured data sources (correct range or prefix).
- After renaming/removing storage units, update every sharding rule that references them.
Example fix
-- before: ds_9 not registered
CREATE SHARDING TABLE RULE t_order (
DATANODES("ds_9.t_order_${0..3}"), ...
);
-- after: register units, then reference them
REGISTER STORAGE UNIT ds_0 (...), ds_1 (...);
CREATE SHARDING TABLE RULE t_order (
DATANODES("ds_${0..1}.t_order_${0..3}"), ...
); Defensive patterns
Strategy: validation
Validate before calling
// Before creating/altering a rule, check every data node's data source is registered
Set<String> registered = /* storage unit names from SHOW STORAGE UNITS */ Set.of("ds_0", "ds_1");
for (String node : List.of("ds_${0..1}.t_order_${0..3}".expanded())) { // expand inline expression
String ds = node.split("\\.")[0];
if (!registered.contains(ds)) { throw new IllegalStateException("Unregistered data source: " + ds); }
} Try / catch
try {
proxySession.executeddl("CREATE SHARDING TABLE RULE ...");
} catch (final DataNodeGenerateException ex) {
// register the missing storage unit, then re-apply the rule
} Prevention
- Always REGISTER STORAGE UNIT before referencing new data sources in rules.
- Keep inline expression ranges in sync with the number of registered data sources.
When it happens
Trigger: An actualDataNodes entry like ds_9.t_order_0 where ds_9 is not among the data source names available to the sharding rule (not registered in mode configuration / not in dataSourceNames), or an inline expression that expands to an unconfigured data source index.
Common situations: Typo in the data source prefix; inline expression ds_${0..4} when only ds_0..ds_2 exist; renaming a data source without updating sharding rules; adding a rule via DistSQL before registering the data source (REGISTER STORAGE UNIT).
Related errors
AI-assisted analysis of apache/shardingsphere@e952770a21 (2026-08-14).
Data as JSON: /api/errors/e141fefd742940cb.
Report an issue: GitHub.