summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSujatha <sujatha.sivakumar@mariadb.com>2020-11-12 13:04:39 +0530
committerSujatha <sujatha.sivakumar@mariadb.com>2020-11-12 13:04:39 +0530
commit984a06db2ce2b2e3c7c5028245905417f2141cd7 (patch)
treeebaa78908f2b70726492b9ac1a69c5496867d308
parentdd33a70dad2b32aa6fcdbd1f8161d5351f6dbebd (diff)
downloadmariadb-git-984a06db2ce2b2e3c7c5028245905417f2141cd7.tar.gz
MDEV-4633: multi_source.simple test fails sporadically
Analysis: ======== Writes to 'rli->log_space_total' needs to be synchronized, otherwise both SQL_THREAD and IO_THREAD can try to modify the variable simultaneously resulting in incorrect rli->log_space_total. In the current test scenario SQL_THREAD is trying to decrement 'rli->log_space_total' in 'purge_first_log' and IO_THREAD is trying to increment the 'rli->log_space_total' in 'queue_event' simultaneously. Hence test occasionally fails with result mismatch. Fix: === Convert 'rli->log_space_total' variable to atomic type.
-rw-r--r--sql/log.cc4
-rw-r--r--sql/log.h4
-rw-r--r--sql/rpl_rli.cc10
-rw-r--r--sql/slave.cc19
4 files changed, 27 insertions, 10 deletions
diff --git a/sql/log.cc b/sql/log.cc
index 54a8bd9552f..dc8df9c6fdb 100644
--- a/sql/log.cc
+++ b/sql/log.cc
@@ -4397,7 +4397,9 @@ int MYSQL_BIN_LOG::purge_first_log(Relay_log_info* rli, bool included)
0, 0, &log_space_reclaimed);
mysql_mutex_lock(&rli->log_space_lock);
- rli->log_space_total-= log_space_reclaimed;
+ my_atomic_add64_explicit((volatile int64*)(&rli->log_space_total),
+ (-(int64)log_space_reclaimed),
+ MY_MEMORY_ORDER_RELAXED);
mysql_cond_broadcast(&rli->log_space_cond);
mysql_mutex_unlock(&rli->log_space_lock);
diff --git a/sql/log.h b/sql/log.h
index 0e6b2c895af..0770861fe01 100644
--- a/sql/log.h
+++ b/sql/log.h
@@ -716,7 +716,9 @@ public:
char buf1[22],buf2[22];
#endif
DBUG_ENTER("harvest_bytes_written");
- (*counter)+=bytes_written;
+
+ my_atomic_add64_explicit((volatile int64*)(counter), bytes_written,
+ MY_MEMORY_ORDER_RELAXED);
DBUG_PRINT("info",("counter: %s bytes_written: %s", llstr(*counter,buf1),
llstr(bytes_written,buf2)));
bytes_written=0;
diff --git a/sql/rpl_rli.cc b/sql/rpl_rli.cc
index 99f8da2c928..d2d1bc3421d 100644
--- a/sql/rpl_rli.cc
+++ b/sql/rpl_rli.cc
@@ -454,7 +454,8 @@ static inline int add_relay_log(Relay_log_info* rli,LOG_INFO* linfo)
linfo->log_file_name);
DBUG_RETURN(1);
}
- rli->log_space_total += s.st_size;
+ my_atomic_add64_explicit((volatile int64*)(&rli->log_space_total),
+ s.st_size, MY_MEMORY_ORDER_RELAXED);
DBUG_PRINT("info",("log_space_total: %llu", rli->log_space_total));
DBUG_RETURN(0);
}
@@ -464,7 +465,8 @@ static int count_relay_log_space(Relay_log_info* rli)
{
LOG_INFO linfo;
DBUG_ENTER("count_relay_log_space");
- rli->log_space_total= 0;
+ my_atomic_store64_explicit((volatile int64*)(&rli->log_space_total), 0,
+ MY_MEMORY_ORDER_RELAXED);
if (rli->relay_log.find_log_pos(&linfo, NullS, 1))
{
sql_print_error("Could not find first log while counting relay log space");
@@ -1223,8 +1225,8 @@ int purge_relay_logs(Relay_log_info* rli, THD *thd, bool just_reset,
strmake_buf(rli->group_relay_log_name, rli->relay_log.get_log_fname());
strmake_buf(rli->event_relay_log_name, rli->relay_log.get_log_fname());
rli->group_relay_log_pos= rli->event_relay_log_pos= BIN_LOG_HEADER_SIZE;
- rli->log_space_total= 0;
-
+ my_atomic_store64_explicit((volatile int64*)(&rli->log_space_total), 0,
+ MY_MEMORY_ORDER_RELAXED);
if (count_relay_log_space(rli))
{
*errmsg= "Error counting relay log space";
diff --git a/sql/slave.cc b/sql/slave.cc
index 87eacfcfd0a..a2c35e5f116 100644
--- a/sql/slave.cc
+++ b/sql/slave.cc
@@ -2373,7 +2373,10 @@ static bool wait_for_relay_log_space(Relay_log_info* rli)
&rli->log_space_lock,
&stage_waiting_for_relay_log_space,
&old_stage);
- while (rli->log_space_limit < rli->log_space_total &&
+ while (rli->log_space_limit <
+ (ulonglong)my_atomic_load64_explicit((volatile int64*)
+ (&rli->log_space_total),
+ MY_MEMORY_ORDER_RELAXED) &&
!(slave_killed=io_slave_killed(mi)) &&
!rli->ignore_log_space_limit)
mysql_cond_wait(&rli->log_space_cond, &rli->log_space_lock);
@@ -2923,7 +2926,10 @@ static bool send_show_master_info_data(THD *thd, Master_info *mi, bool full,
protocol->store(mi->rli.last_error().message, &my_charset_bin);
protocol->store((uint32) mi->rli.slave_skip_counter);
protocol->store((ulonglong) mi->rli.group_master_log_pos);
- protocol->store((ulonglong) mi->rli.log_space_total);
+ protocol->store((ulonglong)
+ my_atomic_load64_explicit((volatile int64*)
+ (&mi->rli.log_space_total),
+ MY_MEMORY_ORDER_RELAXED));
protocol->store(
mi->rli.until_condition==Relay_log_info::UNTIL_NONE ? "None":
@@ -4623,7 +4629,9 @@ Stopping slave I/O thread due to out-of-memory error from master");
#endif
if (rli->log_space_limit && rli->log_space_limit <
- rli->log_space_total &&
+ (ulonglong) my_atomic_load64_explicit((volatile int64*)
+ (&rli->log_space_total),
+ MY_MEMORY_ORDER_RELAXED) &&
!rli->ignore_log_space_limit)
if (wait_for_relay_log_space(rli))
{
@@ -7222,7 +7230,10 @@ static Log_event* next_event(rpl_group_info *rgi, ulonglong *event_size)
is are able to rotate and purge sometime soon.
*/
if (rli->log_space_limit &&
- rli->log_space_limit < rli->log_space_total)
+ rli->log_space_limit <
+ (ulonglong) my_atomic_load64_explicit((volatile int64*)
+ (&rli->log_space_total),
+ MY_MEMORY_ORDER_RELAXED))
{
/* force rotation if not in an unfinished group */
rli->sql_force_rotate_relay= !rli->is_in_group();