MXS-1249: Qc, allow setting the server version
In the case of qc_sqlite, the server version may affect how statements are parsed.
This commit is contained in:
@ -373,6 +373,27 @@ typedef struct query_classifier
|
|||||||
* exhaustion or equivalent.
|
* exhaustion or equivalent.
|
||||||
*/
|
*/
|
||||||
int32_t (*qc_get_preparable_stmt)(GWBUF* stmt, GWBUF** preparable_stmt);
|
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;
|
} 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);
|
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
|
MXS_END_DECLS
|
||||||
|
@ -94,6 +94,16 @@ typedef struct parsing_info_st
|
|||||||
#endif
|
#endif
|
||||||
} parsing_info_t;
|
} 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) (t<QUERY_TYPE_WRITE ? true : false)
|
#define QTYPE_LESS_RESTRICTIVE_THAN_WRITE(t) (t<QUERY_TYPE_WRITE ? true : false)
|
||||||
|
|
||||||
static THD* get_or_create_thd_for_parsing(MYSQL* mysql, char* query_str);
|
static THD* get_or_create_thd_for_parsing(MYSQL* mysql, char* query_str);
|
||||||
@ -2590,6 +2600,20 @@ int32_t qc_mysql_get_function_info(GWBUF* buf,
|
|||||||
return QC_RESULT_OK;
|
return QC_RESULT_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void qc_mysql_set_server_version(uint32_t major, uint32_t minor, uint32_t patch)
|
||||||
|
{
|
||||||
|
this_thread.version_major = major;
|
||||||
|
this_thread.version_minor = minor;
|
||||||
|
this_thread.version_patch = patch;
|
||||||
|
}
|
||||||
|
|
||||||
|
void qc_mysql_get_server_version(uint32_t* major, uint32_t* minor, uint32_t* patch)
|
||||||
|
{
|
||||||
|
*major = this_thread.version_major;
|
||||||
|
*minor = this_thread.version_minor;
|
||||||
|
*patch = this_thread.version_patch;
|
||||||
|
}
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -2743,6 +2767,8 @@ extern "C"
|
|||||||
qc_mysql_get_field_info,
|
qc_mysql_get_field_info,
|
||||||
qc_mysql_get_function_info,
|
qc_mysql_get_function_info,
|
||||||
qc_mysql_get_preparable_stmt,
|
qc_mysql_get_preparable_stmt,
|
||||||
|
qc_mysql_set_server_version,
|
||||||
|
qc_mysql_get_server_version,
|
||||||
};
|
};
|
||||||
|
|
||||||
static MXS_MODULE info =
|
static MXS_MODULE info =
|
||||||
|
@ -114,6 +114,9 @@ static thread_local struct
|
|||||||
bool initialized;
|
bool initialized;
|
||||||
sqlite3* db; // Thread specific database handle.
|
sqlite3* db; // Thread specific database handle.
|
||||||
QC_SQLITE_INFO* info;
|
QC_SQLITE_INFO* info;
|
||||||
|
uint32_t version_major;
|
||||||
|
uint32_t version_minor;
|
||||||
|
uint32_t version_patch;
|
||||||
} this_thread;
|
} this_thread;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -2907,6 +2910,8 @@ static int32_t qc_sqlite_get_canonical(GWBUF* query, char** canonical);
|
|||||||
static int32_t qc_sqlite_query_has_clause(GWBUF* query, int32_t* has_clause);
|
static int32_t qc_sqlite_query_has_clause(GWBUF* query, int32_t* has_clause);
|
||||||
static int32_t qc_sqlite_get_database_names(GWBUF* query, char*** names, int* sizep);
|
static int32_t qc_sqlite_get_database_names(GWBUF* query, char*** names, int* sizep);
|
||||||
static int32_t qc_sqlite_get_preparable_stmt(GWBUF* stmt, GWBUF** preparable_stmt);
|
static int32_t qc_sqlite_get_preparable_stmt(GWBUF* stmt, GWBUF** preparable_stmt);
|
||||||
|
static void qc_sqlite_set_server_version(uint32_t major, uint32_t minor, uint32_t patch);
|
||||||
|
static void qc_sqlite_get_server_version(uint32_t* major, uint32_t* minor, uint32_t* patch);
|
||||||
|
|
||||||
static bool get_key_and_value(char* arg, const char** pkey, const char** pvalue)
|
static bool get_key_and_value(char* arg, const char** pkey, const char** pvalue)
|
||||||
{
|
{
|
||||||
@ -3080,6 +3085,9 @@ static int32_t qc_sqlite_thread_init(void)
|
|||||||
this_thread.info = NULL;
|
this_thread.info = NULL;
|
||||||
|
|
||||||
this_thread.initialized = true;
|
this_thread.initialized = true;
|
||||||
|
this_thread.version_major = 0;
|
||||||
|
this_thread.version_minor = 0;
|
||||||
|
this_thread.version_patch = 0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -3522,6 +3530,24 @@ int32_t qc_sqlite_get_preparable_stmt(GWBUF* stmt, GWBUF** preparable_stmt)
|
|||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void qc_sqlite_set_server_version(uint32_t major, uint32_t minor, uint32_t patch)
|
||||||
|
{
|
||||||
|
QC_TRACE();
|
||||||
|
|
||||||
|
this_thread.version_major = major;
|
||||||
|
this_thread.version_minor = minor;
|
||||||
|
this_thread.version_patch = patch;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void qc_sqlite_get_server_version(uint32_t* major, uint32_t* minor, uint32_t* patch)
|
||||||
|
{
|
||||||
|
QC_TRACE();
|
||||||
|
|
||||||
|
*major = this_thread.version_major;
|
||||||
|
*minor = this_thread.version_minor;
|
||||||
|
*patch = this_thread.version_patch;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* EXPORTS
|
* EXPORTS
|
||||||
*/
|
*/
|
||||||
@ -3548,6 +3574,8 @@ MXS_MODULE* MXS_CREATE_MODULE()
|
|||||||
qc_sqlite_get_field_info,
|
qc_sqlite_get_field_info,
|
||||||
qc_sqlite_get_function_info,
|
qc_sqlite_get_function_info,
|
||||||
qc_sqlite_get_preparable_stmt,
|
qc_sqlite_get_preparable_stmt,
|
||||||
|
qc_sqlite_set_server_version,
|
||||||
|
qc_sqlite_get_server_version,
|
||||||
};
|
};
|
||||||
|
|
||||||
static MXS_MODULE info =
|
static MXS_MODULE info =
|
||||||
|
@ -901,3 +901,19 @@ uint32_t qc_get_trx_type_mask(GWBUF* stmt)
|
|||||||
{
|
{
|
||||||
return qc_get_trx_type_mask_using(stmt, qc_trx_parse_using);
|
return qc_get_trx_type_mask_using(stmt, qc_trx_parse_using);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void qc_set_server_version(uint32_t major, uint32_t minor, uint32_t patch)
|
||||||
|
{
|
||||||
|
QC_TRACE();
|
||||||
|
ss_dassert(classifier);
|
||||||
|
|
||||||
|
classifier->qc_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);
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user