From 199dd5131203fca677a528dcd2d8aa030baa533f Mon Sep 17 00:00:00 2001 From: Johan Wikman Date: Thu, 27 Oct 2016 11:10:36 +0300 Subject: [PATCH] Cache: C_DEBUG removed and debug option extended The development time C_DEBUG is now removed, and replaced with a debug option that allows top-level decisions to be logged. --- Documentation/Filters/Cache.md | 15 ++++++------ server/modules/filter/cache/cache.c | 38 +++++++++++++++++------------ server/modules/filter/cache/cache.h | 11 +++++---- 3 files changed, 36 insertions(+), 28 deletions(-) diff --git a/Documentation/Filters/Cache.md b/Documentation/Filters/Cache.md index c983165e1..53372dcfc 100644 --- a/Documentation/Filters/Cache.md +++ b/Documentation/Filters/Cache.md @@ -106,16 +106,17 @@ An integer value, using which the level of debug logging made by the cache can be controlled. The value is actually a bitfield with different bits denoting different logging. - * `0` (`0b0000`) No logging is made. - * `1` (`0b0001`) A matching rule is logged. - * `2` (`0b0010`) A non-matching rule is logged. - * `4` (`0b0100`) A decision to use data from the cache is logged. - * `8` (`0b1000`) A decision not to use data from the cache is logged. + * ` 0` (`0b00000`) No logging is made. + * ` 1` (`0b00001`) A matching rule is logged. + * ` 2` (`0b00010`) A non-matching rule is logged. + * ` 4` (`0b00100`) A decision to use data from the cache is logged. + * ` 8` (`0b01000`) A decision not to use data from the cache is logged. + * '16' (`0b10000`) Higher level decisions are logged. -Default is `0`. To log everything, give `debug` a value of `15`. +Default is `0`. To log everything, give `debug` a value of `31`. ``` -debug=2 +debug=31 ``` # Rules diff --git a/server/modules/filter/cache/cache.c b/server/modules/filter/cache/cache.c index de830d7cd..2e869cf06 100644 --- a/server/modules/filter/cache/cache.c +++ b/server/modules/filter/cache/cache.c @@ -37,8 +37,6 @@ static int clientReply(FILTER *instance, void *sdata, GWBUF *queue); static void diagnostics(FILTER *instance, void *sdata, DCB *dcb); static uint64_t getCapabilities(void); -#define C_DEBUG(format, ...) MXS_LOG_MESSAGE(LOG_NOTICE, format, ##__VA_ARGS__) - // // Global symbols of the Module // @@ -401,7 +399,10 @@ static int routeQuery(FILTER *instance, void *sdata, GWBUF *packet) else { csdata->state = CACHE_EXPECTING_NOTHING; - C_DEBUG("Using data from cache."); + if (csdata->instance.config & CACHE_DEBUG_DECISIONS) + { + MXS_NOTICE("Using data from cache."); + } gwbuf_free(packet); DCB *dcb = csdata->session->client_dcb; @@ -418,9 +419,13 @@ static int routeQuery(FILTER *instance, void *sdata, GWBUF *packet) } else { - C_DEBUG("autocommit = %s and transaction state %s => Not using or storing to cache.", - session_is_autocommit(csdata->session) ? "ON" : "OFF", - session_trx_state_to_string(session_get_trx_state(csdata->session))); + if (csdata->instance.config & CACHE_DEBUG_DECISIONS) + { + MXS_NOTICE("autocommit = %s and transaction state %s => Not using or " + "storing to cache.", + session_is_autocommit(csdata->session) ? "ON" : "OFF", + session_trx_state_to_string(session_get_trx_state(csdata->session))); + } } } break; @@ -432,7 +437,6 @@ static int routeQuery(FILTER *instance, void *sdata, GWBUF *packet) if (use_default) { - C_DEBUG("Using default processing."); rv = csdata->down.routeQuery(csdata->down.instance, csdata->down.session, packet); } @@ -466,10 +470,13 @@ static int clientReply(FILTER *instance, void *sdata, GWBUF *data) { if (gwbuf_length(csdata->res.data) > csdata->instance->config.max_resultset_size) { - C_DEBUG("Current size %uB of resultset, at least as much " - "as maximum allowed size %uKiB. Not caching.", - gwbuf_length(csdata->res.data), - csdata->instance->config.max_resultset_size / 1024); + if (csdata->instance.config & CACHE_DEBUG_DECISIONS) + { + MXS_NOTICE("Current size %uB of resultset, at least as much " + "as maximum allowed size %uKiB. Not caching.", + gwbuf_length(csdata->res.data), + csdata->instance->config.max_resultset_size / 1024); + } csdata->state = CACHE_IGNORING_RESPONSE; } @@ -714,7 +721,6 @@ static int handle_expecting_response(CACHE_SESSION_DATA *csdata) { case 0x00: // OK case 0xff: // ERR - C_DEBUG("OK or ERR"); store_result(csdata); rv = send_upstream(csdata); @@ -722,14 +728,11 @@ static int handle_expecting_response(CACHE_SESSION_DATA *csdata) break; case 0xfb: // GET_MORE_CLIENT_DATA/SEND_MORE_CLIENT_DATA - C_DEBUG("GET_MORE_CLIENT_DATA"); rv = send_upstream(csdata); csdata->state = CACHE_IGNORING_RESPONSE; break; default: - C_DEBUG("RESULTSET"); - if (csdata->res.n_totalfields != 0) { // We've seen the header and have figured out how many fields there are. @@ -814,7 +817,10 @@ static int handle_expecting_rows(CACHE_SESSION_DATA *csdata) if (csdata->res.n_rows > csdata->instance->config.max_resultset_rows) { - C_DEBUG("Max rows %lu reached, not caching result.", csdata->res.n_rows); + if (csdata->instance.config & CACHE_DEBUG_DECISIONS) + { + MXS_NOTICE("Max rows %lu reached, not caching result.", csdata->res.n_rows); + } rv = send_upstream(csdata); csdata->res.offset = buflen; // To abort the loop. csdata->state = CACHE_IGNORING_RESPONSE; diff --git a/server/modules/filter/cache/cache.h b/server/modules/filter/cache/cache.h index a0fc8bf2b..93c1261e3 100644 --- a/server/modules/filter/cache/cache.h +++ b/server/modules/filter/cache/cache.h @@ -18,11 +18,12 @@ MXS_BEGIN_DECLS -#define CACHE_DEBUG_NONE 0 -#define CACHE_DEBUG_MATCHING 1 -#define CACHE_DEBUG_NON_MATCHING 2 -#define CACHE_DEBUG_USE 4 -#define CACHE_DEBUG_NON_USE 8 +#define CACHE_DEBUG_NONE 0 /* 0b00000 */ +#define CACHE_DEBUG_MATCHING 1 /* 0b00001 */ +#define CACHE_DEBUG_NON_MATCHING 2 /* 0b00010 */ +#define CACHE_DEBUG_USE 4 /* 0b00100 */ +#define CACHE_DEBUG_NON_USE 8 /* 0b01000 */ +#define CACHE_DEBUG_DECISIONS 16 /* 0b10000 */ #define CACHE_DEBUG_RULES (CACHE_DEBUG_MATCHING | CACHE_DEBUG_NON_MATCHING) #define CACHE_DEBUG_USAGE (CACHE_DEBUG_USE | CACHE_DEBUG_NON_USE)