@ -1460,16 +1460,6 @@ __exit_monitor_group_replication_thread:
}
goto __end_process_group_replication_result2 ;
}
/*
if ( num_fields ! = 3 ) {
proxy_error ( " Incorrect number of fields, please report a bug \n " ) ;
goto __end_process_group_replication_result ;
}
if ( num_rows ! = 1 ) {
proxy_error ( " Incorrect number of rows, please report a bug \n " ) ;
goto __end_process_group_replication_result ;
}
*/
MYSQL_ROW row = mysql_fetch_row ( mmsd - > result ) ;
if ( ! strcasecmp ( row [ 0 ] , " YES " ) ) {
viable_candidate = true ;
@ -1486,7 +1476,6 @@ __exit_monitor_group_replication_thread:
mysql_free_result ( mmsd - > result ) ;
mmsd - > result = NULL ;
}
__end_process_group_replication_result :
//proxy_info("GR: %s:%d , viable=%s , ro=%s, trx=%ld, err=%s\n", mmsd->hostname, mmsd->port, (viable_candidate ? "YES": "NO") , (read_only ? "YES": "NO") , transactions_behind, ( mmsd->mysql_error_msg ? mmsd->mysql_error_msg : "") );
if ( mmsd - > mysql_error_msg ) {
//proxy_warning("GR: %s:%d , viable=%s , ro=%s, trx=%ld, err=%s\n", mmsd->hostname, mmsd->port, (viable_candidate ? "YES": "NO") , (read_only ? "YES": "NO") , transactions_behind, ( mmsd->mysql_error_msg ? mmsd->mysql_error_msg : "") );
@ -1675,7 +1664,7 @@ void * monitor_galera_thread(void *arg) {
unsigned long long start_time = mysql_thr - > curtime ;
# ifdef DEBUG
MYSQL * mysqlcopy = NULL ;
MYSQL * mysqlcopy __attribute__ ( ( unused ) ) = NULL ;
# endif // DEBUG
mmsd - > t1 = start_time ;
@ -1815,16 +1804,6 @@ __exit_monitor_galera_thread:
}
goto __end_process_galera_result2 ;
}
/*
if ( num_fields ! = 7 ) {
proxy_error ( " Incorrect number of fields, please report a bug \n " ) ;
goto __end_process_galera_result ;
}
if ( num_rows ! = 1 ) {
proxy_error ( " Incorrect number of rows, please report a bug \n " ) ;
goto __end_process_galera_result ;
}
*/
MYSQL_ROW row = mysql_fetch_row ( mmsd - > result ) ;
if ( row [ 0 ] ) {
wsrep_local_state = atoi ( row [ 0 ] ) ;
@ -1870,7 +1849,6 @@ __exit_monitor_galera_thread:
mysql_free_result ( mmsd - > result ) ;
mmsd - > result = NULL ;
}
__end_process_galera_result :
if ( mmsd - > mysql_error_msg ) {
}
unsigned long long time_now = realtime_time ( ) ;
@ -2056,7 +2034,7 @@ void * monitor_replication_lag_thread(void *arg) {
mysql_thr - > refresh_variables ( ) ;
# ifdef DEBUG
MYSQL * mysqlcopy = NULL ;
MYSQL * mysqlcopy __attribute__ ( ( unused ) ) = NULL ;
# endif // DEBUG
mmsd - > mysql = GloMyMon - > My_Conn_Pool - > get_connection ( mmsd - > hostname , mmsd - > port , mmsd ) ;
@ -2144,6 +2122,7 @@ void * monitor_replication_lag_thread(void *arg) {
MyHGM - > p_update_mysql_error_counter ( p_mysql_error_type : : proxysql , mmsd - > hostgroup_id , mmsd - > hostname , mmsd - > port , mysql_errno ( mmsd - > mysql ) ) ;
unsigned long long now = monotonic_time ( ) ;
# ifdef DEBUG
unsigned long long now = monotonic_time ( ) ;
proxy_error ( " Error after %dms: mmsd %p , MYSQL %p , FD %d : %s \n " , ( now - mmsd - > t1 ) / 1000 , mmsd , mmsd - > mysql , mmsd - > mysql - > net . fd , mmsd - > mysql_error_msg ) ;
# endif // DEBUG
if ( mmsd - > mysql ) {
@ -2834,7 +2813,6 @@ __sleep_monitor_read_only:
void * MySQL_Monitor : : monitor_group_replication ( ) {
// initialize the MySQL Thread (note: this is not a real thread, just the structures associated with it)
// struct event_base *libevent_base;
unsigned int latest_table_servers_version = 0 ;
unsigned int MySQL_Monitor__thread_MySQL_Thread_Variables_version ;
MySQL_Thread * mysql_thr = new MySQL_Thread ( ) ;
mysql_thr - > curtime = monotonic_time ( ) ;
@ -2964,7 +2942,6 @@ __sleep_monitor_group_replication:
void * MySQL_Monitor : : monitor_galera ( ) {
// initialize the MySQL Thread (note: this is not a real thread, just the structures associated with it)
// struct event_base *libevent_base;
unsigned int latest_table_servers_version = 0 ;
unsigned int MySQL_Monitor__thread_MySQL_Thread_Variables_version ;
MySQL_Thread * mysql_thr = new MySQL_Thread ( ) ;
mysql_thr - > curtime = monotonic_time ( ) ;
@ -3263,8 +3240,8 @@ __monitor_run:
My_Conn_Pool - > purge_some_connections ( ) ;
}
usleep ( 200000 ) ;
int qsize = queue - > size ( ) ;
if ( qsize > mysql_thread___monitor_threads_queue_maxsize / 4 ) {
unsigned int qsize = queue - > size ( ) ;
if ( qsize > ( unsigned int ) mysql_thread___monitor_threads_queue_maxsize / 4 ) {
proxy_warning ( " Monitor queue too big: %d \n " , qsize ) ;
unsigned int threads_max = ( unsigned int ) mysql_thread___monitor_threads_max ;
if ( threads_max > num_threads ) {
@ -3287,7 +3264,7 @@ __monitor_run:
// check again. Do we need also aux threads?
usleep ( 50000 ) ;
qsize = queue - > size ( ) ;
if ( qsize > mysql_thread___monitor_threads_queue_maxsize ) {
if ( qsize > ( unsigned int ) mysql_thread___monitor_threads_queue_maxsize ) {
qsize = qsize / 50 ;
unsigned int threads_max = ( unsigned int ) mysql_thread___monitor_threads_max ;
if ( ( qsize + num_threads ) > ( threads_max * 2 ) ) { // allow a small bursts
@ -3298,11 +3275,11 @@ __monitor_run:
ConsumerThread * * threads_aux = ( ConsumerThread * * ) malloc ( sizeof ( ConsumerThread * ) * qsize ) ;
aux_threads = qsize ;
started_threads + = aux_threads ;
for ( int i = 0 ; i < qsize ; i + + ) {
for ( unsigned int i = 0 ; i < qsize ; i + + ) {
threads_aux [ i ] = new ConsumerThread ( * queue , 245 ) ;
threads_aux [ i ] - > start ( 2048 , false ) ;
}
for ( int i = 0 ; i < qsize ; i + + ) {
for ( unsigned int i = 0 ; i < qsize ; i + + ) {
threads_aux [ i ] - > join ( ) ;
delete threads_aux [ i ] ;
}
@ -3722,7 +3699,7 @@ char * MySQL_Monitor::galera_find_last_node(int writer_hostgroup) {
std : : string s = " " ;
for ( it2 = GloMyMon - > Galera_Hosts_Map . begin ( ) ; it2 ! = GloMyMon - > Galera_Hosts_Map . end ( ) ; + + it2 ) {
node = it2 - > second ;
if ( node - > writer_hostgroup = = writer_hostgroup ) {
if ( node - > writer_hostgroup = = ( unsigned int ) writer_hostgroup ) {
Galera_status_entry_t * st = node - > last_entry ( ) ;
if ( st ) {
if ( st - > start_time > = curtime - ti ) { // only consider recent checks
@ -3765,7 +3742,7 @@ std::vector<string> * MySQL_Monitor::galera_find_possible_last_nodes(int writer_
ti * = 2 ;
for ( it2 = GloMyMon - > Galera_Hosts_Map . begin ( ) ; it2 ! = GloMyMon - > Galera_Hosts_Map . end ( ) ; + + it2 ) {
node = it2 - > second ;
if ( node - > writer_hostgroup = = writer_hostgroup ) {
if ( node - > writer_hostgroup = = ( unsigned int ) writer_hostgroup ) {
Galera_status_entry_t * st = node - > last_entry ( ) ;
if ( st ) {
if ( st - > start_time > = curtime - ti ) { // only consider recent checks
@ -3991,7 +3968,6 @@ AWS_Aurora_monitor_node::~AWS_Aurora_monitor_node() {
bool AWS_Aurora_monitor_node : : add_entry ( AWS_Aurora_status_entry * ase ) {
bool ret = false ;
if ( idx_last_entry = = - 1 ) ret = true ;
int prev_last_entry = idx_last_entry ;
idx_last_entry + + ;
if ( idx_last_entry > = AWS_Aurora_Nentries ) {
idx_last_entry = 0 ;
@ -4071,7 +4047,7 @@ void * monitor_AWS_Aurora_thread_HG(void *arg) {
// count the number of hosts
for ( std : : vector < SQLite3_row * > : : iterator it = GloMyMon - > AWS_Aurora_Hosts_resultset - > rows . begin ( ) ; it ! = GloMyMon - > AWS_Aurora_Hosts_resultset - > rows . end ( ) ; + + it ) {
SQLite3_row * r = * it ;
if ( atoi ( r - > fields [ 0 ] ) = = wHG ) {
if ( atoi ( r - > fields [ 0 ] ) = = ( int ) wHG ) {
num_hosts + + ;
if ( max_lag_ms = = 0 ) {
max_lag_ms = atoi ( r - > fields [ 5 ] ) ;
@ -4093,7 +4069,7 @@ void * monitor_AWS_Aurora_thread_HG(void *arg) {
host_def_t * hpa = ( host_def_t * ) malloc ( sizeof ( host_def_t ) * num_hosts ) ;
for ( std : : vector < SQLite3_row * > : : iterator it = GloMyMon - > AWS_Aurora_Hosts_resultset - > rows . begin ( ) ; it ! = GloMyMon - > AWS_Aurora_Hosts_resultset - > rows . end ( ) ; + + it ) {
SQLite3_row * r = * it ;
if ( atoi ( r - > fields [ 0 ] ) = = wHG ) {
if ( atoi ( r - > fields [ 0 ] ) = = ( int ) wHG ) {
hpa [ cur_host_idx ] . host = strdup ( r - > fields [ 2 ] ) ;
hpa [ cur_host_idx ] . port = atoi ( r - > fields [ 3 ] ) ;
hpa [ cur_host_idx ] . use_ssl = atoi ( r - > fields [ 4 ] ) ;
@ -4312,7 +4288,6 @@ __exit_monitor_aws_aurora_HG_thread:
AWS_Aurora_status_entry * ase_l = new AWS_Aurora_status_entry ( time_now , mmsd - > t2 - mmsd - > t1 , mmsd - > mysql_error_msg ) ;
if ( mmsd - > interr = = 0 & & mmsd - > result ) {
int num_fields = 0 ;
int num_rows = 0 ;
num_fields = mysql_num_fields ( mmsd - > result ) ;
if ( num_fields ! = 5 ) {
proxy_error ( " Incorrect number of fields, please report a bug \n " ) ;
@ -4473,7 +4448,6 @@ __exit_monitor_AWS_Aurora_thread_HG_now:
void * MySQL_Monitor : : monitor_aws_aurora ( ) {
// initialize the MySQL Thread (note: this is not a real thread, just the structures associated with it)
unsigned int latest_table_servers_version = 0 ;
unsigned int MySQL_Monitor__thread_MySQL_Thread_Variables_version ;
MySQL_Thread * mysql_thr = new MySQL_Thread ( ) ;
mysql_thr - > curtime = monotonic_time ( ) ;
@ -4481,10 +4455,6 @@ void * MySQL_Monitor::monitor_aws_aurora() {
mysql_thr - > refresh_variables ( ) ;
if ( ! GloMTH ) return NULL ; // quick exit during shutdown/restart
unsigned long long t1 ;
unsigned long long t2 ;
unsigned long long next_loop_at = 0 ;
uint64_t last_raw_checksum = 0 ;
// ADD here an unordered map , Writer HG => next time at
@ -4498,7 +4468,6 @@ void * MySQL_Monitor::monitor_aws_aurora() {
while ( GloMyMon - > shutdown = = false & & mysql_thread___monitor_enabled = = true ) {
unsigned int glover ;
t1 = monotonic_time ( ) ;
if ( ! GloMTH ) return NULL ; // quick exit during shutdown/restart
@ -4507,7 +4476,6 @@ void * MySQL_Monitor::monitor_aws_aurora() {
if ( MySQL_Monitor__thread_MySQL_Thread_Variables_version < glover ) {
MySQL_Monitor__thread_MySQL_Thread_Variables_version = glover ;
mysql_thr - > refresh_variables ( ) ;
next_loop_at = 0 ;
}
// if list of servers or HG or options has changed, triggers new checks
@ -4516,7 +4484,6 @@ void * MySQL_Monitor::monitor_aws_aurora() {
pthread_mutex_unlock ( & aws_aurora_mutex ) ;
if ( new_raw_checksum ! = last_raw_checksum ) {
proxy_info ( " Detected new/changed definition for AWS Aurora monitoring \n " ) ;
next_loop_at = 0 ;
last_raw_checksum = new_raw_checksum ;
if ( pthreads_array ) {
// wait all threads to terminate
@ -4541,7 +4508,7 @@ void * MySQL_Monitor::monitor_aws_aurora() {
bool found = false ;
// very simple search. Far from optimal, but assuming very few HGs it is fast enough
for ( unsigned int i = 0 ; i < hgs_num ; i + + ) {
if ( tmp_hgs_array [ i ] = = wHG ) {
if ( tmp_hgs_array [ i ] = = ( unsigned int ) wHG ) {
found = true ;
}
}
@ -4729,7 +4696,6 @@ __exit_monitor_aws_aurora_thread:
AWS_Aurora_status_entry * ase = new AWS_Aurora_status_entry ( mmsd - > t1 , mmsd - > t2 - mmsd - > t1 , mmsd - > mysql_error_msg ) ;
if ( mmsd - > interr = = 0 & & mmsd - > result ) {
int num_fields = 0 ;
int num_rows = 0 ;
num_fields = mysql_num_fields ( mmsd - > result ) ;
if ( num_fields ! = 5 ) {
proxy_error ( " Incorrect number of fields, please report a bug \n " ) ;
@ -4814,7 +4780,7 @@ unsigned int MySQL_Monitor::estimate_lag(char* server_id, AWS_Aurora_status_entr
unsigned int mlag = 0 ;
unsigned int lag = 0 ;
for ( int i = 1 ; i < = lag_num_checks ; i + + ) {
for ( unsigned int i = 1 ; i < = lag_num_checks ; i + + ) {
if ( ! aase [ idx ] | | ! aase [ idx ] - > host_statuses )
break ;
for ( auto hse : * ( aase [ idx ] - > host_statuses ) ) {
@ -4832,8 +4798,8 @@ unsigned int MySQL_Monitor::estimate_lag(char* server_id, AWS_Aurora_status_entr
}
void MySQL_Monitor : : evaluate_aws_aurora_results ( unsigned int wHG , unsigned int rHG , AWS_Aurora_status_entry * * lasts_ase , unsigned int ase_idx , unsigned int max_latency_ms , unsigned int add_lag_ms , unsigned int min_lag_ms , unsigned int lag_num_checks ) {
unsigned int i = 0 ;
# ifdef TEST_AURORA
unsigned int i = 0 ;
bool verbose = false ;
unsigned int action_yes = 0 ;
unsigned int action_no = 0 ;