Remove multi-packet additions to response parsing

The additions to the packet parsing code weren't necessary once the
statement output change was reverted.
This commit is contained in:
Markus Mäkelä
2017-04-04 09:55:24 +03:00
parent 5037646846
commit 8fe31f360d
6 changed files with 64 additions and 105 deletions

View File

@ -701,8 +701,7 @@ gw_read_and_write(DCB *dcb)
mxs_mysql_is_result_set(read_buffer))
{
bool more = false;
size_t offset = 0;
if (modutil_count_signal_packets(read_buffer, 0, &more, &offset) != 2)
if (modutil_count_signal_packets(read_buffer, 0, &more) != 2)
{
dcb->dcb_readqueue = read_buffer;
return 0;

View File

@ -1539,12 +1539,12 @@ bool mxs_mysql_is_ok_packet(GWBUF *buffer)
return rval;
}
bool mxs_mysql_is_result_set(GWBUF *buffer, size_t offset)
bool mxs_mysql_is_result_set(GWBUF *buffer)
{
bool rval = false;
uint8_t cmd;
if (gwbuf_copy_data(buffer, offset + MYSQL_HEADER_LEN, 1, &cmd))
if (gwbuf_copy_data(buffer, MYSQL_HEADER_LEN, 1, &cmd))
{
switch (cmd)
{
@ -1565,48 +1565,28 @@ bool mxs_mysql_is_result_set(GWBUF *buffer, size_t offset)
return rval;
}
bool mxs_mysql_more_results_after_ok(GWBUF *buffer, size_t extra_offset)
bool mxs_mysql_more_results_after_ok(GWBUF *buffer)
{
bool rval = false;
size_t buflen = gwbuf_length(buffer);
size_t offset = extra_offset;
while (offset < buflen)
// Copy the header
uint8_t header[MYSQL_HEADER_LEN + 1];
gwbuf_copy_data(buffer, 0, sizeof(header), header);
if (header[4] == MYSQL_REPLY_OK)
{
// Copy the header
uint8_t header[MYSQL_HEADER_LEN + 1];
if (gwbuf_copy_data(buffer, offset, sizeof(header), header) != sizeof(header))
{
break;
}
// Copy the payload without the command byte
size_t len = gw_mysql_get_byte3(header);
uint8_t data[len - 1];
gwbuf_copy_data(buffer, MYSQL_HEADER_LEN + 1, sizeof(data), data);
if (header[4] == MYSQL_REPLY_OK)
{
// Copy the payload without the command byte
uint8_t data[len - 1];
gwbuf_copy_data(buffer, offset + MYSQL_HEADER_LEN + 1, sizeof(data), data);
uint8_t* ptr = data;
ptr += mxs_leint_bytes(ptr);
ptr += mxs_leint_bytes(ptr);
uint16_t* status = (uint16_t*)ptr;
rval = (*status) & SERVER_MORE_RESULTS_EXIST;
}
else
{
break;
}
offset += len + MYSQL_HEADER_LEN;
if (offset < buflen)
{
MXS_DEBUG("More data after an OK packet, expecting results: %s", rval ? "YES" : "NO");
}
uint8_t* ptr = data;
ptr += mxs_leint_bytes(ptr);
ptr += mxs_leint_bytes(ptr);
uint16_t* status = (uint16_t*)ptr;
rval = (*status) & SERVER_MORE_RESULTS_EXIST;
}
return rval;
}

View File

@ -719,65 +719,48 @@ static void diagnostics(MXS_ROUTER *instance, DCB *dcb)
*/
bool reply_is_complete(backend_ref_t* bref, GWBUF *buffer)
{
size_t offset = 0;
size_t len = gwbuf_length(buffer);
while (offset < len)
if (bref->reply_state == REPLY_STATE_START && !mxs_mysql_is_result_set(buffer))
{
if (bref->reply_state == REPLY_STATE_START &&
!mxs_mysql_is_result_set(buffer, offset))
if (!mxs_mysql_more_results_after_ok(buffer))
{
if (!mxs_mysql_more_results_after_ok(buffer, offset))
{
/** Not a result set, we have the complete response */
LOG_RS(bref, REPLY_STATE_DONE);
bref->reply_state = REPLY_STATE_DONE;
break;
}
/** Not a result set, we have the complete response */
LOG_RS(bref, REPLY_STATE_DONE);
bref->reply_state = REPLY_STATE_DONE;
}
}
else
{
bool more = false;
int old_eof = bref->reply_state == REPLY_STATE_RSET_ROWS ? 1 : 0;
uint8_t header[MYSQL_HEADER_LEN];
gwbuf_copy_data(buffer, offset, sizeof(header), header);
offset += MYSQL_GET_PAYLOAD_LEN(header) + MYSQL_HEADER_LEN;
int n_eof = modutil_count_signal_packets(buffer, old_eof, &more);
mysql_server_cmd_t cmd = mxs_mysql_current_command(bref->bref_dcb->session);
if (n_eof == 0)
{
/** Waiting for the EOF packet after the column definitions */
LOG_RS(bref, REPLY_STATE_RSET_COLDEF);
bref->reply_state = REPLY_STATE_RSET_COLDEF;
}
else if (n_eof == 1 && cmd != MYSQL_COM_FIELD_LIST)
{
/** Waiting for the EOF packet after the rows */
LOG_RS(bref, REPLY_STATE_RSET_ROWS);
bref->reply_state = REPLY_STATE_RSET_ROWS;
}
else
{
bool more = false;
int old_eof = bref->reply_state == REPLY_STATE_RSET_ROWS ? 1 : 0;
/** We either have a complete result set or a response to
* a COM_FIELD_LIST command */
ss_dassert(n_eof == 2 || (n_eof == 1 && cmd == MYSQL_COM_FIELD_LIST));
LOG_RS(bref, REPLY_STATE_DONE);
bref->reply_state = REPLY_STATE_DONE;
int n_eof = modutil_count_signal_packets(buffer, old_eof, &more, &offset);
mysql_server_cmd_t cmd = mxs_mysql_current_command(bref->bref_dcb->session);
if (n_eof == 0)
if (more)
{
/** Waiting for the EOF packet after the column definitions */
LOG_RS(bref, REPLY_STATE_RSET_COLDEF);
bref->reply_state = REPLY_STATE_RSET_COLDEF;
}
else if (n_eof == 1 && cmd != MYSQL_COM_FIELD_LIST)
{
/** Waiting for the EOF packet after the rows */
LOG_RS(bref, REPLY_STATE_RSET_ROWS);
bref->reply_state = REPLY_STATE_RSET_ROWS;
}
else
{
/** We either have a complete result set or a response to
* a COM_FIELD_LIST command */
ss_dassert(n_eof == 2 || (n_eof == 1 && cmd == MYSQL_COM_FIELD_LIST));
LOG_RS(bref, REPLY_STATE_DONE);
bref->reply_state = REPLY_STATE_DONE;
if (more)
{
/** The server will send more resultsets */
LOG_RS(bref, REPLY_STATE_START);
bref->reply_state = REPLY_STATE_START;
}
else
{
ss_dassert(offset == len);
break;
}
/** The server will send more resultsets */
LOG_RS(bref, REPLY_STATE_START);
bref->reply_state = REPLY_STATE_START;
}
}
}