Skip to content

Commit 1dbe9fd

Browse files
authored
Merge pull request #5385 from sysown/v3.0-2233
Fix #2233: Mirror sessions destination_hostgroup overwritten by fast routing
2 parents b64f2e5 + 458b0db commit 1dbe9fd

File tree

3 files changed

+391
-18
lines changed

3 files changed

+391
-18
lines changed

lib/Query_Processor.cpp

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1631,25 +1631,28 @@ Query_Processor_Output* Query_Processor<QP_DERIVED>::process_query(TypeSession*
16311631

16321632
__exit_process_mysql_query:
16331633
if (qr == NULL || qr->apply == false) {
1634-
// now it is time to check mysql_query_rules_fast_routing
1635-
// it is only check if "apply" is not true
1636-
const char * u = sess->client_myds->myconn->userinfo->username;
1637-
const char * s = sess->client_myds->myconn->userinfo->schemaname;
1638-
1639-
int dst_hg = -1;
1640-
1641-
if (_thr_SQP_rules_fast_routing != nullptr) {
1642-
proxy_debug(PROXY_DEBUG_MYSQL_QUERY_PROCESSOR, 7, "Searching thread-local 'rules_fast_routing' hashmap with: user='%s', schema='%s', and flagIN='%d'\n", u, s, flagIN);
1643-
dst_hg = search_rules_fast_routing_dest_hg(&_thr_SQP_rules_fast_routing, u, s, flagIN, false);
1644-
} else if (rules_fast_routing != nullptr) {
1645-
proxy_debug(PROXY_DEBUG_MYSQL_QUERY_PROCESSOR, 7, "Searching global 'rules_fast_routing' hashmap with: user='%s', schema='%s', and flagIN='%d'\n", u, s, flagIN);
1646-
// NOTE: A pointer to the member 'this->rules_fast_routing' is required, since the value of the
1647-
// member could have changed before the function acquires the internal lock. See function doc.
1648-
dst_hg = search_rules_fast_routing_dest_hg(&this->rules_fast_routing, u, s, flagIN, true);
1649-
}
1634+
// Skip fast routing for mirror sessions - they already have their destination
1635+
if (sess->mirror == false) {
1636+
// now it is time to check mysql_query_rules_fast_routing
1637+
// it is only check if "apply" is not true
1638+
const char * u = sess->client_myds->myconn->userinfo->username;
1639+
const char * s = sess->client_myds->myconn->userinfo->schemaname;
1640+
1641+
int dst_hg = -1;
1642+
1643+
if (_thr_SQP_rules_fast_routing != nullptr) {
1644+
proxy_debug(PROXY_DEBUG_MYSQL_QUERY_PROCESSOR, 7, "Searching thread-local 'rules_fast_routing' hashmap with: user='%s', schema='%s', and flagIN='%d'\n", u, s, flagIN);
1645+
dst_hg = search_rules_fast_routing_dest_hg(&_thr_SQP_rules_fast_routing, u, s, flagIN, false);
1646+
} else if (rules_fast_routing != nullptr) {
1647+
proxy_debug(PROXY_DEBUG_MYSQL_QUERY_PROCESSOR, 7, "Searching global 'rules_fast_routing' hashmap with: user='%s', schema='%s', and flagIN='%d'\n", u, s, flagIN);
1648+
// NOTE: A pointer to the member 'this->rules_fast_routing' is required, since the value of the
1649+
// member could have changed before the function acquires the internal lock. See function doc.
1650+
dst_hg = search_rules_fast_routing_dest_hg(&this->rules_fast_routing, u, s, flagIN, true);
1651+
}
16501652

1651-
if (dst_hg != -1) {
1652-
ret->destination_hostgroup = dst_hg;
1653+
if (dst_hg != -1) {
1654+
ret->destination_hostgroup = dst_hg;
1655+
}
16531656
}
16541657
}
16551658

test/tap/groups/groups.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
"reg_test_3606-mysql_warnings-t" : [ "default-g1","mysql-auto_increment_delay_multiplex=0-g1","mysql-multiplexing=false-g1","mysql-query_digests=0-g1","mysql-query_digests_keep_comment=1-g1" ],
8686
"reg_test_3625-sqlite3_session_client_error_limit-t" : [ "default-g1","mysql-auto_increment_delay_multiplex=0-g1","mysql-multiplexing=false-g1","mysql-query_digests=0-g1","mysql-query_digests_keep_comment=1-g1" ],
8787
"reg_test_3690-admin_large_pkts-t" : [ "default-g1","mysql-auto_increment_delay_multiplex=0-g1","mysql-multiplexing=false-g1","mysql-query_digests=0-g1","mysql-query_digests_keep_comment=1-g1" ],
88+
"reg_test_2233_mirror_fast_routing-t" : [ "default-g1","mysql-auto_increment_delay_multiplex=0-g1","mysql-multiplexing=false-g1","mysql-query_digests=0-g1","mysql-query_digests_keep_comment=1-g1" ],
8889
"reg_test_5233_set_warning-t" : [ "default-g1","mysql-auto_increment_delay_multiplex=0-g1","mysql-multiplexing=false-g1","mysql-query_digests=0-g1","mysql-query_digests_keep_comment=1-g1" ],
8990

9091
"reg_test_3765_ssl_pollout-t" : [ "default-g2","mysql-auto_increment_delay_multiplex=0-g2","mysql-multiplexing=false-g2","mysql-query_digests=0-g2","mysql-query_digests_keep_comment=1-g2" ],

0 commit comments

Comments
 (0)