query_classifier.cc

Replaced fprintf's with log write commands, removed the second argument from call of mysql_reset_thd_for_next_command(thd) according to changes in mariadb/5.5/sql/sql_parse.c #rev 3958.

server/Makefile
	Instead of installing MaxScale.cnf (and overwriting previous config file), install MaxScale_template.cnf to DEST directory.

config.c
	Replace references to 'Gateway' with 'MaxScale', change configuration parameter 'auth' to 'passwd' as it is named in other instances where referenced to password.
This commit is contained in:
vraatikka 2013-11-20 15:55:43 +02:00
parent 0f120e5593
commit 4b1527b1c8
4 changed files with 174 additions and 39 deletions

View File

@ -100,24 +100,27 @@ skygw_query_type_t skygw_query_classifier_get_type(
skygw_query_type_t qtype = QUERY_TYPE_UNKNOWN;
bool failp = FALSE;
//ss_dfprintf(stderr, ">> skygw_query_classifier_get_type\n");
ss_info_dassert(query != NULL, ("query_str is NULL"));
query_str = const_cast<char*>(query);
#if QUERY_DEBUG
fprintf(stderr, " Query \"%s\"\n", query_str);
#endif
skygw_log_write(
LOGFILE_TRACE,
"%lu [skygw_query_classifier_get_type] Query : \"%s\"",
pthread_self(),
query_str);
/** Get server handle */
mysql = mysql_init(NULL);
if (mysql == NULL) {
fprintf(stderr,
"mysql_real_connect failed, %d : %s\n",
mysql_errno(mysql),
mysql_error(mysql));
mysql_library_end();
goto return_without_server;
skygw_log_write_flush(
LOGFILE_ERROR,
"Error : call to mysql_real_connect failed due %d, %s.",
mysql_errno(mysql),
mysql_error(mysql));
mysql_library_end();
goto return_without_server;
}
/** Set methods and authentication to mysql */
@ -132,13 +135,13 @@ skygw_query_type_t skygw_query_classifier_get_type(
thd = get_or_create_thd_for_parsing(mysql, query_str);
if (thd == NULL) {
goto return_with_server_handle;
goto return_with_server_handle;
}
/** Create parse_tree inside thd */
failp = create_parse_tree(thd);
if (failp) {
goto return_with_thd;
goto return_with_thd;
}
qtype = resolve_query_type(thd);
@ -180,7 +183,6 @@ static THD* get_or_create_thd_for_parsing(
bool failp = FALSE;
size_t query_len;
//ss_dfprintf(stderr, "> get_or_create_thd_for_parsing\n");
ss_info_dassert(mysql != NULL, ("mysql is NULL"));
ss_info_dassert(query_str != NULL, ("query_str is NULL"));
@ -194,32 +196,42 @@ static THD* get_or_create_thd_for_parsing(
thd = (THD *)create_embedded_thd(client_flags);
if (thd == NULL) {
ss_dfprintf(stderr, "Couldn't create embedded thd\n");
goto return_thd;
skygw_log_write_flush(
LOGFILE_ERROR,
"Error : Failed to create thread context for parsing. "
"Exiting.");
goto return_thd;
}
mysql->thd = thd;
init_embedded_mysql(mysql, client_flags);
failp = check_embedded_connection(mysql, db);
if (failp) {
ss_dfprintf(stderr, "Checking embedded connection failed.\n");
goto return_err_with_thd;
skygw_log_write_flush(
LOGFILE_ERROR,
"Error : Call to check_embedded_connection failed. "
"Exiting.");
goto return_err_with_thd;
}
thd->clear_data_list();
/** Check that we are calling the client functions in right order */
if (mysql->status != MYSQL_STATUS_READY) {
set_mysql_error(mysql, CR_COMMANDS_OUT_OF_SYNC, unknown_sqlstate);
goto return_err_with_thd;
set_mysql_error(mysql, CR_COMMANDS_OUT_OF_SYNC, unknown_sqlstate);
skygw_log_write_flush(
LOGFILE_ERROR,
"Error : Invalid status %d in embedded server. "
"Exiting.");
goto return_err_with_thd;
}
/* Clear result variables */
/** Clear result variables */
thd->current_stmt= NULL;
thd->store_globals();
/*
We have to call free_old_query before we start to fill mysql->fields
for new query. In the case of embedded server we collect field data
during query execution (not during data retrieval as it is in remote
client). So we have to call free_old_query here
/**
* We have to call free_old_query before we start to fill mysql->fields
* for new query. In the case of embedded server we collect field data
* during query execution (not during data retrieval as it is in remote
* client). So we have to call free_old_query here
*/
free_old_query(mysql);
thd->extra_length = query_len;
@ -284,22 +296,28 @@ static bool create_parse_tree(
const char* virtual_db = "skygw_virtual";
if (parser_state.init(thd, thd->query(), thd->query_length())) {
failp = TRUE;
goto return_here;
failp = TRUE;
goto return_here;
}
mysql_reset_thd_for_next_command(thd, opt_userstat_running);
mysql_reset_thd_for_next_command(thd);
/** Set some database to thd so that parsing won't fail because of
* missing database. Then parse. */
failp = thd->set_db(virtual_db, strlen(virtual_db));
if (failp) {
fprintf(stderr, "Setting database for thd failed\n");
skygw_log_write_flush(
LOGFILE_ERROR,
"Error : Failed to set database in thread context.");
}
failp = parse_sql(thd, &parser_state, NULL);
if (failp) {
fprintf(stderr, "parse_sql failed\n");
skygw_log_write(
LOGFILE_DEBUG,
"%lu [readwritesplit:create_parse_tree] failed to "
"create parse tree.",
pthread_self());
}
return_here:
return failp;

View File

@ -55,7 +55,7 @@ install:
@mkdir -p $(DEST)/MaxScale/etc
@mkdir -p $(DEST)/lib
@mkdir -p $(DEST)/Documentation
install -b MaxScale.cnf $(DEST)/MaxScale/etc
install -b MaxScale_template.cnf $(DEST)/MaxScale/etc
install ../Documentation/*.pdf $(DEST)/Documentation
(cd core; make DEST=$(DEST) install)
(cd modules/routing; make DEST=$(DEST) install)

View File

@ -0,0 +1,117 @@
#
# Example MaxScale.cnf configuration file
#
#
#
# Number of server threads
# Valid options are:
# threads=<number of threads>
[maxscale]
threads=1
# Define a monitor that can be used to determine the state and role of
# the servers.
#
# Valid options are:
#
# module=<name of module to load>
# servers=<server name>,<server name>,...
# user =<user name - must have slave replication and
# slave client privileges>
# passwd=<password of the above user, plain text currently>
[MySQL Monitor]
type=monitor
module=mysqlmon
servers=server1,server2,server3
user=maxuser
passwd=maxpwd
# A series of service definition
#
# Valid options are:
#
# router=<name of router module>
# servers=<server name>,<server name>,...
# user=<User to fetch password inforamtion with>
# passwd=<Password of the user, plain text currently>
#
# Valid router modules currently are:
# readwritesplit, readconnroute and debugcli
[RW Split Router]
type=service
router=readwritesplit
servers=server1,server2,server3
user=maxuser
passwd=maxpwd
[Read Connection Router]
type=service
router=readconnroute
router_options=slave
servers=server1,server2,server3
user=maxuser
passwd=maxpwd
[HTTPD Router]
type=service
router=testroute
servers=server1,server2,server3
[Debug Interface]
type=service
router=debugcli
# Listener definitions for the services
#
# Valid options are:
#
# service=<name of service defined elsewhere>
# protocol=<name of protocol module with which to listen>
# port=<Listening port>
[RW Split Listener]
type=listener
service=RW Split Router
protocol=MySQLClient
port=4006
[Read Connection Listener]
type=listener
service=Read Connection Router
protocol=MySQLClient
port=4008
[Debug Listener]
type=listener
service=Debug Interface
protocol=telnetd
port=4442
[HTTPD Listener]
type=listener
service=HTTPD Router
protocol=HTTPD
port=6444
# Definition of the servers
[server1]
type=server
address=127.0.0.1
port=3000
protocol=MySQLBackend
[server2]
type=server
address=127.0.0.1
port=3001
protocol=MySQLBackend
[server3]
type=server
address=127.0.0.1
port=3002
protocol=MySQLBackend

View File

@ -100,7 +100,7 @@ CONFIG_PARAMETER *param;
}
/**
* Load the configuration file for the gateway
* Load the configuration file for the MaxScale
*
* @param file The filename of the configuration file
* @return A zero return indicates a fatal error reading the configuration
@ -129,7 +129,7 @@ int rval;
}
/**
* Reload the configuration file for the gateway
* Reload the configuration file for the MaxScale
*
* @return A zero return indicates a fatal error reading the configuration
*/
@ -194,7 +194,7 @@ int error_count = 0;
char *user =
config_get_value(obj->parameters, "user");
char *auth =
config_get_value(obj->parameters, "auth");
config_get_value(obj->parameters, "passwd");
if (obj->element && user && auth)
serviceSetUser(obj->element, user, auth);
}
@ -475,7 +475,7 @@ config_threadcount()
}
/**
* Configuration handler for items in the global [gateway] section
* Configuration handler for items in the global [MaxScale] section
*
* @param name The item name
* @param value The item value
@ -541,7 +541,7 @@ SERVER *server;
user = config_get_value(obj->parameters,
"user");
auth = config_get_value(obj->parameters,
"auth");
"passwd");
if (user && auth)
service_update(service, router,
user,
@ -556,7 +556,7 @@ SERVER *server;
user = config_get_value(obj->parameters,
"user");
auth = config_get_value(obj->parameters,
"auth");
"passwd");
obj->element = service_alloc(obj->object,
router);
@ -736,7 +736,7 @@ static char *service_params[] =
"router_options",
"servers",
"user",
"auth",
"passwd",
NULL
};
@ -811,7 +811,7 @@ int i;
skygw_log_write_flush(
LOGFILE_ERROR,
"Error : Unexpected parameter "
"'%s' for xobject '%s' of type "
"'%s' for object '%s' of type "
"'%s'.",
params->name,
obj->object,