From 1cc1b351ffee48bd2b1cd1f8244d6221a8a69162 Mon Sep 17 00:00:00 2001 From: Markus Makela Date: Wed, 18 Mar 2015 19:45:32 +0200 Subject: [PATCH] Updated Schemarouter documentation. --- .../routers/schemarouter/SchemaRouter.md | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/Documentation/routers/schemarouter/SchemaRouter.md b/Documentation/routers/schemarouter/SchemaRouter.md index 3c6730a8d..486be21b2 100644 --- a/Documentation/routers/schemarouter/SchemaRouter.md +++ b/Documentation/routers/schemarouter/SchemaRouter.md @@ -2,6 +2,14 @@ The SchemaRouter router provides an easy and manageable sharding solution by building a single logical database server from multiple separate ones. Each database is shown to the client and queries targeting unique databases are routed to their respective servers. In addition to providing simple database-based sharding, the schemarouter router also enables cross-node session variable usage by routing all queries that modify the session to all nodes. +## Routing Logic + +If a command line client is used, i.e. `mysql`, and a direct connection to the database is initialized without a default database, the router starts with no default server where the queries are routed. This means that each query that doesn't specify a database is routed to the first available server. + +If a `USE ` query is executed or a default database is defined when connecting to MaxScale, all queries without explicitly stated databases will be routed to the server which has this database. If multiple servers have the same database and the user connecting to MaxScale has rights to all of them, the database is associated to the first server that responds when the databases are mapped. In practice this means that query results will always come from a single server but the data might not always be from the same node. + +In almost all the cases these can be avoided by proper server configuration and the databases are always mapped to the same servers. More on configuration in the next chapter. + ## Configuration Here is an example configuration of the schemarouter router: @@ -18,13 +26,13 @@ The module generates the list of databases based on the servers parameter using The list of databases is built by sending a SHOW DATABASES query to all the servers. This requires the user to have at least USAGE and SELECT grants on the databases that need be sharded. For example, if two servers have the database 'shard' and the following rights are granted only on one server, all queries targeting the database 'shard' would be routed to the server where the grants were given. +``` +# Execute this on both servers +CREATE USER 'john'@'%' IDENTIFIED BY 'password'; - # Execute this on both servers - CREATE USER 'john'@'%' IDENTIFIED BY 'password'; - - # Execute this only on the server where you want the queries to go - GRANT SELECT,USAGE ON shard.* TO 'john'@'%'; - +# Execute this only on the server where you want the queries to go +GRANT SELECT,USAGE ON shard.* TO 'john'@'%'; +``` This would in effect allow the user 'john' to only see the database 'shard' on this server. Take notice that these grants are matched against MaxScale's hostname instead of the client's hostname. Only user authentication uses the client's hostname and all other grants use MaxScale's hostname. ## Limitations