From cc038278d67c8f04eed3e6f8b81dbd901062c627 Mon Sep 17 00:00:00 2001 From: Marko Date: Tue, 27 Aug 2019 15:21:22 +0300 Subject: [PATCH 1/2] MXS-2631 Add system test --- maxscale-system-test/CMakeLists.txt | 3 + ....cnf.template.mxs2631_ignore_system_tables | 59 +++++++++++++++++++ .../mxs2631_ignore_system_tables.cpp | 25 ++++++++ 3 files changed, 87 insertions(+) create mode 100644 maxscale-system-test/cnf/maxscale.cnf.template.mxs2631_ignore_system_tables create mode 100644 maxscale-system-test/mxs2631_ignore_system_tables.cpp diff --git a/maxscale-system-test/CMakeLists.txt b/maxscale-system-test/CMakeLists.txt index f8160fed3..49fa2c6e5 100644 --- a/maxscale-system-test/CMakeLists.txt +++ b/maxscale-system-test/CMakeLists.txt @@ -982,6 +982,9 @@ add_test_executable(mxs2609_history_replay.cpp mxs2609_history_replay mxs2609_hi # MXS-2621: Incorrect SQL if lower_case_table_names is used. add_test_executable(mxs2621_lower_case_tables.cpp mxs2621_lower_case_tables mxs2621_lower_case_tables LABELS REPL_BACKEND) +# MXS-2631: Duplicate system tables not ignored +add_test_executable(mxs2631_ignore_system_tables.cpp mxs2631_ignore_system_tables mxs2631_ignore_system_tables LABELS schemarouter BREAKS_REPL REPL_BACKEND) + ############################################ # END: Normal tests # ############################################ diff --git a/maxscale-system-test/cnf/maxscale.cnf.template.mxs2631_ignore_system_tables b/maxscale-system-test/cnf/maxscale.cnf.template.mxs2631_ignore_system_tables new file mode 100644 index 000000000..7d84350a3 --- /dev/null +++ b/maxscale-system-test/cnf/maxscale.cnf.template.mxs2631_ignore_system_tables @@ -0,0 +1,59 @@ +[maxscale] +threads=###threads### +log_warning=1 + +[MySQL-Monitor] +type=monitor +module=mysqlmon +servers=server1,server2,server3,server4 +user=maxskysql +password=skysql + +[Sharding-router] +type=service +router=schemarouter +servers=server1,server2,server3,server4 +user=maxskysql +password=skysql +auth_all_servers=1 +ignore_databases_regex=^(?!(mysql|information_schema|performance_schema)) + +[Sharding-Listener] +type=listener +service=Sharding-router +protocol=MySQLClient +port=4006 + +[CLI] +type=service +router=cli + +[CLI-Listener] +type=listener +service=CLI +protocol=maxscaled +socket=default + +[server1] +type=server +address=###node_server_IP_1### +port=###node_server_port_1### +protocol=MySQLBackend + +[server2] +type=server +address=###node_server_IP_2### +port=###node_server_port_2### +protocol=MySQLBackend + +[server3] +type=server +address=###node_server_IP_3### +port=###node_server_port_3### +protocol=MySQLBackend + +[server4] +type=server +address=###node_server_IP_4### +port=###node_server_port_4### +protocol=MySQLBackend diff --git a/maxscale-system-test/mxs2631_ignore_system_tables.cpp b/maxscale-system-test/mxs2631_ignore_system_tables.cpp new file mode 100644 index 000000000..3eaf5928e --- /dev/null +++ b/maxscale-system-test/mxs2631_ignore_system_tables.cpp @@ -0,0 +1,25 @@ +/** + * MXS-2631: Dublicate system tables found + * + * https://jira.mariadb.org/browse/MXS-2631 + */ + + +#include +#include "testconnections.h" + +int main(int argc, char* argv[]) +{ + TestConnections test(argc, argv); + test.set_timeout(30); + + MYSQL* conn = test.maxscales->open_rwsplit_connection(0); + + test.add_result(execute_query(conn, "SELECT 1"), "Query should succeed."); + + mysql_close(conn); + test.stop_timeout(); + sleep(1); + test.repl->fix_replication(); + return test.global_result; +} From 7a1abc26d8d72f4da75c1d8161917487a140011f Mon Sep 17 00:00:00 2001 From: Marko Date: Fri, 23 Aug 2019 15:33:30 +0300 Subject: [PATCH 2/2] MXS-2631 Fix the ignoring of the system tables --- server/modules/routing/schemarouter/schemarouter.cc | 6 +----- server/modules/routing/schemarouter/schemarouter.hh | 4 ++-- .../modules/routing/schemarouter/schemaroutersession.cc | 9 +++++---- .../modules/routing/schemarouter/schemaroutersession.hh | 2 +- 4 files changed, 9 insertions(+), 12 deletions(-) diff --git a/server/modules/routing/schemarouter/schemarouter.cc b/server/modules/routing/schemarouter/schemarouter.cc index 5f81ef73d..d0816c3b2 100644 --- a/server/modules/routing/schemarouter/schemarouter.cc +++ b/server/modules/routing/schemarouter/schemarouter.cc @@ -26,16 +26,12 @@ Config::Config(MXS_CONFIG_PARAMETER* conf) , ignore_match_data(ignore_regex ? pcre2_match_data_create_from_pattern(ignore_regex, NULL) : NULL) , preferred_server(config_get_server(conf, "preferred_server")) { - ignored_dbs.insert("mysql"); - ignored_dbs.insert("information_schema"); - ignored_dbs.insert("performance_schema"); - // TODO: Don't process this in the router if (MXS_CONFIG_PARAMETER* p = config_get_param(conf, "ignore_databases")) { for (const auto& a : mxs::strtok(p->value, ", \t")) { - ignored_dbs.insert(a); + ignored_tables.insert(a); } } } diff --git a/server/modules/routing/schemarouter/schemarouter.hh b/server/modules/routing/schemarouter/schemarouter.hh index 411d1b667..e8e8b095c 100644 --- a/server/modules/routing/schemarouter/schemarouter.hh +++ b/server/modules/routing/schemarouter/schemarouter.hh @@ -44,9 +44,9 @@ struct Config bool refresh_databases; /**< Are databases refreshed when * they are not found in the hashtable */ bool debug; /**< Enable verbose debug messages to clients */ - pcre2_code* ignore_regex; /**< Regular expression used to ignore databases */ + pcre2_code* ignore_regex; /**< Regular expression used to ignore tables */ pcre2_match_data* ignore_match_data;/**< Match data for @c ignore_regex */ - std::set ignored_dbs; /**< Set of ignored databases */ + std::set ignored_tables; /**< Set of ignored tables */ SERVER* preferred_server; /**< Server to prefer in conflict situations */ Config(MXS_CONFIG_PARAMETER* conf); diff --git a/server/modules/routing/schemarouter/schemaroutersession.cc b/server/modules/routing/schemarouter/schemaroutersession.cc index ff9cd4fdb..94c8200d0 100644 --- a/server/modules/routing/schemarouter/schemaroutersession.cc +++ b/server/modules/routing/schemarouter/schemaroutersession.cc @@ -1194,11 +1194,12 @@ char* get_lenenc_str(void* data) static const std::set always_ignore = {"mysql", "information_schema", "performance_schema"}; -bool SchemaRouterSession::ignore_duplicate_database(const char* data) +bool SchemaRouterSession::ignore_duplicate_table(const std::string& data) { bool rval = false; - if (m_config->ignored_dbs.count(data) || always_ignore.count(data)) + std::string db = data.substr(0, data.find(".")); + if (m_config->ignored_tables.count(data) || always_ignore.count(db)) { rval = true; } @@ -1212,7 +1213,7 @@ bool SchemaRouterSession::ignore_duplicate_database(const char* data) } if (pcre2_match(m_config->ignore_regex, - (PCRE2_SPTR) data, + (PCRE2_SPTR) data.c_str(), PCRE2_ZERO_TERMINATED, 0, 0, @@ -1304,7 +1305,7 @@ enum showdb_response SchemaRouterSession::parse_mapping_response(SSRBackend& bre } else { - if (!ignore_duplicate_database(data) && strchr(data, '.') != NULL) + if (strchr(data, '.') != NULL && !ignore_duplicate_table(std::string(data))) { duplicate_found = true; SERVER* duplicate = m_shard.get_location(data); diff --git a/server/modules/routing/schemarouter/schemaroutersession.hh b/server/modules/routing/schemarouter/schemaroutersession.hh index 9f97a99de..19b75d938 100644 --- a/server/modules/routing/schemarouter/schemaroutersession.hh +++ b/server/modules/routing/schemarouter/schemaroutersession.hh @@ -129,7 +129,7 @@ private: bool get_shard_dcb(DCB** dcb, char* name); bool have_servers(); bool handle_default_db(); - bool ignore_duplicate_database(const char* data); + bool ignore_duplicate_table(const std::string& data); SERVER* get_query_target(GWBUF* buffer); SERVER* get_ps_target(GWBUF* buffer, uint32_t qtype, qc_query_op_t op);