{"record":{"id":"ff925f5d0a86b295","repo":"MyCATApache/Mycat-Server","slug":"invalid-param-connection-request-db-is-schema","errorCode":null,"errorMessage":"invalid param ,connection request db is :${schema} and datanode db is ${database}","messagePattern":"invalid param ,connection request db is :(.+?) and datanode db is (.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/main/java/io/mycat/backend/datasource/PhysicalDBNode.java","lineNumber":83,"sourceCode":"\t */\n\tpublic void getConnectionFromSameSource(String schema,boolean autocommit,\n\t\t\tBackendConnection exitsCon, ResponseHandler handler,\n\t\t\tObject attachment) throws Exception {\n\n\t\tPhysicalDatasource ds = this.dbPool.findDatasouce(exitsCon);\n\t\tif (ds == null) {\n\t\t\tthrow new RuntimeException(\n\t\t\t\t\t\"can't find existing connection,maybe fininshed \" + exitsCon);\n\t\t} else {\n\t\t\tds.getConnection(schema,autocommit, handler, attachment);\n\t\t}\n\n\t}\n\n\tprivate void checkRequest(String schema){\n\t\tif (schema != null\n\t\t\t\t&& !schema.equals(this.database)) {\n\t\t\tthrow new RuntimeException(\n\t\t\t\t\t\"invalid param ,connection request db is :\"\n\t\t\t\t\t\t\t+ schema + \" and datanode db is \"\n\t\t\t\t\t\t\t+ this.database);\n\t\t}\n\t\tif (!dbPool.isInitSuccess()) {\n\t\t\tdbPool.init(dbPool.activedIndex);\n\t\t}\n\t}\n\t\n\tpublic void getConnection(String schema,boolean autoCommit, RouteResultsetNode rrs,\n\t\t\t\t\t\t\tResponseHandler handler, Object attachment) throws Exception {\n\t\tcheckRequest(schema);\n\n\t\tboolean needMaster = !autoCommit && MycatServer.getInstance().getConfig().getSystem().isStrictTxIsolation();\n\t\tif (needMaster && rrs.getRunOnSlave()==null){\n\t\t\trrs.setRunOnSlave(false);//#2305\n\t\t}\n\t\tif (dbPool.isInitSuccess()) {","sourceCodeStart":65,"sourceCodeEnd":101,"githubUrl":"https://github.com/MyCATApache/Mycat-Server/blob/65f8d8beb752f935752f2a0eec0ab017facab9ef/src/main/java/io/mycat/backend/datasource/PhysicalDBNode.java#L65-L101","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["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.","Fix the caller to pass the dataNode's own database as the schema parameter.","Reload Mycat config after correcting schema.xml so this.database and the pools are consistent.","Catch RuntimeException in the connection path and return a clear 'wrong datanode' error to the client."],"exampleFix":"// before\n// route sends a schema 'db1' request to a dataNode whose database is 'db2'\ngetConnection(\"db1\", true, handler, attachment);\n// after\n// ensure the request targets the datanode matching its own database\nif (!schema.equals(node.getDatabase())) {\n    throw new IllegalArgumentException(\"route misconfig: \" + schema + \" != \" + node.getDatabase());\n}\ngetConnection(node.getDatabase(), true, handler, attachment);","handlingStrategy":"validation","validationCode":"if (schema != null && !schema.equals(node.getDatabase())) {\n    throw new IllegalArgumentException(\"schema \" + schema + \" does not match datanode db \" + node.getDatabase());\n}","typeGuard":"boolean matchesDatanode(PhysicalDBNode node, String schema) {\n    return schema == null || node.getDatabase().equals(schema);\n}","tryCatchPattern":"try {\n    node.getConnection(schema, autocommit, handler, attachment);\n} catch (RuntimeException e) {\n    if (e.getMessage() != null && e.getMessage().startsWith(\"invalid param\")) {\n        throw new IllegalArgumentException(\"routing/config mismatch: \" + e.getMessage(), e);\n    }\n    throw e;\n}","preventionTips":["Keep the schema used by routes identical to the dataNode's database value in schema.xml.","Validate schema.xml after every edit (routes vs dataNode databases).","Reload config after changes so dbPool and this.database stay in sync.","Log both requested schema and datanode database on mismatch to speed diagnosis."],"tags":["config","schema-mismatch","datanode","validation"],"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"}