C_DEBUG removed and added a check for packetlen < MAXROWS_EOF_PACKET_LEN

C_DEBUG removed.
A check is now made for packetlen < MAXROWS_EOF_PACKET_LEN.
An empty result set, OK, is send in such situation
This commit is contained in:
MassimilianoPinto
2016-11-07 16:19:38 +01:00
parent 9f01a4612d
commit c36e5f6ba4
2 changed files with 53 additions and 20 deletions

View File

@ -57,8 +57,6 @@ static int clientReply(FILTER *instance, void *sdata, GWBUF *queue);
static void diagnostics(FILTER *instance, void *sdata, DCB *dcb); static void diagnostics(FILTER *instance, void *sdata, DCB *dcb);
static uint64_t getCapabilities(void); static uint64_t getCapabilities(void);
#define C_DEBUG(format, ...) MXS_LOG_MESSAGE(LOG_NOTICE, format, ##__VA_ARGS__)
/* Global symbols of the Module */ /* Global symbols of the Module */
MODULE_INFO info = MODULE_INFO info =
@ -310,7 +308,11 @@ static int routeQuery(FILTER *instance, void *sdata, GWBUF *packet)
} }
} }
C_DEBUG("Maxrows filter is sending data."); if (csdata->instance->config.debug & MAXROWS_DEBUG_DECISIONS)
{
MXS_NOTICE("Maxrows filter is sending data.");
}
return csdata->down.routeQuery(csdata->down.instance, csdata->down.session, packet); return csdata->down.routeQuery(csdata->down.instance, csdata->down.session, packet);
} }
@ -343,10 +345,13 @@ static int clientReply(FILTER *instance, void *sdata, GWBUF *data)
{ {
if (gwbuf_length(csdata->res.data) > csdata->instance->config.max_resultset_size) if (gwbuf_length(csdata->res.data) > csdata->instance->config.max_resultset_size)
{ {
C_DEBUG("Current size %uB of resultset, at least as much " if (csdata->instance->config.debug & MAXROWS_DEBUG_DISCARDING)
"as maximum allowed size %uKiB. Not returning data.", {
gwbuf_length(csdata->res.data), MXS_NOTICE("Current size %uB of resultset, at least as much "
csdata->instance->config.max_resultset_size / 1024); "as maximum allowed size %uKiB. Not returning data.",
gwbuf_length(csdata->res.data),
csdata->instance->config.max_resultset_size / 1024);
}
csdata->state = MAXROWS_DISCARDING_RESPONSE; csdata->state = MAXROWS_DISCARDING_RESPONSE;
} }
@ -585,19 +590,28 @@ static int handle_expecting_response(MAXROWS_SESSION_DATA *csdata)
{ {
case 0x00: // OK case 0x00: // OK
case 0xff: // ERR case 0xff: // ERR
C_DEBUG("OK or ERR"); if (csdata->instance->config.debug & MAXROWS_DEBUG_DECISIONS)
{
MXS_NOTICE("OK or ERR");
}
rv = send_upstream(csdata); rv = send_upstream(csdata);
csdata->state = MAXROWS_IGNORING_RESPONSE; csdata->state = MAXROWS_IGNORING_RESPONSE;
break; break;
case 0xfb: // GET_MORE_CLIENT_DATA/SEND_MORE_CLIENT_DATA case 0xfb: // GET_MORE_CLIENT_DATA/SEND_MORE_CLIENT_DATA
C_DEBUG("GET_MORE_CLIENT_DATA"); if (csdata->instance->config.debug & MAXROWS_DEBUG_DECISIONS)
{
MXS_NOTICE("GET_MORE_CLIENT_DATA");
}
rv = send_upstream(csdata); rv = send_upstream(csdata);
csdata->state = MAXROWS_IGNORING_RESPONSE; csdata->state = MAXROWS_IGNORING_RESPONSE;
break; break;
default: default:
C_DEBUG("RESULTSET"); if (csdata->instance->config.debug & MAXROWS_DEBUG_DECISIONS)
{
MXS_NOTICE("RESULTSET");
}
if (csdata->res.n_totalfields != 0) if (csdata->res.n_totalfields != 0)
{ {
@ -669,9 +683,13 @@ static int handle_rows(MAXROWS_SESSION_DATA *csdata)
case 0xff: // ERR packet after the rows. case 0xff: // ERR packet after the rows.
csdata->res.offset += packetlen; csdata->res.offset += packetlen;
ss_dassert(csdata->res.offset == buflen); ss_dassert(csdata->res.offset == buflen);
if (csdata->instance->config.debug & MAXROWS_DEBUG_DECISIONS)
{
MXS_NOTICE("Error packet seen while handling result set");
}
/* /*
* This is the ERR packet that could terminate a Multi-Resultset. * This is the ERR packet that could terminate a Multi-Resultset.
* Reply to client is the same as in case 0x0
*/ */
if (csdata->state == MAXROWS_DISCARDING_RESPONSE) if (csdata->state == MAXROWS_DISCARDING_RESPONSE)
{ {
@ -702,11 +720,23 @@ static int handle_rows(MAXROWS_SESSION_DATA *csdata)
* If so more results set could come. The end of stream * If so more results set could come. The end of stream
* will be an OK packet. * will be an OK packet.
*/ */
if (packetlen < MAXROWS_EOF_PACKET_LEN)
{
MXS_ERROR("EOF packet has size of %lu instead of %d", packetlen, MAXROWS_EOF_PACKET_LEN);
rv = send_ok_upstream(csdata);
csdata->state = MAXROWS_EXPECTING_NOTHING;
break;
}
int flags = gw_mysql_get_byte2(header + MAXROWS_MYSQL_EOF_PACKET_FLAGS_OFFSET); int flags = gw_mysql_get_byte2(header + MAXROWS_MYSQL_EOF_PACKET_FLAGS_OFFSET);
if (!(flags & SERVER_MORE_RESULTS_EXIST)) if (!(flags & SERVER_MORE_RESULTS_EXIST))
{ {
if (csdata->instance->config.debug & MAXROWS_DEBUG_DECISIONS)
{
MXS_NOTICE("OK or EOF packet seen terminating the resultset");
}
if (csdata->state == MAXROWS_DISCARDING_RESPONSE) if (csdata->state == MAXROWS_DISCARDING_RESPONSE)
{ {
rv = send_ok_upstream(csdata); rv = send_ok_upstream(csdata);
@ -720,7 +750,10 @@ static int handle_rows(MAXROWS_SESSION_DATA *csdata)
} }
else else
{ {
C_DEBUG("EOF or OK seen with SERVER_MORE_RESULTS_EXIST flag: waiting for more data"); if (csdata->instance->config.debug & MAXROWS_DEBUG_DECISIONS)
{
MXS_NOTICE("EOF or OK packet seen with SERVER_MORE_RESULTS_EXIST flag: waiting for more data");
}
} }
break; break;
@ -734,7 +767,10 @@ static int handle_rows(MAXROWS_SESSION_DATA *csdata)
{ {
if (csdata->res.n_rows > csdata->instance->config.max_resultset_rows) if (csdata->res.n_rows > csdata->instance->config.max_resultset_rows)
{ {
C_DEBUG("max_resultset_rows %lu reached, not returning the result.", csdata->res.n_rows); if (csdata->instance->config.debug & MAXROWS_DEBUG_DISCARDING)
{
MXS_INFO("max_resultset_rows %lu reached, not returning the result.", csdata->res.n_rows);
}
csdata->state = MAXROWS_DISCARDING_RESPONSE; csdata->state = MAXROWS_DISCARDING_RESPONSE;
} }

View File

@ -26,15 +26,12 @@ MXS_BEGIN_DECLS
#define MAXROWS_MYSQL_EOF_PACKET_FLAGS_OFFSET (MYSQL_HEADER_LEN + 1 + 2) #define MAXROWS_MYSQL_EOF_PACKET_FLAGS_OFFSET (MYSQL_HEADER_LEN + 1 + 2)
#define MAXROWS_DEBUG_NONE 0 #define MAXROWS_DEBUG_NONE 0
#define MAXROWS_DEBUG_MATCHING 1 #define MAXROWS_DEBUG_DISCARDING 1
#define MAXROWS_DEBUG_NON_MATCHING 2 #define MAXROWS_DEBUG_DECISIONS 2
#define MAXROWS_DEBUG_USE 4
#define MAXROWS_DEBUG_NON_USE 8
#define MAXROWS_DEBUG_RULES (MAXROWS_DEBUG_MATCHING | MAXROWS_DEBUG_NON_MATCHING) #define MAXROWS_DEBUG_USAGE (MAXROWS_DEBUG_DECISIONS | MAXROWS_DEBUG_DISCARDING)
#define MAXROWS_DEBUG_USAGE (MAXROWS_DEBUG_USE | MAXROWS_DEBUG_NON_USE)
#define MAXROWS_DEBUG_MIN MAXROWS_DEBUG_NONE #define MAXROWS_DEBUG_MIN MAXROWS_DEBUG_NONE
#define MAXROWS_DEBUG_MAX (MAXROWS_DEBUG_RULES | MAXROWS_DEBUG_USAGE) #define MAXROWS_DEBUG_MAX MAXROWS_DEBUG_USAGE
// Count // Count
#define MAXROWS_DEFAULT_MAX_RESULTSET_ROWS UINT_MAX #define MAXROWS_DEFAULT_MAX_RESULTSET_ROWS UINT_MAX