From e96b75ae8bc16648f702135f6b457691d14aa73c Mon Sep 17 00:00:00 2001 From: lazio579 Date: Wed, 19 Dec 2018 16:30:48 +0800 Subject: [PATCH] Add option for charset checking --- plugins/admin/admin-commands.c | 15 +++++++++++++++ plugins/admin/admin-commands.h | 1 + plugins/admin/admin-parser.y | 3 +++ plugins/admin/lexer.l | 1 + plugins/proxy/proxy-plugin.c | 7 +++++++ plugins/shard/shard-plugin.c | 7 +++++++ src/chassis-mainloop.h | 1 + 7 files changed, 35 insertions(+) diff --git a/plugins/admin/admin-commands.c b/plugins/admin/admin-commands.c index d099ee5..de152b5 100644 --- a/plugins/admin/admin-commands.c +++ b/plugins/admin/admin-commands.c @@ -926,6 +926,20 @@ void admin_set_maintain(network_mysqld_con* con, int mode) network_mysqld_con_send_ok_full(con->client, affected, 0,2,0); } +void admin_set_charset_check(network_mysqld_con* con, int mode) +{ + if (con->is_admin_client) { + return; + } + + int affected = 0; + if (con->srv->charset_check != mode) { + con->srv->charset_check = mode; + affected = 1; + } + network_mysqld_con_send_ok_full(con->client, affected, 0,2,0); +} + void admin_show_maintain(network_mysqld_con* con) { if (con->is_admin_client) { @@ -1668,6 +1682,7 @@ static struct sql_help_entry_t { {"delete allow_ip/deny_ip '@
'", "delete address from white list of module", ALL_HELP}, {"set reduce_conns (true|false)", "reduce idle connections if set to true", ALL_HELP}, {"set maintain (true|false)", "close all client connections if set to true", ALL_HELP}, + {"set charset_check (true|false)", "check the client charset is equal to the default charset", ALL_HELP}, {"refresh conns", "refresh all server connections", ALL_HELP}, {"show maintain status", "show maintain status", ALL_HELP}, {"show status [like '%pattern%']", "show select/update/insert/delete statistics", ALL_HELP}, diff --git a/plugins/admin/admin-commands.h b/plugins/admin/admin-commands.h index 6347136..36deb8b 100644 --- a/plugins/admin/admin-commands.h +++ b/plugins/admin/admin-commands.h @@ -23,6 +23,7 @@ void admin_acl_add_rule(network_mysqld_con *con, gboolean is_white, char *addr); void admin_acl_delete_rule(network_mysqld_con *con, gboolean is_white, char* ip); void admin_set_reduce_conns(network_mysqld_con* con, int mode); void admin_set_maintain(network_mysqld_con* con, int mode); +void admin_set_charset_check(network_mysqld_con* con, int mode); void admin_show_maintain(network_mysqld_con* con); void admin_show_status(network_mysqld_con* con, const char* like); void admin_show_variables(network_mysqld_con* con, const char* like); diff --git a/plugins/admin/admin-parser.y b/plugins/admin/admin-parser.y index 20f54c6..8498da1 100644 --- a/plugins/admin/admin-parser.y +++ b/plugins/admin/admin-parser.y @@ -211,6 +211,9 @@ cmd ::= SET REDUCE_CONNS boolean(X) SEMI. { cmd ::= SET MAINTAIN boolean(X) SEMI. { admin_set_maintain(con, X); } +cmd ::= SET CHARSET_CHECK boolean(X) SEMI. { + admin_set_charset_check(con, X); +} cmd ::= REFRESH_CONNS SEMI. { admin_set_server_conn_refresh(con); } diff --git a/plugins/admin/lexer.l b/plugins/admin/lexer.l index 5d8e064..d86cb2c 100644 --- a/plugins/admin/lexer.l +++ b/plugins/admin/lexer.l @@ -77,6 +77,7 @@ "master" return TK_MASTER; "slave" return TK_SLAVE; "maintain" return TK_MAINTAIN; +"charset_check" return TK_CHARSET_CHECK; "status" return TK_STATUS; "variables" return TK_VARIABLES; "conn_num" return TK_CONN_NUM; diff --git a/plugins/proxy/proxy-plugin.c b/plugins/proxy/proxy-plugin.c index 123d2bf..34ff312 100644 --- a/plugins/proxy/proxy-plugin.c +++ b/plugins/proxy/proxy-plugin.c @@ -816,6 +816,13 @@ adjust_charset(network_mysqld_con *con, mysqld_query_attr_t *query_attr) g_string_assign_len(con->server->charset, charset->str, charset->len); } + if (con->srv->charset_check) { + if (strcmp(con->client->charset->str, con->srv->default_charset) != 0) { + g_message("%s: client charset:%s, default charset:%s, client address:%s", G_STRLOC, + con->client->charset->str, con->srv->default_charset, con->client->src->name->str); + } + } + if (!query_attr->charset_client_set) { if (!g_string_equal(con->client->charset_client, con->server->charset_client)) { if (con->client->charset_client->len > 0) { diff --git a/plugins/shard/shard-plugin.c b/plugins/shard/shard-plugin.c index af77c4e..a89a2bf 100644 --- a/plugins/shard/shard-plugin.c +++ b/plugins/shard/shard-plugin.c @@ -1601,6 +1601,13 @@ check_and_set_attr_bitmap(network_mysqld_con *con) g_warning("%s: not support different sql modes", G_STRLOC); } + if (con->srv->charset_check) { + if (strcmp(con->client->charset->str, con->srv->default_charset) != 0) { + g_message("%s: client charset:%s, default charset:%s, client address:%s", G_STRLOC, + con->client->charset->str, con->srv->default_charset, con->client->src->name->str); + } + } + if (!g_string_equal(con->client->charset, ss->server->charset)) { ss->attr_diff |= ATTR_DIF_CHARSET; con->unmatched_attribute |= ATTR_DIF_CHARSET; diff --git a/src/chassis-mainloop.h b/src/chassis-mainloop.h index 3c9e92a..75b299d 100644 --- a/src/chassis-mainloop.h +++ b/src/chassis-mainloop.h @@ -139,6 +139,7 @@ struct chassis { unsigned int master_preferred; unsigned int is_manual_down; unsigned int is_reduce_conns; + unsigned int charset_check; unsigned int xa_log_detailed; unsigned int check_slave_delay; int socketpair_mutex;