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

  1. Add dataNode="<existing-dataNode-name>" to the <schema> element in schema.xml.
  2. 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

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


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)