MXS-2631 Fix the ignoring of the system tables

This commit is contained in:
Marko
2019-08-23 15:33:30 +03:00
parent cc038278d6
commit 7a1abc26d8
4 changed files with 9 additions and 12 deletions

View File

@ -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) , ignore_match_data(ignore_regex ? pcre2_match_data_create_from_pattern(ignore_regex, NULL) : NULL)
, preferred_server(config_get_server(conf, "preferred_server")) , 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 // TODO: Don't process this in the router
if (MXS_CONFIG_PARAMETER* p = config_get_param(conf, "ignore_databases")) if (MXS_CONFIG_PARAMETER* p = config_get_param(conf, "ignore_databases"))
{ {
for (const auto& a : mxs::strtok(p->value, ", \t")) for (const auto& a : mxs::strtok(p->value, ", \t"))
{ {
ignored_dbs.insert(a); ignored_tables.insert(a);
} }
} }
} }

View File

@ -44,9 +44,9 @@ struct Config
bool refresh_databases; /**< Are databases refreshed when bool refresh_databases; /**< Are databases refreshed when
* they are not found in the hashtable */ * they are not found in the hashtable */
bool debug; /**< Enable verbose debug messages to clients */ 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 */ pcre2_match_data* ignore_match_data;/**< Match data for @c ignore_regex */
std::set<std::string> ignored_dbs; /**< Set of ignored databases */ std::set<std::string> ignored_tables; /**< Set of ignored tables */
SERVER* preferred_server; /**< Server to prefer in conflict situations */ SERVER* preferred_server; /**< Server to prefer in conflict situations */
Config(MXS_CONFIG_PARAMETER* conf); Config(MXS_CONFIG_PARAMETER* conf);

View File

@ -1194,11 +1194,12 @@ char* get_lenenc_str(void* data)
static const std::set<std::string> always_ignore = {"mysql", "information_schema", "performance_schema"}; static const std::set<std::string> 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; 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; rval = true;
} }
@ -1212,7 +1213,7 @@ bool SchemaRouterSession::ignore_duplicate_database(const char* data)
} }
if (pcre2_match(m_config->ignore_regex, if (pcre2_match(m_config->ignore_regex,
(PCRE2_SPTR) data, (PCRE2_SPTR) data.c_str(),
PCRE2_ZERO_TERMINATED, PCRE2_ZERO_TERMINATED,
0, 0,
0, 0,
@ -1304,7 +1305,7 @@ enum showdb_response SchemaRouterSession::parse_mapping_response(SSRBackend& bre
} }
else else
{ {
if (!ignore_duplicate_database(data) && strchr(data, '.') != NULL) if (strchr(data, '.') != NULL && !ignore_duplicate_table(std::string(data)))
{ {
duplicate_found = true; duplicate_found = true;
SERVER* duplicate = m_shard.get_location(data); SERVER* duplicate = m_shard.get_location(data);

View File

@ -129,7 +129,7 @@ private:
bool get_shard_dcb(DCB** dcb, char* name); bool get_shard_dcb(DCB** dcb, char* name);
bool have_servers(); bool have_servers();
bool handle_default_db(); 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_query_target(GWBUF* buffer);
SERVER* get_ps_target(GWBUF* buffer, uint32_t qtype, qc_query_op_t op); SERVER* get_ps_target(GWBUF* buffer, uint32_t qtype, qc_query_op_t op);