Add GloMTH initialization wait to all monitor threads

Fix race condition where monitor threads were accessing GloMTH before
it was fully initialized, causing Valgrind errors in get_variable_int().

Added wait loop pattern (while GloMTH==NULL { usleep(50000); }) followed
by usleep(100000) to:
- monitor_ping_thread
- monitor_read_only_thread
- monitor_replication_lag_thread
- monitor_group_replication_thread (also moved check before MySQL_Thread creation)
- monitor_galera_thread (also moved check before MySQL_Thread creation)

This matches the existing pattern in monitor_connect_thread.
v3.0-test0213
Rene Cannao 2 months ago
parent f4cd34be5c
commit aa53d990ed

@ -1403,6 +1403,10 @@ void * monitor_ping_thread(const std::vector<MySQL_Monitor_State_Data*>& mmsds)
assert(!mmsds.empty());
mysql_close(mysql_init(NULL));
MySQL_Monitor_State_Data *mmsd = mmsds.front();
while (GloMTH==NULL) {
usleep(50000);
}
usleep(100000);
if (!GloMTH) return NULL; // quick exit during shutdown/restart
MySQL_Thread * mysql_thr = new MySQL_Thread();
mysql_thr->curtime=monotonic_time();
@ -1636,6 +1640,10 @@ void * monitor_read_only_thread(const std::vector<MySQL_Monitor_State_Data*>& da
mysql_close(mysql_init(NULL));
bool timeout_reached = false;
MySQL_Monitor_State_Data *mmsd = data.front();
while (GloMTH==NULL) {
usleep(50000);
}
usleep(100000);
if (!GloMTH) return NULL; // quick exit during shutdown/restart
MySQL_Thread * mysql_thr = new MySQL_Thread();
mysql_thr->curtime=monotonic_time();
@ -1914,10 +1922,14 @@ void * monitor_group_replication_thread(const std::vector<MySQL_Monitor_State_Da
assert(!data.empty());
mysql_close(mysql_init(NULL));
MySQL_Monitor_State_Data *mmsd = data.front();
while (GloMTH==NULL) {
usleep(50000);
}
usleep(100000);
if (!GloMTH) return NULL; // quick exit during shutdown/restart
MySQL_Thread * mysql_thr = new MySQL_Thread();
mysql_thr->curtime=monotonic_time();
mysql_thr->refresh_variables();
if (!GloMTH) return NULL; // quick exit during shutdown/restart
mmsd->mysql=GloMyMon->My_Conn_Pool->get_connection(mmsd->hostname, mmsd->port, mmsd);
unsigned long long start_time=mysql_thr->curtime;
@ -2266,10 +2278,14 @@ void * monitor_galera_thread(const std::vector<MySQL_Monitor_State_Data*>& data)
assert(!data.empty());
mysql_close(mysql_init(NULL));
MySQL_Monitor_State_Data *mmsd = data.front();
while (GloMTH==NULL) {
usleep(50000);
}
usleep(100000);
if (!GloMTH) return NULL; // quick exit during shutdown/restart
MySQL_Thread * mysql_thr = new MySQL_Thread();
mysql_thr->curtime=monotonic_time();
mysql_thr->refresh_variables();
if (!GloMTH) return NULL; // quick exit during shutdown/restart
mmsd->mysql=GloMyMon->My_Conn_Pool->get_connection(mmsd->hostname, mmsd->port, mmsd);
unsigned long long start_time=mysql_thr->curtime;
@ -2667,6 +2683,10 @@ void * monitor_replication_lag_thread(const std::vector<MySQL_Monitor_State_Data
assert(!data.empty());
mysql_close(mysql_init(NULL));
MySQL_Monitor_State_Data *mmsd = data.front();
while (GloMTH==NULL) {
usleep(50000);
}
usleep(100000);
if (!GloMTH) return NULL; // quick exit during shutdown/restart
MySQL_Thread * mysql_thr = new MySQL_Thread();
mysql_thr->curtime=monotonic_time();

Loading…
Cancel
Save