Automatic merge
This commit is contained in:
commit
43000d86de
@ -512,10 +512,7 @@ static int logmanager_write_log(
|
||||
char* wp;
|
||||
int err = 0;
|
||||
blockbuf_t* bb;
|
||||
time_t t;
|
||||
struct tm tm;
|
||||
const char* timestamp_formatstr = "%04d %02d/%02d %02d:%02d:%02d ";
|
||||
const int timestamp_len = 4+1+2+1+2+1+2+1+2+1+2+3;
|
||||
int timestamp_len;
|
||||
|
||||
CHK_LOGMANAGER(lm);
|
||||
|
||||
@ -551,23 +548,16 @@ static int logmanager_write_log(
|
||||
ss_dassert(flush);
|
||||
logfile_flush(lf); /**< here we wake up file writer */
|
||||
} else {
|
||||
timestamp_len = get_timestamp_len();
|
||||
/**
|
||||
* Seek write position and register to block buffer.
|
||||
* Then print formatted string to write position.
|
||||
*/
|
||||
wp = blockbuf_get_writepos(&bb, id, timestamp_len-1+str_len, flush);
|
||||
/** Generate timestamp */
|
||||
t = time(NULL);
|
||||
tm = *(localtime(&t));
|
||||
snprintf(wp,
|
||||
timestamp_len,
|
||||
timestamp_formatstr,
|
||||
tm.tm_year+1900,
|
||||
tm.tm_mon+1,
|
||||
tm.tm_mday,
|
||||
tm.tm_hour,
|
||||
tm.tm_min,
|
||||
tm.tm_sec);
|
||||
/**
|
||||
* Write timestamp with at most <timestamp_len> characters to wp
|
||||
*/
|
||||
timestamp_len = snprint_timestamp(wp, timestamp_len);
|
||||
/**
|
||||
* Write next string to overwrite terminating null character of the
|
||||
* timestamp string.
|
||||
@ -1698,8 +1688,11 @@ static void* thr_filewriter_fun(
|
||||
* get logfile's block buffer list
|
||||
*/
|
||||
bb_list = &lf->lf_blockbuf_list;
|
||||
#if defined(SS_DEBUG)
|
||||
simple_mutex_lock(&bb_list->mlist_mutex, TRUE);
|
||||
CHK_MLIST(bb_list);
|
||||
|
||||
simple_mutex_unlock(&bb_list->mlist_mutex);
|
||||
#endif
|
||||
node = bb_list->mlist_first;
|
||||
|
||||
while (node != NULL) {
|
||||
|
@ -89,9 +89,14 @@ static char datadir[1024] = "";
|
||||
*/
|
||||
static bool do_exit = FALSE;
|
||||
|
||||
/**
|
||||
* Flag to indicate whether libmysqld is successfully initialized.
|
||||
*/
|
||||
static bool libmysqld_started = FALSE;
|
||||
|
||||
static void log_flush_shutdown(void);
|
||||
static void log_flush_cb(void* arg);
|
||||
|
||||
static void libmysqld_done(void);
|
||||
|
||||
/**
|
||||
* Handler for SIGHUP signal. Reload the configuration for the
|
||||
@ -228,6 +233,15 @@ char buf[1024];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static libmysqld_done(void)
|
||||
{
|
||||
if (libmysqld_started) {
|
||||
mysql_library_end();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* The main entry point into the gateway
|
||||
*
|
||||
@ -271,14 +285,14 @@ ssize_t log_flush_timeout_ms = 0;
|
||||
while (argv[n][s] == 0 && s<10) s++;
|
||||
|
||||
if (s==10) {
|
||||
skygw_log_write(
|
||||
LOGFILE_ERROR,
|
||||
"Fatal : missing file name. \n"
|
||||
"Unable to find a MaxScale configuration file, "
|
||||
"either install one in /etc/MaxScale.cnf, "
|
||||
"$MAXSCALE_HOME/etc/MaxScale.cnf "
|
||||
"or use the -c option with configuration file name."
|
||||
" Exiting.\n");
|
||||
skygw_log_write(
|
||||
LOGFILE_ERROR,
|
||||
"Fatal : missing file name. \n"
|
||||
"Unable to find a MaxScale configuration file, "
|
||||
"either install one in /etc/MaxScale.cnf, "
|
||||
"$MAXSCALE_HOME/etc/MaxScale.cnf "
|
||||
"or use the -c option with configuration file "
|
||||
"name. Exiting.\n");
|
||||
}
|
||||
cnf_file = &argv[n][s];
|
||||
}
|
||||
@ -325,8 +339,8 @@ ssize_t log_flush_timeout_ms = 0;
|
||||
gw_daemonize();
|
||||
}
|
||||
|
||||
l = atexit(mysql_library_end);
|
||||
|
||||
l = atexit(libmysqld_done);
|
||||
|
||||
if (l != 0) {
|
||||
fprintf(stderr, "Couldn't register exit function.\n");
|
||||
}
|
||||
@ -383,8 +397,9 @@ ssize_t log_flush_timeout_ms = 0;
|
||||
if (cnf_file == NULL) {
|
||||
skygw_log_write_flush(
|
||||
LOGFILE_ERROR,
|
||||
"Fatal : Unable to find a MaxScale configuration file, either "
|
||||
"install one in /etc/MaxScale.cnf, $MAXSCALE_HOME/etc/MaxScale.cnf "
|
||||
"Fatal : Unable to find a MaxScale configuration "
|
||||
"file, either install one in /etc/MaxScale.cnf, "
|
||||
"$MAXSCALE_HOME/etc/MaxScale.cnf "
|
||||
"or use the -c option. Exiting.\n");
|
||||
exit(1);
|
||||
}
|
||||
@ -412,6 +427,7 @@ ssize_t log_flush_timeout_ms = 0;
|
||||
__LINE__);
|
||||
exit(1);
|
||||
}
|
||||
libmysqld_started = TRUE;
|
||||
|
||||
if (!config_load(cnf_file))
|
||||
{
|
||||
@ -455,13 +471,13 @@ ssize_t log_flush_timeout_ms = 0;
|
||||
thread_wait(threads[n]);
|
||||
|
||||
/**
|
||||
* Wait the timer thread.
|
||||
* Wait the flush thread.
|
||||
*/
|
||||
thread_wait(log_flush_thr);
|
||||
|
||||
/* Stop all the monitors */
|
||||
monitorStopAll();
|
||||
|
||||
|
||||
skygw_log_write(
|
||||
LOGFILE_MESSAGE,
|
||||
"MaxScale shutdown, PID %i\n",
|
||||
|
@ -335,7 +335,7 @@ MONITOR_SERVERS *ptr;
|
||||
if (mysql_thread_init())
|
||||
{
|
||||
skygw_log_write_flush(LOGFILE_ERROR,
|
||||
"Fatal : mysql_init_thread failed in monitor "
|
||||
"Fatal : mysql_thread_init failed in monitor "
|
||||
"module. Exiting.\n");
|
||||
return;
|
||||
}
|
||||
|
@ -373,7 +373,7 @@ MONITOR_SERVERS *ptr;
|
||||
if (mysql_thread_init())
|
||||
{
|
||||
skygw_log_write_flush(LOGFILE_ERROR,
|
||||
"Fatal : mysql_init_thread failed in monitor "
|
||||
"Fatal : mysql_thread_init failed in monitor "
|
||||
"module. Exiting.\n");
|
||||
return;
|
||||
}
|
||||
|
@ -33,9 +33,10 @@
|
||||
* @verbatim
|
||||
* Revision History
|
||||
*
|
||||
* Date Who Description
|
||||
* 20/06/13 Mark Riddoch Initial implementation
|
||||
* 17/07/13 Mark Riddoch Additional commands
|
||||
* Date Who Description
|
||||
* 20/06/13 Mark Riddoch Initial implementation
|
||||
* 17/07/13 Mark Riddoch Additional commands
|
||||
* 09/08/2013 Massimiliano Pinto Addes enable/disable commands (now only for log)
|
||||
*
|
||||
* @endverbatim
|
||||
*/
|
||||
@ -59,6 +60,9 @@
|
||||
#include <monitor.h>
|
||||
#include <debugcli.h>
|
||||
|
||||
#include <skygw_utils.h>
|
||||
#include <log_manager.h>
|
||||
|
||||
#define MAXARGS 5
|
||||
|
||||
#define ARG_TYPE_ADDRESS 1
|
||||
@ -178,6 +182,31 @@ struct subcommand reloadoptions[] = {
|
||||
{0, 0, 0} }
|
||||
};
|
||||
|
||||
static void enable_log_action(DCB *, char *);
|
||||
static void disable_log_action(DCB *, char *);
|
||||
|
||||
/**
|
||||
* * The subcommands of the enable command
|
||||
* */
|
||||
struct subcommand enableoptions[] = {
|
||||
{ "log", 1, enable_log_action, "Enable Log options for MaxScale, options trace | error | message E.g. enable log message.",
|
||||
{ARG_TYPE_STRING, 0, 0} },
|
||||
{ NULL, 0, NULL, NULL,
|
||||
{0, 0, 0} }
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* * The subcommands of the disable command
|
||||
* */
|
||||
struct subcommand disableoptions[] = {
|
||||
{ "log", 1, disable_log_action, "Disable Log for MaxScale, Options: trace | error | message E.g. disable log trace",
|
||||
{ARG_TYPE_STRING, 0, 0} },
|
||||
{ NULL, 0, NULL, NULL,
|
||||
{0, 0, 0} }
|
||||
};
|
||||
|
||||
|
||||
static void telnetdAddUser(DCB *, char *, char *);
|
||||
/**
|
||||
* The subcommands of the add command
|
||||
@ -223,6 +252,8 @@ static struct {
|
||||
{ "show", showoptions },
|
||||
{ "shutdown", shutdownoptions },
|
||||
{ "reload", reloadoptions },
|
||||
{ "enable", enableoptions },
|
||||
{ "disable", disableoptions },
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
@ -621,3 +652,49 @@ restart_monitor(DCB *dcb, MONITOR *monitor)
|
||||
{
|
||||
monitorStart(monitor);
|
||||
}
|
||||
|
||||
/**
|
||||
* The log enable action
|
||||
*/
|
||||
|
||||
static void enable_log_action(DCB *dcb, char *arg1) {
|
||||
logfile_id_t type;
|
||||
int max_len = strlen("message");
|
||||
|
||||
if (strncmp(arg1, "trace", max_len) == 0) {
|
||||
type = LOGFILE_TRACE;
|
||||
} else if (strncmp(arg1, "error", max_len) == 0) {
|
||||
type = LOGFILE_ERROR;
|
||||
} else if (strncmp(arg1, "message", max_len) == 0) {
|
||||
type = LOGFILE_MESSAGE;
|
||||
} else {
|
||||
dcb_printf(dcb, "%s is not supported for enable log\n", arg1);
|
||||
return ;
|
||||
}
|
||||
|
||||
skygw_log_enable(type);
|
||||
}
|
||||
|
||||
/**
|
||||
* The log disable action
|
||||
*/
|
||||
|
||||
static void disable_log_action(DCB *dcb, char *arg1) {
|
||||
logfile_id_t type;
|
||||
int max_len = strlen("message");
|
||||
|
||||
if (strncmp(arg1, "trace", max_len) == 0) {
|
||||
type = LOGFILE_TRACE;
|
||||
} else if (strncmp(arg1, "error", max_len) == 0) {
|
||||
type = LOGFILE_ERROR;
|
||||
} else if (strncmp(arg1, "message", max_len) == 0) {
|
||||
type = LOGFILE_MESSAGE;
|
||||
} else {
|
||||
dcb_printf(dcb, "%s is not supported for disable log\n", arg1);
|
||||
return ;
|
||||
}
|
||||
|
||||
skygw_log_disable(type);
|
||||
}
|
||||
|
||||
////
|
||||
|
@ -263,14 +263,12 @@ int i;
|
||||
&& (inst->servers[i]->server->status & inst->bitmask) == inst->bitvalue)
|
||||
{
|
||||
candidate = inst->servers[i];
|
||||
#if defined(SS_DEBUG)
|
||||
skygw_log_write(
|
||||
LOGFILE_TRACE,
|
||||
"Selected server in port %d to as candidate. "
|
||||
"Connections : %d\n",
|
||||
candidate->server->port,
|
||||
candidate->count);
|
||||
#endif /* SS_DEBUG */
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -289,7 +287,6 @@ int i;
|
||||
*/
|
||||
for (i = 1; inst->servers[i]; i++)
|
||||
{
|
||||
#if defined(SS_DEBUG)
|
||||
skygw_log_write(
|
||||
LOGFILE_TRACE,
|
||||
"Examine server in port %d with %d connections. Status is %d, "
|
||||
@ -298,8 +295,8 @@ int i;
|
||||
inst->servers[i]->count,
|
||||
inst->servers[i]->server->status,
|
||||
inst->bitmask);
|
||||
#endif /* SS_DEBUG */
|
||||
if (inst->servers[i] && SERVER_IS_RUNNING(inst->servers[i]->server)
|
||||
|
||||
if (inst->servers[i] && SERVER_IS_RUNNING(inst->servers[i]->server)
|
||||
&& (inst->servers[i]->server->status & inst->bitmask) == inst->bitvalue)
|
||||
{
|
||||
if (inst->servers[i]->count < candidate->count)
|
||||
@ -328,14 +325,12 @@ int i;
|
||||
atomic_add(&candidate->count, 1);
|
||||
|
||||
client->backend = candidate;
|
||||
#if defined(SS_DEBUG)
|
||||
skygw_log_write(
|
||||
LOGFILE_TRACE,
|
||||
"Final selection is server in port %d. "
|
||||
"Connections : %d\n",
|
||||
candidate->server->port,
|
||||
candidate->count);
|
||||
#endif /* SS_DEBUG */
|
||||
/*
|
||||
* Open a backend connection, putting the DCB for this
|
||||
* connection in the client->dcb
|
||||
|
@ -28,7 +28,9 @@
|
||||
#include "skygw_types.h"
|
||||
#include "skygw_utils.h"
|
||||
|
||||
|
||||
const char* timestamp_formatstr = "%04d %02d/%02d %02d:%02d:%02d ";
|
||||
/** One for terminating '\0' */
|
||||
const int timestamp_len = 4+1 +2+1 +2+1 +2+1 +2+1 +2+3 +1;
|
||||
|
||||
/** Single-linked list for storing test cases */
|
||||
|
||||
@ -622,6 +624,54 @@ bool mlist_cursor_move_to_first(
|
||||
/** End of mlist */
|
||||
|
||||
|
||||
int get_timestamp_len(void)
|
||||
{
|
||||
return timestamp_len;
|
||||
}
|
||||
|
||||
/**
|
||||
* @node Generate and write a timestamp to location passed as argument
|
||||
* by using at most tslen characters.
|
||||
*
|
||||
* Parameters:
|
||||
* @param p_ts - in, use
|
||||
* Write position in memory. Must be filled with at least
|
||||
* <timestamp_len> zeroes
|
||||
*
|
||||
* @return Length of string written. Length includes terminating '\0'.
|
||||
*
|
||||
*
|
||||
* @details (write detailed description here)
|
||||
*
|
||||
*/
|
||||
int snprint_timestamp(
|
||||
char* p_ts,
|
||||
int tslen)
|
||||
{
|
||||
time_t t;
|
||||
struct tm tm;
|
||||
|
||||
if (p_ts == NULL) {
|
||||
goto return_p_ts;
|
||||
}
|
||||
|
||||
/** Generate timestamp */
|
||||
t = time(NULL);
|
||||
tm = *(localtime(&t));
|
||||
snprintf(p_ts,
|
||||
MIN(tslen,timestamp_len),
|
||||
timestamp_formatstr,
|
||||
tm.tm_year+1900,
|
||||
tm.tm_mon+1,
|
||||
tm.tm_mday,
|
||||
tm.tm_hour,
|
||||
tm.tm_min,
|
||||
tm.tm_sec);
|
||||
|
||||
return_p_ts:
|
||||
return (MIN(tslen,timestamp_len));
|
||||
}
|
||||
|
||||
|
||||
static slist_t* slist_init_ex(
|
||||
bool create_cursors)
|
||||
@ -1573,6 +1623,61 @@ return_succp:
|
||||
return succp;
|
||||
}
|
||||
|
||||
static bool file_write_footer(
|
||||
skygw_file_t* file)
|
||||
{
|
||||
bool succp = FALSE;
|
||||
size_t wbytes1;
|
||||
size_t wbytes3;
|
||||
size_t wbytes4;
|
||||
size_t len1;
|
||||
size_t len4;
|
||||
int tslen;
|
||||
const char* header_buf1;
|
||||
char* header_buf3 = NULL;
|
||||
const char* header_buf4;
|
||||
|
||||
CHK_FILE(file);
|
||||
header_buf1 = "MaxScale is shut down\t";
|
||||
tslen = get_timestamp_len();
|
||||
header_buf3 = (char *)malloc(tslen);
|
||||
if (header_buf3 == NULL) {
|
||||
goto return_succp;
|
||||
}
|
||||
tslen = snprint_timestamp(header_buf3, tslen);
|
||||
header_buf4 = "\n--------------------------------------------"
|
||||
"---------------------------\n";
|
||||
|
||||
len1 = strlen(header_buf1);
|
||||
len4 = strlen(header_buf4);
|
||||
#if defined(LAPTOP_TEST)
|
||||
usleep(DISKWRITE_LATENCY);
|
||||
#else
|
||||
wbytes3=fwrite((void*)header_buf3, tslen, 1, file->sf_file);
|
||||
wbytes1=fwrite((void*)header_buf1, len1, 1, file->sf_file);
|
||||
wbytes4=fwrite((void*)header_buf4, len4, 1, file->sf_file);
|
||||
|
||||
if (wbytes1 != 1 || wbytes3 != 1 || wbytes4 != 1) {
|
||||
fprintf(stderr,
|
||||
"Writing header %s %s to %s failed.\n",
|
||||
header_buf1,
|
||||
header_buf3,
|
||||
header_buf4);
|
||||
perror("Logfile header write.\n");
|
||||
goto return_succp;
|
||||
}
|
||||
#endif
|
||||
CHK_FILE(file);
|
||||
|
||||
succp = TRUE;
|
||||
return_succp:
|
||||
if (header_buf3 != NULL) {
|
||||
free(header_buf3);
|
||||
}
|
||||
return succp;
|
||||
}
|
||||
|
||||
|
||||
bool skygw_file_write(
|
||||
skygw_file_t* file,
|
||||
void* data,
|
||||
@ -1671,6 +1776,14 @@ void skygw_file_done(
|
||||
|
||||
if (file != NULL) {
|
||||
CHK_FILE(file);
|
||||
|
||||
if (!file_write_footer(file)) {
|
||||
fprintf(stderr,
|
||||
"Writing header of log file %s failed.\n",
|
||||
file->sf_fname);
|
||||
perror("SkyGW file open\n");
|
||||
}
|
||||
|
||||
fd = fileno(file->sf_file);
|
||||
fsync(fd);
|
||||
err = fclose(file->sf_file);
|
||||
|
@ -125,6 +125,9 @@ int skygw_thread_start(skygw_thread_t* thr);
|
||||
skygw_thr_state_t skygw_thread_get_state(skygw_thread_t* thr);
|
||||
pthread_t skygw_thread_gettid(skygw_thread_t* thr);
|
||||
|
||||
int get_timestamp_len(void);
|
||||
int snprint_timestamp(char* p_ts, int tslen);
|
||||
|
||||
EXTERN_C_BLOCK_BEGIN
|
||||
|
||||
void skygw_thread_set_state(
|
||||
|
Loading…
x
Reference in New Issue
Block a user