From 1034cc51be9a766903ae984b7b707cfafe1e24fa Mon Sep 17 00:00:00 2001 From: Johan Wikman Date: Mon, 19 Jun 2017 11:21:41 +0300 Subject: [PATCH] MXS-1249: Qc, allow setting the server version In the case of qc_sqlite, the server version may affect how statements are parsed. --- include/maxscale/query_classifier.h | 42 +++++++++++++++++++ .../qc_mysqlembedded/qc_mysqlembedded.cc | 26 ++++++++++++ query_classifier/qc_sqlite/qc_sqlite.c | 28 +++++++++++++ server/core/query_classifier.cc | 16 +++++++ 4 files changed, 112 insertions(+) diff --git a/include/maxscale/query_classifier.h b/include/maxscale/query_classifier.h index f10ff0213..ff36205d9 100644 --- a/include/maxscale/query_classifier.h +++ b/include/maxscale/query_classifier.h @@ -373,6 +373,27 @@ typedef struct query_classifier * exhaustion or equivalent. */ int32_t (*qc_get_preparable_stmt)(GWBUF* stmt, GWBUF** preparable_stmt); + + /** + * Set the version of the server. The version may affect how a statement + * is classified. Note that the server version is maintained separately + * for each thread. + * + * @param major The major version. + * @param minor The minor version. + * @param patch The patch version. + */ + void (*qc_set_server_version)(uint32_t major, uint32_t minor, uint32_t patch); + + /** + * Get the thread specific version assumed of the server. If the version has + * not been set, all values are 0. + * + * @param major The major version. + * @param minor The minor version. + * @param patch The patch version. + */ + void (*qc_get_server_version)(uint32_t* major, uint32_t* minor, uint32_t* patch); } QUERY_CLASSIFIER; /** @@ -758,4 +779,25 @@ const char* qc_type_to_string(qc_query_type_t type); */ char* qc_typemask_to_string(uint32_t typemask); +/** + * Set the version of the server. The version may affect how a statement + * is classified. Note that the server version is maintained separately + * for each thread. + * + * @param major The major version. + * @param minor The minor version. + * @param patch The patch version. + */ +void qc_set_server_version(uint32_t major, uint32_t minor, uint32_t patch); + +/** + * Get the thread specific version assumed of the server. If the version has + * not been set, all values are 0. + * + * @param major The major version. + * @param minor The minor version. + * @param patch The patch version. + */ +void qc_get_server_version(uint32_t* major, uint32_t* minor, uint32_t* patch); + MXS_END_DECLS diff --git a/query_classifier/qc_mysqlembedded/qc_mysqlembedded.cc b/query_classifier/qc_mysqlembedded/qc_mysqlembedded.cc index df11b1b01..77597fc4d 100644 --- a/query_classifier/qc_mysqlembedded/qc_mysqlembedded.cc +++ b/query_classifier/qc_mysqlembedded/qc_mysqlembedded.cc @@ -94,6 +94,16 @@ typedef struct parsing_info_st #endif } parsing_info_t; +static thread_local struct +{ + // The version information is not used; the embedded library parses according + // to the version of the embedded library it has been linked with. However, we + // need to store the information so that qc_[get|set]_server_version will work. + uint32_t version_major; + uint32_t version_minor; + uint32_t version_patch; +} this_thread; + #define QTYPE_LESS_RESTRICTIVE_THAN_WRITE(t) (tqc_set_server_version(major, minor, patch); +} + +void qc_get_server_version(uint32_t* major, uint32_t* minor, uint32_t* patch) +{ + QC_TRACE(); + ss_dassert(classifier); + + classifier->qc_get_server_version(major, minor, patch); +}