Updates to dbshard router:

Added a parsing function to query classifier that returns an array of database names the query uses.
Added a check if the query targets a sharded database. If so, a hint is added that routes the query to the named server.
This commit is contained in:
Markus Makela
2014-12-06 11:30:07 +02:00
parent ed8404d9c7
commit 06578c95a5
3 changed files with 159 additions and 25 deletions

View File

@ -1438,3 +1438,50 @@ char* skygw_get_qtype_str(
}
return qtype_str;
}
/**
* Returns an array of strings of databases that this query uses.
* If the database isn't defined in the query, it is assumed that this query only targets the current database.
* The value of @p size is set to the number of allocated strings. The caller is responsible for freeing all the allocated memory.
* @param querybuf GWBUF containing the query
* @param size Size of the resulting array
* @return A new array of strings containing the database names or NULL if no databases were found.
*/
char** skygw_get_database_names(GWBUF* querybuf,int* size)
{
LEX* lex;
TABLE_LIST* tbl;
char **databases = NULL, **tmp = NULL;
int currsz = 0,i = 0;
if( (lex = get_lex(querybuf)) == NULL)
{
goto retblock;
}
lex->current_select = lex->all_selects_list;
while(lex->current_select){
tbl = lex->current_select->join_list->head();
while(tbl)
{
if(strcmp(tbl->db,"skygw_virtual") != 0){
if(i>= currsz){
tmp = (char**)realloc(databases,sizeof(char*)*(currsz*2 + 1));
if(tmp == NULL) goto retblock;
databases = tmp;
currsz = currsz*2 + 1;
}
databases[i++] = strdup(tbl->db);
}
tbl=tbl->next_local;
}
lex->current_select = lex->current_select->next_select_in_list();
}
retblock:
*size = i;
return databases;
}

View File

@ -89,6 +89,7 @@ bool is_drop_table_query(GWBUF* querybuf);
bool skygw_is_real_query(GWBUF* querybuf);
void* skygw_get_affected_tables(void* lexptr);
char** skygw_get_table_names(GWBUF* querybuf,int* tblsize,bool fullnames);
char** skygw_get_database_names(GWBUF* querybuf,int* size);
char* skygw_get_canonical(GWBUF* querybuf);
bool parse_query (GWBUF* querybuf);
parsing_info_t* parsing_info_init(void (*donefun)(void *));