@@ -1953,6 +1953,16 @@ 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 (mybe->server_myds ->myconn ->options .session_track_variables_sent == false ) {
1958+ mybe->server_myds ->myconn ->options .session_track_variables_sent = true ;
1959+ set_previous_status_mode3 ();
1960+ NEXT_IMMEDIATE_NEW (SETTING_SESSION_TRACK_VARIABLES);
1961+ }
1962+
1963+ return false ;
1964+ }
1965+
19561966
19571967bool MySQL_Session::handler_again___verify_multiple_variables (MySQL_Connection* myconn) {
19581968 for (auto i = 0 ; i < SQL_NAME_LAST_LOW_WM; i++) {
@@ -2565,6 +2575,12 @@ bool MySQL_Session::handler_again___status_SETTING_GENERIC_VARIABLE(int *_rc, co
25652575 free (query);
25662576 query=NULL ;
25672577 }
2578+
2579+ if (rc == 0 && strncasecmp (var_name, " session_track_system_variables" , strlen (" session_track_system_variables" )) == 0 ) {
2580+ char *q = (char *)" SET session_track_state_change=ON" ;
2581+ rc = myconn->async_send_simple_command (myds->revents , q, strlen (q));
2582+ }
2583+
25682584 if (rc==0 ) {
25692585 myds->revents |=POLLOUT; // we also set again POLLOUT to send a query immediately!
25702586 myds->DSS = STATE_MARIADB_GENERIC;
@@ -2753,6 +2769,13 @@ bool MySQL_Session::handler_again___status_SETTING_SESSION_TRACK_GTIDS(int *_rc)
27532769 return ret;
27542770}
27552771
2772+ bool MySQL_Session::handler_again___status_SETTING_SESSION_TRACK_VARIABLES (int *_rc) {
2773+ bool ret=false ;
2774+ assert (mybe->server_myds ->myconn );
2775+ ret = handler_again___status_SETTING_GENERIC_VARIABLE (_rc, (char *)" session_track_system_variables" , " *" , false );
2776+ return ret;
2777+ }
2778+
27562779bool MySQL_Session::handler_again___status_CHANGING_SCHEMA (int *_rc) {
27572780 bool ret=false ;
27582781 // fprintf(stderr,"CHANGING_SCHEMA\n");
@@ -4862,6 +4885,28 @@ void MySQL_Session::handler_rc0_Process_GTID(MySQL_Connection *myconn) {
48624885 }
48634886}
48644887
4888+ void MySQL_Session::handler_rc0_Process_Variables (MySQL_Connection *myconn) {
4889+ std::unordered_map<string, string> var_map;
4890+
4891+ if (myconn->get_variables (var_map)) {
4892+ const char *variable = nullptr ;
4893+ const char *value = nullptr ;
4894+
4895+ for (int idx = 0 ; idx < SQL_NAME_LAST_HIGH_WM ; idx++) {
4896+ variable = mysql_tracked_variables[idx].set_variable_name ;
4897+
4898+ auto itr = var_map.find (variable);
4899+ if (itr != var_map.end ()) {
4900+ value = itr->second .c_str ();
4901+ 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, value);
4902+
4903+ mysql_variables.client_set_value (this , idx, value);
4904+ mysql_variables.server_set_value (this , idx, value);
4905+ }
4906+ }
4907+ }
4908+ }
4909+
48654910void MySQL_Session::handler_KillConnectionIfNeeded () {
48664911 if ( // two conditions
48674912 // 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 +5104,10 @@ int MySQL_Session::handler() {
50595104 goto handler_again;
50605105 }
50615106
5107+ if (handler_again___verify_backend_session_track_variables ()) {
5108+ goto handler_again;
5109+ }
5110+
50625111 // Optimize network traffic when we can use 'SET NAMES'
50635112 if (verify_set_names (this )) {
50645113 goto handler_again;
@@ -5139,6 +5188,8 @@ int MySQL_Session::handler() {
51395188
51405189 handler_rc0_Process_GTID (myconn);
51415190
5191+ handler_rc0_Process_Variables (myconn);
5192+
51425193 // if we are locked on hostgroup, the value of autocommit is copied from the backend connection
51435194 // see bug #3549
51445195 if (locked_on_hostgroup >= 0 ) {
@@ -5435,6 +5486,9 @@ bool MySQL_Session::handler_again___multiple_statuses(int *rc) {
54355486 case SETTING_SESSION_TRACK_GTIDS:
54365487 ret = handler_again___status_SETTING_SESSION_TRACK_GTIDS (rc);
54375488 break ;
5489+ case SETTING_SESSION_TRACK_VARIABLES:
5490+ ret = handler_again___status_SETTING_SESSION_TRACK_VARIABLES (rc);
5491+ break ;
54385492 case SETTING_SET_NAMES:
54395493 ret = handler_again___status_CHANGING_CHARSET (rc);
54405494 break ;
0 commit comments