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:
Johan Wikman 2017-02-14 12:27:57 +02:00
parent d05a533611
commit 5f0346f5a9
7 changed files with 8 additions and 146 deletions

View File

@ -324,7 +324,6 @@ int dcb_count_by_usage(DCB_USAGE); /* Return counts of DCBs */
int dcb_persistent_clean_count(DCB *, int, bool); /* Clean persistent and return count */
void dcb_hangup_foreach (struct server* server);
size_t dcb_get_session_id(DCB* dcb);
bool dcb_get_ses_log_info(DCB* dcb, size_t* sesid, int* enabled_logs);
char *dcb_role_name(DCB *); /* Return the name of a role */
int dcb_accept_SSL(DCB* dcb);
int dcb_connect_SSL(DCB* dcb);

View File

@ -64,8 +64,6 @@ typedef struct mxs_log_info
} mxs_log_info_t;
extern int mxs_log_enabled_priorities;
extern ssize_t mxs_log_session_count[];
extern __thread mxs_log_info_t mxs_log_tls;
/**
* Check if specified log type is enabled in general or if it is enabled
@ -74,9 +72,7 @@ extern __thread mxs_log_info_t mxs_log_tls;
* @param priority One of the syslog LOG_ERR, LOG_WARNING, etc. constants.
*/
#define MXS_LOG_PRIORITY_IS_ENABLED(priority) \
(((mxs_log_enabled_priorities & (1 << priority)) || \
(mxs_log_session_count[priority] > 0 && \
mxs_log_tls.li_enabled_priorities & (1 << priority))) ? true : false)
((mxs_log_enabled_priorities & (1 << priority)) ? true : false)
/**
* LOG_AUGMENT_WITH_FUNCTION Each logged line is suffixed with [function-name].

View File

@ -128,7 +128,6 @@ typedef struct session
skygw_chk_t ses_chk_top;
mxs_session_state_t state; /*< Current descriptor state */
size_t ses_id; /*< Unique session identifier */
int enabled_log_priorities; /*< Bitfield of enabled syslog priorities */
struct dcb *client_dcb; /*< The client connection */
void *router_session; /*< The router instance data */
MXS_SESSION_STATS stats; /*< Session statistics */
@ -172,9 +171,6 @@ MXS_SESSION *session_set_dummy(struct dcb *);
const char *session_get_remote(const MXS_SESSION *);
const char *session_get_user(const MXS_SESSION *);
void session_enable_log_priority(MXS_SESSION* ses, int priority);
void session_disable_log_priority(MXS_SESSION* ses, int priority);
/**
* Convert transaction state to string representation.
*

View File

@ -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;
}
/**

View File

@ -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);

View File

@ -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;
}

View File

@ -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)
{