MDEV-34822 pre-fix: Make wsrep_ready flag read lock-free

It's read for every command execution, and during slave replication
for every applied event.

It's also planned to be used during write set applying, so it means
mostly every server thread is going to compete for the mutex covering
this variable, especially considering how rarely it changes.
Converting wsrep_ready to atomic relaxes the things.

Signed-off-by: Julius Goryavsky <julius.goryavsky@mariadb.com>
This commit is contained in:
Denis Protivensky 2024-08-16 11:58:06 +03:00 committed by Julius Goryavsky
parent 024e95128b
commit 9f61aa4f8a
2 changed files with 6 additions and 6 deletions

View File

@ -269,8 +269,8 @@ static char provider_vendor[256]= { 0, };
* Wsrep status variables. LOCK_status must be locked When modifying
* these variables,
*/
std::atomic<bool> wsrep_ready(false);
my_bool wsrep_connected = FALSE;
my_bool wsrep_ready = FALSE;
const char* wsrep_cluster_state_uuid= cluster_uuid_str;
long long wsrep_cluster_conf_id = WSREP_SEQNO_UNDEFINED;
const char* wsrep_cluster_status = "Disconnected";
@ -565,10 +565,7 @@ void wsrep_verify_SE_checkpoint(const wsrep_uuid_t& uuid,
*/
my_bool wsrep_ready_get (void)
{
if (mysql_mutex_lock (&LOCK_wsrep_ready)) abort();
my_bool ret= wsrep_ready;
mysql_mutex_unlock (&LOCK_wsrep_ready);
return ret;
return wsrep_ready;
}
int wsrep_show_ready(THD *thd, SHOW_VAR *var, void *buff,
@ -3452,6 +3449,10 @@ bool wsrep_consistency_check(THD *thd)
// Wait until wsrep has reached ready state
void wsrep_wait_ready(THD *thd)
{
// First check not locking the mutex.
if (wsrep_ready)
return;
mysql_mutex_lock(&LOCK_wsrep_ready);
while(!wsrep_ready)
{

View File

@ -135,7 +135,6 @@ extern const char *wsrep_SR_store_types[];
// MySQL status variables
extern my_bool wsrep_connected;
extern my_bool wsrep_ready;
extern const char* wsrep_cluster_state_uuid;
extern long long wsrep_cluster_conf_id;
extern const char* wsrep_cluster_status;