@@ -1953,6 +1953,25 @@ bool MySQL_Session::handler_again___verify_backend_session_track_gtids() {
19531953 return ret;
19541954}
19551955
1956+ bool MySQL_Session::handler_again___verify_backend_session_track_variables () {
1957+ if (mysql_thread___session_track_variables == session_track_variables::DISABLED) {
1958+ return false ;
1959+ }
1960+
1961+ if (mybe->server_myds ->myconn ->options .session_track_variables_sent == false ) {
1962+ mybe->server_myds ->myconn ->options .session_track_variables_sent = true ;
1963+ set_previous_status_mode3 ();
1964+ NEXT_IMMEDIATE_NEW (SETTING_SESSION_TRACK_VARIABLES);
1965+ }
1966+
1967+ if (mybe->server_myds ->myconn ->options .session_track_state_sent == false ) {
1968+ mybe->server_myds ->myconn ->options .session_track_state_sent = true ;
1969+ set_previous_status_mode3 ();
1970+ NEXT_IMMEDIATE_NEW (SETTING_SESSION_TRACK_STATE);
1971+ }
1972+
1973+ return false ;
1974+ }
19561975
19571976bool MySQL_Session::handler_again___verify_multiple_variables (MySQL_Connection* myconn) {
19581977 for (auto i = 0 ; i < SQL_NAME_LAST_LOW_WM; i++) {
@@ -2753,6 +2772,20 @@ bool MySQL_Session::handler_again___status_SETTING_SESSION_TRACK_GTIDS(int *_rc)
27532772 return ret;
27542773}
27552774
2775+ bool MySQL_Session::handler_again___status_SETTING_SESSION_TRACK_VARIABLES (int *_rc) {
2776+ bool ret=false ;
2777+ assert (mybe->server_myds ->myconn );
2778+ ret = handler_again___status_SETTING_GENERIC_VARIABLE (_rc, (char *)" session_track_system_variables" , " *" , false );
2779+ return ret;
2780+ }
2781+
2782+ bool MySQL_Session::handler_again___status_SETTING_SESSION_TRACK_STATE (int *_rc) {
2783+ bool ret=false ;
2784+ assert (mybe->server_myds ->myconn );
2785+ ret = handler_again___status_SETTING_GENERIC_VARIABLE (_rc, (char *)" session_track_state_change" , " ON" , false );
2786+ return ret;
2787+ }
2788+
27562789bool MySQL_Session::handler_again___status_CHANGING_SCHEMA (int *_rc) {
27572790 bool ret=false ;
27582791 // fprintf(stderr,"CHANGING_SCHEMA\n");
@@ -4862,6 +4895,41 @@ void MySQL_Session::handler_rc0_Process_GTID(MySQL_Connection *myconn) {
48624895 }
48634896}
48644897
4898+ void MySQL_Session::handler_rc0_Process_Variables (MySQL_Connection *myconn) {
4899+ std::unordered_map<string, string> var_map;
4900+
4901+ if (myconn->get_variables (var_map)) {
4902+ std::string variable;
4903+ std::string value;
4904+
4905+ for (int idx = 0 ; idx < SQL_NAME_LAST_HIGH_WM ; idx++) {
4906+ variable = mysql_tracked_variables[idx].set_variable_name ;
4907+
4908+ auto itr = var_map.find (variable);
4909+ if (itr != var_map.end ()) {
4910+ value = itr->second ;
4911+ 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 ());
4912+
4913+ const MARIADB_CHARSET_INFO *ci = NULL ;
4914+ if (variable == " character_set_results" || variable == " character_set_connection" ||
4915+ variable == " character_set_client" || variable == " character_set_database" ) {
4916+ ci = proxysql_find_charset_name (value.c_str ());
4917+ }
4918+ else if (variable == " collation_connection" ) {
4919+ ci = proxysql_find_charset_collate (value.c_str ());
4920+ }
4921+
4922+ if (ci) {
4923+ value = std::to_string (ci->nr );
4924+ }
4925+
4926+ mysql_variables.client_set_value (this , idx, value);
4927+ mysql_variables.server_set_value (this , idx, value.c_str ());
4928+ }
4929+ }
4930+ }
4931+ }
4932+
48654933void MySQL_Session::handler_KillConnectionIfNeeded () {
48664934 if ( // two conditions
48674935 // 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
@@ -5059,6 +5127,10 @@ int MySQL_Session::handler() {
50595127 goto handler_again;
50605128 }
50615129
5130+ if (handler_again___verify_backend_session_track_variables ()) {
5131+ goto handler_again;
5132+ }
5133+
50625134 // Optimize network traffic when we can use 'SET NAMES'
50635135 if (verify_set_names (this )) {
50645136 goto handler_again;
@@ -5139,6 +5211,8 @@ int MySQL_Session::handler() {
51395211
51405212 handler_rc0_Process_GTID (myconn);
51415213
5214+ handler_rc0_Process_Variables (myconn);
5215+
51425216 // if we are locked on hostgroup, the value of autocommit is copied from the backend connection
51435217 // see bug #3549
51445218 if (locked_on_hostgroup >= 0 ) {
@@ -5435,6 +5509,12 @@ bool MySQL_Session::handler_again___multiple_statuses(int *rc) {
54355509 case SETTING_SESSION_TRACK_GTIDS:
54365510 ret = handler_again___status_SETTING_SESSION_TRACK_GTIDS (rc);
54375511 break ;
5512+ case SETTING_SESSION_TRACK_VARIABLES:
5513+ ret = handler_again___status_SETTING_SESSION_TRACK_VARIABLES (rc);
5514+ break ;
5515+ case SETTING_SESSION_TRACK_STATE:
5516+ ret = handler_again___status_SETTING_SESSION_TRACK_STATE (rc);
5517+ break ;
54385518 case SETTING_SET_NAMES:
54395519 ret = handler_again___status_CHANGING_CHARSET (rc);
54405520 break ;
0 commit comments