MXS-2: Week 4
This post is a part of a series of posts that I am writing weekly while fixing MXS-2 issue for MaxScale as part of Google Summer of Code - 2015.
I made a number of changes this week. First of them all was changing the HASHTABLE in BGD_SESSION. Previously, it was used for mapping file name to file handle, but, it needs to store much more information than that. For this purpose, I added a new structure named table_info. The commit with these changes can be sen here.
Followed a small tweak where, me and my mentor(Markus) decided to eliminate the regular expressions from the filter all togther. Since, the filter expects a list of tables for which the data should be logged, we introduced a parameter named tables which expects a list of comma separated unique table names. Here, unique table names signify the format <dbname>.<table name>. Only those tables which are specified in this list are processed and others are ignored. The changes for this are spread over two commits which can be observed here and here.
I also made a small optimization where I avoid generating the data file name over and over again by storing it in a new variable in BGD_SESSION named current_table_data_file. The changes can be seen here.
For extracting data from CREATE TABLE command, I needed to store the schema and column definitions. query_classifier deals with extracting data from queries. So two new structures were introduced namely TableSchema and ColunDef. Their definitions are as follows,
typedef struct column_def ColumnDef; typedef struct table_schema { char *dbname; // database name char *tblname; // table name int ncolumns; // number of columns ColumnDef *head; // head of list of columns ColumnDef *tail; // tail of list of columns } TableSchema; struct column_def { enum enum_field_types type; // columns data type char *colname; // column name void *defval; // default value ColumnDef *next; // next column };
Currently, TableSchema stores a linked list of ColumnDef. I intend to change it in next week with something which will give a little better mapping and access. A new function in query_classifier named skygw_get_schema_from_create extracts the required data from CREATE TABLE queries and returns a TableSchema object. bgdfilter handles the QUERY_OP_CREATE_TABLE in clientReply. All the changes for this can be reviewed here.
I had not handled a case in my implementation until now, wher a db name is specified in the query, e.g. CREATE TABLE test.t1(c1 int). The db name should be taken from the query in this case. So, I changed current_db and new_db in BGD_SESSION to default_db and active_db. active_db will always hold the db name for current query in execution whereas default_db will hold the db name specified in mysql command on terminal while connecting to MaxScale or the db name after USE DATABASE command. Change with respect to this can be seen here.
I still have a few tasks pending, they are as follows,
Creating a metadata file for tables
Logging data from INSERT queries
Making use of the "format" parameter for data logging. (JSON/XML)
Feel free to point out mistakes, if any. Also, suggestions and/or reviews are welcome!















