Remove session command processing from mariadbbackend
With the removal of the old session command implementation, the code that used it can be removed or replaced with newer constructs. As a result, the backend protocol no longer does any session command processing. The three buffer types, GWBUF_TYPE_SESCMD_RESPONSE, GWBUF_TYPE_RESPONSE_END and GWBUF_TYPE_SESCMD as well as their related macros are no longer used and can be removed.
This commit is contained in:
@ -75,76 +75,73 @@ void RWSplitSession::process_sescmd_response(SRWBackend& backend, GWBUF** ppPack
|
||||
{
|
||||
if (backend->has_session_commands())
|
||||
{
|
||||
/** We are executing a session command */
|
||||
if (GWBUF_IS_TYPE_SESCMD_RESPONSE((*ppPacket)))
|
||||
ss_dassert(GWBUF_IS_COLLECTED_RESULT(*ppPacket));
|
||||
uint8_t cmd;
|
||||
gwbuf_copy_data(*ppPacket, MYSQL_HEADER_LEN, 1, &cmd);
|
||||
uint8_t command = backend->next_session_command()->get_command();
|
||||
mxs::SSessionCommand sescmd = backend->next_session_command();
|
||||
uint64_t id = backend->complete_session_command();
|
||||
MXS_PS_RESPONSE resp = {};
|
||||
bool discard = true;
|
||||
|
||||
if (command == MXS_COM_STMT_PREPARE && cmd != MYSQL_REPLY_ERR)
|
||||
{
|
||||
uint8_t cmd;
|
||||
gwbuf_copy_data(*ppPacket, MYSQL_HEADER_LEN, 1, &cmd);
|
||||
uint8_t command = backend->next_session_command()->get_command();
|
||||
mxs::SSessionCommand sescmd = backend->next_session_command();
|
||||
uint64_t id = backend->complete_session_command();
|
||||
MXS_PS_RESPONSE resp = {};
|
||||
bool discard = true;
|
||||
// This should never fail or the backend protocol is broken
|
||||
ss_debug(bool b = )mxs_mysql_extract_ps_response(*ppPacket, &resp);
|
||||
ss_dassert(b);
|
||||
backend->add_ps_handle(id, resp.id);
|
||||
}
|
||||
|
||||
if (command == MXS_COM_STMT_PREPARE && cmd != MYSQL_REPLY_ERR)
|
||||
if (m_recv_sescmd < m_sent_sescmd && id == m_recv_sescmd + 1)
|
||||
{
|
||||
if (!m_current_master || !m_current_master->in_use() || // Session doesn't have a master
|
||||
m_current_master == backend) // This is the master's response
|
||||
{
|
||||
// This should never fail or the backend protocol is broken
|
||||
ss_debug(bool b = )mxs_mysql_extract_ps_response(*ppPacket, &resp);
|
||||
ss_dassert(b);
|
||||
backend->add_ps_handle(id, resp.id);
|
||||
}
|
||||
/** First reply to this session command, route it to the client */
|
||||
++m_recv_sescmd;
|
||||
discard = false;
|
||||
|
||||
if (m_recv_sescmd < m_sent_sescmd && id == m_recv_sescmd + 1)
|
||||
{
|
||||
if (!m_current_master || !m_current_master->in_use() || // Session doesn't have a master
|
||||
m_current_master == backend) // This is the master's response
|
||||
/** Store the master's response so that the slave responses can
|
||||
* be compared to it */
|
||||
m_sescmd_responses[id] = cmd;
|
||||
|
||||
if (cmd == MYSQL_REPLY_ERR)
|
||||
{
|
||||
/** First reply to this session command, route it to the client */
|
||||
++m_recv_sescmd;
|
||||
discard = false;
|
||||
|
||||
/** Store the master's response so that the slave responses can
|
||||
* be compared to it */
|
||||
m_sescmd_responses[id] = cmd;
|
||||
|
||||
if (cmd == MYSQL_REPLY_ERR)
|
||||
{
|
||||
MXS_INFO("Session command no. %lu failed: %s",
|
||||
id, extract_error(*ppPacket).c_str());
|
||||
}
|
||||
else if (command == MXS_COM_STMT_PREPARE)
|
||||
{
|
||||
/** Map the returned response to the internal ID */
|
||||
MXS_INFO("PS ID %u maps to internal ID %lu", resp.id, id);
|
||||
m_qc.ps_id_internal_put(resp.id, id);
|
||||
}
|
||||
|
||||
// Discard any slave connections that did not return the same result
|
||||
for (SlaveResponseList::iterator it = m_slave_responses.begin();
|
||||
it != m_slave_responses.end(); it++)
|
||||
{
|
||||
discard_if_response_differs(it->first, cmd, it->second, sescmd);
|
||||
}
|
||||
|
||||
m_slave_responses.clear();
|
||||
MXS_INFO("Session command no. %lu failed: %s",
|
||||
id, extract_error(*ppPacket).c_str());
|
||||
}
|
||||
else
|
||||
else if (command == MXS_COM_STMT_PREPARE)
|
||||
{
|
||||
/** Record slave command so that the response can be validated
|
||||
* against the master's response when it arrives. */
|
||||
m_slave_responses.push_back(std::make_pair(backend, cmd));
|
||||
/** Map the returned response to the internal ID */
|
||||
MXS_INFO("PS ID %u maps to internal ID %lu", resp.id, id);
|
||||
m_qc.ps_id_internal_put(resp.id, id);
|
||||
}
|
||||
|
||||
// Discard any slave connections that did not return the same result
|
||||
for (SlaveResponseList::iterator it = m_slave_responses.begin();
|
||||
it != m_slave_responses.end(); it++)
|
||||
{
|
||||
discard_if_response_differs(it->first, cmd, it->second, sescmd);
|
||||
}
|
||||
|
||||
m_slave_responses.clear();
|
||||
}
|
||||
else
|
||||
{
|
||||
discard_if_response_differs(backend, m_sescmd_responses[id], cmd, sescmd);
|
||||
/** Record slave command so that the response can be validated
|
||||
* against the master's response when it arrives. */
|
||||
m_slave_responses.push_back(std::make_pair(backend, cmd));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
discard_if_response_differs(backend, m_sescmd_responses[id], cmd, sescmd);
|
||||
}
|
||||
|
||||
if (discard)
|
||||
{
|
||||
gwbuf_free(*ppPacket);
|
||||
*ppPacket = NULL;
|
||||
}
|
||||
if (discard)
|
||||
{
|
||||
gwbuf_free(*ppPacket);
|
||||
*ppPacket = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -501,23 +501,20 @@ void SchemaRouterSession::process_sescmd_response(SSRBackend& bref, GWBUF** ppPa
|
||||
{
|
||||
if (bref->has_session_commands())
|
||||
{
|
||||
/** We are executing a session command */
|
||||
if (GWBUF_IS_TYPE_SESCMD_RESPONSE((*ppPacket)))
|
||||
{
|
||||
uint64_t id = bref->complete_session_command();
|
||||
ss_dassert(GWBUF_IS_COLLECTED_RESULT(*ppPacket));
|
||||
uint64_t id = bref->complete_session_command();
|
||||
|
||||
if (m_replied_sescmd < m_sent_sescmd && id == m_replied_sescmd + 1)
|
||||
{
|
||||
/** First reply to this session command, route it to the client */
|
||||
++m_replied_sescmd;
|
||||
}
|
||||
else
|
||||
{
|
||||
/** The reply to this session command has already been sent to
|
||||
* the client, discard it */
|
||||
gwbuf_free(*ppPacket);
|
||||
*ppPacket = NULL;
|
||||
}
|
||||
if (m_replied_sescmd < m_sent_sescmd && id == m_replied_sescmd + 1)
|
||||
{
|
||||
/** First reply to this session command, route it to the client */
|
||||
++m_replied_sescmd;
|
||||
}
|
||||
else
|
||||
{
|
||||
/** The reply to this session command has already been sent to
|
||||
* the client, discard it */
|
||||
gwbuf_free(*ppPacket);
|
||||
*ppPacket = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1096,28 +1093,6 @@ int SchemaRouterSession::inspect_mapping_states(SSRBackend& bref,
|
||||
return mapped ? 1 : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a fake error message from a DCB.
|
||||
* @param fail_str Custom error message
|
||||
* @param dcb DCB to use as the origin of the error
|
||||
*/
|
||||
void create_error_reply(char* fail_str, DCB* dcb)
|
||||
{
|
||||
MXS_INFO("change_current_db: failed to change database: %s", fail_str);
|
||||
GWBUF* errbuf = modutil_create_mysql_err_msg(1, 0, 1049, "42000", fail_str);
|
||||
|
||||
if (errbuf == NULL)
|
||||
{
|
||||
MXS_ERROR("Creating buffer for error message failed.");
|
||||
return;
|
||||
}
|
||||
/** Set flags that help router to identify session commands reply */
|
||||
gwbuf_set_type(errbuf, GWBUF_TYPE_SESCMD_RESPONSE);
|
||||
gwbuf_set_type(errbuf, GWBUF_TYPE_RESPONSE_END);
|
||||
|
||||
poll_add_epollin_event_to_dcb(dcb, errbuf);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read new database name from COM_INIT_DB packet or a literal USE ... COM_QUERY
|
||||
* packet, check that it exists in the hashtable and copy its name to MYSQL_session.
|
||||
|
Reference in New Issue
Block a user