| 1 |
############################################################################### |
| 2 |
# Bug#25656123 MEMORY LEAK IN MASTER-MASTER GTID REPLICATION WITH |
| 3 |
# SYNC_RELAY_LOG_INFO |
| 4 |
# |
| 5 |
# Problem: Applier thread is leaking memory when it is updating |
| 6 |
# repository tables for ignored/skipped events. |
| 7 |
# |
| 8 |
# Steps to reproduce: |
| 9 |
# |
| 10 |
# 1) Create M1<->M2 replication topology |
| 11 |
# |
| 12 |
# 2) Create a sample table to create ignored/skipped insert events |
| 13 |
# on the table. And run some sample inserts on both nodes, so that |
| 14 |
# initially bytes used will not be counted. |
| 15 |
# |
| 16 |
# 3) If gtid_mode is OFF, set sql_replica_skip_counter to 50 on M2 node |
| 17 |
# and restart sql thread to make the change effective. |
| 18 |
# |
| 19 |
# If gtid_mode is ON, execute 50 empty transactions on M2 node, |
| 20 |
# so that 50 transactions from M1 will be skipped. |
| 21 |
# |
| 22 |
# 4) Record thd::main_mem_root usage values on both servers before |
| 23 |
# starting the experiment. |
| 24 |
# |
| 25 |
# 5) Insert 100 sample queries on M1 node. First 50 inserts will be ignored |
| 26 |
# on M2 node (because sql_replica_skip_counter set to 50 in step-3). |
| 27 |
# Second 50 inserts will be executed on M2 and will be replicated back to |
| 28 |
# M1 node. But they will be ignored on M1 because they were originated on |
| 29 |
# M1 node. |
| 30 |
# |
| 31 |
# 6) Record thd::main_mem_root usage value on M1 after |
| 32 |
# the experiment. Check that thd::main_mem_root value |
| 33 |
# did not increased. |
| 34 |
# |
| 35 |
# 7) Record thd::main_mem_root usage value on M2 after |
| 36 |
# the experiment. Check that thd::main_mem_root value |
| 37 |
# did not increased. |
| 38 |
# |
| 39 |
# 8) Cleanup. |
| 40 |
############################################################################### |
| 41 |
|
| 42 |
# This test is independent of binlog format. Choosing 'row' format. |
| 43 |
--source include/have_binlog_format_row.inc |
| 44 |
|
| 45 |
# sql_replica_skip_counter is not supported with compression |
| 46 |
--source include/not_binlog_transaction_compression_on.inc |
| 47 |
|
| 48 |
# Performance schema Query used to test memory growth |
| 49 |
--let $perf_query=SELECT high_number_of_bytes_used/1024/1024 FROM performance_schema.memory_summary_global_by_event_name WHERE event_name = 'memory/sql/thd::main_mem_root' |
| 50 |
--let $master_uuid=`SELECT @@SERVER_UUID` |
| 51 |
|
| 52 |
--echo # |
| 53 |
--echo # Step-1) Create M1<->M2 replication topology |
| 54 |
--echo # |
| 55 |
--let $rpl_topology= 1->2->1 |
| 56 |
--source include/rpl_init.inc |
| 57 |
|
| 58 |
--echo # |
| 59 |
--echo # Step-2) Create a sample table to create ignored/skipped |
| 60 |
--echo # insert events on the table. And run some sample |
| 61 |
--echo # inserts on both nodes, so that initial hiccups |
| 62 |
--echo # in bytes used will not be counted. |
| 63 |
--echo # |
| 64 |
--let $rpl_connection_name=server_1 |
| 65 |
--source include/rpl_connection.inc |
| 66 |
CREATE TABLE t1(i INT); |
| 67 |
--source include/rpl_sync.inc |
| 68 |
--let $rpl_connection_name=server_1 |
| 69 |
--source include/rpl_connection.inc |
| 70 |
INSERT INTO t1 VALUES (1); |
| 71 |
INSERT INTO t1 VALUES (2); |
| 72 |
--let $rpl_connection_name=server_2 |
| 73 |
--source include/rpl_connection.inc |
| 74 |
INSERT INTO t1 VALUES (3); |
| 75 |
INSERT INTO t1 VALUES (4); |
| 76 |
--source include/rpl_sync.inc |
| 77 |
|
| 78 |
--echo # |
| 79 |
--echo # Step-3) If gtid_mode is OFF, set sql_replica_skip_counter to 50 on |
| 80 |
--echo # M2 node and restart sql thread to make the change effective. |
| 81 |
--echo # |
| 82 |
--echo # If gtid_mode is ON, execute 50 empty transactions on |
| 83 |
--echo # M2 node, so that 50 transactions from M1 will be skipped. |
| 84 |
--echo # |
| 85 |
--let $rpl_connection_name=server_2 |
| 86 |
--source include/rpl_connection.inc |
| 87 |
--source include/stop_slave_sql.inc |
| 88 |
--disable_query_log |
| 89 |
if ( `SELECT @@GLOBAL.GTID_MODE = "OFF"` ) |
| 90 |
{ |
| 91 |
SET GLOBAL sql_replica_skip_counter=50; |
| 92 |
} |
| 93 |
if ( `SELECT @@GLOBAL.GTID_MODE = "ON"` ) |
| 94 |
{ |
| 95 |
--let $trx_no=2 |
| 96 |
while ($trx_no <= 50) |
| 97 |
{ |
| 98 |
--replace_result $master_uuid MASTER_UUID |
| 99 |
--eval SET GTID_NEXT='$master_uuid:$trx_no' |
| 100 |
BEGIN; |
| 101 |
COMMIT; |
| 102 |
--inc $trx_no |
| 103 |
} |
| 104 |
SET GTID_NEXT='AUTOMATIC'; |
| 105 |
} |
| 106 |
--enable_query_log |
| 107 |
--source include/start_slave_sql.inc |
| 108 |
|
| 109 |
--echo # |
| 110 |
--echo # Step-4) Record thd::main_mem_root usage values on both servers before |
| 111 |
--echo # starting the experiment. |
| 112 |
--echo # |
| 113 |
--let $rpl_connection_name=server_1 |
| 114 |
--source include/rpl_connection.inc |
| 115 |
|
| 116 |
--let $thd_mem_root_usage_on_M1_before_experiment=`$perf_query` |
| 117 |
|
| 118 |
--let $rpl_connection_name=server_2 |
| 119 |
--source include/rpl_connection.inc |
| 120 |
--let $thd_mem_root_usage_on_M2_before_experiment=`$perf_query` |
| 121 |
|
| 122 |
--echo # |
| 123 |
--echo # Step-5) Insert 100 sample queries on M1 node. First 50 inserts will |
| 124 |
--echo # be ignored on M2 node (because sql_replica_skip_counter set to |
| 125 |
--echo # 50). Second 50 inserts will be executed on M2 and will be |
| 126 |
--echo # replicated back to M1 node. But they will be ignored on M1 |
| 127 |
--echo # because they were originated on M1 node. |
| 128 |
--echo # |
| 129 |
--let $rpl_connection_name=server_1 |
| 130 |
--source include/rpl_connection.inc |
| 131 |
--disable_query_log |
| 132 |
--let $i=0 |
| 133 |
while ($i < 100) |
| 134 |
{ |
| 135 |
--eval INSERT INTO t1 VALUES ($i) |
| 136 |
--inc $i |
| 137 |
} |
| 138 |
--enable_query_log |
| 139 |
--source include/rpl_sync.inc |
| 140 |
# Wait for all the events from M2 reach M1 back (they will be ignored but we |
| 141 |
# should wait till all the events reach M1 to verify our experiment). |
| 142 |
# Simple sync will not work in case of GTIDs, as the GTID_EXECUTED already contains |
| 143 |
# everything, sync will think that everything is applied. |
| 144 |
# So to achieve what we wanted, execute a sample query on M2 that will *not* be ignored |
| 145 |
# by M1, and wait till M1 executes that particular query (i.e., a query and then sync). |
| 146 |
--let $rpl_connection_name=server_2 |
| 147 |
--source include/rpl_connection.inc |
| 148 |
INSERT INTO t1 VALUES (100); |
| 149 |
--source include/rpl_sync.inc |
| 150 |
|
| 151 |
--echo # |
| 152 |
--echo # Step-6) Record thd::main_mem_root usage value on M1 after |
| 153 |
--echo # the experiment. Check that thd::main_mem_root value |
| 154 |
--echo # did not increased. |
| 155 |
--echo # |
| 156 |
--let $rpl_connection_name=server_1 |
| 157 |
--source include/rpl_connection.inc |
| 158 |
--let $thd_mem_root_usage_on_M1_after_experiment=`$perf_query` |
| 159 |
--let $assert_text= thd::main_mem_root on M1 should be the same value as before experiment value. |
| 160 |
# Tolerate up to 1M change. The usage value is converted to MB earlier by |
| 161 |
# (high_number_of_bytes_used/1024/1024) but it is evaluated as double making |
| 162 |
# the precision of this check in bytes. As any background thread can add |
| 163 |
# to mem root allocation, with zero tolerance it results in intermittent |
| 164 |
# failure. Failure observed in ASAN build with 64 bytes more allocation |
| 165 |
# after clone GTID background is added. |
| 166 |
--let $assert_cond= $thd_mem_root_usage_on_M1_after_experiment < $thd_mem_root_usage_on_M1_before_experiment + 1 |
| 167 |
--source include/assert.inc |
| 168 |
|
| 169 |
--echo # |
| 170 |
--echo # Step-7) Record thd::main_mem_root usage value on M2 after |
| 171 |
--echo # the experiment. Check that thd::main_mem_root value |
| 172 |
--echo # did not increased. |
| 173 |
--echo # |
| 174 |
--let $rpl_connection_name=server_2 |
| 175 |
--source include/rpl_connection.inc |
| 176 |
--let $thd_mem_root_usage_on_M2_after_experiment=`$perf_query` |
| 177 |
--let $assert_text= thd::main_mem_root on M2 should be the same value as before experiment value. |
| 178 |
# Tolerate up to 1M change. |
| 179 |
--let $assert_cond= $thd_mem_root_usage_on_M2_after_experiment < $thd_mem_root_usage_on_M2_before_experiment + 1 |
| 180 |
--source include/assert.inc |
| 181 |
|
| 182 |
--echo # |
| 183 |
--echo # Step-8) Cleanup. |
| 184 |
--echo # |
| 185 |
DROP TABLE t1; |
| 186 |
--source include/rpl_end.inc |