MyCATApache/Mycat-Server · critical · RuntimeException
in noSharding mode schema must have default dataNode
Error message
${name} in noSharding mode schema must have default dataNode What it means
SchemaConfig's constructor determines a schema is in noSharding mode when it has no <table> entries; in that mode the schema itself must carry a default dataNode. If tables is null/empty and dataNode is null, a RuntimeException is thrown because Mycat would have nowhere to route queries for the schema.
Solutions
- Add dataNode="<existing-dataNode-name>" to the <schema> element in schema.xml.
- Add at least one <table> mapping to the schema so it is no longer noSharding mode.
Example fix
// before (schema.xml) <schema name="TESTDB" checkSQLschema="true"></schema> // after <schema name="TESTDB" checkSQLschema="true" dataNode="dn1"></schema>
Defensive patterns
Strategy: validation
Validate before calling
// XML/config check before loading
boolean hasTables = schemaTables != null && !schemaTables.isEmpty();
if (!hasTables && (schemaDataNode == null || schemaDataNode.isEmpty())) {
throw new IllegalArgumentException("noSharding schema requires dataNode attribute");
} Try / catch
try { new SchemaConfig(...); } catch (RuntimeException e) { if (e.getMessage().contains("must have default dataNode")) { LOG.error("Schema {} needs dataNode attribute", name); } throw e; } Prevention
- Always set dataNode on schemas that contain no table elements.
- Template your schema.xml with a required dataNode placeholder.
- Run schema.xml validation in CI before deploying Mycat.
When it happens
Trigger: Constructing a SchemaConfig (via schema.xml parsing) where the schema has no child table elements and no dataNode attribute is set.
Common situations: Defining a schema element with an empty or absent table list and forgetting dataNode="dn1"; migrating a schema from sharded to no-sharding mode and dropping the dataNode attribute.
Understand the failure class
Background: "is required", "must be set", "missing required field": configuration validation errors across open-source libraries — this error's family across 36 libraries.
Related errors
- SelfCheck### user refered schemas is empty!
- ruleRequired but rule is null
- SelfCheck### user all node is empty!
- SelfCheck### users node within the item is empty!
- SelfCheck### schema
AI-assisted analysis of MyCATApache/Mycat-Server@65f8d8beb7 (2026-09-11).
Data as JSON: /api/errors/bc7e1bcd1528ba46.
Report an issue: GitHub.
Appendix: source
Thrown at src/main/java/io/mycat/config/model/SchemaConfig.java:73
* ,then A is root table
*/
private final Map<String, TableConfig> joinRel2TableMap = new HashMap<String, TableConfig>();
private final String[] allDataNodeStrArr;
private Map<String,String> dataNodeDbTypeMap=new HashMap<>();
public SchemaConfig(String name, String dataNode,
Map<String, TableConfig> tables, int defaultMaxLimit,
boolean checkSQLschema,String randomDataNode) {
this.name = name;
this.dataNode = dataNode;
this.checkSQLSchema = checkSQLschema;
this.tables = tables;
this.defaultMaxLimit = defaultMaxLimit;
buildJoinMap(tables);
this.noSharding = (tables == null || tables.isEmpty());
if (noSharding && dataNode == null) {
throw new RuntimeException(name
+ " in noSharding mode schema must have default dataNode ");
}
this.metaDataNodes = buildMetaDataNodes();
this.allDataNodes = buildAllDataNodes();
// this.metaDataNodes = buildAllDataNodes();
if (this.allDataNodes != null && !this.allDataNodes.isEmpty()) {
String[] dnArr = new String[this.allDataNodes.size()];
dnArr = this.allDataNodes.toArray(dnArr);
this.allDataNodeStrArr = dnArr;
} else {
this.allDataNodeStrArr = null;
}
this.randomDataNode =randomDataNode;
}
public String getDefaultDataNodeDbType()
{
return defaultDataNodeDbType;View on GitHub (pinned to 65f8d8beb7)