MyCATApache/Mycat-Server · error · IllegalArgumentException
can't find datanode for sharding column
Error message
can't find datanode for sharding column:{col} val:{colValue} What it means
ruleCalculate evaluates each sharding column value through the table rule's partition algorithm. When algorithm.calculate(value) returns null, the value cannot be mapped to any configured data node index, and IllegalArgumentException('can't find datanode for sharding column:...') is thrown. This typically means the value is outside the algorithm's supported input space.
Solutions
- Fix the data so sharding-key values fall inside the algorithm's supported range/format
- Update the rule config (range file, map file, or algorithm params) to cover the offending values
- Pre-validate sharding column values in application code and reject/convert invalid values before issuing SQL
Example fix
// before
Integer idx = algorithm.calculate("abc"); // null -> error
// after: guard in app code
if (!shardValueMatchesRule(value)) { throw new IllegalArgumentException("invalid shard value: " + value); }
Integer idx = algorithm.calculate(value); Defensive patterns
Strategy: validation
Validate before calling
// before issuing SQL with shard key
Integer idx = rule.getRuleAlgorithm().calculate(String.valueOf(shardValue));
if (idx == null) throw new IllegalArgumentException("shard value not mappable: " + shardValue); Try / catch
try { execute(sql); } catch (IllegalArgumentException e) { if (e.getMessage().startsWith("can't find datanode")) { /* fix value or rule config */ } throw e; } Prevention
- Match sharding column data types to the algorithm (numeric algorithm -> numeric values)
- Extend range/map files to cover all real key values
- Log and alert on null algorithm results in pre-prod tests
When it happens
Trigger: DML/SELECT routed by rule where the sharding column value yields null from the rule algorithm — e.g. a non-numeric string with a numeric partition algorithm (NumberFormatException caught returning null), a date out of the configured range, or an enum value with no mapping in a map-file based rule.
Common situations: Inserting rows whose shard key values fall outside auto-sharding-long's date range; strings passed to a long/int algorithm; partition map file (mapping file) missing the used values; NULL handling mismatch.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- can't find any valid datanode : -> ->
- find no Route:
- parent key can't find any valid datanode
- invalid route in sql, multi tables found but datanode has…
- route rule for table
AI-assisted analysis of MyCATApache/Mycat-Server@65f8d8beb7 (2026-09-11).
Data as JSON: /api/errors/810ffb784285f654.
Report an issue: GitHub.
Appendix: source
Thrown at src/main/java/io/mycat/route/util/RouterUtil.java:1185
return retNodeSet;
}
/**
* @return dataNodeIndex -> [partitionKeysValueTuple+]
*/
public static Set<String> ruleCalculate(TableConfig tc,
Set<ColumnRoutePair> colRoutePairSet,Map<String,Integer> dataNodeSlotMap) {
Set<String> routeNodeSet = new LinkedHashSet<String>();
String col = tc.getRule().getColumn();
RuleConfig rule = tc.getRule();
AbstractPartitionAlgorithm algorithm = rule.getRuleAlgorithm();
for (ColumnRoutePair colPair : colRoutePairSet) {
if (colPair.colValue != null) {
Integer nodeIndx = algorithm.calculate(StringUtil.removeBackquote(colPair.colValue));
if (nodeIndx == null) {
throw new IllegalArgumentException(
"can't find datanode for sharding column:" + col
+ " val:" + colPair.colValue);
} else {
String dataNode = tc.getDataNodes().get(nodeIndx);
routeNodeSet.add(dataNode);
if(algorithm instanceof SlotFunction) {
dataNodeSlotMap.put(dataNode,((SlotFunction) algorithm).slotValue());
}
colPair.setNodeId(nodeIndx);
}
} else if (colPair.rangeValue != null) {
Integer[] nodeRange = algorithm.calculateRange(
String.valueOf(colPair.rangeValue.beginValue),
String.valueOf(colPair.rangeValue.endValue));
if (nodeRange != null) {
/**
* 不能确认 colPair的 nodeid是否会有其它影响
*/
View on GitHub (pinned to 65f8d8beb7)