diff --git a/server/core/poll.c b/server/core/poll.c index 54308f7df..75a178186 100644 --- a/server/core/poll.c +++ b/server/core/poll.c @@ -155,6 +155,8 @@ return_rc: /** * Remove a descriptor from the set of descriptors within the * polling environment. + * The state change command may fail because concurrent threads may call + * dcb_set_state simultaneously and the conflict is prevented in dcb_set_state. * * @param dcb The descriptor to remove * @return -1 on error or 0 on success @@ -169,6 +171,10 @@ poll_remove_dcb(DCB *dcb) CHK_DCB(dcb); + if (dcb->state != DCB_STATE_POLLING) { + goto return_rc; + } + /** * Set state to NOPOLLING and remove dcb from poll set. */ @@ -195,22 +201,6 @@ poll_remove_dcb(DCB *dcb) rc = 0; goto return_rc; } - /** - * State transition failed. This may be due some more serious error - * in how dcb is handled. - */ - else - { - skygw_log_write_flush( - LOGFILE_ERROR, - "%lu [poll_remove_dcb] Unable to set state %s for dcb %p " - "in state %s. Removing from poll set failed.", - pthread_self(), - STRDCBSTATE(new_state), - STRDCBSTATE(old_state)); - ss_dassert(false); - goto return_rc; - } /** Set bit for each maxscale thread */ bitmask_copy(&dcb->memdata.bitmask, poll_bitmask()); @@ -315,10 +305,9 @@ poll_waitevents(void *arg) if (dcb_fake_write_ev[dcb->fd] != 0) { skygw_log_write( LOGFILE_DEBUG, - "%lu %d [poll_waitevents] " + "%lu [poll_waitevents] " "Added fake events %d to ev %d.", pthread_self(), - thread_id, dcb_fake_write_ev[dcb->fd], ev); ev |= dcb_fake_write_ev[dcb->fd]; @@ -333,9 +322,8 @@ poll_waitevents(void *arg) skygw_log_write_flush( LOGFILE_DEBUG, - "%lu %d [poll_waitevents] event %d dcb %p", + "%lu [poll_waitevents] event %d dcb %p", pthread_self(), - thread_id, ev, dcb); @@ -347,10 +335,9 @@ poll_waitevents(void *arg) eno = dcb_fake_write_errno[dcb->fd]; skygw_log_write( LOGFILE_DEBUG, - "%lu %d [poll_waitevents] " + "%lu [poll_waitevents] " "Added fake errno %d. %s", pthread_self(), - thread_id, eno, strerror(eno)); } @@ -359,10 +346,9 @@ poll_waitevents(void *arg) if (eno != 0) { skygw_log_write( LOGFILE_DEBUG, - "%lu %d [poll_waitevents] " + "%lu [poll_waitevents] " "EPOLLERR due %d, %s.", pthread_self(), - thread_id, eno, strerror(eno)); } @@ -404,10 +390,9 @@ poll_waitevents(void *arg) { skygw_log_write( LOGFILE_DEBUG, - "%lu %d [poll_waitevents] " + "%lu [poll_waitevents] " "Accept in fd %d", pthread_self(), - thread_id, dcb->fd); atomic_add(&pollStats.n_accept, 1); dcb->func.accept(dcb); @@ -416,10 +401,9 @@ poll_waitevents(void *arg) { skygw_log_write( LOGFILE_DEBUG, - "%lu %d [poll_waitevents] " + "%lu [poll_waitevents] " "Read in dcb %p fd %d", pthread_self(), - thread_id, dcb, dcb->fd); atomic_add(&pollStats.n_read, 1); diff --git a/server/core/session.c b/server/core/session.c index 8344f9504..05c0d9e71 100644 --- a/server/core/session.c +++ b/server/core/session.c @@ -70,8 +70,8 @@ session_alloc(SERVICE *service, DCB *client) errno = 0; skygw_log_write_flush( LOGFILE_ERROR, - "%lu [session_alloc] Allocating memory for session " - "object failed. Errno %d, %s.", + "%lu [session_alloc] FAiled to allocate memory for session " + "object due error %d, %s.", pthread_self(), eno, strerror(eno)); @@ -126,8 +126,8 @@ session_alloc(SERVICE *service, DCB *client) client->session = NULL; skygw_log_write_flush( LOGFILE_ERROR, - "%lu [session_alloc] Creating router client session " - "failed. Freeing session.", + "%lu [session_alloc] Failed to create router " + "client session. Freeing allocated resources.", pthread_self()); free(session); session = NULL; diff --git a/server/modules/routing/readconnroute.c b/server/modules/routing/readconnroute.c index 21b09dfb1..ef882bd07 100644 --- a/server/modules/routing/readconnroute.c +++ b/server/modules/routing/readconnroute.c @@ -304,9 +304,10 @@ int i; if(inst->servers[i]) { skygw_log_write( LOGFILE_TRACE, - "Examine server in port %d with %d connections. " - "Status is %d, " + "%lu [newSession] Examine server in port %d with " + "%d connections. Status is %d, " "inst->bitvalue is %d", + pthread_self(), inst->servers[i]->server->port, inst->servers[i]->current_connection_count, inst->servers[i]->server->status, @@ -348,8 +349,9 @@ int i; if (!candidate) { skygw_log_write_flush( LOGFILE_ERROR, - "%lu [newSession] Couldn't find eligible candidate " - "server. Exiting.", + "%lu [newSession] Failed to create new routing session. " + "Couldn't find eligible candidate server. Freeing " + "allocated resources.", pthread_self()); free(client_ses); return NULL; @@ -380,8 +382,9 @@ int i; atomic_add(&candidate->current_connection_count, -1); skygw_log_write( LOGFILE_ERROR, - "%lu [newSession] Failed to establish connection to " - "server in port %d. Exiting.", + "%lu [newSession] Failed to create new routing session. " + "Couldn't establish connection to candidate server " + "listening to port %d. Freeing allocated resources.", pthread_self(), candidate->server->port); free(client_ses); @@ -493,38 +496,38 @@ bool succp = false; static int routeQuery(ROUTER *instance, void *router_session, GWBUF *queue) { -ROUTER_INSTANCE *inst = (ROUTER_INSTANCE *)instance; -ROUTER_CLIENT_SES *session = (ROUTER_CLIENT_SES *)router_session; -uint8_t *payload = GWBUF_DATA(queue); -int mysql_command; -int rc; + ROUTER_INSTANCE *inst = (ROUTER_INSTANCE *)instance; + ROUTER_CLIENT_SES *rsession = (ROUTER_CLIENT_SES *)router_session; + uint8_t *payload = GWBUF_DATA(queue); + int mysql_command; + int rc; inst->stats.n_queries++; - mysql_command = MYSQL_GET_COMMAND(payload); switch(mysql_command) { case MYSQL_COM_CHANGE_USER: - rc = session->backend_dcb->func.auth( - session->backend_dcb, + rc = rsession->backend_dcb->func.auth( + rsession->backend_dcb, NULL, - session->backend_dcb->session, + rsession->backend_dcb->session, queue); break; default: - rc = session->backend_dcb->func.write( - session->backend_dcb, + rc = rsession->backend_dcb->func.write( + rsession->backend_dcb, queue); - } - CHK_PROTOCOL(((MySQLProtocol*)session->backend_dcb->protocol)); + } + + CHK_PROTOCOL(((MySQLProtocol*)rsession->backend_dcb->protocol)); skygw_log_write( LOGFILE_DEBUG, "%lu [readconnroute:routeQuery] Routed command %d to dcb %p " "with return value %d.", pthread_self(), mysql_command, - session->backend_dcb, + rsession->backend_dcb, rc); return rc;