@@ -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,41 @@ 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+ std::string variable;
4893+ std::string value;
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 ;
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.c_str (), value.c_str ());
4902+
4903+ const MARIADB_CHARSET_INFO *ci = NULL ;
4904+ if (variable == " character_set_results" || variable == " character_set_connection" ||
4905+ variable == " character_set_client" || variable == " character_set_database" ) {
4906+ ci = proxysql_find_charset_name (value.c_str ());
4907+ }
4908+ else if (variable == " collation_connection" ) {
4909+ ci = proxysql_find_charset_collate (value.c_str ());
4910+ }
4911+
4912+ if (ci) {
4913+ value = std::to_string (ci->nr );
4914+ }
4915+
4916+ mysql_variables.client_set_value (this , idx, value);
4917+ mysql_variables.server_set_value (this , idx, value.c_str ());
4918+ }
4919+ }
4920+ }
4921+ }
4922+
48654923void MySQL_Session::handler_KillConnectionIfNeeded () {
48664924 if ( // two conditions
48674925 // 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 +5117,10 @@ int MySQL_Session::handler() {
50595117 goto handler_again;
50605118 }
50615119
5120+ if (handler_again___verify_backend_session_track_variables ()) {
5121+ goto handler_again;
5122+ }
5123+
50625124 // Optimize network traffic when we can use 'SET NAMES'
50635125 if (verify_set_names (this )) {
50645126 goto handler_again;
@@ -5139,6 +5201,8 @@ int MySQL_Session::handler() {
51395201
51405202 handler_rc0_Process_GTID (myconn);
51415203
5204+ handler_rc0_Process_Variables (myconn);
5205+
51425206 // if we are locked on hostgroup, the value of autocommit is copied from the backend connection
51435207 // see bug #3549
51445208 if (locked_on_hostgroup >= 0 ) {
@@ -5435,6 +5499,9 @@ bool MySQL_Session::handler_again___multiple_statuses(int *rc) {
54355499 case SETTING_SESSION_TRACK_GTIDS:
54365500 ret = handler_again___status_SETTING_SESSION_TRACK_GTIDS (rc);
54375501 break ;
5502+ case SETTING_SESSION_TRACK_VARIABLES:
5503+ ret = handler_again___status_SETTING_SESSION_TRACK_VARIABLES (rc);
5504+ break ;
54385505 case SETTING_SET_NAMES:
54395506 ret = handler_again___status_CHANGING_CHARSET (rc);
54405507 break ;
0 commit comments