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

@ -62,12 +62,10 @@ GWBUF* modutil_create_mysql_err_msg(int packet_number,
* @param reply Buffer to use * @param reply Buffer to use
* @param n_found Number of previous found packets * @param n_found Number of previous found packets
* @param more Set to true of more results exist * @param more Set to true of more results exist
* @param offset_out Initial offset into the buffer. This offset is set to point
* to the first byte after the last packet in the buffer.
* *
* @return Total number of EOF and ERR packets including the ones already found * @return Total number of EOF and ERR packets including the ones already found
*/ */
int modutil_count_signal_packets(GWBUF *reply, int n_found, bool* more, size_t* offset_out); int modutil_count_signal_packets(GWBUF *reply, int n_found, bool* more);
mxs_pcre2_result_t modutil_mysql_wildcard_match(const char* pattern, const char* string); mxs_pcre2_result_t modutil_mysql_wildcard_match(const char* pattern, const char* string);

View File

@ -432,21 +432,19 @@ bool mxs_mysql_is_ok_packet(GWBUF *buffer);
* @brief Check if a buffer contains a result set * @brief Check if a buffer contains a result set
* *
* @param buffer Buffer to check * @param buffer Buffer to check
* @param offset Offset into the buffer
* *
* @return True if the @c buffer at @c offset contains the start of a result set * @return True if the @c buffer contains the start of a result set
*/ */
bool mxs_mysql_is_result_set(GWBUF *buffer, size_t offset); bool mxs_mysql_is_result_set(GWBUF *buffer);
/** /**
* @brief Check if the OK packet is followed by another result * @brief Check if the OK packet is followed by another result
* *
* @param buffer Buffer to check * @param buffer Buffer to check
* @param offset Offset into the buffer
* *
* @return True if more results are expected * @return True if more results are expected
*/ */
bool mxs_mysql_more_results_after_ok(GWBUF *buffer, size_t extra_offset); bool mxs_mysql_more_results_after_ok(GWBUF *buffer);
/** Get current command for a session */ /** Get current command for a session */
mysql_server_cmd_t mxs_mysql_current_command(MXS_SESSION* session); mysql_server_cmd_t mxs_mysql_current_command(MXS_SESSION* session);

View File

@ -635,17 +635,18 @@ GWBUF* modutil_get_complete_packets(GWBUF **p_readbuf)
return complete; return complete;
} }
int modutil_count_signal_packets(GWBUF *reply, int n_found, bool* more, size_t* offset) int modutil_count_signal_packets(GWBUF *reply, int n_found, bool* more)
{ {
unsigned int len = gwbuf_length(reply); unsigned int len = gwbuf_length(reply);
int eof = 0; int eof = 0;
int err = 0; int err = 0;
size_t offset = 0;
while (*offset < len) while (offset < len)
{ {
uint8_t header[MYSQL_HEADER_LEN + 5]; // Maximum size of an EOF packet uint8_t header[MYSQL_HEADER_LEN + 5]; // Maximum size of an EOF packet
gwbuf_copy_data(reply, *offset, MYSQL_HEADER_LEN + 1, header); gwbuf_copy_data(reply, offset, MYSQL_HEADER_LEN + 1, header);
unsigned int pktlen = MYSQL_GET_PAYLOAD_LEN(header) + MYSQL_HEADER_LEN; unsigned int pktlen = MYSQL_GET_PAYLOAD_LEN(header) + MYSQL_HEADER_LEN;
@ -659,16 +660,16 @@ int modutil_count_signal_packets(GWBUF *reply, int n_found, bool* more, size_t*
eof++; eof++;
} }
if (*offset + pktlen >= len || (eof + err + n_found) >= 2) if (offset + pktlen >= len || (eof + err + n_found) >= 2)
{ {
gwbuf_copy_data(reply, *offset, sizeof(header), header); gwbuf_copy_data(reply, offset, sizeof(header), header);
uint16_t* status = (uint16_t*)(header + MYSQL_HEADER_LEN + 1 + 2); // Skip command and warning count uint16_t* status = (uint16_t*)(header + MYSQL_HEADER_LEN + 1 + 2); // Skip command and warning count
*more = ((*status) & SERVER_MORE_RESULTS_EXIST); *more = ((*status) & SERVER_MORE_RESULTS_EXIST);
*offset += pktlen; offset += pktlen;
break; break;
} }
*offset += pktlen; offset += pktlen;
} }
int total = err + eof + n_found; int total = err + eof + n_found;

View File

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

View File

@ -1539,12 +1539,12 @@ bool mxs_mysql_is_ok_packet(GWBUF *buffer)
return rval; return rval;
} }
bool mxs_mysql_is_result_set(GWBUF *buffer, size_t offset) bool mxs_mysql_is_result_set(GWBUF *buffer)
{ {
bool rval = false; bool rval = false;
uint8_t cmd; 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) switch (cmd)
{ {
@ -1565,48 +1565,28 @@ bool mxs_mysql_is_result_set(GWBUF *buffer, size_t offset)
return rval; 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; 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 // Copy the payload without the command byte
uint8_t header[MYSQL_HEADER_LEN + 1];
if (gwbuf_copy_data(buffer, offset, sizeof(header), header) != sizeof(header))
{
break;
}
size_t len = gw_mysql_get_byte3(header); 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) uint8_t* ptr = data;
{ ptr += mxs_leint_bytes(ptr);
// Copy the payload without the command byte ptr += mxs_leint_bytes(ptr);
uint8_t data[len - 1]; uint16_t* status = (uint16_t*)ptr;
gwbuf_copy_data(buffer, offset + MYSQL_HEADER_LEN + 1, sizeof(data), data); rval = (*status) & SERVER_MORE_RESULTS_EXIST;
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");
}
} }
return rval; 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) bool reply_is_complete(backend_ref_t* bref, GWBUF *buffer)
{ {
size_t offset = 0; if (bref->reply_state == REPLY_STATE_START && !mxs_mysql_is_result_set(buffer))
size_t len = gwbuf_length(buffer);
while (offset < len)
{ {
if (bref->reply_state == REPLY_STATE_START && if (!mxs_mysql_more_results_after_ok(buffer))
!mxs_mysql_is_result_set(buffer, offset))
{ {
if (!mxs_mysql_more_results_after_ok(buffer, offset)) /** Not a result set, we have the complete response */
{ LOG_RS(bref, REPLY_STATE_DONE);
/** Not a result set, we have the complete response */ bref->reply_state = REPLY_STATE_DONE;
LOG_RS(bref, REPLY_STATE_DONE); }
bref->reply_state = REPLY_STATE_DONE; }
break; else
} {
bool more = false;
int old_eof = bref->reply_state == REPLY_STATE_RSET_ROWS ? 1 : 0;
uint8_t header[MYSQL_HEADER_LEN]; int n_eof = modutil_count_signal_packets(buffer, old_eof, &more);
gwbuf_copy_data(buffer, offset, sizeof(header), header); mysql_server_cmd_t cmd = mxs_mysql_current_command(bref->bref_dcb->session);
offset += MYSQL_GET_PAYLOAD_LEN(header) + MYSQL_HEADER_LEN;
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 else
{ {
bool more = false; /** We either have a complete result set or a response to
int old_eof = bref->reply_state == REPLY_STATE_RSET_ROWS ? 1 : 0; * 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); if (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 */ /** The server will send more resultsets */
LOG_RS(bref, REPLY_STATE_RSET_COLDEF); LOG_RS(bref, REPLY_STATE_START);
bref->reply_state = REPLY_STATE_RSET_COLDEF; bref->reply_state = REPLY_STATE_START;
}
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;
}
} }
} }
} }