Remove support for session specific log priorities
No need to maintain information in thread local storage, which just added complexity and also incurred a slight performance penalty.
This commit is contained in:
@ -167,32 +167,6 @@ size_t dcb_get_session_id(
|
||||
return (dcb && dcb->session) ? dcb->session->ses_id : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read log info from session through DCB and store values to memory locations
|
||||
* passed as parameters.
|
||||
*
|
||||
* @param dcb DCB
|
||||
* @param sesid location where session id is to be copied
|
||||
* @param enabled_log_prioritiess bit field indicating which log types are enabled for the
|
||||
* session
|
||||
*
|
||||
*@return true if call arguments included memory addresses, false if any of the
|
||||
* parameters was NULL.
|
||||
*/
|
||||
bool dcb_get_ses_log_info(
|
||||
DCB *dcb,
|
||||
size_t *sesid,
|
||||
int *enabled_log_priorities)
|
||||
{
|
||||
if (sesid && enabled_log_priorities && dcb && dcb->session)
|
||||
{
|
||||
*sesid = dcb->session->ses_id;
|
||||
*enabled_log_priorities = dcb->session->enabled_log_priorities;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Initialize a DCB
|
||||
*
|
||||
@ -586,10 +560,6 @@ dcb_process_victim_queue(int threadid)
|
||||
}
|
||||
}
|
||||
|
||||
dcb_get_ses_log_info(dcb,
|
||||
&mxs_log_tls.li_sesid,
|
||||
&mxs_log_tls.li_enabled_priorities);
|
||||
|
||||
/** Move to the next DCB before freeing the previous one */
|
||||
dcblist = dcblist->memdata.next;
|
||||
|
||||
@ -600,8 +570,6 @@ dcb_process_victim_queue(int threadid)
|
||||
dcb_remove_from_list(dcb);
|
||||
dcb_final_free(dcb);
|
||||
}
|
||||
/** Reset threads session data */
|
||||
mxs_log_tls.li_sesid = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -126,18 +126,6 @@ static struct
|
||||
*/
|
||||
int mxs_log_enabled_priorities = 0;
|
||||
|
||||
/**
|
||||
* Thread-specific struct variable for storing current session id and currently
|
||||
* enabled log files for the session.
|
||||
*/
|
||||
__thread mxs_log_info_t mxs_log_tls = {0, 0};
|
||||
|
||||
/**
|
||||
* Global counter for each log file type. It indicates for how many sessions
|
||||
* each log type is currently enabled.
|
||||
*/
|
||||
ssize_t mxs_log_session_count[LOG_DEBUG + 1] = {0};
|
||||
|
||||
/**
|
||||
* BUFSIZ comes from the system. It equals with block size or
|
||||
* its multiplication.
|
||||
@ -788,22 +776,7 @@ static int logmanager_write_log(int priority,
|
||||
|
||||
/** Length of string that will be written, limited by bufsize */
|
||||
size_t safe_str_len;
|
||||
/** Length of session id */
|
||||
size_t sesid_str_len;
|
||||
size_t cmplen = 0;
|
||||
/**
|
||||
* 2 braces, 2 spaces and terminating char
|
||||
* If session id is stored to mxs_log_tls structure, allocate
|
||||
* room for session id too.
|
||||
*/
|
||||
if ((priority == LOG_INFO) && (mxs_log_tls.li_sesid != 0))
|
||||
{
|
||||
sesid_str_len = 5 * sizeof(char) + get_decimal_len(mxs_log_tls.li_sesid);
|
||||
}
|
||||
else
|
||||
{
|
||||
sesid_str_len = 0;
|
||||
}
|
||||
|
||||
if (do_highprecision)
|
||||
{
|
||||
timestamp_len = get_timestamp_len_hp();
|
||||
@ -812,18 +785,17 @@ static int logmanager_write_log(int priority,
|
||||
{
|
||||
timestamp_len = get_timestamp_len();
|
||||
}
|
||||
cmplen = sesid_str_len > 0 ? sesid_str_len - sizeof(char) : 0;
|
||||
|
||||
bool overflow = false;
|
||||
/** Find out how much can be safely written with current block size */
|
||||
if (timestamp_len - sizeof(char) + cmplen + str_len > lf->lf_buf_size)
|
||||
if (timestamp_len - sizeof(char) + str_len > lf->lf_buf_size)
|
||||
{
|
||||
safe_str_len = lf->lf_buf_size;
|
||||
overflow = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
safe_str_len = timestamp_len - sizeof(char) + cmplen + str_len;
|
||||
safe_str_len = timestamp_len - sizeof(char) + str_len;
|
||||
}
|
||||
/**
|
||||
* Seek write position and register to block buffer.
|
||||
@ -862,7 +834,7 @@ static int logmanager_write_log(int priority,
|
||||
}
|
||||
else
|
||||
{
|
||||
wp = (char*)MXS_MALLOC(sizeof(char) * (timestamp_len - sizeof(char) + cmplen + str_len + 1));
|
||||
wp = (char*)MXS_MALLOC(sizeof(char) * (timestamp_len - sizeof(char) + str_len + 1));
|
||||
}
|
||||
|
||||
if (wp == NULL)
|
||||
@ -890,20 +862,13 @@ static int logmanager_write_log(int priority,
|
||||
{
|
||||
timestamp_len = snprint_timestamp(wp, timestamp_len);
|
||||
}
|
||||
if (sesid_str_len != 0)
|
||||
{
|
||||
/**
|
||||
* Write session id
|
||||
*/
|
||||
snprintf(wp + timestamp_len, sesid_str_len, "[%lu] ", mxs_log_tls.li_sesid);
|
||||
sesid_str_len -= 1; /*< don't calculate terminating char anymore */
|
||||
}
|
||||
|
||||
/**
|
||||
* Write next string to overwrite terminating null character
|
||||
* of the timestamp string.
|
||||
*/
|
||||
snprintf(wp + timestamp_len + sesid_str_len,
|
||||
safe_str_len - timestamp_len - sesid_str_len,
|
||||
snprintf(wp + timestamp_len,
|
||||
safe_str_len - timestamp_len,
|
||||
"%s",
|
||||
str);
|
||||
|
||||
|
@ -920,10 +920,6 @@ process_pollq(int thread_id, struct epoll_event *event)
|
||||
if (eno == 0)
|
||||
{
|
||||
ts_stats_increment(pollStats.n_write, thread_id);
|
||||
/** Read session id to thread's local storage */
|
||||
dcb_get_ses_log_info(dcb,
|
||||
&mxs_log_tls.li_sesid,
|
||||
&mxs_log_tls.li_enabled_priorities);
|
||||
|
||||
if (poll_dcb_session_check(dcb, "write_ready"))
|
||||
{
|
||||
@ -952,9 +948,6 @@ process_pollq(int thread_id, struct epoll_event *event)
|
||||
pthread_self(),
|
||||
dcb->fd);
|
||||
ts_stats_increment(pollStats.n_accept, thread_id);
|
||||
dcb_get_ses_log_info(dcb,
|
||||
&mxs_log_tls.li_sesid,
|
||||
&mxs_log_tls.li_enabled_priorities);
|
||||
|
||||
if (poll_dcb_session_check(dcb, "accept"))
|
||||
{
|
||||
@ -969,10 +962,6 @@ process_pollq(int thread_id, struct epoll_event *event)
|
||||
dcb,
|
||||
dcb->fd);
|
||||
ts_stats_increment(pollStats.n_read, thread_id);
|
||||
/** Read session id to thread's local storage */
|
||||
dcb_get_ses_log_info(dcb,
|
||||
&mxs_log_tls.li_sesid,
|
||||
&mxs_log_tls.li_enabled_priorities);
|
||||
|
||||
if (poll_dcb_session_check(dcb, "read"))
|
||||
{
|
||||
@ -1005,10 +994,6 @@ process_pollq(int thread_id, struct epoll_event *event)
|
||||
strerror_r(eno, errbuf, sizeof(errbuf)));
|
||||
}
|
||||
ts_stats_increment(pollStats.n_error, thread_id);
|
||||
/** Read session id to thread's local storage */
|
||||
dcb_get_ses_log_info(dcb,
|
||||
&mxs_log_tls.li_sesid,
|
||||
&mxs_log_tls.li_enabled_priorities);
|
||||
|
||||
if (poll_dcb_session_check(dcb, "error"))
|
||||
{
|
||||
@ -1033,11 +1018,6 @@ process_pollq(int thread_id, struct epoll_event *event)
|
||||
{
|
||||
dcb->flags |= DCBF_HUNG;
|
||||
|
||||
/** Read session id to thread's local storage */
|
||||
dcb_get_ses_log_info(dcb,
|
||||
&mxs_log_tls.li_sesid,
|
||||
&mxs_log_tls.li_enabled_priorities);
|
||||
|
||||
if (poll_dcb_session_check(dcb, "hangup EPOLLHUP"))
|
||||
{
|
||||
dcb->func.hangup(dcb);
|
||||
@ -1064,11 +1044,6 @@ process_pollq(int thread_id, struct epoll_event *event)
|
||||
{
|
||||
dcb->flags |= DCBF_HUNG;
|
||||
|
||||
/** Read session id to thread's local storage */
|
||||
dcb_get_ses_log_info(dcb,
|
||||
&mxs_log_tls.li_sesid,
|
||||
&mxs_log_tls.li_enabled_priorities);
|
||||
|
||||
if (poll_dcb_session_check(dcb, "hangup EPOLLRDHUP"))
|
||||
{
|
||||
dcb->func.hangup(dcb);
|
||||
@ -1091,9 +1066,6 @@ process_pollq(int thread_id, struct epoll_event *event)
|
||||
|
||||
ts_stats_set_max(queueStats.maxexectime, qtime, thread_id);
|
||||
|
||||
/** Reset session id from thread's local storage */
|
||||
mxs_log_tls.li_sesid = 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -243,37 +243,6 @@ session_set_dummy(DCB *client_dcb)
|
||||
return session;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable specified log priority for the current session and increase logger
|
||||
* counter.
|
||||
* Generic logging setting has precedence over session-specific setting.
|
||||
*
|
||||
* @param session session
|
||||
* @param priority syslog priority
|
||||
*/
|
||||
void session_enable_log_priority(MXS_SESSION* session, int priority)
|
||||
{
|
||||
session->enabled_log_priorities |= (1 << priority);
|
||||
atomic_add((int *)&mxs_log_session_count[priority], 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable specified log priority for the current session and decrease logger
|
||||
* counter.
|
||||
* Generic logging setting has precedence over session-specific setting.
|
||||
*
|
||||
* @param session session
|
||||
* @param priority syslog priority
|
||||
*/
|
||||
void session_disable_log_priority(MXS_SESSION* session, int priority)
|
||||
{
|
||||
if (session->enabled_log_priorities & (1 << priority))
|
||||
{
|
||||
session->enabled_log_priorities &= ~(1 << priority);
|
||||
atomic_add((int *)&mxs_log_session_count[priority], -1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Link a session to a DCB.
|
||||
*
|
||||
@ -384,9 +353,6 @@ static void session_free(MXS_SESSION *session)
|
||||
|
||||
MXS_INFO("Stopped %s client session [%lu]", session->service->name, session->ses_id);
|
||||
|
||||
/** Disable trace and decrease trace logger counter */
|
||||
session_disable_log_priority(session, LOG_INFO);
|
||||
|
||||
/** If session doesn't have parent referencing to it, it can be freed */
|
||||
if (!session->ses_is_child)
|
||||
{
|
||||
|
Reference in New Issue
Block a user