@@ -1957,6 +1957,25 @@ bool MySQL_Session::handler_again___verify_backend_session_track_gtids() {
19571957 return ret;
19581958}
19591959
1960+ bool MySQL_Session::handler_again___verify_backend_session_track_variables () {
1961+ if (mysql_thread___session_track_variables == session_track_variables::DISABLED) {
1962+ return false ;
1963+ }
1964+
1965+ if (mybe->server_myds ->myconn ->options .session_track_variables_sent == false ) {
1966+ mybe->server_myds ->myconn ->options .session_track_variables_sent = true ;
1967+ set_previous_status_mode3 ();
1968+ NEXT_IMMEDIATE_NEW (SETTING_SESSION_TRACK_VARIABLES);
1969+ }
1970+
1971+ if (mybe->server_myds ->myconn ->options .session_track_state_sent == false ) {
1972+ mybe->server_myds ->myconn ->options .session_track_state_sent = true ;
1973+ set_previous_status_mode3 ();
1974+ NEXT_IMMEDIATE_NEW (SETTING_SESSION_TRACK_STATE);
1975+ }
1976+
1977+ return false ;
1978+ }
19601979
19611980bool MySQL_Session::handler_again___verify_multiple_variables (MySQL_Connection* myconn) {
19621981 for (auto i = 0 ; i < SQL_NAME_LAST_LOW_WM; i++) {
@@ -2757,6 +2776,20 @@ bool MySQL_Session::handler_again___status_SETTING_SESSION_TRACK_GTIDS(int *_rc)
27572776 return ret;
27582777}
27592778
2779+ bool MySQL_Session::handler_again___status_SETTING_SESSION_TRACK_VARIABLES (int *_rc) {
2780+ bool ret=false ;
2781+ assert (mybe->server_myds ->myconn );
2782+ ret = handler_again___status_SETTING_GENERIC_VARIABLE (_rc, (char *)" session_track_system_variables" , " *" , false );
2783+ return ret;
2784+ }
2785+
2786+ bool MySQL_Session::handler_again___status_SETTING_SESSION_TRACK_STATE (int *_rc) {
2787+ bool ret=false ;
2788+ assert (mybe->server_myds ->myconn );
2789+ ret = handler_again___status_SETTING_GENERIC_VARIABLE (_rc, (char *)" session_track_state_change" , " ON" , false );
2790+ return ret;
2791+ }
2792+
27602793bool MySQL_Session::handler_again___status_CHANGING_SCHEMA (int *_rc) {
27612794 bool ret=false ;
27622795 // fprintf(stderr,"CHANGING_SCHEMA\n");
@@ -4898,6 +4931,41 @@ void MySQL_Session::handler_rc0_Process_GTID(MySQL_Connection *myconn) {
48984931 }
48994932}
49004933
4934+ void MySQL_Session::handler_rc0_Process_Variables (MySQL_Connection *myconn) {
4935+ std::unordered_map<string, string> var_map;
4936+
4937+ if (myconn->get_variables (var_map)) {
4938+ std::string variable;
4939+ std::string value;
4940+
4941+ for (int idx = 0 ; idx < SQL_NAME_LAST_HIGH_WM ; idx++) {
4942+ variable = mysql_tracked_variables[idx].set_variable_name ;
4943+
4944+ auto itr = var_map.find (variable);
4945+ if (itr != var_map.end ()) {
4946+ value = itr->second ;
4947+ proxy_debug (PROXY_DEBUG_MYSQL_CONNECTION, 7 , " Session=%p, backend=%p. Notification for session_track_system_variables: variable=%s, value=%s\n " , this , this ->mybe , variable.c_str (), value.c_str ());
4948+
4949+ const MARIADB_CHARSET_INFO *ci = NULL ;
4950+ if (variable == " character_set_results" || variable == " character_set_connection" ||
4951+ variable == " character_set_client" || variable == " character_set_database" ) {
4952+ ci = proxysql_find_charset_name (value.c_str ());
4953+ }
4954+ else if (variable == " collation_connection" ) {
4955+ ci = proxysql_find_charset_collate (value.c_str ());
4956+ }
4957+
4958+ if (ci) {
4959+ value = std::to_string (ci->nr );
4960+ }
4961+
4962+ mysql_variables.client_set_value (this , idx, value);
4963+ mysql_variables.server_set_value (this , idx, value.c_str ());
4964+ }
4965+ }
4966+ }
4967+ }
4968+
49014969void MySQL_Session::handler_KillConnectionIfNeeded () {
49024970 if ( // two conditions
49034971 // If the server connection is in a non-idle state (ASYNC_IDLE), and the current time is greater than or equal to mybe->server_myds->wait_until
@@ -5095,6 +5163,10 @@ int MySQL_Session::handler() {
50955163 goto handler_again;
50965164 }
50975165
5166+ if (handler_again___verify_backend_session_track_variables ()) {
5167+ goto handler_again;
5168+ }
5169+
50985170 // Optimize network traffic when we can use 'SET NAMES'
50995171 if (verify_set_names (this )) {
51005172 goto handler_again;
@@ -5175,6 +5247,8 @@ int MySQL_Session::handler() {
51755247
51765248 handler_rc0_Process_GTID (myconn);
51775249
5250+ handler_rc0_Process_Variables (myconn);
5251+
51785252 // if we are locked on hostgroup, the value of autocommit is copied from the backend connection
51795253 // see bug #3549
51805254 if (locked_on_hostgroup >= 0 ) {
@@ -5471,6 +5545,12 @@ bool MySQL_Session::handler_again___multiple_statuses(int *rc) {
54715545 case SETTING_SESSION_TRACK_GTIDS:
54725546 ret = handler_again___status_SETTING_SESSION_TRACK_GTIDS (rc);
54735547 break ;
5548+ case SETTING_SESSION_TRACK_VARIABLES:
5549+ ret = handler_again___status_SETTING_SESSION_TRACK_VARIABLES (rc);
5550+ break ;
5551+ case SETTING_SESSION_TRACK_STATE:
5552+ ret = handler_again___status_SETTING_SESSION_TRACK_STATE (rc);
5553+ break ;
54745554 case SETTING_SET_NAMES:
54755555 ret = handler_again___status_CHANGING_CHARSET (rc);
54765556 break ;
0 commit comments