{"record":{"id":"810ffb784285f654","repo":"MyCATApache/Mycat-Server","slug":"can-t-find-datanode-for-sharding-column-col-val","errorCode":null,"errorMessage":"can't find datanode for sharding column:{col} val:{colValue}","messagePattern":"can't find datanode for sharding column:(.+?) val:(.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/io/mycat/route/util/RouterUtil.java","lineNumber":1185,"sourceCode":"\r\n\t\treturn retNodeSet;\r\n\t}\r\n\r\n\r\n\t/**\r\n\t * @return dataNodeIndex -&gt; [partitionKeysValueTuple+]\r\n\t */\r\n\tpublic static Set<String> ruleCalculate(TableConfig tc,\r\n\t\t\tSet<ColumnRoutePair> colRoutePairSet,Map<String,Integer>   dataNodeSlotMap)  {\r\n\t\tSet<String> routeNodeSet = new LinkedHashSet<String>();\r\n\t\tString col = tc.getRule().getColumn();\r\n\t\tRuleConfig rule = tc.getRule();\r\n\t\tAbstractPartitionAlgorithm algorithm = rule.getRuleAlgorithm();\r\n\t\tfor (ColumnRoutePair colPair : colRoutePairSet) {\r\n\t\t\tif (colPair.colValue != null) {\r\n\t\t\t\tInteger nodeIndx = algorithm.calculate(StringUtil.removeBackquote(colPair.colValue));\r\n\t\t\t\tif (nodeIndx == null) {\r\n\t\t\t\t\tthrow new IllegalArgumentException(\r\n\t\t\t\t\t\t\t\"can't find datanode for sharding column:\" + col\r\n\t\t\t\t\t\t\t\t\t+ \" val:\" + colPair.colValue);\r\n\t\t\t\t} else {\r\n\t\t\t\t\tString dataNode = tc.getDataNodes().get(nodeIndx);\r\n\t\t\t\t\trouteNodeSet.add(dataNode);\r\n\t\t\t\t\tif(algorithm instanceof SlotFunction) {\r\n\t\t\t\t\t\tdataNodeSlotMap.put(dataNode,((SlotFunction) algorithm).slotValue());\r\n\t\t\t\t\t}\r\n\t\t\t\t\tcolPair.setNodeId(nodeIndx);\r\n\t\t\t\t}\r\n\t\t\t} else if (colPair.rangeValue != null) {\r\n\t\t\t\tInteger[] nodeRange = algorithm.calculateRange(\r\n\t\t\t\t\t\tString.valueOf(colPair.rangeValue.beginValue),\r\n\t\t\t\t\t\tString.valueOf(colPair.rangeValue.endValue));\r\n\t\t\t\tif (nodeRange != null) {\r\n\t\t\t\t\t/**\r\n\t\t\t\t\t * 不能确认 colPair的 nodeid是否会有其它影响\r\n\t\t\t\t\t */\r","sourceCodeStart":1167,"sourceCodeEnd":1203,"githubUrl":"https://github.com/MyCATApache/Mycat-Server/blob/65f8d8beb752f935752f2a0eec0ab017facab9ef/src/main/java/io/mycat/route/util/RouterUtil.java#L1167-L1203","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nInteger idx = algorithm.calculate(\"abc\"); // null -> error\n// after: guard in app code\nif (!shardValueMatchesRule(value)) { throw new IllegalArgumentException(\"invalid shard value: \" + value); }\nInteger idx = algorithm.calculate(value);","handlingStrategy":"validation","validationCode":"// before issuing SQL with shard key\nInteger idx = rule.getRuleAlgorithm().calculate(String.valueOf(shardValue));\nif (idx == null) throw new IllegalArgumentException(\"shard value not mappable: \" + shardValue);","typeGuard":null,"tryCatchPattern":"try { execute(sql); } catch (IllegalArgumentException e) { if (e.getMessage().startsWith(\"can't find datanode\")) { /* fix value or rule config */ } throw e; }","preventionTips":["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"],"tags":["sharding","algorithm","routing"],"backgroundTag":"invalid-argument-value","analyzedSha":"65f8d8beb752f935752f2a0eec0ab017facab9ef","analyzedAt":"2026-09-11T00:12:21.696Z","contentChangedAt":"2026-09-11T00:12:21.696Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}