MyCATApache/Mycat-Server · error · RuntimeException

invalid param ,connection request db is

Error message

invalid param ,connection request db is :${schema} and datanode db is ${database}

What it means

checkRequest validates that the schema requested for a backend connection matches the datanode's configured database. If a caller asks getConnection for a schema different from this.database, Mycat throws this RuntimeException, because one PhysicalDBNode can only serve connections to its own database. After the schema check it also initializes the dbPool if not yet initialized.

Solutions

  1. Align schema.xml: make the route's target dataNode's database match the requested schema, or fix the route rule so requests go to the correct dataNode.
  2. Fix the caller to pass the dataNode's own database as the schema parameter.
  3. Reload Mycat config after correcting schema.xml so this.database and the pools are consistent.
  4. Catch RuntimeException in the connection path and return a clear 'wrong datanode' error to the client.

Example fix

// before
// route sends a schema 'db1' request to a dataNode whose database is 'db2'
getConnection("db1", true, handler, attachment);
// after
// ensure the request targets the datanode matching its own database
if (!schema.equals(node.getDatabase())) {
    throw new IllegalArgumentException("route misconfig: " + schema + " != " + node.getDatabase());
}
getConnection(node.getDatabase(), true, handler, attachment);
Defensive patterns

Strategy: validation

Validate before calling

if (schema != null && !schema.equals(node.getDatabase())) {
    throw new IllegalArgumentException("schema " + schema + " does not match datanode db " + node.getDatabase());
}

Type guard

boolean matchesDatanode(PhysicalDBNode node, String schema) {
    return schema == null || node.getDatabase().equals(schema);
}

Try / catch

try {
    node.getConnection(schema, autocommit, handler, attachment);
} catch (RuntimeException e) {
    if (e.getMessage() != null && e.getMessage().startsWith("invalid param")) {
        throw new IllegalArgumentException("routing/config mismatch: " + e.getMessage(), e);
    }
    throw e;
}

Prevention

When it happens

Trigger: Calling PhysicalDBNode.getConnection(schema, ...) passing a schema string that differs from the datanode's configured database value — the route or caller targeted a dataNode whose database differs from the requested schema.

Common situations: schema.xml misconfiguration: a route rule points a SQL statement at a dataNode whose database differs from the schema in use; or application/protocol code passes the wrong currentSchema when requesting backend connections.

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


AI-assisted analysis of MyCATApache/Mycat-Server@65f8d8beb7 (2026-09-11). Data as JSON: /api/errors/ff925f5d0a86b295. Report an issue: GitHub.

Appendix: source

Thrown at src/main/java/io/mycat/backend/datasource/PhysicalDBNode.java:83

	 */
	public void getConnectionFromSameSource(String schema,boolean autocommit,
			BackendConnection exitsCon, ResponseHandler handler,
			Object attachment) throws Exception {

		PhysicalDatasource ds = this.dbPool.findDatasouce(exitsCon);
		if (ds == null) {
			throw new RuntimeException(
					"can't find existing connection,maybe fininshed " + exitsCon);
		} else {
			ds.getConnection(schema,autocommit, handler, attachment);
		}

	}

	private void checkRequest(String schema){
		if (schema != null
				&& !schema.equals(this.database)) {
			throw new RuntimeException(
					"invalid param ,connection request db is :"
							+ schema + " and datanode db is "
							+ this.database);
		}
		if (!dbPool.isInitSuccess()) {
			dbPool.init(dbPool.activedIndex);
		}
	}
	
	public void getConnection(String schema,boolean autoCommit, RouteResultsetNode rrs,
							ResponseHandler handler, Object attachment) throws Exception {
		checkRequest(schema);

		boolean needMaster = !autoCommit && MycatServer.getInstance().getConfig().getSystem().isStrictTxIsolation();
		if (needMaster && rrs.getRunOnSlave()==null){
			rrs.setRunOnSlave(false);//#2305
		}
		if (dbPool.isInitSuccess()) {

View on GitHub (pinned to 65f8d8beb7)