MAX-328, Add session identifier to trace log entries. Session id is given to session in session_alloc and stored to thread's local storage variable when thread picks a new event from epoll_wait.

This commit is contained in:
VilhoRaatikka
2014-11-17 23:27:14 +02:00
parent 70eef7aaa8
commit a30fc0c787
6 changed files with 92 additions and 15 deletions

View File

@ -90,6 +90,21 @@ static int dcb_null_close(DCB *dcb);
static int dcb_null_auth(DCB *dcb, SERVER *server, SESSION *session, GWBUF *buf);
static int dcb_isvalid_nolock(DCB *dcb);
size_t dcb_get_session_id(
DCB* dcb)
{
size_t rval;
if (dcb != NULL && dcb->session != NULL)
{
rval = dcb->session->ses_id;
}
else
{
rval = 0;
}
return rval;
}
/**
* Return the pointer to the lsit of zombie DCB's
*

View File

@ -41,6 +41,8 @@
extern int lm_enabled_logfiles_bitmask;
extern __thread size_t tls_sesid;
/**
* @file poll.c - Abstraction of the epoll functionality
*
@ -677,6 +679,7 @@ uint32_t ev;
#else
atomic_add(&pollStats.n_write,
1);
LOGIF(LT, (tls_sesid = dcb_get_session_id(dcb)));
dcb->func.write_ready(dcb);
#endif
} else {
@ -712,6 +715,7 @@ uint32_t ev;
dcb->fd)));
atomic_add(
&pollStats.n_accept, 1);
LOGIF(LT, (tls_sesid = dcb_get_session_id(dcb)));
dcb->func.accept(dcb);
}
else
@ -724,6 +728,7 @@ uint32_t ev;
dcb,
dcb->fd)));
atomic_add(&pollStats.n_read, 1);
LOGIF(LT, (tls_sesid = dcb_get_session_id(dcb)));
dcb->func.read(dcb);
}
#if MUTEX_BLOCK
@ -759,6 +764,7 @@ uint32_t ev;
strerror(eno))));
}
atomic_add(&pollStats.n_error, 1);
LOGIF(LT, (tls_sesid = dcb_get_session_id(dcb)));
dcb->func.error(dcb);
}
@ -783,6 +789,7 @@ uint32_t ev;
{
dcb->flags |= DCBF_HUNG;
spinlock_release(&dcb->dcb_initlock);
LOGIF(LT, (tls_sesid = dcb_get_session_id(dcb)));
dcb->func.hangup(dcb);
}
else
@ -811,12 +818,14 @@ uint32_t ev;
{
dcb->flags |= DCBF_HUNG;
spinlock_release(&dcb->dcb_initlock);
LOGIF(LT, (tls_sesid = dcb_get_session_id(dcb)));
dcb->func.hangup(dcb);
}
else
spinlock_release(&dcb->dcb_initlock);
}
#endif
LOGIF(LT, tls_sesid = 0);
spinlock_acquire(&pollqlock);
if (dcb->evq.pending_events == 0)

View File

@ -43,7 +43,10 @@
#include <skygw_utils.h>
#include <log_manager.h>
/** Defined in log_manager.cc */
extern int lm_enabled_logfiles_bitmask;
/** Global session id; updated safely by holding session_spin */
static size_t session_id;
static SPINLOCK session_spin = SPINLOCK_INIT;
static SESSION *allSessions = NULL;
@ -216,10 +219,29 @@ session_alloc(SERVICE *service, DCB *client_dcb)
session->state = SESSION_STATE_ROUTER_READY;
spinlock_release(&session->ses_lock);
spinlock_acquire(&session_spin);
session->ses_id = ++session_id; /*< assign an id and increase */
session->next = allSessions;
allSessions = session;
spinlock_release(&session_spin);
if (session->client->user == NULL)
{
LOGIF(LT, (skygw_log_write(
LOGFILE_TRACE,
"Started session [%lu] for %s service ",
session->ses_id,
service->name)));
}
else
{
LOGIF(LT, (skygw_log_write(
LOGFILE_TRACE,
"Started %s client session [%lu] for '%s' from %s",
service->name,
session->ses_id,
session->client->user,
session->client->remote)));
}
atomic_add(&service->stats.n_sessions, 1);
atomic_add(&service->stats.n_current, 1);
CHK_SESSION(session);
@ -352,6 +374,13 @@ bool session_free(
}
free(session->filters);
}
LOGIF(LT, (skygw_log_write(
LOGFILE_TRACE,
"Stopped %s client session [%lu]",
session->service->name,
session->ses_id)));
free(session);
succp = true;

View File

@ -307,16 +307,11 @@ int dcb_remove_callback(DCB *, DCB_REASON, int (*)(struct dcb *, DCB_REASON, vo
void *);
int dcb_isvalid(DCB *); /* Check the DCB is in the linked list */
bool dcb_set_state(
DCB* dcb,
dcb_state_t new_state,
dcb_state_t* old_state);
void dcb_call_foreach (DCB_REASON reason);
bool dcb_set_state(DCB* dcb, dcb_state_t new_state, dcb_state_t* old_state);
void dcb_call_foreach (DCB_REASON reason);
size_t dcb_get_session_id(DCB* dcb);;
void dcb_call_foreach (
DCB_REASON reason);
/**
* DCB flags values
*/

View File

@ -110,6 +110,7 @@ typedef struct session {
#endif
SPINLOCK ses_lock;
session_state_t state; /**< Current descriptor state */
size_t ses_id; /**< unique session identifier */
struct dcb *client; /**< The client connection */
void *data; /**< The session data */
void *router_session;/**< The router instance data */