The database name the client is connecting with is now checked that it exists in the hashtable before setting the session into a valid state.

This commit is contained in:
Markus Makela 2015-02-03 11:54:13 +02:00
parent 7b8579163a
commit 0b5bedd2b8
2 changed files with 25 additions and 2 deletions

View File

@ -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

View File

@ -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)
{