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

View File

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

View File

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

View File

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

View File

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

View File

@ -150,18 +150,18 @@ static bool resolve_maxscale_homedir(
*/
static void sighup_handler (int i)
{
skygw_log_write(
LOGIF(LM, (skygw_log_write(
LOGFILE_MESSAGE,
"Refreshing configuration following SIGHUP\n");
"Refreshing configuration following SIGHUP\n")));
config_reload();
}
static void sigterm_handler (int i) {
extern void shutdown_server();
skygw_log_write_flush(
LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR,
"MaxScale received signal SIGTERM. Exiting.");
"MaxScale received signal SIGTERM. Exiting.")));
shutdown_server();
}
@ -170,9 +170,9 @@ sigint_handler (int i)
{
extern void shutdown_server();
skygw_log_write_flush(
LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR,
"MaxScale received signal SIGINT. Shutting down.");
"MaxScale received signal SIGINT. Shutting down.")));
shutdown_server();
fprintf(stderr, "\n\nShutting down MaxScale\n\n");
}
@ -203,12 +203,12 @@ static int signal_set (int sig, void (*handler)(int)) {
{
int eno = errno;
errno = 0;
skygw_log_write_flush(
LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR,
"Error : Failed call sigaction() in %s due to %d, %s.",
program_invocation_short_name,
eno,
strerror(eno));
strerror(eno))));
rc = 1;
}
return rc;
@ -232,13 +232,13 @@ int ntfw_cb(
int eno = errno;
errno = 0;
skygw_log_write(
LOGIF(LE, (skygw_log_write(
LOGFILE_ERROR,
"Error : Failed to remove the data directory %s of "
"MaxScale due to %d, %s.",
datadir,
eno,
strerror(eno));
strerror(eno))));
}
return rc;
}
@ -488,9 +488,10 @@ static bool resolve_maxscale_homedir(
{
fprintf(stderr, "\n*\n* Warning : MAXSCALE_HOME environment variable "
"is not set.\n*\n");
skygw_log_write_flush(LOGFILE_ERROR,
"Warning : MAXSCALE_HOME environment "
"variable is not set.");
LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR,
"Warning : MAXSCALE_HOME environment "
"variable is not set.")));
}
free(tmp);
/**
@ -620,12 +621,13 @@ static void print_log_n_stderr(
char* fpr_end = "\n*\n";
if (do_log) {
skygw_log_write_flush(LOGFILE_ERROR,
"%s %s %s %s",
log_err,
logstr,
eno == 0 ? " " : "Error :",
eno == 0 ? " " : strerror(eno));
LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR,
"%s %s %s %s",
log_err,
logstr,
eno == 0 ? " " : "Error :",
eno == 0 ? " " : strerror(eno))));
}
if (do_stderr) {
fprintf(stderr,
@ -656,13 +658,13 @@ static bool file_is_readable(
absolute_pathname,
strerror(eno));
}
skygw_log_write_flush(
LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR,
"Warning : Failed to read the configuration file %s due "
"to %d, %s.",
absolute_pathname,
eno,
strerror(eno));
strerror(eno))));
succp = false;
}
return succp;
@ -687,13 +689,13 @@ static bool file_is_writable(
eno,
strerror(eno));
}
skygw_log_write_flush(
LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR,
"Error : unable to open file %s for write due "
"to %d, %s.",
absolute_pathname,
eno,
strerror(eno));
strerror(eno))));
succp = false;
}
return succp;
@ -747,14 +749,14 @@ static char* get_expanded_pathname(
relative_path,
strerror(eno));
skygw_log_write_flush(
LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR,
"Warning : Failed to read the "
"directory %s, due "
"to %d, %s.",
relative_path,
eno,
strerror(eno));
strerror(eno))));
free(expanded_path);
*output_path = NULL;
goto return_cnf_file_buf;
@ -1200,11 +1202,18 @@ int main(int argc, char **argv)
cnf_file_path,
datadir);
}
skygw_log_write_flush(LOGFILE_MESSAGE, "Home directory : %s", home_dir);
skygw_log_write_flush(LOGFILE_MESSAGE, "Data directory : %s", datadir);
skygw_log_write_flush(LOGFILE_MESSAGE,
"Configuration file : %s",
cnf_file_path);
LOGIF(LM, (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",
cnf_file_path)));
/* Update the server options */
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,
"Error : mysql_library_init failed. It is a "
"mandatory component, required by router services and "
@ -1269,7 +1278,7 @@ int main(int argc, char **argv)
mysql_errno(NULL),
mysql_error(NULL),
__FILE__,
__LINE__);
__LINE__)));
rc = 1;
goto return_main;
}
@ -1280,21 +1289,21 @@ int main(int argc, char **argv)
char* fprerr = "Failed to load MaxScale configuration "
"file. Exiting.";
print_log_n_stderr(false, !daemon_mode, fprerr, fprerr, 0);
skygw_log_write_flush(
LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR,
"Error : Failed to load MaxScale configuration file %s. "
"Exiting.",
cnf_file_path);
cnf_file_path)));
rc = 1;
goto return_main;
}
skygw_log_write(
LOGIF(LM, (skygw_log_write(
LOGFILE_MESSAGE,
"SkySQL MaxScale (C) SkySQL Ab 2013");
skygw_log_write(
"SkySQL MaxScale (C) SkySQL Ab 2013")));
LOGIF(LM, (skygw_log_write(
LOGFILE_MESSAGE,
"MaxScale is running in process %i",
getpid());
getpid())));
poll_init();
@ -1329,9 +1338,9 @@ int main(int argc, char **argv)
{
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.",
config_threadcount());
config_threadcount())));
/**
* Serve clients.
*/
@ -1354,9 +1363,13 @@ int main(int argc, char **argv)
/* Stop all the monitors */
monitorStopAll();
skygw_log_write(LOGFILE_MESSAGE, "MaxScale is shutting down.");
LOGIF(LM, (skygw_log_write(
LOGFILE_MESSAGE,
"MaxScale is shutting down.")));
datadir_cleanup();
skygw_log_write(LOGFILE_MESSAGE, "MaxScale shutdown completed.");
LOGIF(LM, (skygw_log_write(
LOGFILE_MESSAGE,
"MaxScale shutdown completed.")));
return_main:
return 0;
@ -1382,7 +1395,8 @@ static void log_flush_cb(
{
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) {
skygw_log_flush(LOGFILE_ERROR);
skygw_log_flush(LOGFILE_MESSAGE);
@ -1390,5 +1404,6 @@ static void log_flush_cb(
skygw_log_flush(LOGFILE_DEBUG);
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 <log_manager.h>
extern int lm_enabled_logfiles_bitmask;
static MODULES *registered = NULL;
static MODULES *find_module(const char *module);
@ -85,33 +87,33 @@ MODULES *mod;
sprintf(fname, "%s/modules/lib%s.so", home, module);
if (access(fname, F_OK) == -1)
{
skygw_log_write_flush(
LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR,
"Error : Unable to find library for "
"module: %s.",
module);
module)));
return NULL;
}
}
if ((dlhandle = dlopen(fname, RTLD_NOW|RTLD_LOCAL)) == NULL)
{
skygw_log_write_flush(
LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR,
"Error : Unable to load library for module: "
"%s, %s.",
module,
dlerror());
dlerror())));
return NULL;
}
if ((sym = dlsym(dlhandle, "version")) == NULL)
{
skygw_log_write_flush(
LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR,
"Error : Version interface not supported by "
"module: %s, %s.",
module,
dlerror());
dlerror())));
dlclose(dlhandle);
return NULL;
}
@ -129,23 +131,23 @@ MODULES *mod;
if ((sym = dlsym(dlhandle, "GetModuleObject")) == NULL)
{
skygw_log_write_flush(
LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR,
"Error : Expected entry point interface missing "
"from module: %s, %s.",
module,
dlerror());
dlerror())));
dlclose(dlhandle);
return NULL;
}
ep = sym;
modobj = ep();
skygw_log_write_flush(
LOGIF(LM, (skygw_log_write_flush(
LOGFILE_MESSAGE,
"Loaded module %s: %s.",
module,
version);
version)));
register_module(module, type, dlhandle, version, modobj);
}
else

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -37,6 +37,8 @@
#include <skygw_utils.h>
#include <log_manager.h>
extern int lm_enabled_logfiles_bitmask;
/**
* @file telnetd.c - telnet daemon protocol module
*
@ -107,7 +109,9 @@ version()
void
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 <log_manager.h>
extern int lm_enabled_logfiles_bitmask;
static char *version_str = "V1.0.1";
/* The router entry points */
@ -88,7 +90,10 @@ version()
void
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);
instances = NULL;
}

View File

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

View File

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