Remove unused locks and variables

Removed unused spinlocks from DCBs, sessions and the MySQL protocol
structs. They were used in a context where only one thread has access to
the structure.

Removed unused member variables from DCBs.
This commit is contained in:
Markus Mäkelä
2017-02-03 17:26:55 +02:00
parent 517ecd9a12
commit ce5cd69eb3
15 changed files with 36 additions and 217 deletions

View File

@ -638,9 +638,7 @@ gw_reply_on_error(DCB *dcb, mxs_auth_state_t state)
session->router_session,
errbuf, dcb, ERRACT_REPLY_CLIENT, &succp);
spinlock_acquire(&session->ses_lock);
session->state = SESSION_STATE_STOPPING;
spinlock_release(&session->ses_lock);
ss_dassert(dcb->dcb_errhandle_called);
}
else
@ -737,9 +735,7 @@ gw_read_and_write(DCB *dcb)
if (!succp)
{
spinlock_acquire(&session->ses_lock);
session->state = SESSION_STATE_STOPPING;
spinlock_release(&session->ses_lock);
}
return 0;
}
@ -1174,22 +1170,7 @@ static int gw_error_backend_event(DCB *dcb)
0,
"Lost connection to backend server.");
spinlock_acquire(&session->ses_lock);
ses_state = session->state;
spinlock_release(&session->ses_lock);
/**
* Session might be initialized when DCB already is in the poll set.
* Thus hangup can occur in the middle of session initialization.
* Only complete and successfully initialized sessions allow for
* calling error handler.
*/
while (ses_state == SESSION_STATE_READY)
{
spinlock_acquire(&session->ses_lock);
ses_state = session->state;
spinlock_release(&session->ses_lock);
}
if (ses_state != SESSION_STATE_ROUTER_READY)
{
@ -1226,9 +1207,7 @@ static int gw_error_backend_event(DCB *dcb)
*/
if (!succp)
{
spinlock_acquire(&session->ses_lock);
session->state = SESSION_STATE_STOPPING;
spinlock_release(&session->ses_lock);
}
retblock:
@ -1278,22 +1257,7 @@ static int gw_backend_hangup(DCB *dcb)
0,
"Lost connection to backend server.");
spinlock_acquire(&session->ses_lock);
ses_state = session->state;
spinlock_release(&session->ses_lock);
/**
* Session might be initialized when DCB already is in the poll set.
* Thus hangup can occur in the middle of session initialization.
* Only complete and successfully initialized sessions allow for
* calling error handler.
*/
while (ses_state == SESSION_STATE_READY)
{
spinlock_acquire(&session->ses_lock);
ses_state = session->state;
spinlock_release(&session->ses_lock);
}
if (ses_state != SESSION_STATE_ROUTER_READY)
{
@ -1331,9 +1295,7 @@ static int gw_backend_hangup(DCB *dcb)
/** There are no required backends available, close session. */
if (!succp)
{
spinlock_acquire(&session->ses_lock);
session->state = SESSION_STATE_STOPPING;
spinlock_release(&session->ses_lock);
}
retblock:
@ -1372,7 +1334,7 @@ static int gw_backend_close(DCB *dcb)
* but client's close and adding client's DCB to zombies list is executed
* only if client's DCB's state does _not_ change in parallel.
*/
spinlock_acquire(&session->ses_lock);
/**
* If session->state is STOPPING, start closing client session.
* Otherwise only this backend connection is closed.
@ -1382,19 +1344,9 @@ static int gw_backend_close(DCB *dcb)
{
if (session->client_dcb->state == DCB_STATE_POLLING)
{
spinlock_release(&session->ses_lock);
/** Close client DCB */
dcb_close(session->client_dcb);
}
else
{
spinlock_release(&session->ses_lock);
}
}
else
{
spinlock_release(&session->ses_lock);
}
}
return 1;
@ -1472,9 +1424,7 @@ static int backend_write_delayqueue(DCB *dcb, GWBUF *buffer)
if (!succp)
{
spinlock_acquire(&session->ses_lock);
session->state = SESSION_STATE_STOPPING;
spinlock_release(&session->ses_lock);
}
}
@ -1565,8 +1515,6 @@ static int gw_change_user(DCB *backend,
memcpy(&backend_protocol->charset, client_auth_packet, sizeof(int));
}
spinlock_acquire(&in_session->ses_lock);
/* save current_database name */
strcpy(current_database, current_session->db);
@ -1586,7 +1534,6 @@ static int gw_change_user(DCB *backend,
sizeof(client_protocol->scramble),
username, client_sha1);
strcpy(current_session->db, current_database);
spinlock_release(&in_session->ses_lock);
if (auth_ret != 0)
{
@ -1594,7 +1541,6 @@ static int gw_change_user(DCB *backend,
{
/* Try authentication again with new repository data */
/* Note: if no auth client authentication will fail */
spinlock_acquire(&in_session->ses_lock);
*current_session->db = 0;
auth_ret = gw_check_mysql_scramble_data(
backend->session->client_dcb,
@ -1603,7 +1549,6 @@ static int gw_change_user(DCB *backend,
sizeof(client_protocol->scramble),
username, client_sha1);
strcpy(current_session->db, current_database);
spinlock_release(&in_session->ses_lock);
}
}

View File

@ -1362,7 +1362,6 @@ gw_client_close(DCB *dcb)
if (session != NULL && SESSION_STATE_DUMMY != session->state)
{
CHK_SESSION(session);
spinlock_acquire(&session->ses_lock);
if (session->state != SESSION_STATE_STOPPING)
{
@ -1376,14 +1375,9 @@ gw_client_close(DCB *dcb)
*/
if (session->router_session != NULL)
{
spinlock_release(&session->ses_lock);
/** Close router session and all its connections */
router->closeSession(router_instance, session->router_session);
}
else
{
spinlock_release(&session->ses_lock);
}
}
return 1;
}

View File

@ -132,27 +132,21 @@ void mysql_protocol_done(DCB* dcb)
p = (MySQLProtocol *)dcb->protocol;
spinlock_acquire(&p->protocol_lock);
if (p->protocol_state != MYSQL_PROTOCOL_ACTIVE)
if (p->protocol_state == MYSQL_PROTOCOL_ACTIVE)
{
goto retblock;
scmd = p->protocol_cmd_history;
while (scmd != NULL)
{
scmd2 = scmd->scom_next;
MXS_FREE(scmd);
scmd = scmd2;
}
gwbuf_free(p->stored_query);
p->protocol_state = MYSQL_PROTOCOL_DONE;
}
scmd = p->protocol_cmd_history;
while (scmd != NULL)
{
scmd2 = scmd->scom_next;
MXS_FREE(scmd);
scmd = scmd2;
}
gwbuf_free(p->stored_query);
p->protocol_state = MYSQL_PROTOCOL_DONE;
retblock:
spinlock_release(&p->protocol_lock);
}
/**
@ -660,8 +654,6 @@ void protocol_archive_srv_command(MySQLProtocol* p)
CHK_PROTOCOL(p);
spinlock_acquire(&p->protocol_lock);
if (p->protocol_state != MYSQL_PROTOCOL_ACTIVE)
{
goto retblock;
@ -710,7 +702,6 @@ void protocol_archive_srv_command(MySQLProtocol* p)
}
retblock:
spinlock_release(&p->protocol_lock);
CHK_PROTOCOL(p);
}
@ -725,11 +716,10 @@ void protocol_add_srv_command(MySQLProtocol* p,
#if defined(EXTRA_SS_DEBUG)
server_command_t* c;
#endif
spinlock_acquire(&p->protocol_lock);
if (p->protocol_state != MYSQL_PROTOCOL_ACTIVE)
{
goto retblock;
return;
}
/** this is the only server command in protocol */
if (p->protocol_command.scom_cmd == MYSQL_COM_UNDEFINED)
@ -758,8 +748,6 @@ void protocol_add_srv_command(MySQLProtocol* p,
c = c->scom_next;
}
#endif
retblock:
spinlock_release(&p->protocol_lock);
}
@ -772,7 +760,7 @@ retblock:
void protocol_remove_srv_command(MySQLProtocol* p)
{
server_command_t* s;
spinlock_acquire(&p->protocol_lock);
s = &p->protocol_command;
#if defined(EXTRA_SS_DEBUG)
MXS_INFO("Removed command %s from fd %d.",
@ -788,8 +776,6 @@ void protocol_remove_srv_command(MySQLProtocol* p)
p->protocol_command = *(s->scom_next);
MXS_FREE(s->scom_next);
}
spinlock_release(&p->protocol_lock);
}
mysql_server_cmd_t protocol_get_srv_command(MySQLProtocol* p,
@ -889,10 +875,8 @@ bool protocol_get_response_status(MySQLProtocol* p,
CHK_PROTOCOL(p);
spinlock_acquire(&p->protocol_lock);
*npackets = p->protocol_command.scom_nresponse_packets;
*nbytes = (ssize_t)p->protocol_command.scom_nbytes_to_read;
spinlock_release(&p->protocol_lock);
if (*npackets < 0 && *nbytes == 0)
{
@ -912,14 +896,10 @@ void protocol_set_response_status(MySQLProtocol* p,
{
CHK_PROTOCOL(p);
spinlock_acquire(&p->protocol_lock);
p->protocol_command.scom_nbytes_to_read = nbytes;
ss_dassert(p->protocol_command.scom_nbytes_to_read >= 0);
p->protocol_command.scom_nresponse_packets = npackets_left;
spinlock_release(&p->protocol_lock);
}
char* create_auth_failed_msg(GWBUF*readbuf,