Add more packet splitting debug assertions

Having more debug assertions in functions that split packets guarantees
that they work as expected.
This commit is contained in:
Markus Mäkelä
2018-07-20 11:16:39 +03:00
parent d68f20b75b
commit bbe4f42935
3 changed files with 13 additions and 12 deletions

View File

@ -795,6 +795,7 @@ gwbuf_make_contiguous(GWBUF *orig)
if (orig == NULL) if (orig == NULL)
{ {
ss_info_dassert(!true, "gwbuf_make_contiguous: NULL buffer");
return NULL; return NULL;
} }
if (orig->next == NULL) if (orig->next == NULL)

View File

@ -485,6 +485,17 @@ int modutil_send_mysql_err_packet(DCB *dcb,
return dcb->func.write(dcb, buf); return dcb->func.write(dcb, buf);
} }
// Helper function for debug assertions
static bool only_one_packet(GWBUF* buffer)
{
ss_dassert(buffer);
uint8_t header[4] = {};
gwbuf_copy_data(buffer, 0, MYSQL_HEADER_LEN, header);
size_t packet_len = gw_mysql_get_byte3(header);
size_t buffer_len = gwbuf_length(buffer);
return packet_len + MYSQL_HEADER_LEN == buffer_len;
}
/** /**
* Return the first packet from a buffer. * Return the first packet from a buffer.
* *
@ -531,6 +542,7 @@ GWBUF* modutil_get_next_MySQL_packet(GWBUF** p_readbuf)
} }
} }
ss_dassert(!packet || only_one_packet(packet));
return packet; return packet;
} }

View File

@ -1576,17 +1576,6 @@ static bool reauthenticate_client(MXS_SESSION* session, GWBUF* packetbuf)
return rval; return rval;
} }
// Helper function for debug assertions
static bool only_one_packet(GWBUF* buffer)
{
ss_dassert(buffer);
uint8_t header[4] = {};
gwbuf_copy_data(buffer, 0, MYSQL_HEADER_LEN, header);
size_t packet_len = gw_mysql_get_byte3(header);
size_t buffer_len = gwbuf_length(buffer);
return packet_len + MYSQL_HEADER_LEN == buffer_len;
}
/** /**
* Detect if buffer includes partial mysql packet or multiple packets. * Detect if buffer includes partial mysql packet or multiple packets.
* Store partial packet to dcb_readqueue. Send complete packets one by one * Store partial packet to dcb_readqueue. Send complete packets one by one
@ -1616,7 +1605,6 @@ static int route_by_statement(MXS_SESSION* session, uint64_t capabilities, GWBUF
if (packetbuf != NULL) if (packetbuf != NULL)
{ {
ss_dassert(only_one_packet(packetbuf));
CHK_GWBUF(packetbuf); CHK_GWBUF(packetbuf);
MySQLProtocol* proto = (MySQLProtocol*)session->client_dcb->protocol; MySQLProtocol* proto = (MySQLProtocol*)session->client_dcb->protocol;