@@ -1923,6 +1923,16 @@ bool MySQL_Session::handler_again___verify_backend_session_track_gtids() {
19231923 return ret;
19241924}
19251925
1926+ bool MySQL_Session::handler_again___verify_backend_session_track_variables () {
1927+ if (mybe->server_myds ->myconn ->options .session_track_variables_sent == false ) {
1928+ mybe->server_myds ->myconn ->options .session_track_variables_sent = true ;
1929+ set_previous_status_mode3 ();
1930+ NEXT_IMMEDIATE_NEW (SETTING_SESSION_TRACK_VARIABLES);
1931+ }
1932+
1933+ return false ;
1934+ }
1935+
19261936
19271937bool MySQL_Session::handler_again___verify_multiple_variables (MySQL_Connection* myconn) {
19281938 for (auto i = 0 ; i < SQL_NAME_LAST_LOW_WM; i++) {
@@ -2535,6 +2545,12 @@ bool MySQL_Session::handler_again___status_SETTING_GENERIC_VARIABLE(int *_rc, co
25352545 free (query);
25362546 query=NULL ;
25372547 }
2548+
2549+ if (rc == 0 && strncasecmp (var_name, " session_track_system_variables" , strlen (" session_track_system_variables" )) == 0 ) {
2550+ char *q = (char *)" SET session_track_state_change=ON" ;
2551+ rc = myconn->async_send_simple_command (myds->revents , q, strlen (q));
2552+ }
2553+
25382554 if (rc==0 ) {
25392555 myds->revents |=POLLOUT; // we also set again POLLOUT to send a query immediately!
25402556 myds->DSS = STATE_MARIADB_GENERIC;
@@ -2723,6 +2739,13 @@ bool MySQL_Session::handler_again___status_SETTING_SESSION_TRACK_GTIDS(int *_rc)
27232739 return ret;
27242740}
27252741
2742+ bool MySQL_Session::handler_again___status_SETTING_SESSION_TRACK_VARIABLES (int *_rc) {
2743+ bool ret=false ;
2744+ assert (mybe->server_myds ->myconn );
2745+ ret = handler_again___status_SETTING_GENERIC_VARIABLE (_rc, (char *)" session_track_system_variables" , " *" , false );
2746+ return ret;
2747+ }
2748+
27262749bool MySQL_Session::handler_again___status_CHANGING_SCHEMA (int *_rc) {
27272750 bool ret=false ;
27282751 // fprintf(stderr,"CHANGING_SCHEMA\n");
@@ -4829,6 +4852,28 @@ void MySQL_Session::handler_rc0_Process_GTID(MySQL_Connection *myconn) {
48294852 }
48304853}
48314854
4855+ void MySQL_Session::handler_rc0_Process_Variables (MySQL_Connection *myconn) {
4856+ std::unordered_map<string, string> var_map;
4857+
4858+ if (myconn->get_variables (var_map)) {
4859+ const char *variable = nullptr ;
4860+ const char *value = nullptr ;
4861+
4862+ for (int idx = 0 ; idx < SQL_NAME_LAST_HIGH_WM ; idx++) {
4863+ variable = mysql_tracked_variables[idx].set_variable_name ;
4864+
4865+ auto itr = var_map.find (variable);
4866+ if (itr != var_map.end ()) {
4867+ value = itr->second .c_str ();
4868+ 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);
4869+
4870+ mysql_variables.client_set_value (this , idx, value);
4871+ mysql_variables.server_set_value (this , idx, value);
4872+ }
4873+ }
4874+ }
4875+ }
4876+
48324877void MySQL_Session::handler_KillConnectionIfNeeded () {
48334878 if ( // two conditions
48344879 // 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
@@ -5026,6 +5071,10 @@ int MySQL_Session::handler() {
50265071 goto handler_again;
50275072 }
50285073
5074+ if (handler_again___verify_backend_session_track_variables ()) {
5075+ goto handler_again;
5076+ }
5077+
50295078 // Optimize network traffic when we can use 'SET NAMES'
50305079 if (verify_set_names (this )) {
50315080 goto handler_again;
@@ -5106,6 +5155,8 @@ int MySQL_Session::handler() {
51065155
51075156 handler_rc0_Process_GTID (myconn);
51085157
5158+ handler_rc0_Process_Variables (myconn);
5159+
51095160 // if we are locked on hostgroup, the value of autocommit is copied from the backend connection
51105161 // see bug #3549
51115162 if (locked_on_hostgroup >= 0 ) {
@@ -5402,6 +5453,9 @@ bool MySQL_Session::handler_again___multiple_statuses(int *rc) {
54025453 case SETTING_SESSION_TRACK_GTIDS:
54035454 ret = handler_again___status_SETTING_SESSION_TRACK_GTIDS (rc);
54045455 break ;
5456+ case SETTING_SESSION_TRACK_VARIABLES:
5457+ ret = handler_again___status_SETTING_SESSION_TRACK_VARIABLES (rc);
5458+ break ;
54055459 case SETTING_SET_NAMES:
54065460 ret = handler_again___status_CHANGING_CHARSET (rc);
54075461 break ;
0 commit comments