Log: skygw_log_flush replaced with mxs_log_flush.

skygw_log_flush replaced with mxs_log_flush and skygw_log_sync_all
with mxs_log_flush_sync.
This commit is contained in:
Johan Wikman 2015-11-12 11:10:26 +02:00
parent c7a329e43e
commit 05fbdb1b76
16 changed files with 111 additions and 115 deletions

View File

@ -1308,38 +1308,6 @@ static int log_write(int priority,
return rv;
}
int skygw_log_flush(logfile_id_t id)
{
int err = -1;
if (id == LOGFILE_ERROR)
{
if (logmanager_register(false))
{
CHK_LOGMANAGER(lm);
logfile_t *lf = logmanager_get_logfile(lm);
CHK_LOGFILE(lf);
logfile_flush(lf);
err = 0;
logmanager_unregister();
}
else
{
ss_dfprintf(stderr, "Can't register to logmanager, flushing failed.\n");
}
}
else
{
// We'll pretend everything went ok.
err = 0;
}
return err;
}
/**
* @node Register as a logging client to logmanager.
*
@ -2592,26 +2560,6 @@ void flushall_logfiles(bool flush)
simple_mutex_unlock(&lm->lm_mutex);
}
/**
* Flush all log files synchronously
*/
void skygw_log_sync_all(void)
{
if (!log_config.use_stdout)
{
skygw_log_write(LOGFILE_TRACE,"Starting log flushing to disk.");
}
/** If initialization of the log manager has not been done, lm pointer can be
* NULL. */
if (lm)
{
flushall_logfiles(true);
skygw_message_send(lm->lm_logmes);
skygw_message_wait(lm->lm_clientmes);
}
}
/**
* Toggle high precision logging
* @param val 0 for disabled, 1 for enabled
@ -2652,7 +2600,63 @@ void logmanager_enable_maxscalelog(int val)
*/
int mxs_log_flush()
{
return skygw_log_flush(LOGFILE_ERROR);
int err = -1;
if (logmanager_register(false))
{
CHK_LOGMANAGER(lm);
logfile_t *lf = logmanager_get_logfile(lm);
CHK_LOGFILE(lf);
logfile_flush(lf);
err = 0;
logmanager_unregister();
}
else
{
ss_dfprintf(stderr, "Can't register to logmanager, flushing failed.\n");
}
return err;
}
/**
* Explicitly ensure that all pending log messages are flushed.
*
* @return 0 if the flushing was successfully performed, otherwise -1.
*
* When the function returns 0, the flushing has been initiated and the
* flushing thread has indicated that the operation has been performed.
* However, 0 will be returned also in the case that the flushing thread
* for, whatever reason, failed to actually flush the log.
*/
int mxs_log_flush_sync(void)
{
int err = 0;
if (!log_config.use_stdout)
{
MXS_INFO("Starting log flushing to disk.");
}
/** If initialization of the log manager has not been done, lm pointer can be
* NULL. */
// TODO: Why is logmanager_register() not called here?
if (lm)
{
flushall_logfiles(true);
err = skygw_message_send(lm->lm_logmes);
if (!err)
{
// TODO: Add error handling to skygw_message_wait. Now void.
skygw_message_wait(lm->lm_clientmes);
}
}
return err;
}
/**

View File

@ -142,7 +142,9 @@ bool mxs_log_init(const char* ident, const char* logdir, log_target_t target);
void mxs_log_finish(void);
int mxs_log_flush();
int mxs_log_flush_sync();
int mxs_log_rotate();
int mxs_log_enable_priority(int priority);
int mxs_log_disable_priority(int priority);
@ -150,14 +152,8 @@ int mxs_log_message(int priority,
const char* file, int line, const char* function,
const char* format, ...);
/**
* free private write buffer list
*/
int skygw_log_flush(logfile_id_t id);
void skygw_log_sync_all(void);
int skygw_log_enable(logfile_id_t id);
int skygw_log_disable(logfile_id_t id);
void skygw_log_sync_all(void);
void skygw_set_highp(int);
void logmanager_enable_syslog(int);
void logmanager_enable_maxscalelog(int);

View File

@ -152,14 +152,14 @@ int main(int argc, char* argv[])
logstr = ("Fourth write, no flush. Next flush only.");
err = skygw_log_write(LOGFILE_ERROR, logstr);
err = skygw_log_flush(LOGFILE_ERROR);
err = mxs_log_flush();
logstr = "My name is %s %d years and %d months.";
#if !defined(SS_DEBUG)
skygw_log_enable(LOGFILE_TRACE);
#endif
err = skygw_log_write(LOGFILE_TRACE, logstr, "TraceyTracey", 3, 7);
skygw_log_flush(LOGFILE_TRACE);
mxs_log_flush();
#if !defined(SS_DEBUG)
skygw_log_enable(LOGFILE_TRACE);
#endif
@ -508,7 +508,7 @@ static void* thr_run(void* data)
int err;
mxs_log_init(NULL, "/tmp", LOG_TARGET_FS);
skygw_log_flush(LOGFILE_MESSAGE);
mxs_log_flush();
logstr = ("Hi, how are you?");
err = skygw_log_write(LOGFILE_MESSAGE, logstr);
@ -518,8 +518,7 @@ static void* thr_run(void* data)
}
ss_dassert(err == 0);
mxs_log_finish();
skygw_log_flush(LOGFILE_TRACE);
skygw_log_flush(LOGFILE_MESSAGE);
mxs_log_flush();
logstr = ("I was wondering, you know, it has been such a lovely weather whole morning and "
"I thought that would you like to come to my place and have a little piece of "
"cheese with us. Just me and my mom - and you, of course. Then, if you wish, "
@ -541,7 +540,7 @@ static void* thr_run(void* data)
ss_dassert(err == 0);
mxs_log_init(NULL, "/tmp", LOG_TARGET_FS);
mxs_log_init(NULL, "/tmp", LOG_TARGET_FS);
skygw_log_flush(LOGFILE_ERROR);
mxs_log_flush();
logstr = ("For automatic and register variables, it is done each time the function or block is entered.");
#if !defined(SS_DEBUG)
@ -568,7 +567,7 @@ static void* thr_run(void* data)
ss_dassert(err == 0);
mxs_log_init(NULL, "/tmp", LOG_TARGET_FS);
mxs_log_finish();
skygw_log_flush(LOGFILE_ERROR);
mxs_log_flush();
mxs_log_finish();
mxs_log_init(NULL, "/tmp", LOG_TARGET_FS);
logstr = ("..and you?");
@ -615,7 +614,7 @@ static void* thr_run(void* data)
#if !defined(SS_DEBUG)
skygw_log_enable(LOGFILE_TRACE);
#endif
skygw_log_flush(LOGFILE_TRACE);
mxs_log_flush();
logstr = ("For automatic and register variables, it is done each time the function or block is entered.");
#if !defined(SS_DEBUG)
skygw_log_enable(LOGFILE_TRACE);

View File

@ -107,7 +107,7 @@ int main(int argc, char** argv)
nanosleep(&ts1, NULL);
}
skygw_log_flush(LOGFILE_ERROR);
mxs_log_flush();
mxs_log_finish();
free(message);
return 0;

View File

@ -980,7 +980,7 @@ int dcb_read_SSL(DCB *dcb,
if (GWBUF_LENGTH(buffer) != n)
{
skygw_log_sync_all();
mxs_log_flush_sync();
}
ss_info_dassert((buffer->start <= buffer->end), "Buffer start has passed end.");

View File

@ -316,7 +316,7 @@ static void sigterm_handler (int i) {
skygw_log_write_flush(
LOGFILE_ERROR,
"MaxScale received signal SIGTERM. Exiting.");
skygw_log_sync_all();
mxs_log_flush_sync();
shutdown_server();
}
@ -328,7 +328,7 @@ sigint_handler (int i)
skygw_log_write_flush(
LOGFILE_ERROR,
"MaxScale received signal SIGINT. Shutting down.");
skygw_log_sync_all();
mxs_log_flush_sync();
shutdown_server();
fprintf(stderr, "\n\nShutting down MaxScale\n\n");
}
@ -409,7 +409,7 @@ sigfatal_handler(int i)
}
}
skygw_log_sync_all();
mxs_log_flush_sync();
/* re-raise signal to enforce core dump */
fprintf(stderr, "\n\nWriting core dump\n");
@ -822,7 +822,7 @@ static bool file_is_readable(
absolute_pathname,
eno,
strerror_r(eno, errbuf, sizeof(errbuf)));
skygw_log_sync_all();
mxs_log_flush_sync();
succp = false;
}
return succp;
@ -2054,10 +2054,7 @@ static void log_flush_cb(
LOGIF(LM, (skygw_log_write(LOGFILE_MESSAGE,
"Started MaxScale log flusher.")));
while (!do_exit) {
skygw_log_flush(LOGFILE_ERROR);
skygw_log_flush(LOGFILE_MESSAGE);
skygw_log_flush(LOGFILE_TRACE);
skygw_log_flush(LOGFILE_DEBUG);
mxs_log_flush();
nanosleep(&ts1, NULL);
}
LOGIF(LM, (skygw_log_write(LOGFILE_MESSAGE,

View File

@ -56,7 +56,7 @@ int main(int argc, char **argv)
rval = 1;
}
skygw_log_sync_all();
mxs_log_flush_sync();
mxs_log_finish();
return rval;

View File

@ -74,7 +74,7 @@ main(int argc, char **argv)
}
free(pw);
skygw_log_sync_all();
mxs_log_flush_sync();
mxs_log_finish();
return rval;
}

View File

@ -44,7 +44,7 @@
* test1 Allocate table of users and mess around with it
*
*/
void skygw_log_sync_all(void);
int mxs_log_flush_sync(void);
static int
test1()
{
@ -56,13 +56,13 @@ HINT *hint;
char* name = strdup("name");
hint = hint_create_parameter(NULL, name, "value");
free(name);
skygw_log_sync_all();
mxs_log_flush_sync();
ss_info_dassert(NULL != hint, "New hint list should not be null");
ss_info_dassert(0 == strcmp("value", hint->value), "Hint value should be correct");
ss_info_dassert(0 != hint_exists(&hint, HINT_PARAMETER), "Hint of parameter type should exist");
ss_dfprintf(stderr, "\t..done\nFree hints.");
if (NULL != hint) hint_free(hint);
skygw_log_sync_all();
mxs_log_flush_sync();
ss_dfprintf(stderr, "\t..done\n");
return 0;

View File

@ -55,7 +55,7 @@ char *status;
ss_dfprintf(stderr,
"testserver : creating server called MyServer");
server = server_alloc("MyServer", "HTTPD", 9876);
skygw_log_sync_all();
mxs_log_flush_sync();
//ss_info_dassert(NULL != service, "New server with valid protocol and port must not be null");
//ss_info_dassert(0 != service_isvalid(service), "Service must be valid after creation");
@ -63,32 +63,32 @@ char *status;
ss_dfprintf(stderr, "\t..done\nTest Parameter for Server.");
ss_info_dassert(NULL == serverGetParameter(server, "name"), "Parameter should be null when not set");
serverAddParameter(server, "name", "value");
skygw_log_sync_all();
mxs_log_flush_sync();
ss_info_dassert(0 == strcmp("value", serverGetParameter(server, "name")), "Parameter should be returned correctly");
ss_dfprintf(stderr, "\t..done\nTesting Unique Name for Server.");
ss_info_dassert(NULL == server_find_by_unique_name("uniquename"), "Should not find non-existent unique name.");
server_set_unique_name(server, "uniquename");
skygw_log_sync_all();
mxs_log_flush_sync();
ss_info_dassert(server == server_find_by_unique_name("uniquename"), "Should find by unique name.");
ss_dfprintf(stderr, "\t..done\nTesting Status Setting for Server.");
status = server_status(server);
skygw_log_sync_all();
mxs_log_flush_sync();
ss_info_dassert(0 == strcmp("Running", status), "Status of Server should be Running by default.");
if (NULL != status) free(status);
server_set_status(server, SERVER_MASTER);
status = server_status(server);
skygw_log_sync_all();
mxs_log_flush_sync();
ss_info_dassert(0 == strcmp("Master, Running", status), "Should find correct status.");
server_clear_status(server, SERVER_MASTER);
free(status);
status = server_status(server);
skygw_log_sync_all();
mxs_log_flush_sync();
ss_info_dassert(0 == strcmp("Running", status), "Status of Server should be Running after master status cleared.");
if (NULL != status) free(status);
ss_dfprintf(stderr, "\t..done\nRun Prints for Server and all Servers.");
printServer(server);
printAllServers();
skygw_log_sync_all();
mxs_log_flush_sync();
ss_dfprintf(stderr, "\t..done\nFreeing Server.");
ss_info_dassert(0 != server_free(server), "Free should succeed");
ss_dfprintf(stderr, "\t..done\n");

View File

@ -60,12 +60,12 @@ init_test_env(NULL);
ss_dfprintf(stderr,
"testservice : creating service called MyService with router nonexistent");
service = service_alloc("MyService", "non-existent");
skygw_log_sync_all();
mxs_log_flush_sync();
ss_info_dassert(NULL == service, "New service with invalid router should be null");
ss_info_dassert(0 == service_isvalid(service), "Service must not be valid after incorrect creation");
ss_dfprintf(stderr, "\t..done\nValid service creation, router testroute.");
service = service_alloc("MyService", "testroute");
skygw_log_sync_all();
mxs_log_flush_sync();
ss_info_dassert(NULL != service, "New service with valid router must not be null");
ss_info_dassert(0 != service_isvalid(service), "Service must be valid after creation");
ss_info_dassert(0 == strcmp("MyService", service_get_name(service)), "Service must have given name");
@ -73,26 +73,26 @@ init_test_env(NULL);
ss_info_dassert(0 != serviceAddProtocol(service, "testprotocol", "localhost", 9876), "Add Protocol should succeed");
ss_info_dassert(0 != serviceHasProtocol(service, "testprotocol", 9876), "Service should have new protocol as requested");
serviceStartProtocol(service, "testprotocol", 9876);
skygw_log_sync_all();
mxs_log_flush_sync();
ss_dfprintf(stderr, "\t..done\nStarting Service.");
result = serviceStart(service);
skygw_log_sync_all();
mxs_log_flush_sync();
ss_info_dassert(0 != result, "Start should succeed");
serviceStop(service);
skygw_log_sync_all();
mxs_log_flush_sync();
ss_info_dassert(service->state == SERVICE_STATE_STOPPED, "Stop should succeed");
result = serviceStartAll();
skygw_log_sync_all();
mxs_log_flush_sync();
ss_info_dassert(0 != result, "Start all should succeed");
ss_dfprintf(stderr, "\t..done\nTiming out a session.");
service->conn_timeout = 1;
result = serviceStart(service);
skygw_log_sync_all();
mxs_log_flush_sync();
ss_info_dassert(0 != result, "Start should succeed");
serviceStop(service);
skygw_log_sync_all();
mxs_log_flush_sync();
ss_info_dassert(service->state == SERVICE_STATE_STOPPED, "Stop should succeed");
if((dcb = dcb_alloc(DCB_ROLE_REQUEST_HANDLER)) == NULL)

View File

@ -58,39 +58,39 @@ int result, count;
ss_dfprintf(stderr,
"testusers : Initialise the user table.");
users = users_alloc();
skygw_log_sync_all();
mxs_log_flush_sync();
ss_info_dassert(NULL != users, "Allocating user table should not return NULL.")
ss_dfprintf(stderr, "\t..done\nAdd a user");
count = users_add(users, "username", "authorisation");
skygw_log_sync_all();
mxs_log_flush_sync();
ss_info_dassert(1 == count, "Should add one user");
authdata = users_fetch(users, "username");
skygw_log_sync_all();
mxs_log_flush_sync();
ss_info_dassert(NULL != authdata, "Fetch valid user must not return NULL");
ss_info_dassert(0 == strcmp("authorisation", authdata), "User authorisation should be correct");
ss_dfprintf(stderr, "\t..done\nPrint users");
usersPrint(users);
skygw_log_sync_all();
mxs_log_flush_sync();
ss_dfprintf(stderr, "\t..done\nUpdate a user");
count = users_update(users, "username", "newauth");
skygw_log_sync_all();
mxs_log_flush_sync();
ss_info_dassert(1 == count, "Should update just one user");
authdata = users_fetch(users, "username");
skygw_log_sync_all();
mxs_log_flush_sync();
ss_info_dassert(NULL != authdata, "Fetch valid user must not return NULL");
ss_info_dassert(0 == strcmp("newauth", authdata), "User authorisation should be correctly updated");
ss_dfprintf(stderr, "\t..done\nAdd another user");
count = users_add(users, "username2", "authorisation2");
skygw_log_sync_all();
mxs_log_flush_sync();
ss_info_dassert(1 == count, "Should add one user");
ss_dfprintf(stderr, "\t..done\nDelete a user.");
count = users_delete(users, "username");
skygw_log_sync_all();
mxs_log_flush_sync();
ss_info_dassert(1 == count, "Should delete just one user");
ss_dfprintf(stderr, "\t..done\nFree user table.");
users_free(users);
skygw_log_sync_all();
mxs_log_flush_sync();
ss_dfprintf(stderr, "\t..done\n");
return 0;

View File

@ -2231,7 +2231,7 @@ int main(int argc, char** argv)
printf("Failed to parse rule. Read the error log for the reason of the failure.\n");
}
skygw_log_sync_all();
mxs_log_flush_sync();
return 0;
}

View File

@ -137,7 +137,7 @@ int main(int argc, char **argv) {
LOGIF(LE, (skygw_log_write_flush(LOGFILE_ERROR,
"Error: Memory allocation failed for ROUTER_INSTANCE")));
skygw_log_sync_all();
mxs_log_flush_sync();
mxs_log_finish();
return 1;
@ -161,7 +161,7 @@ int main(int argc, char **argv) {
"Failed to open binlog file %s: %s",
path, strerror(errno))));
skygw_log_sync_all();
mxs_log_flush_sync();
mxs_log_finish();
free(inst);
@ -194,12 +194,12 @@ int main(int argc, char **argv) {
close(inst->binlog_fd);
skygw_log_sync_all();
mxs_log_flush_sync();
LOGIF(LM, (skygw_log_write_flush(LOGFILE_MESSAGE,
"Check retcode: %i, Binlog Pos = %llu", ret, inst->binlog_position)));
skygw_log_sync_all();
mxs_log_flush_sync();
mxs_log_finish();
free(inst);

View File

@ -127,7 +127,7 @@ int main(int argc, char **argv) {
LOGIF(LE, (skygw_log_write_flush(LOGFILE_ERROR,
"Error: Memory allocation FAILED for ROUTER_INSTANCE")));
skygw_log_sync_all();
mxs_log_flush_sync();
mxs_log_finish();
return 1;
@ -578,7 +578,7 @@ int main(int argc, char **argv) {
return 1;
}
skygw_log_sync_all();
mxs_log_flush_sync();
mxs_log_finish();
free(inst);

View File

@ -55,11 +55,11 @@
# define ss_dassert(exp) if(!(exp)){(skygw_log_write(LE,\
"debug assert %s:%d\n", \
(char*)__FILE__, \
__LINE__));skygw_log_sync_all();assert(exp);}
__LINE__));mxs_log_flush_sync();assert(exp);}
#define ss_info_dassert(exp,info) if(!(exp)){(skygw_log_write(LE,\
"debug assert %s:%d %s\n", \
(char*)__FILE__, \
__LINE__,info));skygw_log_sync_all();assert(exp);}
__LINE__,info));mxs_log_flush_sync();assert(exp);}
# define ss_debug(exp) exp
# define ss_dfprintf fprintf
# define ss_dfflush fflush