diff --git a/Documentation/dbshard/DBShard.md b/Documentation/dbshard/DBShard.md index 38f7d73a6..58e2a58f4 100644 --- a/Documentation/dbshard/DBShard.md +++ b/Documentation/dbshard/DBShard.md @@ -13,7 +13,17 @@ Here is an example configuration of the dbshard router: user=myuser passwd=mypwd -The module generates the list of databases based on the servers parameter using the connecting client's credentials. The user and passwd parameters define the credentials that are used to fetch the authentication data from the database servers. The credentials used only require the same grants as mentioned in the README. +The module generates the list of databases based on the servers parameter using the connecting client's credentials. The user and passwd parameters define the credentials that are used to fetch the authentication data from the database servers. The credentials used only require the same grants as mentioned in the configuration documentation. + +The list of databases is built by sending a SHOW DATABASES query to all the servers. This requires the user to have usage access 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 this server. + + CREATE USER 'john'@'%' IDENTIFIED BY 'password'; + REVOKE USAGE ON *.* FROM 'john'@'%'; + GRANT USAGE ON shard.* TO 'john'@'%'; + +This would in effect allow the user 'john' to only see the database 'shard' on this server. ## Limitations diff --git a/server/modules/routing/dbshard/dbshard.c b/server/modules/routing/dbshard/dbshard.c index e8d61dbd6..59fb6219c 100644 --- a/server/modules/routing/dbshard/dbshard.c +++ b/server/modules/routing/dbshard/dbshard.c @@ -1825,7 +1825,7 @@ static int routeQuery( } ss_dassert(!GWBUF_IS_TYPE_UNDEFINED(querybuf)); - if(!router_cli_ses->hash_init) + if(!rses_is_closed && !router_cli_ses->hash_init) { router_cli_ses->queue = querybuf; return 1; @@ -2479,6 +2479,19 @@ static void clientReply ( if(mapped) { + /* + * Check if the session is reconnecting with a database name + * that is not in the hashtable. If the database is not found + * then close the session. + */ + + if(router_cli_ses->rses_mysql_session->db[0] != '\0' && + hashtable_fetch(router_cli_ses->dbhash, + router_cli_ses->rses_mysql_session->db) == NULL) + { + router_cli_ses->rses_closed = true; + } + router_cli_ses->hash_init = true; if(router_cli_ses->queue) {