| 1 |
# ==== Purpose ==== |
| 2 |
# |
| 3 |
# This test script serves as the functionality testing for the table |
| 4 |
# performance_schema.replication_connection_status. Test for ddl and dml |
| 5 |
# operations is a part of the perfschema suite. The ddl/dml tests are named: |
| 6 |
# 1) ddl_replication_connection_status.test and |
| 7 |
# 2) dml_replication_connection_status.test. |
| 8 |
# |
| 9 |
# This test script does the following: |
| 10 |
|
| 11 |
# - Verify that SELECT works for every field in the table. |
| 12 |
# - The SELECT per field produces an output similar to the corresponding field |
| 13 |
# in SHOW SLAVE STATUS(SSS), if there is one. |
| 14 |
# - If there is no matching field in SSS, we resort to other method of testing |
| 15 |
# those fields. |
| 16 |
# |
| 17 |
# The follwing scenarios are tested: |
| 18 |
# |
| 19 |
# - Test each field on a fresh replication setup. |
| 20 |
# - Cause an error in the IO thread and check for the correctness of the error |
| 21 |
# number, meaasge and timestamp field. |
| 22 |
# - Verify that the error fields are preserved after STOP SLAVE, thread_id |
| 23 |
# changes to NULL and service_state to "off". |
| 24 |
# - Start server with gtid-mode=on and test the RECEIVED_TRANSACTION_SET field. |
| 25 |
# Also, make sure the value in this field is preserved after STOP SLAVE. |
| 26 |
# - Test Group Replication related fields. They should be set NULL when plugin |
| 27 |
# is not installed on slave. |
| 28 |
# - When Group Replication plugin is not installed, table must return an empty |
| 29 |
# set. |
| 30 |
# ==== Related Worklog ==== |
| 31 |
# |
| 32 |
# WL#3656: PERFORMANCE SCHEMA table for SHOW SLAVE STATUS |
| 33 |
# WL#6841: PERFORMANCE SCHEMA to show Group Replication kernel stats |
| 34 |
# |
| 35 |
source include/not_valgrind.inc; |
| 36 |
source include/master-slave.inc; |
| 37 |
source include/have_binlog_format_mixed.inc; |
| 38 |
|
| 39 |
--let $assert_text= On master, the table should return an empty set. |
| 40 |
--let $assert_cond= [select count(*) from performance_schema.replication_connection_status] = 0 |
| 41 |
--source include/assert.inc |
| 42 |
|
| 43 |
--connection slave |
| 44 |
|
| 45 |
--let $Group_Name= query_get_value(select Group_Name from performance_schema.replication_connection_status, Group_Name, 1) |
| 46 |
--let $assert_text= On slave, the group_name should be set NULL |
| 47 |
--let $assert_cond= "$Group_Name"= "" |
| 48 |
--source include/assert.inc |
| 49 |
|
| 50 |
--echo |
| 51 |
--echo # Verify that SELECT works for every field and produces an output similar |
| 52 |
--echo # to the corresponding field in SHOW SLAVE STATUS(SSS). To verify the |
| 53 |
--echo # correctness of thread_id field, we check for the name of the thread. |
| 54 |
--echo |
| 55 |
|
| 56 |
let $sss_value= query_get_value(SHOW SLAVE STATUS, Master_UUID, 1); |
| 57 |
let $ps_value= query_get_value(select Source_UUID from performance_schema.replication_connection_status, Source_UUID, 1); |
| 58 |
let $assert_text= Value returned by SSS and PS table for Source_UUID should be same.; |
| 59 |
let $assert_cond= "$sss_value" = "$ps_value"; |
| 60 |
source include/assert.inc; |
| 61 |
|
| 62 |
let $thread_name= `select name from performance_schema.threads where thread_id= (select Thread_Id from performance_schema.replication_connection_status)`; |
| 63 |
let $assert_text= thread_name should should indicate io thread.; |
| 64 |
let $assert_cond= "$thread_name" = "thread/sql/replica_io"; |
| 65 |
source include/assert.inc; |
| 66 |
|
| 67 |
let $sss_value= query_get_value(SHOW SLAVE STATUS, Slave_IO_Running, 1); |
| 68 |
let $ps_value= query_get_value(select Service_State from performance_schema.replication_connection_status, Service_State, 1); |
| 69 |
let $assert_text= SSS shows Slave_IO_Running as "Yes". So, Service_State from this PS table should be "ON".; |
| 70 |
let $assert_cond= "$sss_value" = "Yes" AND "$ps_value"= "ON"; |
| 71 |
source include/assert.inc; |
| 72 |
|
| 73 |
# |
| 74 |
# Heartbeat count and last hearbeat timestamp are not in SSS, but these are in |
| 75 |
# IS. So to test count_received_heartbeats and last_heartbeat_timestamp |
| 76 |
# we compare values from IS and PS unlike SSS and PS for other fields in this |
| 77 |
# test. |
| 78 |
let $ps_value= query_get_value(select last_heartbeat_timestamp from performance_schema.replication_connection_status, last_heartbeat_timestamp, 1); |
| 79 |
let $assert_text= PS table should output 0000-00-00 00:00:00.000000 indicating no heartbeats have been received; |
| 80 |
let $assert_cond= "$ps_value"= "0000-00-00 00:00:00.000000"; |
| 81 |
source include/assert.inc; |
| 82 |
|
| 83 |
let $sss_value= query_get_value(SHOW SLAVE STATUS, Retrieved_Gtid_Set, 1); |
| 84 |
let $ps_value= query_get_value(select Received_Transaction_Set from performance_schema.replication_connection_status, Received_Transaction_Set, 1); |
| 85 |
let $assert_text= Value returned by SSS and PS table for Received_Transaction_Set should be same.; |
| 86 |
let $assert_cond= "$sss_value" = "$ps_value"; |
| 87 |
source include/assert.inc; |
| 88 |
|
| 89 |
let $sss_value= query_get_value(SHOW SLAVE STATUS, Last_IO_Errno, 1); |
| 90 |
let $ps_value= query_get_value(select Last_Error_Number from performance_schema.replication_connection_status, Last_Error_Number, 1); |
| 91 |
let $assert_text= Value returned by SSS and PS table for Last_Error_Number should be same.; |
| 92 |
let $assert_cond= "$sss_value" = "$ps_value"; |
| 93 |
source include/assert.inc; |
| 94 |
|
| 95 |
let $sss_value= query_get_value(SHOW SLAVE STATUS, Last_IO_Error, 1); |
| 96 |
let $ps_value= query_get_value(select Last_Error_Message from performance_schema.replication_connection_status, Last_Error_Message, 1); |
| 97 |
let $assert_text= Value returned by SSS and PS table for Last_Error_Message should be same.; |
| 98 |
let $assert_cond= "$sss_value" = "$ps_value"; |
| 99 |
source include/assert.inc; |
| 100 |
|
| 101 |
let $sss_value= query_get_value(SHOW SLAVE STATUS, Last_IO_Error_Timestamp, 1); |
| 102 |
let $ps_value= query_get_value(select Last_Error_Timestamp from performance_schema.replication_connection_status, Last_Error_Timestamp, 1); |
| 103 |
let $assert_text= Value returned by PS table for Last_Error_Timestamp should be 0000-00-00 00:00:00.000000.; |
| 104 |
let $assert_cond= "$ps_value" = "0000-00-00 00:00:00.000000"; |
| 105 |
source include/assert.inc; |
| 106 |
|
| 107 |
source include/stop_slave.inc; |
| 108 |
|
| 109 |
--echo |
| 110 |
--echo # heartbeat count and last heartbeat timestamp are indeterministic so we |
| 111 |
--echo # can not test for their exact values. We will thus check for >0 number |
| 112 |
--echo # of heartbeats and last heartbeat timestamp!= zeros. |
| 113 |
--echo |
| 114 |
|
| 115 |
CHANGE REPLICATION SOURCE to SOURCE_HEARTBEAT_PERIOD= 0.5; |
| 116 |
|
| 117 |
set @restore_replica_net_timeout= @@global.replica_net_timeout; |
| 118 |
set @@global.replica_net_timeout= 10; |
| 119 |
|
| 120 |
source include/start_slave.inc; |
| 121 |
|
| 122 |
# there is an explicit sleep lasting longer than replica_net_timeout |
| 123 |
# to ensure that nothing will come to slave from master for that period. |
| 124 |
# That would cause reconnecting and relaylog rotation w/o the fix i.e |
| 125 |
# without a heartbeat received. |
| 126 |
|
| 127 |
sleep 15; |
| 128 |
|
| 129 |
# |
| 130 |
# proof that there has been received at least one heartbeat; |
| 131 |
# The exact number of received heartbeat is an indeterministic value |
| 132 |
# and therefore it's not recorded into results. |
| 133 |
# |
| 134 |
|
| 135 |
let $slave_wait_param_counter= 300; |
| 136 |
let $slave_value= query_get_value(select count_received_heartbeats from performance_schema.replication_connection_status, count_received_heartbeats, 1); |
| 137 |
|
| 138 |
# Checking the fact that at least one heartbeat is received |
| 139 |
while (!$slave_value) |
| 140 |
{ |
| 141 |
dec $slave_wait_param_counter; |
| 142 |
if (!$slave_wait_param_counter) |
| 143 |
{ |
| 144 |
query_vertical show slave status; |
| 145 |
select count_received_heartbeats from performance_schema.replication_connection_status; |
| 146 |
--die ERROR: failed while waiting for replica to generate a heartbeat. |
| 147 |
exit; |
| 148 |
} |
| 149 |
sleep 0.1; |
| 150 |
let $slave_value= query_get_value(select count_received_heartbeats from performance_schema.replication_connection_status, count_received_heartbeats, 1); |
| 151 |
} |
| 152 |
|
| 153 |
--echo |
| 154 |
--echo A heartbeat has been received by the slave |
| 155 |
--echo |
| 156 |
|
| 157 |
# |
| 158 |
# check for non-zero value of the Slave_last_heartbeat variable when the slave is enabled |
| 159 |
# |
| 160 |
let $ps_value= query_get_value(select last_heartbeat_timestamp from performance_schema.replication_connection_status, last_heartbeat_timestamp, 1); |
| 161 |
let $assert_text= last_heartbeat_timestamp should NOT be zero; |
| 162 |
let $assert_cond= "$ps_value" != "0000-00-00 00:00:00"; |
| 163 |
source include/assert.inc; |
| 164 |
|
| 165 |
# Reset replica_net_timeout to default after testing heartbeats. |
| 166 |
set @@global.replica_net_timeout= @restore_replica_net_timeout; |
| 167 |
|
| 168 |
--echo |
| 169 |
--echo # We now introduce an error in the IO thread and check for the correctness |
| 170 |
--echo # of error number, message and timestamp fields. |
| 171 |
--echo |
| 172 |
|
| 173 |
# Cause an error in IO thread. |
| 174 |
--connection slave |
| 175 |
source include/stop_slave.inc; |
| 176 |
replace_result $MYSQL_TEST_DIR MYSQL_TEST_DIR; |
| 177 |
replace_column 2 ####; |
| 178 |
eval CHANGE REPLICATION SOURCE to |
| 179 |
SOURCE_USER='replssl', |
| 180 |
SOURCE_PASSWORD=''; |
| 181 |
|
| 182 |
start slave io_thread; |
| 183 |
let $slave_param= Last_IO_Errno; |
| 184 |
let $slave_param_value= 1045; |
| 185 |
source include/wait_for_slave_param.inc; |
| 186 |
|
| 187 |
--echo |
| 188 |
--echo # Extract the error related fields from SSS and PS table and compare |
| 189 |
--echo # them for correctness. |
| 190 |
--echo |
| 191 |
|
| 192 |
let $sss_value= query_get_value(SHOW SLAVE STATUS, Last_IO_Errno, 1); |
| 193 |
let $ps_value= query_get_value(select Last_Error_Number from performance_schema.replication_connection_status, Last_Error_Number, 1); |
| 194 |
let $assert_text= Value returned by SSS and PS table for Last_Error_Number should be same.; |
| 195 |
let $assert_cond= "$sss_value" = "$ps_value"; |
| 196 |
source include/assert.inc; |
| 197 |
|
| 198 |
# Availability of special characters like single quote and backtick character |
| 199 |
# makes it difficult use the assert.inc or mysql functionstrcmp(). |
| 200 |
# So, the equality of error messages is checked using the below perl code. |
| 201 |
|
| 202 |
let $sss_value= query_get_value(SHOW SLAVE STATUS, Last_IO_Error, 1); |
| 203 |
let $ps_value= query_get_value(select Last_Error_Message from performance_schema.replication_connection_status, Last_Error_Message, 1); |
| 204 |
|
| 205 |
let PS_VALUE= $ps_value; |
| 206 |
let SSS_VALUE= $sss_value; |
| 207 |
|
| 208 |
perl; |
| 209 |
use strict; |
| 210 |
my $ps_value= $ENV{'PS_VALUE'}; |
| 211 |
my $sss_value= $ENV{'SSS_VALUE'}; |
| 212 |
|
| 213 |
if ($ps_value eq $sss_value) |
| 214 |
{ |
| 215 |
print "Value returned by SSS and PS table for Last_Error_Message is same.\n"; |
| 216 |
} |
| 217 |
else |
| 218 |
{ |
| 219 |
print "Value returned by SSS and PS table for Last_Error_Message is NOT same\n"; |
| 220 |
} |
| 221 |
EOF |
| 222 |
|
| 223 |
# End of perl code for testing the error message. |
| 224 |
|
| 225 |
# The timestamp format is slightly different in SSS and PS. |
| 226 |
# SSS => YYMMDD HH:MM:SS |
| 227 |
# PS => YYYY-MM-DD HH:MM:SS.ssssss |
| 228 |
# To match the two, we get rid of hyphons from PS output and first two digits |
| 229 |
# the year field and the microseconds (after WL7319) so that it can be matched |
| 230 |
# directly. |
| 231 |
|
| 232 |
let $sss_value= query_get_value(SHOW SLAVE STATUS, Last_IO_Error_Timestamp, 1); |
| 233 |
let $ps_value= query_get_value(select Last_Error_Timestamp from performance_schema.replication_connection_status, Last_Error_Timestamp, 1); |
| 234 |
let $ps_value_without_hyphons= `SELECT REPLACE("$ps_value", '-', '')`; |
| 235 |
let $ps_value_in_sss_format= `select substring("$ps_value_without_hyphons", 3)`; |
| 236 |
let $ps_value_without_microseconds= `select substring_index("$ps_value_in_sss_format", '.', 1)`; |
| 237 |
let $assert_text= Value returned by SSS and PS table for Last_Error_Timestamp should be same.; |
| 238 |
let $assert_cond= "$sss_value" = "$ps_value_without_microseconds"; |
| 239 |
source include/assert.inc; |
| 240 |
|
| 241 |
--echo |
| 242 |
--echo # Verify that source_UUID and the error related fields are preserved |
| 243 |
--echo # after STOP SLAVE, thread_id changes to NULL and service_state to "off". |
| 244 |
--echo |
| 245 |
|
| 246 |
--let $slave_io_errno= convert_error(ER_ACCESS_DENIED_ERROR) |
| 247 |
source include/stop_slave.inc; |
| 248 |
|
| 249 |
--echo |
| 250 |
--echo # 1. Verify that thread_id changes to NULL and service_state to "off" on |
| 251 |
--echo # STOP SLAVE. |
| 252 |
--echo |
| 253 |
|
| 254 |
let $ps_value= query_get_value(select thread_id from performance_schema.replication_connection_status, thread_id, 1); |
| 255 |
let $assert_text= After STOP SLAVE, thread_id should be NULL; |
| 256 |
let $assert_cond= "$ps_value" = "NULL"; |
| 257 |
source include/assert.inc; |
| 258 |
|
| 259 |
let $sss_value= query_get_value(SHOW SLAVE STATUS, Slave_IO_Running, 1); |
| 260 |
let $ps_value= query_get_value(select Service_State from performance_schema.replication_connection_status, Service_State, 1); |
| 261 |
let $assert_text= SSS shows Slave_IO_Running as "No". So, Service_State from this PS table should be "OFF".; |
| 262 |
let $assert_cond= "$sss_value" = "No" AND "$ps_value"= "OFF"; |
| 263 |
source include/assert.inc; |
| 264 |
|
| 265 |
--echo |
| 266 |
--echo # 2. Extract the source_UUID and the error related fields from SSS and PS |
| 267 |
--echo # table and compare them. These fields should preserve their values. |
| 268 |
--echo |
| 269 |
|
| 270 |
let $sss_value= query_get_value(SHOW SLAVE STATUS, Master_UUID, 1); |
| 271 |
let $ps_value= query_get_value(select Source_UUID from performance_schema.replication_connection_status, Source_UUID, 1); |
| 272 |
let $assert_text= Value returned by SSS and PS table for Source_UUID should be same.; |
| 273 |
let $assert_cond= "$sss_value" = "$ps_value"; |
| 274 |
source include/assert.inc; |
| 275 |
|
| 276 |
let $sss_value= query_get_value(SHOW SLAVE STATUS, Last_IO_Errno, 1); |
| 277 |
let $ps_value= query_get_value(select Last_Error_Number from performance_schema.replication_connection_status, Last_Error_Number, 1); |
| 278 |
let $assert_text= Value returned by SSS and PS table for Last_Error_Number should be same.; |
| 279 |
let $assert_cond= "$sss_value" = "$ps_value"; |
| 280 |
source include/assert.inc; |
| 281 |
|
| 282 |
# Availability of special characters like single quote and backtick character |
| 283 |
# makes it difficult use the assert.inc or mysql functionstrcmp(). |
| 284 |
# So, the equality of error messages is checked using the below perl code. |
| 285 |
|
| 286 |
let $sss_value= query_get_value(SHOW SLAVE STATUS, Last_IO_Error, 1); |
| 287 |
let $ps_value= query_get_value(select Last_Error_Message from performance_schema.replication_connection_status, Last_Error_Message, 1); |
| 288 |
|
| 289 |
let PS_VALUE= $ps_value; |
| 290 |
let SSS_VALUE= $sss_value; |
| 291 |
|
| 292 |
perl; |
| 293 |
use strict; |
| 294 |
my $ps_value= $ENV{'PS_VALUE'}; |
| 295 |
my $sss_value= $ENV{'SSS_VALUE'}; |
| 296 |
|
| 297 |
if ($ps_value eq $sss_value) |
| 298 |
{ |
| 299 |
print "Value returned by SSS and PS table for Last_Error_Message is same.\n"; |
| 300 |
} |
| 301 |
else |
| 302 |
{ |
| 303 |
print "Value returned by SSS and PS table for Last_Error_Message is NOT same\n"; |
| 304 |
} |
| 305 |
EOF |
| 306 |
|
| 307 |
# End of perl code for testing error message. |
| 308 |
|
| 309 |
# The timestamp format is slightly different in SSS and PS. |
| 310 |
# SSS => YYMMDD HH:MM:SS |
| 311 |
# PS => YYYY-MM-DD HH:MM:SS.ssssss |
| 312 |
# To match the two, we get rid of hyphons from PS output and first two digits |
| 313 |
# the year field and also the microseconds (after WL#7319) so that it can be |
| 314 |
# matched directly. |
| 315 |
|
| 316 |
let $sss_value= query_get_value(SHOW SLAVE STATUS, Last_IO_Error_Timestamp, 1); |
| 317 |
let $ps_value= query_get_value(select Last_Error_Timestamp from performance_schema.replication_connection_status, Last_Error_Timestamp, 1); |
| 318 |
let $assert_text= Value returned by SSS and PS table for Last_Error_Timestamp should be same.; |
| 319 |
let $ps_value_without_hyphons= `SELECT REPLACE("$ps_value", '-', '')`; |
| 320 |
let $ps_value_in_sss_format= `select substring("$ps_value_without_hyphons", 3)`; |
| 321 |
let $ps_value_without_microseconds= `select substring_index("$ps_value_in_sss_format", '.', 1)`; |
| 322 |
let $assert_text= Value returned by SSS and PS table for Last_Error_Timestamp should be same.; |
| 323 |
let $assert_cond= "$sss_value" = "$ps_value_without_microseconds"; |
| 324 |
source include/assert.inc; |
| 325 |
|
| 326 |
--echo |
| 327 |
--echo # Restart the master and slave servers in gtid-mode=on, execute some |
| 328 |
--echo # transactions and verify the 'Received_Transaction_Set' field. |
| 329 |
--echo |
| 330 |
|
| 331 |
let $rpl_server_number= 1; |
| 332 |
let $rpl_start_with_gtids= 1; |
| 333 |
source include/rpl_restart_server.inc; |
| 334 |
|
| 335 |
let $rpl_server_number= 2; |
| 336 |
let $rpl_start_with_gtids= 1; |
| 337 |
source include/rpl_restart_server.inc; |
| 338 |
|
| 339 |
--connection slave |
| 340 |
replace_column 2 ####; |
| 341 |
CHANGE REPLICATION SOURCE to |
| 342 |
SOURCE_USER = 'root', |
| 343 |
SOURCE_AUTO_POSITION= 1; |
| 344 |
source include/start_slave.inc; |
| 345 |
|
| 346 |
--connection master |
| 347 |
use test; |
| 348 |
create table t(a int); |
| 349 |
insert into t values(1); |
| 350 |
|
| 351 |
--source include/sync_slave_sql_with_master.inc |
| 352 |
|
| 353 |
let $sss_value= query_get_value(SHOW SLAVE STATUS, Retrieved_Gtid_Set, 1); |
| 354 |
let $ps_value= query_get_value(select Received_Transaction_Set from performance_schema.replication_connection_status, Received_Transaction_Set, 1); |
| 355 |
let $assert_text= Value returned by SSS and PS table for Received_Transaction_Set should be same.; |
| 356 |
let $assert_cond= "$sss_value" = "$ps_value"; |
| 357 |
source include/assert.inc; |
| 358 |
|
| 359 |
--echo |
| 360 |
--echo # Verify that the value for 'Received_Transaction_Set' field is preserved |
| 361 |
--echo # after STOP SLAVE. |
| 362 |
--echo |
| 363 |
|
| 364 |
--source include/stop_slave.inc |
| 365 |
--let $old_ps_value= $ps_value |
| 366 |
--let $assert_text= Received_Transaction_Set should not have changed after STOP SLAVE |
| 367 |
--let $assert_cond= "$ps_value" = "$old_ps_value"; |
| 368 |
--source include/assert.inc |
| 369 |
|
| 370 |
--echo |
| 371 |
--echo # Verify that the value for 'Received_Transaction_Set' is cleared |
| 372 |
--echo # after RESET SLAVE. |
| 373 |
--echo |
| 374 |
|
| 375 |
RESET SLAVE; |
| 376 |
--let $assert_cond= Received_Transaction_Set = "" FROM performance_schema.replication_connection_status |
| 377 |
--let $assert_text= Received_Transaction_Set should be empty after RESET SLAVE |
| 378 |
--source include/assert.inc |
| 379 |
|
| 380 |
source include/start_slave.inc; |
| 381 |
--connection master |
| 382 |
drop table t; |
| 383 |
--source include/sync_slave_sql_with_master.inc |
| 384 |
|
| 385 |
let $rpl_only_running_threads= 1; |
| 386 |
|
| 387 |
source include/stop_slave.inc; |
| 388 |
--connection slave |
| 389 |
CHANGE REPLICATION SOURCE TO SOURCE_AUTO_POSITION = 0 FOR CHANNEL ''; |
| 390 |
# Reset the gtid mode if the test started with gtid_mode=OFF |
| 391 |
if ($gtid_mode_on == 0) { |
| 392 |
--let $rpl_gtid_mode = 0 |
| 393 |
--let $rpl_set_enforce_gtid_consistency = 0 |
| 394 |
} |
| 395 |
--let $no_extra_info = 1 |
| 396 |
--source include/rpl_set_gtid_mode.inc |
| 397 |
|
| 398 |
source include/rpl_end.inc; |