Surrounded every log writing command with LOGIF macro, which tests if the given logfile id matches with those enabled. The comparison is done against local variable and expensive function call is avoided.

This commit is contained in:
vraatikka
2013-12-12 16:14:33 +02:00
parent 272ca036e4
commit d403018fd9
23 changed files with 540 additions and 472 deletions

View File

@ -57,6 +57,8 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdarg.h> #include <stdarg.h>
extern int lm_enabled_logfiles_bitmask;
#define QTYPE_LESS_RESTRICTIVE_THAN_WRITE(t) (t<QUERY_TYPE_WRITE ? true : false) #define QTYPE_LESS_RESTRICTIVE_THAN_WRITE(t) (t<QUERY_TYPE_WRITE ? true : false)
static THD* get_or_create_thd_for_parsing( static THD* get_or_create_thd_for_parsing(
@ -103,21 +105,21 @@ skygw_query_type_t skygw_query_classifier_get_type(
ss_info_dassert(query != NULL, ("query_str is NULL")); ss_info_dassert(query != NULL, ("query_str is NULL"));
query_str = const_cast<char*>(query); query_str = const_cast<char*>(query);
skygw_log_write( LOGIF(LT, (skygw_log_write(
LOGFILE_TRACE, LOGFILE_TRACE,
"%lu [skygw_query_classifier_get_type] Query : \"%s\"", "%lu [skygw_query_classifier_get_type] Query : \"%s\"",
pthread_self(), pthread_self(),
query_str); query_str)));
/** Get server handle */ /** Get server handle */
mysql = mysql_init(NULL); mysql = mysql_init(NULL);
if (mysql == NULL) { if (mysql == NULL) {
skygw_log_write_flush( LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR, LOGFILE_ERROR,
"Error : call to mysql_real_connect failed due %d, %s.", "Error : call to mysql_real_connect failed due %d, %s.",
mysql_errno(mysql), mysql_errno(mysql),
mysql_error(mysql)); mysql_error(mysql))));
mysql_library_end(); mysql_library_end();
goto return_without_server; goto return_without_server;
@ -196,10 +198,10 @@ static THD* get_or_create_thd_for_parsing(
thd = (THD *)create_embedded_thd(client_flags); thd = (THD *)create_embedded_thd(client_flags);
if (thd == NULL) { if (thd == NULL) {
skygw_log_write_flush( LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR, LOGFILE_ERROR,
"Error : Failed to create thread context for parsing. " "Error : Failed to create thread context for parsing. "
"Exiting."); "Exiting.")));
goto return_thd; goto return_thd;
} }
mysql->thd = thd; mysql->thd = thd;
@ -207,10 +209,10 @@ static THD* get_or_create_thd_for_parsing(
failp = check_embedded_connection(mysql, db); failp = check_embedded_connection(mysql, db);
if (failp) { if (failp) {
skygw_log_write_flush( LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR, LOGFILE_ERROR,
"Error : Call to check_embedded_connection failed. " "Error : Call to check_embedded_connection failed. "
"Exiting."); "Exiting.")));
goto return_err_with_thd; goto return_err_with_thd;
} }
thd->clear_data_list(); thd->clear_data_list();
@ -218,10 +220,10 @@ static THD* get_or_create_thd_for_parsing(
/** Check that we are calling the client functions in right order */ /** Check that we are calling the client functions in right order */
if (mysql->status != MYSQL_STATUS_READY) { if (mysql->status != MYSQL_STATUS_READY) {
set_mysql_error(mysql, CR_COMMANDS_OUT_OF_SYNC, unknown_sqlstate); set_mysql_error(mysql, CR_COMMANDS_OUT_OF_SYNC, unknown_sqlstate);
skygw_log_write_flush( LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR, LOGFILE_ERROR,
"Error : Invalid status %d in embedded server. " "Error : Invalid status %d in embedded server. "
"Exiting."); "Exiting.")));
goto return_err_with_thd; goto return_err_with_thd;
} }
/** Clear result variables */ /** Clear result variables */
@ -306,18 +308,18 @@ static bool create_parse_tree(
failp = thd->set_db(virtual_db, strlen(virtual_db)); failp = thd->set_db(virtual_db, strlen(virtual_db));
if (failp) { if (failp) {
skygw_log_write_flush( LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR, LOGFILE_ERROR,
"Error : Failed to set database in thread context."); "Error : Failed to set database in thread context.")));
} }
failp = parse_sql(thd, &parser_state, NULL); failp = parse_sql(thd, &parser_state, NULL);
if (failp) { if (failp) {
skygw_log_write( LOGIF(LD, (skygw_log_write(
LOGFILE_DEBUG, LOGFILE_DEBUG,
"%lu [readwritesplit:create_parse_tree] failed to " "%lu [readwritesplit:create_parse_tree] failed to "
"create parse tree.", "create parse tree.",
pthread_self()); pthread_self())));
} }
return_here: return_here:
return failp; return failp;
@ -473,12 +475,12 @@ static skygw_query_type_t resolve_query_type(
Item::Type itype; Item::Type itype;
itype = item->type(); itype = item->type();
skygw_log_write( LOGIF(LD, (skygw_log_write(
LOGFILE_DEBUG, LOGFILE_DEBUG,
"%lu [resolve_query_type] Item %s:%s", "%lu [resolve_query_type] Item %s:%s",
pthread_self(), pthread_self(),
item->name, item->name,
STRITEMTYPE(itype)); STRITEMTYPE(itype))));
if (itype == Item::SUBSELECT_ITEM) { if (itype == Item::SUBSELECT_ITEM) {
continue; continue;
@ -538,32 +540,32 @@ static skygw_query_type_t resolve_query_type(
* belongs to this category. * belongs to this category.
*/ */
func_qtype = QUERY_TYPE_WRITE; func_qtype = QUERY_TYPE_WRITE;
skygw_log_write( LOGIF(LD, (skygw_log_write(
LOGFILE_DEBUG, LOGFILE_DEBUG,
"%lu [resolve_query_type] " "%lu [resolve_query_type] "
"functype FUNC_SP, stored proc " "functype FUNC_SP, stored proc "
"or unknown function.", "or unknown function.",
"%s:%s", "%s:%s",
pthread_self()); pthread_self())));
break; break;
case Item_func::UDF_FUNC: case Item_func::UDF_FUNC:
func_qtype = QUERY_TYPE_WRITE; func_qtype = QUERY_TYPE_WRITE;
skygw_log_write( LOGIF(LD, (skygw_log_write(
LOGFILE_DEBUG, LOGFILE_DEBUG,
"%lu [resolve_query_type] " "%lu [resolve_query_type] "
"functype UDF_FUNC, user-defined " "functype UDF_FUNC, user-defined "
"function.", "function.",
pthread_self()); pthread_self())));
break; break;
case Item_func::NOW_FUNC: case Item_func::NOW_FUNC:
case Item_func::GSYSVAR_FUNC: case Item_func::GSYSVAR_FUNC:
func_qtype = QUERY_TYPE_LOCAL_READ; func_qtype = QUERY_TYPE_LOCAL_READ;
skygw_log_write( LOGIF(LD, (skygw_log_write(
LOGFILE_DEBUG, LOGFILE_DEBUG,
"%lu [resolve_query_type] " "%lu [resolve_query_type] "
"functype NOW_FUNC, could be " "functype NOW_FUNC, could be "
"executed in MaxScale.", "executed in MaxScale.",
pthread_self()); pthread_self())));
break; break;
case Item_func::UNKNOWN_FUNC: case Item_func::UNKNOWN_FUNC:
func_qtype = QUERY_TYPE_READ; func_qtype = QUERY_TYPE_READ;
@ -572,20 +574,20 @@ static skygw_query_type_t resolve_query_type(
* type, for example, rand(), soundex(), * type, for example, rand(), soundex(),
* repeat() . * repeat() .
*/ */
skygw_log_write( LOGIF(LD, (skygw_log_write(
LOGFILE_DEBUG, LOGFILE_DEBUG,
"%lu [resolve_query_type] " "%lu [resolve_query_type] "
"functype UNKNOWN_FUNC, " "functype UNKNOWN_FUNC, "
"typically some system function.", "typically some system function.",
pthread_self()); pthread_self())));
break; break;
default: default:
skygw_log_write( LOGIF(LD, (skygw_log_write(
LOGFILE_DEBUG, LOGFILE_DEBUG,
"%lu [resolve_query_type] " "%lu [resolve_query_type] "
"Unknown functype. Something " "Unknown functype. Something "
"has gone wrong.", "has gone wrong.",
pthread_self()); pthread_self())));
break; break;
} /**< switch */ } /**< switch */
/**< Set new query type */ /**< Set new query type */

View File

@ -27,6 +27,8 @@
#include <skygw_utils.h> #include <skygw_utils.h>
#include <log_manager.h> #include <log_manager.h>
extern int lm_enabled_logfiles_bitmask;
/** /**
* @file adminusers.c - Administration user account management * @file adminusers.c - Administration user account management
* *
@ -39,7 +41,6 @@
* *
* @endverbatim * @endverbatim
*/ */
static USERS *loadUsers(); static USERS *loadUsers();
static void initialise(); static void initialise();
@ -156,16 +157,19 @@ char fname[1024], *home, *cpasswd;
if (users == NULL) if (users == NULL)
{ {
skygw_log_write(LOGFILE_MESSAGE,"Create initial password file."); LOGIF(LM,
(skygw_log_write(LOGFILE_MESSAGE,
"Create initial password file.")));
if ((users = users_alloc()) == NULL) if ((users = users_alloc()) == NULL)
return ADMIN_ERR_NOMEM; return ADMIN_ERR_NOMEM;
if ((fp = fopen(fname, "w")) == NULL) if ((fp = fopen(fname, "w")) == NULL)
{ {
skygw_log_write_flush( LOGIF(LE,
(skygw_log_write_flush(
LOGFILE_ERROR, LOGFILE_ERROR,
"Error : Unable to create password file %s.", "Error : Unable to create password file %s.",
fname); fname)));
return ADMIN_ERR_PWDFILEOPEN; return ADMIN_ERR_PWDFILEOPEN;
} }
fclose(fp); fclose(fp);
@ -178,9 +182,10 @@ char fname[1024], *home, *cpasswd;
users_add(users, uname, cpasswd); users_add(users, uname, cpasswd);
if ((fp = fopen(fname, "a")) == NULL) if ((fp = fopen(fname, "a")) == NULL)
{ {
skygw_log_write_flush(LOGFILE_ERROR, LOGIF(LE,
(skygw_log_write_flush(LOGFILE_ERROR,
"Error : Unable to append to password file %s.", "Error : Unable to append to password file %s.",
fname); fname)));
return ADMIN_ERR_FILEAPPEND; return ADMIN_ERR_FILEAPPEND;
} }
fprintf(fp, "%s:%s\n", uname, cpasswd); fprintf(fp, "%s:%s\n", uname, cpasswd);
@ -212,18 +217,18 @@ char* admin_remove_user(
int n_deleted; int n_deleted;
if (!admin_search_user(uname)) { if (!admin_search_user(uname)) {
skygw_log_write_flush( LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR, LOGFILE_ERROR,
"Error : Couldn't find user %s. Removing user failed", "Error : Couldn't find user %s. Removing user failed",
uname); uname)));
return ADMIN_ERR_USERNOTFOUND; return ADMIN_ERR_USERNOTFOUND;
} }
if (admin_verify(uname, passwd) == 0) { if (admin_verify(uname, passwd) == 0) {
skygw_log_write_flush( LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR, LOGFILE_ERROR,
"Error : Authentication failed, wrong user/password " "Error : Authentication failed, wrong user/password "
"combination. Removing user failed."); "combination. Removing user failed.")));
return ADMIN_ERR_AUTHENTICATION; return ADMIN_ERR_AUTHENTICATION;
} }
@ -232,10 +237,10 @@ char* admin_remove_user(
n_deleted = users_delete(users, uname); n_deleted = users_delete(users, uname);
if (n_deleted == 0) { if (n_deleted == 0) {
skygw_log_write_flush( LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR, LOGFILE_ERROR,
"Error : Deleting the only user is forbidden. Add new " "Error : Deleting the only user is forbidden. Add new "
"user before deleting the one."); "user before deleting the one.")));
return ADMIN_ERR_DELLASTUSER; return ADMIN_ERR_DELLASTUSER;
} }
/** /**
@ -254,13 +259,13 @@ char* admin_remove_user(
if ((fp = fopen(fname, "r")) == NULL) if ((fp = fopen(fname, "r")) == NULL)
{ {
int err = errno; int err = errno;
skygw_log_write_flush( LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR, LOGFILE_ERROR,
"Error : Unable to open password file %s : errno %d.\n" "Error : Unable to open password file %s : errno %d.\n"
"Removing user from file failed; it must be done " "Removing user from file failed; it must be done "
"manually.", "manually.",
fname, fname,
err); err)));
return ADMIN_ERR_PWDFILEOPEN; return ADMIN_ERR_PWDFILEOPEN;
} }
/** /**
@ -269,13 +274,13 @@ char* admin_remove_user(
if ((fp_tmp = fopen(fname_tmp, "w")) == NULL) if ((fp_tmp = fopen(fname_tmp, "w")) == NULL)
{ {
int err = errno; int err = errno;
skygw_log_write_flush( LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR, LOGFILE_ERROR,
"Error : Unable to open tmp file %s : errno %d.\n" "Error : Unable to open tmp file %s : errno %d.\n"
"Removing user from passwd file failed; it must be done " "Removing user from passwd file failed; it must be done "
"manually.", "manually.",
fname_tmp, fname_tmp,
err); err)));
fclose(fp); fclose(fp);
return ADMIN_ERR_TMPFILEOPEN; return ADMIN_ERR_TMPFILEOPEN;
} }
@ -285,13 +290,13 @@ char* admin_remove_user(
*/ */
if (fgetpos(fp, &rpos) != 0) { if (fgetpos(fp, &rpos) != 0) {
int err = errno; int err = errno;
skygw_log_write_flush( LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR, LOGFILE_ERROR,
"Error : Unable to process passwd file %s : errno %d.\n" "Error : Unable to process passwd file %s : errno %d.\n"
"Removing user from file failed, and must be done " "Removing user from file failed, and must be done "
"manually.", "manually.",
fname, fname,
err); err)));
fclose(fp); fclose(fp);
unlink(fname_tmp); unlink(fname_tmp);
return ADMIN_ERR_PWDFILEACCESS; return ADMIN_ERR_PWDFILEACCESS;
@ -311,14 +316,14 @@ char* admin_remove_user(
if (fgetpos(fp, &rpos) != 0) { if (fgetpos(fp, &rpos) != 0) {
int err = errno; int err = errno;
skygw_log_write_flush( LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR, LOGFILE_ERROR,
"Error : Unable to process passwd file %s : " "Error : Unable to process passwd file %s : "
"errno %d.\n" "errno %d.\n"
"Removing user from file failed, and must be " "Removing user from file failed, and must be "
"done manually.", "done manually.",
fname, fname,
err); err)));
fclose(fp); fclose(fp);
unlink(fname_tmp); unlink(fname_tmp);
return ADMIN_ERR_PWDFILEACCESS; return ADMIN_ERR_PWDFILEACCESS;
@ -330,14 +335,14 @@ char* admin_remove_user(
*/ */
if (rename(fname_tmp, fname)) { if (rename(fname_tmp, fname)) {
int err = errno; int err = errno;
skygw_log_write_flush( LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR, LOGFILE_ERROR,
"Error : Unable to rename new passwd file %s : errno " "Error : Unable to rename new passwd file %s : errno "
"%d.\n" "%d.\n"
"Rename it to %s manually.", "Rename it to %s manually.",
fname_tmp, fname_tmp,
err, err,
fname); fname)));
unlink(fname_tmp); unlink(fname_tmp);
fclose(fp_tmp); fclose(fp_tmp);
return ADMIN_ERR_PWDFILEACCESS; return ADMIN_ERR_PWDFILEACCESS;

View File

@ -41,6 +41,8 @@
#include <skygw_utils.h> #include <skygw_utils.h>
#include <log_manager.h> #include <log_manager.h>
extern int lm_enabled_logfiles_bitmask;
static int process_config_context(CONFIG_CONTEXT *); static int process_config_context(CONFIG_CONTEXT *);
static int process_config_update(CONFIG_CONTEXT *); static int process_config_update(CONFIG_CONTEXT *);
static void free_config_context(CONFIG_CONTEXT *); static void free_config_context(CONFIG_CONTEXT *);
@ -178,10 +180,10 @@ int error_count = 0;
char *type = config_get_value(obj->parameters, "type"); char *type = config_get_value(obj->parameters, "type");
if (type == NULL) if (type == NULL)
{ {
skygw_log_write_flush( LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR, LOGFILE_ERROR,
"Error : Configuration object '%s' has no type.", "Error : Configuration object '%s' has no type.",
obj->object); obj->object)));
error_count++; error_count++;
} }
else if (!strcmp(type, "service")) else if (!strcmp(type, "service"))
@ -204,22 +206,22 @@ int error_count = 0;
} }
else if (user && auth == NULL) else if (user && auth == NULL)
{ {
skygw_log_write_flush( LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR, LOGFILE_ERROR,
"Error : Service '%s' has a " "Error : Service '%s' has a "
"user defined but no " "user defined but no "
"corresponding password.", "corresponding password.",
obj->object); obj->object)));
} }
} }
else else
{ {
obj->element = NULL; obj->element = NULL;
skygw_log_write_flush( LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR, LOGFILE_ERROR,
"Error : No router defined for service " "Error : No router defined for service "
"'%s'\n", "'%s'\n",
obj->object); obj->object)));
error_count++; error_count++;
} }
} }
@ -247,25 +249,25 @@ int error_count = 0;
else else
{ {
obj->element = NULL; obj->element = NULL;
skygw_log_write_flush( LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR, LOGFILE_ERROR,
"Error : Server '%s' is missing a " "Error : Server '%s' is missing a "
"required configuration parameter. A " "required configuration parameter. A "
"server must " "server must "
"have address, port and protocol " "have address, port and protocol "
"defined.", "defined.",
obj->object); obj->object)));
error_count++; error_count++;
} }
if (obj->element && monuser && monpw) if (obj->element && monuser && monpw)
serverAddMonUser(obj->element, monuser, monpw); serverAddMonUser(obj->element, monuser, monpw);
else if (monuser && monpw == NULL) else if (monuser && monpw == NULL)
{ {
skygw_log_write_flush( LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR, LOGFILE_ERROR,
"Error : Server '%s' has a monitoruser" "Error : Server '%s' has a monitoruser"
"defined but no corresponding password.", "defined but no corresponding password.",
obj->object); obj->object)));
} }
} }
obj = obj->next; obj = obj->next;
@ -311,12 +313,12 @@ int error_count = 0;
} }
else if (servers == NULL) else if (servers == NULL)
{ {
skygw_log_write_flush( LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR, LOGFILE_ERROR,
"Error : The service '%s' is missing a " "Error : The service '%s' is missing a "
"definition of the servers that provide " "definition of the servers that provide "
"the service.", "the service.",
obj->object); obj->object)));
} }
if (roptions && obj->element) if (roptions && obj->element)
{ {
@ -351,24 +353,24 @@ int error_count = 0;
} }
else else
{ {
skygw_log_write_flush( LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR, LOGFILE_ERROR,
"Error : Listener '%s', " "Error : Listener '%s', "
"service '%s' not found. " "service '%s' not found. "
"Listener will not execute.", "Listener will not execute.",
obj->object, service); obj->object, service)));
error_count++; error_count++;
} }
} }
else else
{ {
skygw_log_write_flush( LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR, LOGFILE_ERROR,
"Error : Listener '%s' is misisng a " "Error : Listener '%s' is misisng a "
"required " "required "
"parameter. A Listener must have a " "parameter. A Listener must have a "
"service, port and protocol defined.", "service, port and protocol defined.",
obj->object); obj->object)));
error_count++; error_count++;
} }
} }
@ -415,32 +417,32 @@ int error_count = 0;
} }
else if (obj->element && user) else if (obj->element && user)
{ {
skygw_log_write_flush( LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR, "Error: " LOGFILE_ERROR, "Error: "
"Monitor '%s' defines a " "Monitor '%s' defines a "
"username with no password.", "username with no password.",
obj->object); obj->object)));
error_count++; error_count++;
} }
} }
else else
{ {
obj->element = NULL; obj->element = NULL;
skygw_log_write_flush( LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR, LOGFILE_ERROR,
"Error : Monitor '%s' is missing a " "Error : Monitor '%s' is missing a "
"require module parameter.", "require module parameter.",
obj->object); obj->object)));
error_count++; error_count++;
} }
} }
else if (strcmp(type, "server") != 0) else if (strcmp(type, "server") != 0)
{ {
skygw_log_write_flush( LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR, LOGFILE_ERROR,
"Error : Configuration object '%s' has an " "Error : Configuration object '%s' has an "
"invalid type specified.", "invalid type specified.",
obj->object); obj->object)));
error_count++; error_count++;
} }
@ -449,12 +451,12 @@ int error_count = 0;
if (error_count) if (error_count)
{ {
skygw_log_write_flush( LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR, LOGFILE_ERROR,
"Error : %d errors where encountered processing the " "Error : %d errors where encountered processing the "
"configuration file '%s'.", "configuration file '%s'.",
error_count, error_count,
config_file); config_file)));
return 0; return 0;
} }
return 1; return 1;
@ -568,10 +570,13 @@ SERVER *server;
{ {
char *type = config_get_value(obj->parameters, "type"); char *type = config_get_value(obj->parameters, "type");
if (type == NULL) if (type == NULL)
skygw_log_write_flush( {
LOGIF(LE,
(skygw_log_write_flush(
LOGFILE_ERROR, LOGFILE_ERROR,
"Error : Configuration object %s has no type.", "Error : Configuration object %s has no type.",
obj->object); obj->object)));
}
else if (!strcmp(type, "service")) else if (!strcmp(type, "service"))
{ {
char *router = config_get_value(obj->parameters, char *router = config_get_value(obj->parameters,
@ -616,11 +621,11 @@ SERVER *server;
else else
{ {
obj->element = NULL; obj->element = NULL;
skygw_log_write_flush( LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR, LOGFILE_ERROR,
"Error : No router defined for service " "Error : No router defined for service "
"'%s'.", "'%s'.",
obj->object); obj->object)));
} }
} }
else if (!strcmp(type, "server")) else if (!strcmp(type, "server"))
@ -664,14 +669,14 @@ SERVER *server;
} }
else else
{ {
skygw_log_write_flush( LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR, LOGFILE_ERROR,
"Error : Server '%s' is missing a " "Error : Server '%s' is missing a "
"required " "required "
"configuration parameter. A server must " "configuration parameter. A server must "
"have address, port and protocol " "have address, port and protocol "
"defined.", "defined.",
obj->object); obj->object)));
} }
} }
obj = obj->next; obj = obj->next;
@ -763,11 +768,11 @@ SERVER *server;
else if (strcmp(type, "server") != 0 && else if (strcmp(type, "server") != 0 &&
strcmp(type, "monitor") != 0) strcmp(type, "monitor") != 0)
{ {
skygw_log_write_flush( LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR, LOGFILE_ERROR,
"Error : Configuration object %s has an invalid " "Error : Configuration object %s has an invalid "
"type specified.", "type specified.",
obj->object); obj->object)));
} }
obj = obj->next; obj = obj->next;
} }
@ -853,14 +858,14 @@ int i;
if (!strcmp(params->name, param_set[i])) if (!strcmp(params->name, param_set[i]))
found = 1; found = 1;
if (found == 0) if (found == 0)
skygw_log_write_flush( LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR, LOGFILE_ERROR,
"Error : Unexpected parameter " "Error : Unexpected parameter "
"'%s' for object '%s' of type " "'%s' for object '%s' of type "
"'%s'.", "'%s'.",
params->name, params->name,
obj->object, obj->object,
type); type)));
params = params->next; params = params->next;
} }
} }

View File

@ -39,6 +39,8 @@
#include <log_manager.h> #include <log_manager.h>
#include <secrets.h> #include <secrets.h>
extern int lm_enabled_logfiles_bitmask;
static int getUsers(SERVICE *service, struct users *users); static int getUsers(SERVICE *service, struct users *users);
/** /**
@ -103,28 +105,28 @@ getUsers(SERVICE *service, struct users *users)
serviceGetUser(service, &service_user, &service_passwd); serviceGetUser(service, &service_user, &service_passwd);
/** multi-thread environment requires that thread init succeeds. */ /** multi-thread environment requires that thread init succeeds. */
if (mysql_thread_init()) { if (mysql_thread_init()) {
skygw_log_write_flush( LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR, LOGFILE_ERROR,
"Error : mysql_thread_init failed."); "Error : mysql_thread_init failed.")));
return -1; return -1;
} }
con = mysql_init(NULL); con = mysql_init(NULL);
if (con == NULL) { if (con == NULL) {
skygw_log_write_flush( LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR, LOGFILE_ERROR,
"Error : mysql_init: %s", "Error : mysql_init: %s",
mysql_error(con)); mysql_error(con))));
return -1; return -1;
} }
if (mysql_options(con, MYSQL_OPT_USE_REMOTE_CONNECTION, NULL)) { if (mysql_options(con, MYSQL_OPT_USE_REMOTE_CONNECTION, NULL)) {
skygw_log_write_flush( LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR, LOGFILE_ERROR,
"Error : failed to set external connection. " "Error : failed to set external connection. "
"It is needed for backend server connections. " "It is needed for backend server connections. "
"Exiting."); "Exiting.")));
return -1; return -1;
} }
/* /*
@ -148,34 +150,34 @@ getUsers(SERVICE *service, struct users *users)
free(dpwd); free(dpwd);
if (server == NULL) if (server == NULL)
{ {
skygw_log_write_flush( LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR, LOGFILE_ERROR,
"Error : Unable to get user data from backend database " "Error : Unable to get user data from backend database "
"for service %s. Missing server information.", "for service %s. Missing server information.",
service->name); service->name)));
mysql_close(con); mysql_close(con);
return -1; return -1;
} }
if (mysql_query(con, "SELECT user, password FROM mysql.user")) { if (mysql_query(con, "SELECT user, password FROM mysql.user")) {
skygw_log_write_flush( LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR, LOGFILE_ERROR,
"Error : Loading users for service %s encountered " "Error : Loading users for service %s encountered "
"error: %s.", "error: %s.",
service->name, service->name,
mysql_error(con)); mysql_error(con))));
mysql_close(con); mysql_close(con);
return -1; return -1;
} }
result = mysql_store_result(con); result = mysql_store_result(con);
if (result == NULL) { if (result == NULL) {
skygw_log_write_flush( LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR, LOGFILE_ERROR,
"Error : Loading users for service %s encountered " "Error : Loading users for service %s encountered "
"error: %s.", "error: %s.",
service->name, service->name,
mysql_error(con)); mysql_error(con))));
mysql_close(con); mysql_close(con);
return -1; return -1;
} }

View File

@ -191,10 +191,10 @@ dcb_add_to_zombieslist(DCB *dcb)
if (ptr == dcb) if (ptr == dcb)
{ {
skygw_log_write_flush( LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR, LOGFILE_ERROR,
"Error : Attempt to add DCB to zombies " "Error : Attempt to add DCB to zombies "
"list when it is already in the list"); "list when it is already in the list")));
break; break;
} }
ptr = ptr->memdata.next; ptr = ptr->memdata.next;
@ -338,14 +338,14 @@ bool succp = false;
zombies = tptr; zombies = tptr;
else else
lptr->memdata.next = tptr; lptr->memdata.next = tptr;
skygw_log_write_flush( LOGIF(LD, (skygw_log_write_flush(
LOGFILE_DEBUG, LOGFILE_DEBUG,
"%lu [dcb_process_zombies] Remove dcb %p fd %d " "%lu [dcb_process_zombies] Remove dcb %p fd %d "
"in state %s from zombies list.", "in state %s from zombies list.",
pthread_self(), pthread_self(),
ptr, ptr,
ptr->fd, ptr->fd,
STRDCBSTATE(ptr->state)); STRDCBSTATE(ptr->state))));
ss_info_dassert(ptr->state == DCB_STATE_ZOMBIE, ss_info_dassert(ptr->state == DCB_STATE_ZOMBIE,
"dcb not in DCB_STATE_ZOMBIE state."); "dcb not in DCB_STATE_ZOMBIE state.");
/** /**
@ -382,24 +382,24 @@ bool succp = false;
if (rc < 0) { if (rc < 0) {
int eno = errno; int eno = errno;
errno = 0; errno = 0;
skygw_log_write_flush( LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR, LOGFILE_ERROR,
"Error : Failed to close " "Error : Failed to close "
"socket %d on dcb %p due error %d, %s.", "socket %d on dcb %p due error %d, %s.",
dcb->fd, dcb->fd,
dcb, dcb,
eno, eno,
strerror(eno)); strerror(eno))));
} }
#if defined(SS_DEBUG) #if defined(SS_DEBUG)
else { else {
skygw_log_write_flush( LOGIF(LD, (skygw_log_write_flush(
LOGFILE_DEBUG, LOGFILE_DEBUG,
"%lu [dcb_process_zombies] Closed socket " "%lu [dcb_process_zombies] Closed socket "
"%d on dcb %p.", "%d on dcb %p.",
pthread_self(), pthread_self(),
dcb->fd, dcb->fd,
dcb); dcb)));
conn_open[dcb->fd] = false; conn_open[dcb->fd] = false;
ss_debug(dcb->fd = -1;) ss_debug(dcb->fd = -1;)
} }
@ -443,12 +443,12 @@ int rc;
{ {
dcb_set_state(dcb, DCB_STATE_DISCONNECTED, NULL); dcb_set_state(dcb, DCB_STATE_DISCONNECTED, NULL);
dcb_final_free(dcb); dcb_final_free(dcb);
skygw_log_write_flush( LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR, LOGFILE_ERROR,
"Error : Failed to load protocol module for %s, free " "Error : Failed to load protocol module for %s, free "
"dcb %p\n", "dcb %p\n",
protocol, protocol,
dcb); dcb)));
return NULL; return NULL;
} }
memcpy(&(dcb->func), funcs, sizeof(GWPROTOCOL)); memcpy(&(dcb->func), funcs, sizeof(GWPROTOCOL));
@ -458,18 +458,18 @@ int rc;
*/ */
if (!session_link_dcb(session, dcb)) if (!session_link_dcb(session, dcb))
{ {
skygw_log_write( LOGIF(LD, (skygw_log_write(
LOGFILE_DEBUG, LOGFILE_DEBUG,
"%lu [dcb_connect] Failed to link to session, the " "%lu [dcb_connect] Failed to link to session, the "
"session has been removed.", "session has been removed.",
pthread_self()); pthread_self())));
dcb_final_free(dcb); dcb_final_free(dcb);
return NULL; return NULL;
} }
fd = dcb->func.connect(dcb, server, session); fd = dcb->func.connect(dcb, server, session);
if (fd == -1) { if (fd == -1) {
skygw_log_write( LOGIF(LD, (skygw_log_write(
LOGFILE_DEBUG, LOGFILE_DEBUG,
"%lu [dcb_connect] Failed to connect to server %s:%d, " "%lu [dcb_connect] Failed to connect to server %s:%d, "
"from backend dcb %p, client dcp %p fd %d.", "from backend dcb %p, client dcp %p fd %d.",
@ -478,12 +478,12 @@ int rc;
server->port, server->port,
dcb, dcb,
session->client, session->client,
session->client->fd); session->client->fd)));
dcb_set_state(dcb, DCB_STATE_DISCONNECTED, NULL); dcb_set_state(dcb, DCB_STATE_DISCONNECTED, NULL);
dcb_final_free(dcb); dcb_final_free(dcb);
return NULL; return NULL;
} else { } else {
skygw_log_write_flush( LOGIF(LD, (skygw_log_write_flush(
LOGFILE_DEBUG, LOGFILE_DEBUG,
"%lu [dcb_connect] Connected to server %s:%d, " "%lu [dcb_connect] Connected to server %s:%d, "
"from backend dcb %p, client dcp %p fd %d.", "from backend dcb %p, client dcp %p fd %d.",
@ -492,7 +492,7 @@ int rc;
server->port, server->port,
dcb, dcb,
session->client, session->client,
session->client->fd); session->client->fd)));
} }
ss_dassert(dcb->fd == -1); /**< must be uninitialized at this point */ ss_dassert(dcb->fd == -1); /**< must be uninitialized at this point */
/** /**
@ -556,7 +556,7 @@ int eno = 0;
if (rc == -1) { if (rc == -1) {
eno = errno; eno = errno;
errno = 0; errno = 0;
skygw_log_write_flush( LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR, LOGFILE_ERROR,
"Error : ioctl FIONREAD for dcb %p in " "Error : ioctl FIONREAD for dcb %p in "
"state %s fd %d failed due error %d, %s.", "state %s fd %d failed due error %d, %s.",
@ -564,7 +564,7 @@ int eno = 0;
STRDCBSTATE(dcb->state), STRDCBSTATE(dcb->state),
dcb->fd, dcb->fd,
eno, eno,
strerror(eno)); strerror(eno))));
n = -1; n = -1;
goto return_n; goto return_n;
} }
@ -581,14 +581,14 @@ int eno = 0;
* This is a fatal error which should cause shutdown. * This is a fatal error which should cause shutdown.
* vraa : todo shutdown if memory allocation fails. * vraa : todo shutdown if memory allocation fails.
*/ */
skygw_log_write_flush( LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR, LOGFILE_ERROR,
"Error : Failed to allocate read buffer " "Error : Failed to allocate read buffer "
"for dcb %p fd %d, due %d, %s.", "for dcb %p fd %d, due %d, %s.",
dcb, dcb,
dcb->fd, dcb->fd,
eno, eno,
strerror(eno)); strerror(eno))));
n = -1; n = -1;
ss_dassert(buffer != NULL); ss_dassert(buffer != NULL);
@ -603,7 +603,7 @@ int eno = 0;
errno = 0; errno = 0;
if (eno != EAGAIN && eno != EWOULDBLOCK) { if (eno != EAGAIN && eno != EWOULDBLOCK) {
skygw_log_write_flush( LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR, LOGFILE_ERROR,
"Error : Read failed, dcb %p in state " "Error : Read failed, dcb %p in state "
"%s fd %d, due %d, %s.", "%s fd %d, due %d, %s.",
@ -611,7 +611,7 @@ int eno = 0;
STRDCBSTATE(dcb->state), STRDCBSTATE(dcb->state),
dcb->fd, dcb->fd,
eno, eno,
strerror(eno)); strerror(eno))));
} }
else else
{ {
@ -625,7 +625,7 @@ int eno = 0;
gwbuf_free(buffer); gwbuf_free(buffer);
goto return_n; goto return_n;
} }
skygw_log_write( LOGIF(LD, (skygw_log_write(
LOGFILE_DEBUG, LOGFILE_DEBUG,
"%lu [dcb_read] Read %d bytes from dcb %p in state %s " "%lu [dcb_read] Read %d bytes from dcb %p in state %s "
"fd %d.", "fd %d.",
@ -633,7 +633,7 @@ int eno = 0;
n, n,
dcb, dcb,
STRDCBSTATE(dcb->state), STRDCBSTATE(dcb->state),
dcb->fd); dcb->fd)));
/** Append read data to the gwbuf */ /** Append read data to the gwbuf */
*head = gwbuf_append(*head, buffer); *head = gwbuf_append(*head, buffer);
} /**< while (true) */ } /**< while (true) */
@ -680,7 +680,6 @@ dcb_write(DCB *dcb, GWBUF *queue)
*/ */
dcb->writeq = gwbuf_append(dcb->writeq, queue); dcb->writeq = gwbuf_append(dcb->writeq, queue);
dcb->stats.n_buffered++; dcb->stats.n_buffered++;
#if 1
LOGIF(LD, (skygw_log_write( LOGIF(LD, (skygw_log_write(
LOGFILE_DEBUG, LOGFILE_DEBUG,
"%lu [dcb_write] Append to writequeue. %d writes " "%lu [dcb_write] Append to writequeue. %d writes "
@ -690,17 +689,6 @@ dcb_write(DCB *dcb, GWBUF *queue)
dcb, dcb,
STRDCBSTATE(dcb->state), STRDCBSTATE(dcb->state),
dcb->fd))); dcb->fd)));
#else
skygw_log_write(
LOGFILE_DEBUG,
"%lu [dcb_write] Append to writequeue. %d writes "
"buffered for dcb %p in state %s fd %d",
pthread_self(),
dcb->stats.n_buffered,
dcb,
STRDCBSTATE(dcb->state),
dcb->fd);
#endif
} }
else else
{ {
@ -743,7 +731,7 @@ dcb_write(DCB *dcb, GWBUF *queue)
errno = 0; errno = 0;
if (saved_errno == EPIPE) { if (saved_errno == EPIPE) {
skygw_log_write( LOGIF(LD, (skygw_log_write(
LOGFILE_DEBUG, LOGFILE_DEBUG,
"%lu [dcb_write] Write to dcb " "%lu [dcb_write] Write to dcb "
"%p in state %s fd %d failed " "%p in state %s fd %d failed "
@ -753,11 +741,11 @@ dcb_write(DCB *dcb, GWBUF *queue)
STRDCBSTATE(dcb->state), STRDCBSTATE(dcb->state),
dcb->fd, dcb->fd,
saved_errno, saved_errno,
strerror(saved_errno)); strerror(saved_errno))));
} else if (saved_errno != EAGAIN && } else if (saved_errno != EAGAIN &&
saved_errno != EWOULDBLOCK) saved_errno != EWOULDBLOCK)
{ {
skygw_log_write_flush( LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR, LOGFILE_ERROR,
"Error : Write to dcb %p in " "Error : Write to dcb %p in "
"state %s fd %d failed due " "state %s fd %d failed due "
@ -766,7 +754,7 @@ dcb_write(DCB *dcb, GWBUF *queue)
STRDCBSTATE(dcb->state), STRDCBSTATE(dcb->state),
dcb->fd, dcb->fd,
saved_errno, saved_errno,
strerror(saved_errno)); strerror(saved_errno))));
} }
break; break;
} }
@ -775,7 +763,7 @@ dcb_write(DCB *dcb, GWBUF *queue)
* queue with have. * queue with have.
*/ */
queue = gwbuf_consume(queue, w); queue = gwbuf_consume(queue, w);
skygw_log_write( LOGIF(LD, (skygw_log_write(
LOGFILE_DEBUG, LOGFILE_DEBUG,
"%lu [dcb_write] Wrote %d Bytes to dcb %p in " "%lu [dcb_write] Wrote %d Bytes to dcb %p in "
"state %s fd %d", "state %s fd %d",
@ -783,7 +771,7 @@ dcb_write(DCB *dcb, GWBUF *queue)
w, w,
dcb, dcb,
STRDCBSTATE(dcb->state), STRDCBSTATE(dcb->state),
dcb->fd); dcb->fd)));
} }
/** /**
* What wasn't successfully written is stored to write queue * What wasn't successfully written is stored to write queue
@ -803,12 +791,12 @@ dcb_write(DCB *dcb, GWBUF *queue)
saved_errno != EWOULDBLOCK) saved_errno != EWOULDBLOCK)
{ {
queue = gwbuf_consume(queue, gwbuf_length(queue)); queue = gwbuf_consume(queue, gwbuf_length(queue));
skygw_log_write_flush( LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR, LOGFILE_ERROR,
"Error : Writing to %s socket failed due %d, %s.", "Error : Writing to %s socket failed due %d, %s.",
dcb_isclient(dcb) ? "client" : "backend server", dcb_isclient(dcb) ? "client" : "backend server",
saved_errno, saved_errno,
strerror(saved_errno)); strerror(saved_errno))));
spinlock_release(&dcb->writeqlock); spinlock_release(&dcb->writeqlock);
return 0; return 0;
@ -858,7 +846,7 @@ int saved_errno = 0;
{ {
break; break;
} }
skygw_log_write_flush( LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR, LOGFILE_ERROR,
"Error : Write to dcb %p " "Error : Write to dcb %p "
"in state %s fd %d failed due errno %d, %s", "in state %s fd %d failed due errno %d, %s",
@ -866,7 +854,7 @@ int saved_errno = 0;
STRDCBSTATE(dcb->state), STRDCBSTATE(dcb->state),
dcb->fd, dcb->fd,
saved_errno, saved_errno,
strerror(saved_errno)); strerror(saved_errno))));
break; break;
} }
/* /*
@ -874,7 +862,7 @@ int saved_errno = 0;
* queue with have. * queue with have.
*/ */
dcb->writeq = gwbuf_consume(dcb->writeq, w); dcb->writeq = gwbuf_consume(dcb->writeq, w);
skygw_log_write( LOGIF(LD, (skygw_log_write(
LOGFILE_DEBUG, LOGFILE_DEBUG,
"%lu [dcb_drain_writeq] Wrote %d Bytes to dcb %p " "%lu [dcb_drain_writeq] Wrote %d Bytes to dcb %p "
"in state %s fd %d", "in state %s fd %d",
@ -882,7 +870,7 @@ int saved_errno = 0;
w, w,
dcb, dcb,
STRDCBSTATE(dcb->state), STRDCBSTATE(dcb->state),
dcb->fd); dcb->fd)));
n += w; n += w;
} }
} }
@ -933,21 +921,21 @@ dcb_close(DCB *dcb)
dcb->state == DCB_STATE_ZOMBIE); dcb->state == DCB_STATE_ZOMBIE);
if (rc == 0) { if (rc == 0) {
skygw_log_write( LOGIF(LD, (skygw_log_write(
LOGFILE_DEBUG, LOGFILE_DEBUG,
"%lu [dcb_close] Removed dcb %p in state %s from " "%lu [dcb_close] Removed dcb %p in state %s from "
"poll set.", "poll set.",
pthread_self(), pthread_self(),
dcb, dcb,
STRDCBSTATE(dcb->state)); STRDCBSTATE(dcb->state))));
} else { } else {
skygw_log_write( LOGIF(LE, (skygw_log_write(
LOGFILE_ERROR, LOGFILE_ERROR,
"%lu [dcb_close] Error : Removing dcb %p in state %s from " "%lu [dcb_close] Error : Removing dcb %p in state %s from "
"poll set failed.", "poll set failed.",
pthread_self(), pthread_self(),
dcb, dcb,
STRDCBSTATE(dcb->state)); STRDCBSTATE(dcb->state))));
} }
if (dcb->state == DCB_STATE_NOPOLLING) { if (dcb->state == DCB_STATE_NOPOLLING) {
@ -1269,25 +1257,25 @@ static bool dcb_set_state_nomutex(
break; break;
default: default:
skygw_log_write_flush( LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR, LOGFILE_ERROR,
"Error : Unknown dcb state %s for " "Error : Unknown dcb state %s for "
"dcb %p", "dcb %p",
STRDCBSTATE(dcb->state), STRDCBSTATE(dcb->state),
dcb); dcb)));
ss_dassert(false); ss_dassert(false);
break; break;
} /* switch (dcb->state) */ } /* switch (dcb->state) */
if (succp) { if (succp) {
skygw_log_write( LOGIF(LD, (skygw_log_write(
LOGFILE_DEBUG, LOGFILE_DEBUG,
"%lu [dcb_set_state_nomutex] dcb %p fd %d %s -> %s", "%lu [dcb_set_state_nomutex] dcb %p fd %d %s -> %s",
pthread_self(), pthread_self(),
dcb, dcb,
dcb->fd, dcb->fd,
STRDCBSTATE(state), STRDCBSTATE(state),
STRDCBSTATE(dcb->state)); STRDCBSTATE(dcb->state))));
} }
return succp; return succp;
} }

View File

@ -150,18 +150,18 @@ static bool resolve_maxscale_homedir(
*/ */
static void sighup_handler (int i) static void sighup_handler (int i)
{ {
skygw_log_write( LOGIF(LM, (skygw_log_write(
LOGFILE_MESSAGE, LOGFILE_MESSAGE,
"Refreshing configuration following SIGHUP\n"); "Refreshing configuration following SIGHUP\n")));
config_reload(); config_reload();
} }
static void sigterm_handler (int i) { static void sigterm_handler (int i) {
extern void shutdown_server(); extern void shutdown_server();
skygw_log_write_flush( LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR, LOGFILE_ERROR,
"MaxScale received signal SIGTERM. Exiting."); "MaxScale received signal SIGTERM. Exiting.")));
shutdown_server(); shutdown_server();
} }
@ -170,9 +170,9 @@ sigint_handler (int i)
{ {
extern void shutdown_server(); extern void shutdown_server();
skygw_log_write_flush( LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR, LOGFILE_ERROR,
"MaxScale received signal SIGINT. Shutting down."); "MaxScale received signal SIGINT. Shutting down.")));
shutdown_server(); shutdown_server();
fprintf(stderr, "\n\nShutting down MaxScale\n\n"); fprintf(stderr, "\n\nShutting down MaxScale\n\n");
} }
@ -203,12 +203,12 @@ static int signal_set (int sig, void (*handler)(int)) {
{ {
int eno = errno; int eno = errno;
errno = 0; errno = 0;
skygw_log_write_flush( LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR, LOGFILE_ERROR,
"Error : Failed call sigaction() in %s due to %d, %s.", "Error : Failed call sigaction() in %s due to %d, %s.",
program_invocation_short_name, program_invocation_short_name,
eno, eno,
strerror(eno)); strerror(eno))));
rc = 1; rc = 1;
} }
return rc; return rc;
@ -232,13 +232,13 @@ int ntfw_cb(
int eno = errno; int eno = errno;
errno = 0; errno = 0;
skygw_log_write( LOGIF(LE, (skygw_log_write(
LOGFILE_ERROR, LOGFILE_ERROR,
"Error : Failed to remove the data directory %s of " "Error : Failed to remove the data directory %s of "
"MaxScale due to %d, %s.", "MaxScale due to %d, %s.",
datadir, datadir,
eno, eno,
strerror(eno)); strerror(eno))));
} }
return rc; return rc;
} }
@ -488,9 +488,10 @@ static bool resolve_maxscale_homedir(
{ {
fprintf(stderr, "\n*\n* Warning : MAXSCALE_HOME environment variable " fprintf(stderr, "\n*\n* Warning : MAXSCALE_HOME environment variable "
"is not set.\n*\n"); "is not set.\n*\n");
skygw_log_write_flush(LOGFILE_ERROR, LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR,
"Warning : MAXSCALE_HOME environment " "Warning : MAXSCALE_HOME environment "
"variable is not set."); "variable is not set.")));
} }
free(tmp); free(tmp);
/** /**
@ -620,12 +621,13 @@ static void print_log_n_stderr(
char* fpr_end = "\n*\n"; char* fpr_end = "\n*\n";
if (do_log) { if (do_log) {
skygw_log_write_flush(LOGFILE_ERROR, LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR,
"%s %s %s %s", "%s %s %s %s",
log_err, log_err,
logstr, logstr,
eno == 0 ? " " : "Error :", eno == 0 ? " " : "Error :",
eno == 0 ? " " : strerror(eno)); eno == 0 ? " " : strerror(eno))));
} }
if (do_stderr) { if (do_stderr) {
fprintf(stderr, fprintf(stderr,
@ -656,13 +658,13 @@ static bool file_is_readable(
absolute_pathname, absolute_pathname,
strerror(eno)); strerror(eno));
} }
skygw_log_write_flush( LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR, LOGFILE_ERROR,
"Warning : Failed to read the configuration file %s due " "Warning : Failed to read the configuration file %s due "
"to %d, %s.", "to %d, %s.",
absolute_pathname, absolute_pathname,
eno, eno,
strerror(eno)); strerror(eno))));
succp = false; succp = false;
} }
return succp; return succp;
@ -687,13 +689,13 @@ static bool file_is_writable(
eno, eno,
strerror(eno)); strerror(eno));
} }
skygw_log_write_flush( LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR, LOGFILE_ERROR,
"Error : unable to open file %s for write due " "Error : unable to open file %s for write due "
"to %d, %s.", "to %d, %s.",
absolute_pathname, absolute_pathname,
eno, eno,
strerror(eno)); strerror(eno))));
succp = false; succp = false;
} }
return succp; return succp;
@ -747,14 +749,14 @@ static char* get_expanded_pathname(
relative_path, relative_path,
strerror(eno)); strerror(eno));
skygw_log_write_flush( LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR, LOGFILE_ERROR,
"Warning : Failed to read the " "Warning : Failed to read the "
"directory %s, due " "directory %s, due "
"to %d, %s.", "to %d, %s.",
relative_path, relative_path,
eno, eno,
strerror(eno)); strerror(eno))));
free(expanded_path); free(expanded_path);
*output_path = NULL; *output_path = NULL;
goto return_cnf_file_buf; goto return_cnf_file_buf;
@ -1200,11 +1202,18 @@ int main(int argc, char **argv)
cnf_file_path, cnf_file_path,
datadir); datadir);
} }
skygw_log_write_flush(LOGFILE_MESSAGE, "Home directory : %s", home_dir); LOGIF(LM, (skygw_log_write_flush(
skygw_log_write_flush(LOGFILE_MESSAGE, "Data directory : %s", datadir); LOGFILE_MESSAGE,
skygw_log_write_flush(LOGFILE_MESSAGE, "Home directory : %s",
home_dir)));
LOGIF(LM, (skygw_log_write_flush(
LOGFILE_MESSAGE,
"Data directory : %s",
datadir)));
LOGIF(LM, (skygw_log_write_flush(
LOGFILE_MESSAGE,
"Configuration file : %s", "Configuration file : %s",
cnf_file_path); cnf_file_path)));
/* Update the server options */ /* Update the server options */
for (i = 0; server_options[i]; i++) for (i = 0; server_options[i]; i++)
@ -1261,7 +1270,7 @@ int main(int argc, char **argv)
} }
} }
} }
skygw_log_write_flush( LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR, LOGFILE_ERROR,
"Error : mysql_library_init failed. It is a " "Error : mysql_library_init failed. It is a "
"mandatory component, required by router services and " "mandatory component, required by router services and "
@ -1269,7 +1278,7 @@ int main(int argc, char **argv)
mysql_errno(NULL), mysql_errno(NULL),
mysql_error(NULL), mysql_error(NULL),
__FILE__, __FILE__,
__LINE__); __LINE__)));
rc = 1; rc = 1;
goto return_main; goto return_main;
} }
@ -1280,21 +1289,21 @@ int main(int argc, char **argv)
char* fprerr = "Failed to load MaxScale configuration " char* fprerr = "Failed to load MaxScale configuration "
"file. Exiting."; "file. Exiting.";
print_log_n_stderr(false, !daemon_mode, fprerr, fprerr, 0); print_log_n_stderr(false, !daemon_mode, fprerr, fprerr, 0);
skygw_log_write_flush( LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR, LOGFILE_ERROR,
"Error : Failed to load MaxScale configuration file %s. " "Error : Failed to load MaxScale configuration file %s. "
"Exiting.", "Exiting.",
cnf_file_path); cnf_file_path)));
rc = 1; rc = 1;
goto return_main; goto return_main;
} }
skygw_log_write( LOGIF(LM, (skygw_log_write(
LOGFILE_MESSAGE, LOGFILE_MESSAGE,
"SkySQL MaxScale (C) SkySQL Ab 2013"); "SkySQL MaxScale (C) SkySQL Ab 2013")));
skygw_log_write( LOGIF(LM, (skygw_log_write(
LOGFILE_MESSAGE, LOGFILE_MESSAGE,
"MaxScale is running in process %i", "MaxScale is running in process %i",
getpid()); getpid())));
poll_init(); poll_init();
@ -1329,9 +1338,9 @@ int main(int argc, char **argv)
{ {
threads[n] = thread_start(poll_waitevents, (void *)(n + 1)); threads[n] = thread_start(poll_waitevents, (void *)(n + 1));
} }
skygw_log_write(LOGFILE_MESSAGE, LOGIF(LM, (skygw_log_write(LOGFILE_MESSAGE,
"MaxScale started with %d server threads.", "MaxScale started with %d server threads.",
config_threadcount()); config_threadcount())));
/** /**
* Serve clients. * Serve clients.
*/ */
@ -1354,9 +1363,13 @@ int main(int argc, char **argv)
/* Stop all the monitors */ /* Stop all the monitors */
monitorStopAll(); monitorStopAll();
skygw_log_write(LOGFILE_MESSAGE, "MaxScale is shutting down."); LOGIF(LM, (skygw_log_write(
LOGFILE_MESSAGE,
"MaxScale is shutting down.")));
datadir_cleanup(); datadir_cleanup();
skygw_log_write(LOGFILE_MESSAGE, "MaxScale shutdown completed."); LOGIF(LM, (skygw_log_write(
LOGFILE_MESSAGE,
"MaxScale shutdown completed.")));
return_main: return_main:
return 0; return 0;
@ -1382,7 +1395,8 @@ static void log_flush_cb(
{ {
ssize_t timeout_ms = *(ssize_t *)arg; ssize_t timeout_ms = *(ssize_t *)arg;
skygw_log_write(LOGFILE_MESSAGE, "Started MaxScale log flusher."); LOGIF(LM, (skygw_log_write(LOGFILE_MESSAGE,
"Started MaxScale log flusher.")));
while (!do_exit) { while (!do_exit) {
skygw_log_flush(LOGFILE_ERROR); skygw_log_flush(LOGFILE_ERROR);
skygw_log_flush(LOGFILE_MESSAGE); skygw_log_flush(LOGFILE_MESSAGE);
@ -1390,5 +1404,6 @@ static void log_flush_cb(
skygw_log_flush(LOGFILE_DEBUG); skygw_log_flush(LOGFILE_DEBUG);
usleep(timeout_ms*1000); usleep(timeout_ms*1000);
} }
skygw_log_write(LOGFILE_MESSAGE, "Finished MaxScale log flusher."); LOGIF(LM, (skygw_log_write(LOGFILE_MESSAGE,
"Finished MaxScale log flusher.")));
} }

View File

@ -41,6 +41,8 @@
#include <skygw_utils.h> #include <skygw_utils.h>
#include <log_manager.h> #include <log_manager.h>
extern int lm_enabled_logfiles_bitmask;
static MODULES *registered = NULL; static MODULES *registered = NULL;
static MODULES *find_module(const char *module); static MODULES *find_module(const char *module);
@ -85,33 +87,33 @@ MODULES *mod;
sprintf(fname, "%s/modules/lib%s.so", home, module); sprintf(fname, "%s/modules/lib%s.so", home, module);
if (access(fname, F_OK) == -1) if (access(fname, F_OK) == -1)
{ {
skygw_log_write_flush( LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR, LOGFILE_ERROR,
"Error : Unable to find library for " "Error : Unable to find library for "
"module: %s.", "module: %s.",
module); module)));
return NULL; return NULL;
} }
} }
if ((dlhandle = dlopen(fname, RTLD_NOW|RTLD_LOCAL)) == NULL) if ((dlhandle = dlopen(fname, RTLD_NOW|RTLD_LOCAL)) == NULL)
{ {
skygw_log_write_flush( LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR, LOGFILE_ERROR,
"Error : Unable to load library for module: " "Error : Unable to load library for module: "
"%s, %s.", "%s, %s.",
module, module,
dlerror()); dlerror())));
return NULL; return NULL;
} }
if ((sym = dlsym(dlhandle, "version")) == NULL) if ((sym = dlsym(dlhandle, "version")) == NULL)
{ {
skygw_log_write_flush( LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR, LOGFILE_ERROR,
"Error : Version interface not supported by " "Error : Version interface not supported by "
"module: %s, %s.", "module: %s, %s.",
module, module,
dlerror()); dlerror())));
dlclose(dlhandle); dlclose(dlhandle);
return NULL; return NULL;
} }
@ -129,23 +131,23 @@ MODULES *mod;
if ((sym = dlsym(dlhandle, "GetModuleObject")) == NULL) if ((sym = dlsym(dlhandle, "GetModuleObject")) == NULL)
{ {
skygw_log_write_flush( LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR, LOGFILE_ERROR,
"Error : Expected entry point interface missing " "Error : Expected entry point interface missing "
"from module: %s, %s.", "from module: %s, %s.",
module, module,
dlerror()); dlerror())));
dlclose(dlhandle); dlclose(dlhandle);
return NULL; return NULL;
} }
ep = sym; ep = sym;
modobj = ep(); modobj = ep();
skygw_log_write_flush( LOGIF(LM, (skygw_log_write_flush(
LOGFILE_MESSAGE, LOGFILE_MESSAGE,
"Loaded module %s: %s.", "Loaded module %s: %s.",
module, module,
version); version)));
register_module(module, type, dlhandle, version, modobj); register_module(module, type, dlhandle, version, modobj);
} }
else else

View File

@ -36,6 +36,7 @@
#include <skygw_utils.h> #include <skygw_utils.h>
#include <log_manager.h> #include <log_manager.h>
extern int lm_enabled_logfiles_bitmask;
static MONITOR *allMonitors = NULL; static MONITOR *allMonitors = NULL;
static SPINLOCK monLock = SPINLOCK_INIT; static SPINLOCK monLock = SPINLOCK_INIT;
@ -61,10 +62,10 @@ MONITOR *mon;
mon->name = strdup(name); mon->name = strdup(name);
if ((mon->module = load_module(module, MODULE_MONITOR)) == NULL) if ((mon->module = load_module(module, MODULE_MONITOR)) == NULL)
{ {
skygw_log_write_flush( LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR, LOGFILE_ERROR,
"Error : Unable to load monitor module '%s'.", "Error : Unable to load monitor module '%s'.",
name); name)));
free(mon->name); free(mon->name);
free(mon); free(mon);
return NULL; return NULL;

View File

@ -28,6 +28,8 @@
#include <skygw_utils.h> #include <skygw_utils.h>
#include <log_manager.h> #include <log_manager.h>
extern int lm_enabled_logfiles_bitmask;
/** /**
* @file poll.c - Abstraction of the epoll functionality * @file poll.c - Abstraction of the epoll functionality
* *
@ -119,7 +121,7 @@ poll_add_dcb(DCB *dcb)
if (rc != 0) { if (rc != 0) {
int eno = errno; int eno = errno;
errno = 0; errno = 0;
skygw_log_write_flush( LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR, LOGFILE_ERROR,
"Error : Adding dcb %p in state %s " "Error : Adding dcb %p in state %s "
"to poll set failed. epoll_ctl failed due " "to poll set failed. epoll_ctl failed due "
@ -127,24 +129,24 @@ poll_add_dcb(DCB *dcb)
dcb, dcb,
STRDCBSTATE(dcb->state), STRDCBSTATE(dcb->state),
eno, eno,
strerror(eno)); strerror(eno))));
} else { } else {
skygw_log_write( LOGIF(LD, (skygw_log_write(
LOGFILE_DEBUG, LOGFILE_DEBUG,
"%lu [poll_add_dcb] Added dcb %p in state %s to " "%lu [poll_add_dcb] Added dcb %p in state %s to "
"poll set.", "poll set.",
pthread_self(), pthread_self(),
dcb, dcb,
STRDCBSTATE(dcb->state)); STRDCBSTATE(dcb->state))));
} }
ss_dassert(rc == 0); /**< trap in debug */ ss_dassert(rc == 0); /**< trap in debug */
} else { } else {
skygw_log_write_flush( LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR, LOGFILE_ERROR,
"Error : Unable to set new state for dcb %p " "Error : Unable to set new state for dcb %p "
"in state %s. Adding to poll set failed.", "in state %s. Adding to poll set failed.",
dcb, dcb,
STRDCBSTATE(dcb->state)); STRDCBSTATE(dcb->state))));
} }
return rc; return rc;
@ -188,11 +190,11 @@ poll_remove_dcb(DCB *dcb)
if (rc != 0) { if (rc != 0) {
int eno = errno; int eno = errno;
errno = 0; errno = 0;
skygw_log_write_flush( LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR, LOGFILE_ERROR,
"Error : epoll_ctl failed due %d, %s.", "Error : epoll_ctl failed due %d, %s.",
eno, eno,
strerror(eno)); strerror(eno))));
} }
ss_dassert(rc == 0); /**< trap in debug */ ss_dassert(rc == 0); /**< trap in debug */
} }
@ -258,11 +260,12 @@ poll_waitevents(void *arg)
nfds = epoll_wait(epoll_fd, events, MAX_EVENTS, -1); nfds = epoll_wait(epoll_fd, events, MAX_EVENTS, -1);
#else /* BLOCKINGPOLL */ #else /* BLOCKINGPOLL */
if (!no_op) { if (!no_op) {
skygw_log_write(LOGFILE_DEBUG, LOGIF(LD, (skygw_log_write(
LOGFILE_DEBUG,
"%lu [poll_waitevents] MaxScale thread " "%lu [poll_waitevents] MaxScale thread "
"%d > epoll_wait <", "%d > epoll_wait <",
pthread_self(), pthread_self(),
thread_id); thread_id)));
no_op = TRUE; no_op = TRUE;
} }
#if 0 #if 0
@ -273,13 +276,13 @@ poll_waitevents(void *arg)
{ {
int eno = errno; int eno = errno;
errno = 0; errno = 0;
skygw_log_write( LOGIF(LD, (skygw_log_write(
LOGFILE_DEBUG, LOGFILE_DEBUG,
"%lu [poll_waitevents] epoll_wait returned " "%lu [poll_waitevents] epoll_wait returned "
"%d, errno %d", "%d, errno %d",
pthread_self(), pthread_self(),
nfds, nfds,
eno); eno)));
no_op = FALSE; no_op = FALSE;
} }
else if (nfds == 0) else if (nfds == 0)
@ -312,11 +315,11 @@ poll_waitevents(void *arg)
#endif /* BLOCKINGPOLL */ #endif /* BLOCKINGPOLL */
if (nfds > 0) if (nfds > 0)
{ {
skygw_log_write( LOGIF(LD, (skygw_log_write(
LOGFILE_DEBUG, LOGFILE_DEBUG,
"%lu [poll_waitevents] epoll_wait found %d fds", "%lu [poll_waitevents] epoll_wait found %d fds",
pthread_self(), pthread_self(),
nfds); nfds)));
atomic_add(&pollStats.n_polls, 1); atomic_add(&pollStats.n_polls, 1);
for (i = 0; i < nfds; i++) for (i = 0; i < nfds; i++)
@ -328,13 +331,13 @@ poll_waitevents(void *arg)
#if defined(SS_DEBUG) #if defined(SS_DEBUG)
if (dcb_fake_write_ev[dcb->fd] != 0) { if (dcb_fake_write_ev[dcb->fd] != 0) {
skygw_log_write( LOGIF(LD, (skygw_log_write(
LOGFILE_DEBUG, LOGFILE_DEBUG,
"%lu [poll_waitevents] " "%lu [poll_waitevents] "
"Added fake events %d to ev %d.", "Added fake events %d to ev %d.",
pthread_self(), pthread_self(),
dcb_fake_write_ev[dcb->fd], dcb_fake_write_ev[dcb->fd],
ev); ev)));
ev |= dcb_fake_write_ev[dcb->fd]; ev |= dcb_fake_write_ev[dcb->fd];
dcb_fake_write_ev[dcb->fd] = 0; dcb_fake_write_ev[dcb->fd] = 0;
} }
@ -345,14 +348,14 @@ poll_waitevents(void *arg)
ss_dassert(dcb->state != DCB_STATE_FREED); ss_dassert(dcb->state != DCB_STATE_FREED);
ss_debug(spinlock_release(&dcb->dcb_initlock);) ss_debug(spinlock_release(&dcb->dcb_initlock);)
skygw_log_write( LOGIF(LT, (skygw_log_write(
LOGFILE_TRACE, LOGFILE_TRACE,
"%lu [poll_waitevents] event %d dcb %p " "%lu [poll_waitevents] event %d dcb %p "
"role %s", "role %s",
pthread_self(), pthread_self(),
ev, ev,
dcb, dcb,
STRDCBROLE(dcb->dcb_role)); STRDCBROLE(dcb->dcb_role))));
if (ev & EPOLLERR) if (ev & EPOLLERR)
{ {
@ -360,25 +363,25 @@ poll_waitevents(void *arg)
#if defined(SS_DEBUG) #if defined(SS_DEBUG)
if (eno == 0) { if (eno == 0) {
eno = dcb_fake_write_errno[dcb->fd]; eno = dcb_fake_write_errno[dcb->fd];
skygw_log_write( LOGIF(LD, (skygw_log_write(
LOGFILE_DEBUG, LOGFILE_DEBUG,
"%lu [poll_waitevents] " "%lu [poll_waitevents] "
"Added fake errno %d. " "Added fake errno %d. "
"%s", "%s",
pthread_self(), pthread_self(),
eno, eno,
strerror(eno)); strerror(eno))));
} }
dcb_fake_write_errno[dcb->fd] = 0; dcb_fake_write_errno[dcb->fd] = 0;
#endif #endif
if (eno != 0) { if (eno != 0) {
skygw_log_write( LOGIF(LD, (skygw_log_write(
LOGFILE_DEBUG, LOGFILE_DEBUG,
"%lu [poll_waitevents] " "%lu [poll_waitevents] "
"EPOLLERR due %d, %s.", "EPOLLERR due %d, %s.",
pthread_self(), pthread_self(),
eno, eno,
strerror(eno)); strerror(eno))));
} }
atomic_add(&pollStats.n_error, 1); atomic_add(&pollStats.n_error, 1);
dcb->func.error(dcb); dcb->func.error(dcb);
@ -388,7 +391,7 @@ poll_waitevents(void *arg)
int eno = 0; int eno = 0;
eno = gw_getsockerrno(dcb->fd); eno = gw_getsockerrno(dcb->fd);
skygw_log_write( LOGIF(LD, (skygw_log_write(
LOGFILE_DEBUG, LOGFILE_DEBUG,
"%lu [poll_waitevents] " "%lu [poll_waitevents] "
"EPOLLHUP on dcb %p, fd %d. " "EPOLLHUP on dcb %p, fd %d. "
@ -397,7 +400,7 @@ poll_waitevents(void *arg)
dcb, dcb,
dcb->fd, dcb->fd,
eno, eno,
strerror(eno)); strerror(eno))));
atomic_add(&pollStats.n_hup, 1); atomic_add(&pollStats.n_hup, 1);
dcb->func.hangup(dcb); dcb->func.hangup(dcb);
} }
@ -426,7 +429,7 @@ poll_waitevents(void *arg)
&dcb->dcb_write_lock); &dcb->dcb_write_lock);
#endif #endif
} else { } else {
skygw_log_write( LOGIF(LD, (skygw_log_write(
LOGFILE_DEBUG, LOGFILE_DEBUG,
"%lu [poll_waitevents] " "%lu [poll_waitevents] "
"EPOLLOUT due %d, %s. " "EPOLLOUT due %d, %s. "
@ -435,7 +438,7 @@ poll_waitevents(void *arg)
eno, eno,
strerror(eno), strerror(eno),
dcb, dcb,
dcb->fd); dcb->fd)));
} }
} }
if (ev & EPOLLIN) if (ev & EPOLLIN)
@ -449,25 +452,25 @@ poll_waitevents(void *arg)
#endif #endif
if (dcb->state == DCB_STATE_LISTENING) if (dcb->state == DCB_STATE_LISTENING)
{ {
skygw_log_write( LOGIF(LD, (skygw_log_write(
LOGFILE_DEBUG, LOGFILE_DEBUG,
"%lu [poll_waitevents] " "%lu [poll_waitevents] "
"Accept in fd %d", "Accept in fd %d",
pthread_self(), pthread_self(),
dcb->fd); dcb->fd)));
atomic_add( atomic_add(
&pollStats.n_accept, 1); &pollStats.n_accept, 1);
dcb->func.accept(dcb); dcb->func.accept(dcb);
} }
else else
{ {
skygw_log_write( LOGIF(LD, (skygw_log_write(
LOGFILE_DEBUG, LOGFILE_DEBUG,
"%lu [poll_waitevents] " "%lu [poll_waitevents] "
"Read in dcb %p fd %d", "Read in dcb %p fd %d",
pthread_self(), pthread_self(),
dcb, dcb,
dcb->fd); dcb->fd)));
atomic_add(&pollStats.n_read, 1); atomic_add(&pollStats.n_read, 1);
dcb->func.read(dcb); dcb->func.read(dcb);
} }

View File

@ -22,6 +22,7 @@
#include <log_manager.h> #include <log_manager.h>
#include <ctype.h> #include <ctype.h>
extern int lm_enabled_logfiles_bitmask;
/** /**
* Generate a random printable character * Generate a random printable character
* *
@ -75,13 +76,13 @@ int len;
if (access(secret_file, R_OK) == -1) { if (access(secret_file, R_OK) == -1) {
int eno = errno; int eno = errno;
errno = 0; errno = 0;
skygw_log_write_flush( LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR, LOGFILE_ERROR,
"Error : access for secrets file " "Error : access for secrets file "
"[%s] failed. Error %d, %s.", "[%s] failed. Error %d, %s.",
secret_file, secret_file,
eno, eno,
strerror(eno)); strerror(eno))));
return NULL; return NULL;
} }
@ -90,13 +91,13 @@ int len;
{ {
int eno = errno; int eno = errno;
errno = 0; errno = 0;
skygw_log_write_flush( LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR, LOGFILE_ERROR,
"Error : Failed opening secret " "Error : Failed opening secret "
"file [%s]. Error %d, %s.", "file [%s]. Error %d, %s.",
secret_file, secret_file,
eno, eno,
strerror(eno)); strerror(eno))));
return NULL; return NULL;
} }
@ -105,13 +106,13 @@ int len;
if (fstat(fd, &secret_stats) < 0) { if (fstat(fd, &secret_stats) < 0) {
int eno = errno; int eno = errno;
errno = 0; errno = 0;
skygw_log_write_flush( LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR, LOGFILE_ERROR,
"Error : fstat for secret file %s " "Error : fstat for secret file %s "
"failed. Error %d, %s.", "failed. Error %d, %s.",
secret_file, secret_file,
eno, eno,
strerror(eno)); strerror(eno))));
return NULL; return NULL;
} }
@ -119,31 +120,31 @@ int len;
{ {
int eno = errno; int eno = errno;
errno = 0; errno = 0;
skygw_log_write_flush( LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR, LOGFILE_ERROR,
"Error : Secrets file %s has " "Error : Secrets file %s has "
"incorrect size. Error %d, %s.", "incorrect size. Error %d, %s.",
secret_file, secret_file,
eno, eno,
strerror(eno)); strerror(eno))));
return NULL; return NULL;
} }
if (secret_stats.st_mode != (S_IRUSR|S_IFREG)) if (secret_stats.st_mode != (S_IRUSR|S_IFREG))
{ {
skygw_log_write_flush( LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR, LOGFILE_ERROR,
"Error : Ignoring secrets file " "Error : Ignoring secrets file "
"%s, invalid permissions.", "%s, invalid permissions.",
secret_file); secret_file)));
return NULL; return NULL;
} }
if ((keys = (MAXKEYS *)malloc(sizeof(MAXKEYS))) == NULL) if ((keys = (MAXKEYS *)malloc(sizeof(MAXKEYS))) == NULL)
{ {
skygw_log_write_flush( LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR, LOGFILE_ERROR,
"Error : Memory allocation failed " "Error : Memory allocation failed "
"for key structure."); "for key structure.")));
return NULL; return NULL;
} }
@ -158,7 +159,7 @@ int len;
int eno = errno; int eno = errno;
errno = 0; errno = 0;
free(keys); free(keys);
skygw_log_write_flush( LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR, LOGFILE_ERROR,
"Error : Read from secrets file " "Error : Read from secrets file "
"%s failed. Read %d, expected %d bytes. Error %d, %s.", "%s failed. Read %d, expected %d bytes. Error %d, %s.",
@ -166,7 +167,7 @@ int len;
len, len,
sizeof(MAXKEYS), sizeof(MAXKEYS),
eno, eno,
strerror(eno)); strerror(eno))));
return NULL; return NULL;
} }
@ -175,13 +176,13 @@ int len;
int eno = errno; int eno = errno;
errno = 0; errno = 0;
free(keys); free(keys);
skygw_log_write_flush( LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR, LOGFILE_ERROR,
"Error : Failed closing the " "Error : Failed closing the "
"secrets file %s. Error %d, %s.", "secrets file %s. Error %d, %s.",
secret_file, secret_file,
eno, eno,
strerror(eno)); strerror(eno))));
return NULL; return NULL;
} }
ss_dassert(keys != NULL); ss_dassert(keys != NULL);
@ -205,13 +206,13 @@ MAXKEYS key;
/* Open for writing | Create | Truncate the file for writing */ /* Open for writing | Create | Truncate the file for writing */
if ((fd = open(secret_file, O_CREAT | O_WRONLY | O_TRUNC, S_IRUSR)) < 0) if ((fd = open(secret_file, O_CREAT | O_WRONLY | O_TRUNC, S_IRUSR)) < 0)
{ {
skygw_log_write_flush( LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR, LOGFILE_ERROR,
"Error : failed opening secret " "Error : failed opening secret "
"file [%s]. Error %d, %s.", "file [%s]. Error %d, %s.",
secret_file, secret_file,
errno, errno,
strerror(errno)); strerror(errno))));
return 1; return 1;
} }
@ -222,26 +223,26 @@ MAXKEYS key;
/* Write data */ /* Write data */
if (write(fd, &key, sizeof(key)) < 0) if (write(fd, &key, sizeof(key)) < 0)
{ {
skygw_log_write_flush( LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR, LOGFILE_ERROR,
"Error : failed writing into " "Error : failed writing into "
"secret file [%s]. Error %d, %s.", "secret file [%s]. Error %d, %s.",
secret_file, secret_file,
errno, errno,
strerror(errno)); strerror(errno))));
return 1; return 1;
} }
/* close file */ /* close file */
if (close(fd) < 0) if (close(fd) < 0)
{ {
skygw_log_write_flush( LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR, LOGFILE_ERROR,
"Error : failed closing the " "Error : failed closing the "
"secret file [%s]. Error %d, %s.", "secret file [%s]. Error %d, %s.",
secret_file, secret_file,
errno, errno,
strerror(errno)); strerror(errno))));
} }
chmod(secret_file, S_IRUSR); chmod(secret_file, S_IRUSR);

View File

@ -37,6 +37,8 @@
#include <skygw_utils.h> #include <skygw_utils.h>
#include <log_manager.h> #include <log_manager.h>
extern int lm_enabled_logfiles_bitmask;
static SPINLOCK server_spin = SPINLOCK_INIT; static SPINLOCK server_spin = SPINLOCK_INIT;
static SERVER *allServers = NULL; static SERVER *allServers = NULL;
@ -309,11 +311,11 @@ server_update(SERVER *server, char *protocol, char *user, char *passwd)
{ {
if (!strcmp(server->protocol, protocol)) if (!strcmp(server->protocol, protocol))
{ {
skygw_log_write( LOGIF(LM, (skygw_log_write(
LOGFILE_MESSAGE, LOGFILE_MESSAGE,
"Update server protocol for server %s to protocol %s.", "Update server protocol for server %s to protocol %s.",
server->name, server->name,
protocol); protocol)));
free(server->protocol); free(server->protocol);
server->protocol = strdup(protocol); server->protocol = strdup(protocol);
} }
@ -322,10 +324,10 @@ server_update(SERVER *server, char *protocol, char *user, char *passwd)
if (strcmp(server->monuser, user) == 0 || if (strcmp(server->monuser, user) == 0 ||
strcmp(server->monpw, passwd) == 0) strcmp(server->monpw, passwd) == 0)
{ {
skygw_log_write( LOGIF(LM, (skygw_log_write(
LOGFILE_MESSAGE, LOGFILE_MESSAGE,
"Update server monitor credentials for server %s", "Update server monitor credentials for server %s",
server->name); server->name)));
free(server->monuser); free(server->monuser);
free(server->monpw); free(server->monpw);
serverAddMonUser(server, user, passwd); serverAddMonUser(server, user, passwd);

View File

@ -43,6 +43,8 @@
#include <skygw_utils.h> #include <skygw_utils.h>
#include <log_manager.h> #include <log_manager.h>
extern int lm_enabled_logfiles_bitmask;
static SPINLOCK service_spin = SPINLOCK_INIT; static SPINLOCK service_spin = SPINLOCK_INIT;
static SERVICE *allServices = NULL; static SERVICE *allServices = NULL;
@ -110,10 +112,10 @@ GWPROTOCOL *funcs;
} }
if (strcmp(port->protocol, "MySQLClient") == 0) { if (strcmp(port->protocol, "MySQLClient") == 0) {
int loaded = load_mysql_users(service); int loaded = load_mysql_users(service);
skygw_log_write( LOGIF(LM, (skygw_log_write(
LOGFILE_MESSAGE, LOGFILE_MESSAGE,
"Loaded %d MySQL Users.", "Loaded %d MySQL Users.",
loaded); loaded)));
} }
if ((funcs = if ((funcs =
@ -121,12 +123,12 @@ GWPROTOCOL *funcs;
{ {
free(port->listener); free(port->listener);
port->listener = NULL; port->listener = NULL;
skygw_log_write_flush( LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR, LOGFILE_ERROR,
"Error : Unable to load protocol module %s. Listener " "Error : Unable to load protocol module %s. Listener "
"for service %s not started.", "for service %s not started.",
port->protocol, port->protocol,
service->name); service->name)));
return 0; return 0;
} }
memcpy(&(port->listener->func), funcs, sizeof(GWPROTOCOL)); memcpy(&(port->listener->func), funcs, sizeof(GWPROTOCOL));
@ -145,12 +147,12 @@ GWPROTOCOL *funcs;
} else { } else {
dcb_close(port->listener); dcb_close(port->listener);
skygw_log_write_flush( LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR, LOGFILE_ERROR,
"Error : Unable to start to listen port %d for %s %s.", "Error : Unable to start to listen port %d for %s %s.",
port->port, port->port,
port->protocol, port->protocol,
service->name); service->name)));
} }
return listeners; return listeners;
} }
@ -629,20 +631,20 @@ void *router_obj;
{ {
if ((router_obj = load_module(router, MODULE_ROUTER)) == NULL) if ((router_obj = load_module(router, MODULE_ROUTER)) == NULL)
{ {
skygw_log_write_flush( LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR, LOGFILE_ERROR,
"Error : Failed to update router " "Error : Failed to update router "
"for service %s to %s.", "for service %s to %s.",
service->name, service->name,
router); router)));
} }
else else
{ {
skygw_log_write( LOGIF(LM, (skygw_log_write(
LOGFILE_MESSAGE, LOGFILE_MESSAGE,
"Update router for service %s to %s.", "Update router for service %s to %s.",
service->name, service->name,
router); router)));
free(service->routerModule); free(service->routerModule);
service->routerModule = strdup(router); service->routerModule = strdup(router);
service->router = router_obj; service->router = router_obj;
@ -652,10 +654,10 @@ void *router_obj;
(strcmp(service->credentials.name, user) != 0 || (strcmp(service->credentials.name, user) != 0 ||
strcmp(service->credentials.authdata, auth) != 0)) strcmp(service->credentials.authdata, auth) != 0))
{ {
skygw_log_write( LOGIF(LM, (skygw_log_write(
LOGFILE_MESSAGE, LOGFILE_MESSAGE,
"Update credentials for service %s.", "Update credentials for service %s.",
service->name); service->name)));
serviceSetUser(service, user, auth); serviceSetUser(service, user, auth);
} }
} }

View File

@ -42,6 +42,7 @@
#include <skygw_utils.h> #include <skygw_utils.h>
#include <log_manager.h> #include <log_manager.h>
extern int lm_enabled_logfiles_bitmask;
static SPINLOCK session_spin = SPINLOCK_INIT; static SPINLOCK session_spin = SPINLOCK_INIT;
static SESSION *allSessions = NULL; static SESSION *allSessions = NULL;
@ -69,12 +70,12 @@ session_alloc(SERVICE *service, DCB *client_dcb)
if (session == NULL) { if (session == NULL) {
int eno = errno; int eno = errno;
errno = 0; errno = 0;
skygw_log_write_flush( LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR, LOGFILE_ERROR,
"Error : Failed to allocate memory for " "Error : Failed to allocate memory for "
"session object due error %d, %s.", "session object due error %d, %s.",
eno, eno,
strerror(eno)); strerror(eno))));
goto return_session; goto return_session;
} }
#if defined(SS_DEBUG) #if defined(SS_DEBUG)
@ -135,10 +136,10 @@ session_alloc(SERVICE *service, DCB *client_dcb)
session_free(session); session_free(session);
client_dcb->session = NULL; client_dcb->session = NULL;
session = NULL; session = NULL;
skygw_log_write_flush( LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR, LOGFILE_ERROR,
"Error : Failed to create router " "Error : Failed to create router "
"client session. Freeing allocated resources."); "client session. Freeing allocated resources.")));
goto return_session; goto return_session;
} }

View File

@ -42,6 +42,8 @@
#include <skygw_utils.h> #include <skygw_utils.h>
#include <log_manager.h> #include <log_manager.h>
extern int lm_enabled_logfiles_bitmask;
// used in the hex2bin function // used in the hex2bin function
#define char_val(X) (X >= '0' && X <= '9' ? X-'0' :\ #define char_val(X) (X >= '0' && X <= '9' ? X-'0' :\
X >= 'A' && X <= 'Z' ? X-'A'+10 :\ X >= 'A' && X <= 'Z' ? X-'A'+10 :\
@ -61,22 +63,22 @@ int setnonblocking(int fd) {
int fl; int fl;
if ((fl = fcntl(fd, F_GETFL, 0)) == -1) { if ((fl = fcntl(fd, F_GETFL, 0)) == -1) {
skygw_log_write_flush( LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR, LOGFILE_ERROR,
"Error : Can't GET fcntl for %i, errno = %d, %s.", "Error : Can't GET fcntl for %i, errno = %d, %s.",
fd, fd,
errno, errno,
strerror(errno)); strerror(errno))));
return 1; return 1;
} }
if (fcntl(fd, F_SETFL, fl | O_NONBLOCK) == -1) { if (fcntl(fd, F_SETFL, fl | O_NONBLOCK) == -1) {
skygw_log_write_flush( LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR, LOGFILE_ERROR,
"Error : Can't SET fcntl for %i, errno = %d, %s", "Error : Can't SET fcntl for %i, errno = %d, %s",
fd, fd,
errno, errno,
strerror(errno)); strerror(errno))));
return 1; return 1;
} }
return 0; return 0;

View File

@ -41,6 +41,8 @@
#include <secrets.h> #include <secrets.h>
#include <dcb.h> #include <dcb.h>
extern int lm_enabled_logfiles_bitmask;
static void monitorMain(void *); static void monitorMain(void *);
static char *version_str = "V1.0.0"; static char *version_str = "V1.0.0";
@ -72,8 +74,10 @@ version()
void void
ModuleInit() ModuleInit()
{ {
skygw_log_write( LOGFILE_MESSAGE, "Initialise the MySQL Galera Monitor module %s.\n", LOGIF(LM, (skygw_log_write(
version_str); LOGFILE_MESSAGE,
"Initialise the MySQL Galera Monitor module %s.\n",
version_str)));
} }
/** /**
@ -334,9 +338,10 @@ MONITOR_SERVERS *ptr;
if (mysql_thread_init()) if (mysql_thread_init())
{ {
skygw_log_write_flush(LOGFILE_ERROR, LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR,
"Fatal : mysql_thread_init failed in monitor " "Fatal : mysql_thread_init failed in monitor "
"module. Exiting.\n"); "module. Exiting.\n")));
return; return;
} }
handle->status = MONITOR_RUNNING; handle->status = MONITOR_RUNNING;

View File

@ -45,6 +45,8 @@
#include <secrets.h> #include <secrets.h>
#include <dcb.h> #include <dcb.h>
extern int lm_enabled_logfiles_bitmask;
static void monitorMain(void *); static void monitorMain(void *);
static char *version_str = "V1.0.0"; static char *version_str = "V1.0.0";
@ -76,10 +78,10 @@ version()
void void
ModuleInit() ModuleInit()
{ {
skygw_log_write( LOGIF(LM, (skygw_log_write(
LOGFILE_MESSAGE, LOGFILE_MESSAGE,
"Initialise the MySQL Monitor module %s.", "Initialise the MySQL Monitor module %s.",
version_str); version_str)));
} }
/** /**
@ -384,9 +386,10 @@ MONITOR_SERVERS *ptr;
if (mysql_thread_init()) if (mysql_thread_init())
{ {
skygw_log_write_flush(LOGFILE_ERROR, LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR,
"Fatal : mysql_thread_init failed in monitor " "Fatal : mysql_thread_init failed in monitor "
"module. Exiting.\n"); "module. Exiting.\n")));
return; return;
} }
handle->status = MONITOR_RUNNING; handle->status = MONITOR_RUNNING;

View File

@ -44,6 +44,8 @@
* *
*/ */
extern int lm_enabled_logfiles_bitmask;
static char *version_str = "V2.0.0"; static char *version_str = "V2.0.0";
static int gw_create_backend_connection(DCB *backend, SERVER *server, SESSION *in_session); static int gw_create_backend_connection(DCB *backend, SERVER *server, SESSION *in_session);
static int gw_read_backend_event(DCB* dcb); static int gw_read_backend_event(DCB* dcb);
@ -119,12 +121,12 @@ static MYSQL_session* gw_get_shared_session_auth_info(
if (dcb->session->state != SESSION_STATE_ALLOC) { if (dcb->session->state != SESSION_STATE_ALLOC) {
auth_info = dcb->session->data; auth_info = dcb->session->data;
} else { } else {
skygw_log_write_flush( LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR, LOGFILE_ERROR,
"%lu [gw_get_shared_session_auth_info] Couldn't get " "%lu [gw_get_shared_session_auth_info] Couldn't get "
"session authentication info. Session in a wrong state %d.", "session authentication info. Session in a wrong state %d.",
pthread_self(), pthread_self(),
dcb->session->state); dcb->session->state)));
} }
spinlock_release(&dcb->session->ses_lock); spinlock_release(&dcb->session->ses_lock);
@ -152,7 +154,7 @@ static int gw_read_backend_event(DCB *dcb) {
backend_protocol = (MySQLProtocol *) dcb->protocol; backend_protocol = (MySQLProtocol *) dcb->protocol;
CHK_PROTOCOL(backend_protocol); CHK_PROTOCOL(backend_protocol);
skygw_log_write( LOGIF(LD, (skygw_log_write(
LOGFILE_DEBUG, LOGFILE_DEBUG,
"%lu [gw_read_backend_event] Read dcb %p fd %d protocol " "%lu [gw_read_backend_event] Read dcb %p fd %d protocol "
"state %d, %s.", "state %d, %s.",
@ -160,7 +162,7 @@ static int gw_read_backend_event(DCB *dcb) {
dcb, dcb,
dcb->fd, dcb->fd,
backend_protocol->state, backend_protocol->state,
STRPROTOCOLSTATE(backend_protocol->state)); STRPROTOCOLSTATE(backend_protocol->state))));
/* backend is connected: /* backend is connected:
@ -242,17 +244,17 @@ static int gw_read_backend_event(DCB *dcb) {
case -1: case -1:
backend_protocol->state = MYSQL_AUTH_FAILED; backend_protocol->state = MYSQL_AUTH_FAILED;
skygw_log_write_flush( LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR, LOGFILE_ERROR,
"Error : backend server didn't " "Error : backend server didn't "
"accept authentication for user " "accept authentication for user "
"%s.", "%s.",
current_session->user); current_session->user)));
break; break;
case 1: case 1:
backend_protocol->state = MYSQL_IDLE; backend_protocol->state = MYSQL_IDLE;
skygw_log_write_flush( LOGIF(LD, (skygw_log_write_flush(
LOGFILE_DEBUG, LOGFILE_DEBUG,
"%lu [gw_read_backend_event] " "%lu [gw_read_backend_event] "
"gw_receive_backend_auth succeed. " "gw_receive_backend_auth succeed. "
@ -260,11 +262,11 @@ static int gw_read_backend_event(DCB *dcb) {
pthread_self(), pthread_self(),
dcb, dcb,
dcb->fd, dcb->fd,
current_session->user); current_session->user)));
break; break;
default: default:
ss_dassert(receive_rc == 0); ss_dassert(receive_rc == 0);
skygw_log_write_flush( LOGIF(LD, (skygw_log_write_flush(
LOGFILE_DEBUG, LOGFILE_DEBUG,
"%lu [gw_read_backend_event] " "%lu [gw_read_backend_event] "
"gw_receive_backend_auth read " "gw_receive_backend_auth read "
@ -273,7 +275,7 @@ static int gw_read_backend_event(DCB *dcb) {
pthread_self(), pthread_self(),
dcb, dcb,
dcb->fd, dcb->fd,
current_session->user); current_session->user)));
rc = 0; rc = 0;
goto return_with_lock; goto return_with_lock;
break; break;
@ -305,12 +307,12 @@ static int gw_read_backend_event(DCB *dcb) {
**/ **/
ss_dassert(rsession != NULL); ss_dassert(rsession != NULL);
skygw_log_write_flush( LOGIF(LD, (skygw_log_write_flush(
LOGFILE_DEBUG, LOGFILE_DEBUG,
"%lu [gw_read_backend_event] " "%lu [gw_read_backend_event] "
"Call closeSession for backend's " "Call closeSession for backend's "
"router client session.", "router client session.",
pthread_self()); pthread_self())));
/* close router_session */ /* close router_session */
router->closeSession(router_instance, rsession); router->closeSession(router_instance, rsession);
rc = 1; rc = 1;
@ -319,14 +321,14 @@ static int gw_read_backend_event(DCB *dcb) {
else else
{ {
ss_dassert(backend_protocol->state == MYSQL_IDLE); ss_dassert(backend_protocol->state == MYSQL_IDLE);
skygw_log_write_flush( LOGIF(LD, (skygw_log_write_flush(
LOGFILE_DEBUG, LOGFILE_DEBUG,
"%lu [gw_read_backend_event] " "%lu [gw_read_backend_event] "
"gw_receive_backend_auth succeed. Fd %d, " "gw_receive_backend_auth succeed. Fd %d, "
"user %s.", "user %s.",
pthread_self(), pthread_self(),
dcb->fd, dcb->fd,
current_session->user); current_session->user)));
/* check the delay queue and flush the data */ /* check the delay queue and flush the data */
if (dcb->delayq) if (dcb->delayq)
@ -435,7 +437,7 @@ static int gw_write_backend_event(DCB *dcb) {
0, 0,
"Writing to backend failed due invalid Maxscale " "Writing to backend failed due invalid Maxscale "
"state."); "state.");
skygw_log_write( LOGIF(LD, (skygw_log_write(
LOGFILE_DEBUG, LOGFILE_DEBUG,
"%lu [gw_write_backend_event] Write to backend " "%lu [gw_write_backend_event] Write to backend "
"dcb %p fd %d " "dcb %p fd %d "
@ -443,23 +445,23 @@ static int gw_write_backend_event(DCB *dcb) {
pthread_self(), pthread_self(),
dcb, dcb,
dcb->fd, dcb->fd,
STRDCBSTATE(dcb->state)); STRDCBSTATE(dcb->state))));
skygw_log_write_flush( LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR, LOGFILE_ERROR,
"Error : Attempt to write buffered data to backend " "Error : Attempt to write buffered data to backend "
"failed " "failed "
"due internal inconsistent state."); "due internal inconsistent state.")));
rc = 0; rc = 0;
} else { } else {
skygw_log_write( LOGIF(LD, (skygw_log_write(
LOGFILE_DEBUG, LOGFILE_DEBUG,
"%lu [gw_write_backend_event] Dcb %p in state %s " "%lu [gw_write_backend_event] Dcb %p in state %s "
"but there's nothing to write either.", "but there's nothing to write either.",
pthread_self(), pthread_self(),
dcb, dcb,
STRDCBSTATE(dcb->state)); STRDCBSTATE(dcb->state))));
rc = 1; rc = 1;
} }
goto return_rc; goto return_rc;
@ -473,14 +475,14 @@ static int gw_write_backend_event(DCB *dcb) {
dcb_drain_writeq(dcb); dcb_drain_writeq(dcb);
rc = 1; rc = 1;
return_rc: return_rc:
skygw_log_write( LOGIF(LD, (skygw_log_write(
LOGFILE_DEBUG, LOGFILE_DEBUG,
"%lu [gw_write_backend_event] " "%lu [gw_write_backend_event] "
"wrote to dcb %p fd %d, return %d", "wrote to dcb %p fd %d, return %d",
pthread_self(), pthread_self(),
dcb, dcb,
dcb->fd, dcb->fd,
rc); rc)));
return rc; return rc;
} }
@ -507,14 +509,14 @@ gw_MySQLWrite_backend(DCB *dcb, GWBUF *queue)
/** Free buffer memory */ /** Free buffer memory */
gwbuf_consume(queue, GWBUF_LENGTH(queue)); gwbuf_consume(queue, GWBUF_LENGTH(queue));
skygw_log_write( LOGIF(LD, (skygw_log_write(
LOGFILE_DEBUG, LOGFILE_DEBUG,
"%lu [gw_MySQLWrite_backend] Write to backend failed. " "%lu [gw_MySQLWrite_backend] Write to backend failed. "
"Backend dcb %p fd %d is %s.", "Backend dcb %p fd %d is %s.",
pthread_self(), pthread_self(),
dcb, dcb,
dcb->fd, dcb->fd,
STRDCBSTATE(dcb->state)); STRDCBSTATE(dcb->state))));
spinlock_release(&dcb->authlock); spinlock_release(&dcb->authlock);
return 0; return 0;
@ -525,14 +527,14 @@ gw_MySQLWrite_backend(DCB *dcb, GWBUF *queue)
* connected with auth ok * connected with auth ok
*/ */
if (backend_protocol->state != MYSQL_IDLE) { if (backend_protocol->state != MYSQL_IDLE) {
skygw_log_write( LOGIF(LD, (skygw_log_write(
LOGFILE_DEBUG, LOGFILE_DEBUG,
"%lu [gw_MySQLWrite_backend] dcb %p fd %d protocol " "%lu [gw_MySQLWrite_backend] dcb %p fd %d protocol "
"state %s.", "state %s.",
pthread_self(), pthread_self(),
dcb, dcb,
dcb->fd, dcb->fd,
STRPROTOCOLSTATE(backend_protocol->state)); STRPROTOCOLSTATE(backend_protocol->state))));
backend_set_delayqueue(dcb, queue); backend_set_delayqueue(dcb, queue);
spinlock_release(&dcb->authlock); spinlock_release(&dcb->authlock);
@ -589,24 +591,24 @@ static int gw_error_backend_event(DCB *dcb) {
"Closed backend connection."); "Closed backend connection.");
rc = 1; rc = 1;
} }
skygw_log_write_flush( LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR, LOGFILE_ERROR,
"%lu [gw_error_backend_event] Some error occurred in backend. " "%lu [gw_error_backend_event] Some error occurred in backend. "
"rc = %d", "rc = %d",
pthread_self(), pthread_self(),
rc); rc)));
rsession = session->router_session; rsession = session->router_session;
ss_dassert(rsession != NULL); ss_dassert(rsession != NULL);
/** /**
* vraa : errorHandle * vraa : errorHandle
* rsession should never be NULL here. * rsession should never be NULL here.
*/ */
skygw_log_write_flush( LOGIF(LD, (skygw_log_write_flush(
LOGFILE_DEBUG, LOGFILE_DEBUG,
"%lu [gw_error_backend_event] " "%lu [gw_error_backend_event] "
"Call closeSession for backend " "Call closeSession for backend "
"session.", "session.",
pthread_self()); pthread_self())));
router->closeSession(router_instance, rsession); router->closeSession(router_instance, rsession);
@ -640,15 +642,15 @@ static int gw_create_backend_connection(
ss_dassert(protocol != NULL); ss_dassert(protocol != NULL);
if (protocol == NULL) { if (protocol == NULL) {
skygw_log_write( LOGIF(LD, (skygw_log_write(
LOGFILE_DEBUG, LOGFILE_DEBUG,
"%lu [gw_create_backend_connection] Failed to create " "%lu [gw_create_backend_connection] Failed to create "
"protocol object for backend connection.", "protocol object for backend connection.",
pthread_self()); pthread_self())));
skygw_log_write_flush( LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR, LOGFILE_ERROR,
"Error: Failed to create " "Error: Failed to create "
"protocol object for backend connection."); "protocol object for backend connection.")));
goto return_fd; goto return_fd;
} }
@ -663,7 +665,7 @@ static int gw_create_backend_connection(
ss_dassert(fd > 0); ss_dassert(fd > 0);
protocol->fd = fd; protocol->fd = fd;
protocol->state = MYSQL_CONNECTED; protocol->state = MYSQL_CONNECTED;
skygw_log_write( LOGIF(LD, (skygw_log_write(
LOGFILE_DEBUG, LOGFILE_DEBUG,
"%lu [gw_create_backend_connection] Established " "%lu [gw_create_backend_connection] Established "
"connection to %s:%i, protocol fd %d client " "connection to %s:%i, protocol fd %d client "
@ -672,14 +674,14 @@ static int gw_create_backend_connection(
server->name, server->name,
server->port, server->port,
protocol->fd, protocol->fd,
session->client->fd); session->client->fd)));
break; break;
case 1: case 1:
ss_dassert(fd > 0); ss_dassert(fd > 0);
protocol->state = MYSQL_PENDING_CONNECT; protocol->state = MYSQL_PENDING_CONNECT;
protocol->fd = fd; protocol->fd = fd;
skygw_log_write( LOGIF(LD, (skygw_log_write(
LOGFILE_DEBUG, LOGFILE_DEBUG,
"%lu [gw_create_backend_connection] Connection " "%lu [gw_create_backend_connection] Connection "
"pending to %s:%i, protocol fd %d client fd %d.", "pending to %s:%i, protocol fd %d client fd %d.",
@ -687,13 +689,13 @@ static int gw_create_backend_connection(
server->name, server->name,
server->port, server->port,
protocol->fd, protocol->fd,
session->client->fd); session->client->fd)));
break; break;
default: default:
ss_dassert(fd == -1); ss_dassert(fd == -1);
ss_dassert(protocol->state == MYSQL_ALLOC); ss_dassert(protocol->state == MYSQL_ALLOC);
skygw_log_write( LOGIF(LD, (skygw_log_write(
LOGFILE_DEBUG, LOGFILE_DEBUG,
"%lu [gw_create_backend_connection] Connection " "%lu [gw_create_backend_connection] Connection "
"failed to %s:%i, protocol fd %d client fd %d.", "failed to %s:%i, protocol fd %d client fd %d.",
@ -701,7 +703,7 @@ static int gw_create_backend_connection(
server->name, server->name,
server->port, server->port,
protocol->fd, protocol->fd,
session->client->fd); session->client->fd)));
break; break;
} /**< switch */ } /**< switch */
@ -790,11 +792,11 @@ static int backend_write_delayqueue(DCB *dcb)
if (rc == 0) { if (rc == 0) {
/** vraa : errorHandle */ /** vraa : errorHandle */
skygw_log_write_flush( LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR, LOGFILE_ERROR,
"%lu [backend_write_delayqueue] Some error occurred in " "%lu [backend_write_delayqueue] Some error occurred in "
"backend.", "backend.",
pthread_self()); pthread_self())));
mysql_send_custom_error( mysql_send_custom_error(
dcb->session->client, dcb->session->client,

View File

@ -33,6 +33,8 @@
#include <log_manager.h> #include <log_manager.h>
#include <mysql_client_server_protocol.h> #include <mysql_client_server_protocol.h>
extern int lm_enabled_logfiles_bitmask;
static char *version_str = "V1.0.0"; static char *version_str = "V1.0.0";
static int gw_MySQLAccept(DCB *listener); static int gw_MySQLAccept(DCB *listener);
@ -462,7 +464,7 @@ int gw_read_client_event(DCB* dcb) {
int eno = errno; int eno = errno;
errno = 0; errno = 0;
skygw_log_write( LOGIF(LE, (skygw_log_write(
LOGFILE_ERROR, LOGFILE_ERROR,
"%lu [gw_read_client_event] ioctl FIONREAD for fd " "%lu [gw_read_client_event] ioctl FIONREAD for fd "
"%d failed. errno %d, %s. dcb->state = %d", "%d failed. errno %d, %s. dcb->state = %d",
@ -470,7 +472,7 @@ int gw_read_client_event(DCB* dcb) {
dcb->fd, dcb->fd,
eno, eno,
strerror(eno), strerror(eno),
dcb->state); dcb->state)));
rc = 1; rc = 1;
goto return_rc; goto return_rc;
} }
@ -605,13 +607,13 @@ int gw_read_client_event(DCB* dcb) {
if(rsession == NULL) { if(rsession == NULL) {
/** COM_QUIT */ /** COM_QUIT */
if (mysql_command == '\x01') { if (mysql_command == '\x01') {
skygw_log_write_flush( LOGIF(LD, (skygw_log_write_flush(
LOGFILE_DEBUG, LOGFILE_DEBUG,
"%lu [gw_read_client_event] Client read " "%lu [gw_read_client_event] Client read "
"COM_QUIT and rsession == NULL. Closing " "COM_QUIT and rsession == NULL. Closing "
"client dcb %p.", "client dcb %p.",
pthread_self(), pthread_self(),
dcb); dcb)));
(dcb->func).close(dcb); (dcb->func).close(dcb);
} else { } else {
/* Send a custom error as MySQL command reply */ /* Send a custom error as MySQL command reply */
@ -631,12 +633,12 @@ int gw_read_client_event(DCB* dcb) {
/** Route COM_QUIT to backend */ /** Route COM_QUIT to backend */
if (mysql_command == '\x01') { if (mysql_command == '\x01') {
router->routeQuery(router_instance, rsession, queue); router->routeQuery(router_instance, rsession, queue);
skygw_log_write_flush( LOGIF(LD, (skygw_log_write_flush(
LOGFILE_DEBUG, LOGFILE_DEBUG,
"%lu [gw_read_client_event] Routed COM_QUIT to " "%lu [gw_read_client_event] Routed COM_QUIT to "
"backend. Close client dcb %p", "backend. Close client dcb %p",
pthread_self(), pthread_self(),
dcb); dcb)));
/** close client connection */ /** close client connection */
(dcb->func).close(dcb); (dcb->func).close(dcb);
@ -929,22 +931,22 @@ int gw_MySQLAccept(DCB *listener)
* Exceeded system's (ENFILE) or processes * Exceeded system's (ENFILE) or processes
* (EMFILE) max. number of files limit. * (EMFILE) max. number of files limit.
*/ */
skygw_log_write( LOGIF(LD, (skygw_log_write(
LOGFILE_DEBUG, LOGFILE_DEBUG,
"%lu [gw_MySQLAccept] Error %d, %s. ", "%lu [gw_MySQLAccept] Error %d, %s. ",
pthread_self(), pthread_self(),
eno, eno,
strerror(eno)); strerror(eno))));
if (i == 0) if (i == 0)
{ {
skygw_log_write_flush( LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR, LOGFILE_ERROR,
"Error %d, %s. " "Error %d, %s. "
"Failed to accept new client " "Failed to accept new client "
"connection.", "connection.",
eno, eno,
strerror(eno)); strerror(eno))));
} }
i++; i++;
usleep(100*i*i); usleep(100*i*i);
@ -960,18 +962,18 @@ int gw_MySQLAccept(DCB *listener)
/** /**
* Other error. * Other error.
*/ */
skygw_log_write( LOGIF(LD, (skygw_log_write(
LOGFILE_DEBUG, LOGFILE_DEBUG,
"%lu [gw_MySQLAccept] Error %d, %s.", "%lu [gw_MySQLAccept] Error %d, %s.",
pthread_self(), pthread_self(),
eno, eno,
strerror(eno)); strerror(eno))));
skygw_log_write_flush( LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR, LOGFILE_ERROR,
"Error %d, %s." "Error %d, %s."
"Failed to accept new client connection.", "Failed to accept new client connection.",
eno, eno,
strerror(eno)); strerror(eno))));
rc = 1; rc = 1;
goto return_rc; goto return_rc;
} /* if (eno == ..) */ } /* if (eno == ..) */
@ -981,11 +983,11 @@ int gw_MySQLAccept(DCB *listener)
listener->stats.n_accepts++; listener->stats.n_accepts++;
#if defined(SS_DEBUG) #if defined(SS_DEBUG)
skygw_log_write_flush( LOGIF(LD, (skygw_log_write_flush(
LOGFILE_DEBUG, LOGFILE_DEBUG,
"%lu [gw_MySQLAccept] Accepted fd %d.", "%lu [gw_MySQLAccept] Accepted fd %d.",
pthread_self(), pthread_self(),
c_sock); c_sock)));
conn_open[c_sock] = true; conn_open[c_sock] = true;
#endif #endif
/* set nonblocking */ /* set nonblocking */
@ -1003,11 +1005,11 @@ int gw_MySQLAccept(DCB *listener)
if (protocol == NULL) { if (protocol == NULL) {
/** delete client_dcb */ /** delete client_dcb */
dcb_close(client_dcb); dcb_close(client_dcb);
skygw_log_write_flush( LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR, LOGFILE_ERROR,
"%lu [gw_MySQLAccept] Failed to create " "%lu [gw_MySQLAccept] Failed to create "
"protocol object for client connection.", "protocol object for client connection.",
pthread_self()); pthread_self())));
rc = 1; rc = 1;
goto return_rc; goto return_rc;
} }
@ -1038,25 +1040,25 @@ int gw_MySQLAccept(DCB *listener)
dcb_close(client_dcb); dcb_close(client_dcb);
/** Previous state is recovered in poll_add_dcb. */ /** Previous state is recovered in poll_add_dcb. */
skygw_log_write_flush( LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR, LOGFILE_ERROR,
"%lu [gw_MySQLAccept] Failed to add dcb %p for " "%lu [gw_MySQLAccept] Failed to add dcb %p for "
"fd %d to epoll set.", "fd %d to epoll set.",
pthread_self(), pthread_self(),
client_dcb, client_dcb,
client_dcb->fd); client_dcb->fd)));
rc = 1; rc = 1;
goto return_rc; goto return_rc;
} }
else else
{ {
skygw_log_write( LOGIF(LD, (skygw_log_write(
LOGFILE_DEBUG, LOGFILE_DEBUG,
"%lu [gw_MySQLAccept] Added dcb %p for fd " "%lu [gw_MySQLAccept] Added dcb %p for fd "
"%d to epoll set.", "%d to epoll set.",
pthread_self(), pthread_self(),
client_dcb, client_dcb,
client_dcb->fd); client_dcb->fd)));
} }
} /**< while 1 */ } /**< while 1 */
#if defined(SS_DEBUG) #if defined(SS_DEBUG)

View File

@ -33,6 +33,8 @@
#include <skygw_utils.h> #include <skygw_utils.h>
#include <log_manager.h> #include <log_manager.h>
extern int lm_enabled_logfiles_bitmask;
extern int gw_read_backend_event(DCB* dcb); extern int gw_read_backend_event(DCB* dcb);
extern int gw_write_backend_event(DCB *dcb); extern int gw_write_backend_event(DCB *dcb);
extern int gw_MySQLWrite_backend(DCB *dcb, GWBUF *queue); extern int gw_MySQLWrite_backend(DCB *dcb, GWBUF *queue);
@ -64,13 +66,13 @@ MySQLProtocol* mysql_protocol_init(
if (p == NULL) { if (p == NULL) {
int eno = errno; int eno = errno;
errno = 0; errno = 0;
skygw_log_write_flush( LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR, LOGFILE_ERROR,
"%lu [mysql_init_protocol] MySQL protocol init failed : " "%lu [mysql_init_protocol] MySQL protocol init failed : "
"memory allocation due error %d, %s.", "memory allocation due error %d, %s.",
pthread_self(), pthread_self(),
eno, eno,
strerror(eno)); strerror(eno))));
goto return_p; goto return_p;
} }
p->state = MYSQL_ALLOC; p->state = MYSQL_ALLOC;
@ -326,7 +328,7 @@ int gw_receive_backend_auth(
uint8_t* tmpbuf = uint8_t* tmpbuf =
(uint8_t *)calloc(1, GWBUF_LENGTH(head)+1); (uint8_t *)calloc(1, GWBUF_LENGTH(head)+1);
memcpy(tmpbuf, ptr, GWBUF_LENGTH(head)); memcpy(tmpbuf, ptr, GWBUF_LENGTH(head));
skygw_log_write( LOGIF(LD, (skygw_log_write(
LOGFILE_DEBUG, LOGFILE_DEBUG,
"%lu [gw_receive_backend_auth] Invalid " "%lu [gw_receive_backend_auth] Invalid "
"authentication message from backend dcb %p " "authentication message from backend dcb %p "
@ -335,12 +337,12 @@ int gw_receive_backend_auth(
dcb, dcb,
dcb->fd, dcb->fd,
tmpbuf[4], tmpbuf[4],
tmpbuf); tmpbuf)));
skygw_log_write_flush( LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR, LOGFILE_ERROR,
"Error : Invalid authentication message from " "Error : Invalid authentication message from "
"backend server. Authentication failed."); "backend server. Authentication failed.")));
free(tmpbuf); free(tmpbuf);
rc = -1; rc = -1;
} }
@ -356,7 +358,7 @@ int gw_receive_backend_auth(
* although no bytes was read. * although no bytes was read.
*/ */
rc = 0; rc = 0;
skygw_log_write( LOGIF(LD, (skygw_log_write(
LOGFILE_DEBUG, LOGFILE_DEBUG,
"%lu [gw_receive_backend_auth] Read zero bytes from " "%lu [gw_receive_backend_auth] Read zero bytes from "
"backend dcb %p fd %d in state %s. n %d, head %p, len %d", "backend dcb %p fd %d in state %s. n %d, head %p, len %d",
@ -366,13 +368,13 @@ int gw_receive_backend_auth(
STRDCBSTATE(dcb->state), STRDCBSTATE(dcb->state),
n, n,
head, head,
(head == NULL) ? 0 : GWBUF_LENGTH(head)); (head == NULL) ? 0 : GWBUF_LENGTH(head))));
} }
else else
{ {
ss_dassert(n < 0 && head == NULL); ss_dassert(n < 0 && head == NULL);
rc = -1; rc = -1;
skygw_log_write( LOGIF(LD, (skygw_log_write(
LOGFILE_DEBUG, LOGFILE_DEBUG,
"%lu [gw_receive_backend_auth] Reading from backend dcb %p " "%lu [gw_receive_backend_auth] Reading from backend dcb %p "
"fd %d in state %s failed. n %d, head %p, len %d", "fd %d in state %s failed. n %d, head %p, len %d",
@ -382,7 +384,7 @@ int gw_receive_backend_auth(
STRDCBSTATE(dcb->state), STRDCBSTATE(dcb->state),
n, n,
head, head,
(head == NULL) ? 0 : GWBUF_LENGTH(head)); (head == NULL) ? 0 : GWBUF_LENGTH(head))));
} }
return rc; return rc;
@ -615,7 +617,7 @@ int gw_do_connect_to_backend(
if (so < 0) { if (so < 0) {
int eno = errno; int eno = errno;
errno = 0; errno = 0;
skygw_log_write_flush( LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR, LOGFILE_ERROR,
"Error: Establishing connection to backend server " "Error: Establishing connection to backend server "
"%s:%d failed. Socket creation failed due " "%s:%d failed. Socket creation failed due "
@ -623,7 +625,7 @@ int gw_do_connect_to_backend(
host, host,
port, port,
eno, eno,
strerror(eno)); strerror(eno))));
rv = -1; rv = -1;
goto return_rv; goto return_rv;
} }
@ -644,40 +646,40 @@ int gw_do_connect_to_backend(
int rc; int rc;
int oldfd = so; int oldfd = so;
skygw_log_write_flush( LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR, LOGFILE_ERROR,
"Error: Failed to connect backend server %s:%d, " "Error: Failed to connect backend server %s:%d, "
"due %d, %s.", "due %d, %s.",
host, host,
port, port,
eno, eno,
strerror(eno)); strerror(eno))));
/** Close newly created socket. */ /** Close newly created socket. */
rc = close(so); rc = close(so);
if (rc != 0) { if (rc != 0) {
int eno = errno; int eno = errno;
errno = 0; errno = 0;
skygw_log_write_flush( LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR, LOGFILE_ERROR,
"Error: Failed to " "Error: Failed to "
"close socket %d due %d, %s.", "close socket %d due %d, %s.",
oldfd, oldfd,
eno, eno,
strerror(eno)); strerror(eno))));
} }
goto return_rv; goto return_rv;
} }
} }
*fd = so; *fd = so;
skygw_log_write_flush( LOGIF(LD, (skygw_log_write_flush(
LOGFILE_DEBUG, LOGFILE_DEBUG,
"%lu [gw_do_connect_to_backend] Connected to backend server " "%lu [gw_do_connect_to_backend] Connected to backend server "
"%s:%d, fd %d.", "%s:%d, fd %d.",
pthread_self(), pthread_self(),
host, host,
port, port,
so); so)));
#if defined(SS_DEBUG) #if defined(SS_DEBUG)
conn_open[so] = true; conn_open[so] = true;
#endif #endif
@ -1173,13 +1175,13 @@ mysql_send_auth_error (DCB *dcb, int packet_number, int in_affected_rows, const
if (dcb->state != DCB_STATE_POLLING) if (dcb->state != DCB_STATE_POLLING)
{ {
skygw_log_write( LOGIF(LD, (skygw_log_write(
LOGFILE_DEBUG, LOGFILE_DEBUG,
"%lu [mysql_send_auth_error] dcb %p is in a state %s, " "%lu [mysql_send_auth_error] dcb %p is in a state %s, "
"and it is not in epoll set anymore. Skip error sending.", "and it is not in epoll set anymore. Skip error sending.",
pthread_self(), pthread_self(),
dcb, dcb,
STRDCBSTATE(dcb->state)); STRDCBSTATE(dcb->state))));
return 0; return 0;
} }
mysql_errno = 1045; mysql_errno = 1045;

View File

@ -37,6 +37,8 @@
#include <skygw_utils.h> #include <skygw_utils.h>
#include <log_manager.h> #include <log_manager.h>
extern int lm_enabled_logfiles_bitmask;
/** /**
* @file telnetd.c - telnet daemon protocol module * @file telnetd.c - telnet daemon protocol module
* *
@ -107,7 +109,9 @@ version()
void void
ModuleInit() ModuleInit()
{ {
skygw_log_write(LOGFILE_TRACE, "Initialise Telnetd Protocol module.\n"); LOGIF(LT, (skygw_log_write(
LOGFILE_TRACE,
"Initialise Telnetd Protocol module.\n")));
} }
/** /**

View File

@ -43,6 +43,8 @@
#include <skygw_utils.h> #include <skygw_utils.h>
#include <log_manager.h> #include <log_manager.h>
extern int lm_enabled_logfiles_bitmask;
static char *version_str = "V1.0.1"; static char *version_str = "V1.0.1";
/* The router entry points */ /* The router entry points */
@ -88,7 +90,10 @@ version()
void void
ModuleInit() ModuleInit()
{ {
skygw_log_write( LOGFILE_MESSAGE, "Initialise debug CLI router module %s.\n", version_str); LOGIF(LM, (skygw_log_write(
LOGFILE_MESSAGE,
"Initialise debug CLI router module %s.\n",
version_str)));
spinlock_init(&instlock); spinlock_init(&instlock);
instances = NULL; instances = NULL;
} }

View File

@ -84,6 +84,8 @@
#include <mysql_client_server_protocol.h> #include <mysql_client_server_protocol.h>
extern int lm_enabled_logfiles_bitmask;
static char *version_str = "V1.0.2"; static char *version_str = "V1.0.2";
/* The router entry points */ /* The router entry points */
@ -144,9 +146,9 @@ version()
void void
ModuleInit() ModuleInit()
{ {
skygw_log_write( LOGIF(LM, (skygw_log_write(
LOGFILE_MESSAGE, LOGFILE_MESSAGE,
"Initialise readconnroute router module %s.\n", version_str); "Initialise readconnroute router module %s.\n", version_str)));
spinlock_init(&instlock); spinlock_init(&instlock);
instances = NULL; instances = NULL;
} }
@ -245,10 +247,11 @@ int i, n;
} }
else else
{ {
skygw_log_write(LOGFILE_ERROR, LOGIF(LE, (skygw_log_write(
LOGFILE_ERROR,
"Warning : Unsupported router " "Warning : Unsupported router "
"option %s for readconnroute.", "option %s for readconnroute.",
options[i]); options[i])));
} }
} }
} }
@ -281,13 +284,13 @@ ROUTER_CLIENT_SES *client_rses;
BACKEND *candidate = NULL; BACKEND *candidate = NULL;
int i; int i;
skygw_log_write_flush( LOGIF(LD, (skygw_log_write_flush(
LOGFILE_DEBUG, LOGFILE_DEBUG,
"%lu [newSession] new router session with session " "%lu [newSession] new router session with session "
"%p, and inst %p.", "%p, and inst %p.",
pthread_self(), pthread_self(),
session, session,
inst); inst)));
client_rses = (ROUTER_CLIENT_SES *)calloc(1, sizeof(ROUTER_CLIENT_SES)); client_rses = (ROUTER_CLIENT_SES *)calloc(1, sizeof(ROUTER_CLIENT_SES));
@ -321,7 +324,7 @@ int i;
*/ */
for (i = 0; inst->servers[i]; i++) { for (i = 0; inst->servers[i]; i++) {
if(inst->servers[i]) { if(inst->servers[i]) {
skygw_log_write( LOGIF(LD, (skygw_log_write(
LOGFILE_DEBUG, LOGFILE_DEBUG,
"%lu [newSession] Examine server in port %d with " "%lu [newSession] Examine server in port %d with "
"%d connections. Status is %d, " "%d connections. Status is %d, "
@ -330,7 +333,7 @@ int i;
inst->servers[i]->server->port, inst->servers[i]->server->port,
inst->servers[i]->current_connection_count, inst->servers[i]->current_connection_count,
inst->servers[i]->server->status, inst->servers[i]->server->status,
inst->bitmask); inst->bitmask)));
} }
if (inst->servers[i] && if (inst->servers[i] &&
@ -367,11 +370,11 @@ int i;
/* no candidate server here, clean and return NULL */ /* no candidate server here, clean and return NULL */
if (!candidate) { if (!candidate) {
skygw_log_write_flush( LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR, LOGFILE_ERROR,
"Error : Failed to create new routing session. " "Error : Failed to create new routing session. "
"Couldn't find eligible candidate server. Freeing " "Couldn't find eligible candidate server. Freeing "
"allocated resources."); "allocated resources.")));
free(client_rses); free(client_rses);
return NULL; return NULL;
} }
@ -382,13 +385,13 @@ int i;
*/ */
atomic_add(&candidate->current_connection_count, 1); atomic_add(&candidate->current_connection_count, 1);
client_rses->backend = candidate; client_rses->backend = candidate;
skygw_log_write( LOGIF(LD, (skygw_log_write(
LOGFILE_DEBUG, LOGFILE_DEBUG,
"%lu [newSession] Selected server in port %d. " "%lu [newSession] Selected server in port %d. "
"Connections : %d\n", "Connections : %d\n",
pthread_self(), pthread_self(),
candidate->server->port, candidate->server->port,
candidate->current_connection_count); candidate->current_connection_count)));
/* /*
* Open a backend connection, putting the DCB for this * Open a backend connection, putting the DCB for this
* connection in the client_rses->backend_dcb * connection in the client_rses->backend_dcb
@ -464,7 +467,7 @@ static void freeSession(
} }
spinlock_release(&router->lock); spinlock_release(&router->lock);
skygw_log_write_flush( LOGIF(LD, (skygw_log_write_flush(
LOGFILE_DEBUG, LOGFILE_DEBUG,
"%lu [freeSession] Unlinked router_client_session %p from " "%lu [freeSession] Unlinked router_client_session %p from "
"router %p and from server on port %d. Connections : %d. ", "router %p and from server on port %d. Connections : %d. ",
@ -472,7 +475,7 @@ static void freeSession(
router_cli_ses, router_cli_ses,
router, router,
router_cli_ses->backend->server->port, router_cli_ses->backend->server->port,
prev_val-1); prev_val-1)));
free(router_cli_ses); free(router_cli_ses);
} }
@ -559,11 +562,11 @@ routeQuery(ROUTER *instance, void *router_session, GWBUF *queue)
if (rses_is_closed || backend_dcb == NULL) if (rses_is_closed || backend_dcb == NULL)
{ {
skygw_log_write( LOGIF(LE, (skygw_log_write(
LOGFILE_ERROR, LOGFILE_ERROR,
"Error: Failed to route MySQL command %d to backend " "Error: Failed to route MySQL command %d to backend "
"server.", "server.",
mysql_command); mysql_command)));
goto return_rc; goto return_rc;
} }
@ -581,14 +584,14 @@ routeQuery(ROUTER *instance, void *router_session, GWBUF *queue)
} }
CHK_PROTOCOL(((MySQLProtocol*)backend_dcb->protocol)); CHK_PROTOCOL(((MySQLProtocol*)backend_dcb->protocol));
skygw_log_write( LOGIF(LD, (skygw_log_write(
LOGFILE_DEBUG, LOGFILE_DEBUG,
"%lu [readconnroute:routeQuery] Routed command %d to dcb %p " "%lu [readconnroute:routeQuery] Routed command %d to dcb %p "
"with return value %d.", "with return value %d.",
pthread_self(), pthread_self(),
mysql_command, mysql_command,
backend_dcb, backend_dcb,
rc); rc)));
return_rc: return_rc:
return rc; return rc;
} }

View File

@ -30,6 +30,8 @@
#include <dcb.h> #include <dcb.h>
#include <spinlock.h> #include <spinlock.h>
extern int lm_enabled_logfiles_bitmask;
/** /**
* @file readwritesplit.c The entry points for the read/write query splitting * @file readwritesplit.c The entry points for the read/write query splitting
* router module. * router module.
@ -107,9 +109,9 @@ version()
void void
ModuleInit() ModuleInit()
{ {
skygw_log_write_flush( LOGIF(LM, (skygw_log_write_flush(
LOGFILE_MESSAGE, LOGFILE_MESSAGE,
"Initializing statemend-based read/write split router module."); "Initializing statemend-based read/write split router module.")));
spinlock_init(&instlock); spinlock_init(&instlock);
instances = NULL; instances = NULL;
} }
@ -167,11 +169,11 @@ static ROUTER* createInstance(
if (options != NULL) if (options != NULL)
{ {
skygw_log_write_flush( LOGIF(LM, (skygw_log_write_flush(
LOGFILE_MESSAGE, LOGFILE_MESSAGE,
"Router options supplied to read/write statement router " "Router options supplied to read/write statement router "
"module but none are supported. The options will be " "module but none are supported. The options will be "
"ignored."); "ignored.")));
} }
/** /**
@ -230,11 +232,11 @@ static ROUTER* createInstance(
} }
else else
{ {
skygw_log_write_flush( LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR, LOGFILE_ERROR,
"Warning : Unsupported router option %s " "Warning : Unsupported router option %s "
"for readwritesplitrouter.", "for readwritesplitrouter.",
options[i]); options[i])));
} }
} }
} }
@ -541,7 +543,7 @@ static int routeQuery(
if (rses_is_closed || (master_dcb == NULL && slave_dcb == NULL)) if (rses_is_closed || (master_dcb == NULL && slave_dcb == NULL))
{ {
skygw_log_write( LOGIF(LE, (skygw_log_write(
LOGFILE_ERROR, LOGFILE_ERROR,
"Error: Failed to route %s:%s:\"%s\" to backend server. " "Error: Failed to route %s:%s:\"%s\" to backend server. "
"%s.", "%s.",
@ -549,25 +551,26 @@ static int routeQuery(
STRQTYPE(qtype), STRQTYPE(qtype),
(querystr == NULL ? "(empty)" : querystr), (querystr == NULL ? "(empty)" : querystr),
(rses_is_closed ? "Router was closed" : (rses_is_closed ? "Router was closed" :
"Router has no backend servers where to route to")); "Router has no backend servers where to route to"))));
goto return_ret; goto return_ret;
} }
skygw_log_write(LOGFILE_TRACE, LOGIF(LT, (skygw_log_write(LOGFILE_TRACE,
"String\t\"%s\"", "String\t\"%s\"",
querystr == NULL ? "(empty)" : querystr); querystr == NULL ? "(empty)" : querystr)));
skygw_log_write(LOGFILE_TRACE, LOGIF(LT, (skygw_log_write(LOGFILE_TRACE,
"Packet type\t%s", "Packet type\t%s",
STRPACKETTYPE(packet_type)); STRPACKETTYPE(packet_type))));
switch (qtype) { switch (qtype) {
case QUERY_TYPE_WRITE: case QUERY_TYPE_WRITE:
skygw_log_write(LOGFILE_TRACE, LOGIF(LT, (skygw_log_write(
LOGFILE_TRACE,
"%lu [routeQuery:rwsplit] Query type\t%s, routing to " "%lu [routeQuery:rwsplit] Query type\t%s, routing to "
"Master.", "Master.",
pthread_self(), pthread_self(),
STRQTYPE(qtype)); STRQTYPE(qtype))));
ret = master_dcb->func.write(master_dcb, querybuf); ret = master_dcb->func.write(master_dcb, querybuf);
atomic_add(&inst->stats.n_master, 1); atomic_add(&inst->stats.n_master, 1);
@ -576,11 +579,12 @@ static int routeQuery(
break; break;
case QUERY_TYPE_READ: case QUERY_TYPE_READ:
skygw_log_write(LOGFILE_TRACE, LOGIF(LT, (skygw_log_write(
LOGFILE_TRACE,
"%lu [routeQuery:rwsplit] Query type\t%s, " "%lu [routeQuery:rwsplit] Query type\t%s, "
"routing to Slave.", "routing to Slave.",
pthread_self(), pthread_self(),
STRQTYPE(qtype)); STRQTYPE(qtype))));
ret = slave_dcb->func.write(slave_dcb, querybuf); ret = slave_dcb->func.write(slave_dcb, querybuf);
atomic_add(&inst->stats.n_slave, 1); atomic_add(&inst->stats.n_slave, 1);
@ -588,12 +592,11 @@ static int routeQuery(
goto return_ret; goto return_ret;
break; break;
case QUERY_TYPE_SESSION_WRITE: case QUERY_TYPE_SESSION_WRITE:
/** /**
* Update connections which are used in this session. * Update connections which are used in this session.
* *
* For each connection, add a flag which indicates that * For each connection updated, add a flag which indicates that
* OK Packet must arrive for this command before server * OK Packet must arrive for this command before server
* in question is allowed to be used by router. That is, * in question is allowed to be used by router. That is,
* maintain a queue of pending OK packets and remove item * maintain a queue of pending OK packets and remove item
@ -618,12 +621,16 @@ static int routeQuery(
* vraa 9.12.13 * vraa 9.12.13
* *
*/ */
#if defined(FULL_RWSPLIT) LOGIF(LT, (skygw_log_write(
skygw_log_write(LOGFILE_TRACE, LOGFILE_TRACE,
"%lu [routeQuery:rwsplit] Query type\t%s, " "%lu [routeQuery:rwsplit] DCB M:%p s:%p, "
"routing to all servers.", "Query type\t%s, "
"packet type %s, routing to all servers.",
pthread_self(), pthread_self(),
STRQTYPE(qtype)); master_dcb,
slave_dcb,
STRQTYPE(qtype),
STRPACKETTYPE(packet_type))));
bufcopy = gwbuf_clone(querybuf); bufcopy = gwbuf_clone(querybuf);
@ -646,6 +653,11 @@ static int routeQuery(
bufcopy); bufcopy);
break; break;
case COM_QUERY:
ret = master_dcb->func.session(master_dcb, (void *)querybuf);
slave_dcb->func.session(slave_dcb, (void *)bufcopy);
break;
default: default:
ret = master_dcb->func.session(master_dcb, (void *)querybuf); ret = master_dcb->func.session(master_dcb, (void *)querybuf);
slave_dcb->func.session(slave_dcb, (void *)bufcopy); slave_dcb->func.session(slave_dcb, (void *)bufcopy);
@ -655,15 +667,14 @@ static int routeQuery(
atomic_add(&inst->stats.n_all, 1); atomic_add(&inst->stats.n_all, 1);
goto return_ret; goto return_ret;
break; break;
#else
/** fall through */
#endif
default: default:
skygw_log_write(LOGFILE_TRACE, LOGIF(LT, (skygw_log_write(
LOGFILE_TRACE,
"%lu [routeQuery:rwsplit] Query type\t%s, " "%lu [routeQuery:rwsplit] Query type\t%s, "
"routing to Master by default.", "routing to Master by default.",
pthread_self(), pthread_self(),
STRQTYPE(qtype)); STRQTYPE(qtype))));
/** /**
* Is this really ok? * Is this really ok?
@ -892,7 +903,7 @@ static bool search_backend_servers(
BACKEND* be = router->servers[i]; BACKEND* be = router->servers[i];
if (be != NULL) { if (be != NULL) {
skygw_log_write( LOGIF(LT, (skygw_log_write(
LOGFILE_TRACE, LOGFILE_TRACE,
"%lu [search_backend_servers] Examine server " "%lu [search_backend_servers] Examine server "
"%s:%d with %d connections. Status is %d, " "%s:%d with %d connections. Status is %d, "
@ -902,7 +913,7 @@ static bool search_backend_servers(
be->backend_server->port, be->backend_server->port,
be->backend_conn_count, be->backend_conn_count,
be->backend_server->status, be->backend_server->status,
router->bitmask); router->bitmask)));
} }
if (be != NULL && if (be != NULL &&
@ -958,36 +969,36 @@ static bool search_backend_servers(
if (p_slave != NULL && be_slave == NULL) { if (p_slave != NULL && be_slave == NULL) {
succp = false; succp = false;
skygw_log_write_flush( LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR, LOGFILE_ERROR,
"Error : Couldn't find suitable Slave from %d " "Error : Couldn't find suitable Slave from %d "
"candidates.", "candidates.",
i); i)));
} }
if (p_master != NULL && be_master == NULL) { if (p_master != NULL && be_master == NULL) {
succp = false; succp = false;
skygw_log_write_flush( LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR, LOGFILE_ERROR,
"Error : Couldn't find suitable Master from %d " "Error : Couldn't find suitable Master from %d "
"candidates.", "candidates.",
i); i)));
} }
if (be_slave != NULL) { if (be_slave != NULL) {
*p_slave = be_slave; *p_slave = be_slave;
skygw_log_write( LOGIF(LT, (skygw_log_write(
LOGFILE_TRACE, LOGFILE_TRACE,
"%lu [readwritesplit:search_backend_servers] Selected " "%lu [readwritesplit:search_backend_servers] Selected "
"Slave %s:%d from %d candidates.", "Slave %s:%d from %d candidates.",
pthread_self(), pthread_self(),
be_slave->backend_server->name, be_slave->backend_server->name,
be_slave->backend_server->port, be_slave->backend_server->port,
i); i)));
} }
if (be_master != NULL) { if (be_master != NULL) {
*p_master = be_master; *p_master = be_master;
skygw_log_write( LOGIF(LT, (skygw_log_write(
LOGFILE_TRACE, LOGFILE_TRACE,
"%lu [readwritesplit:search_backend_servers] Selected " "%lu [readwritesplit:search_backend_servers] Selected "
"Master %s:%d " "Master %s:%d "
@ -995,7 +1006,7 @@ static bool search_backend_servers(
pthread_self(), pthread_self(),
be_master->backend_server->name, be_master->backend_server->name,
be_master->backend_server->port, be_master->backend_server->port,
i); i)));
} }
return succp; return succp;
} }