polardbxengine/mysql-test/suite/rpl/t/rpl_perfschema_log_status_b...

289 lines
11 KiB
Plaintext

# ==== Purpose ====
#
# This test case will test expected blockages when querying
# performance_schema.log_status table.
#
# It will use 6 additional connections to the slave server to
# send a statement that is expected to be blocked. Then, it will
# proceed with the blockage by using debug instrumentation to
# pause the thread generating the result before actually collecting
# the log information.
#
# The test case will send all 6 statements expected to block, and will
# wait until all report as doing something in performance_schema.threads.
#
# Finally, the test case will release the blockage and will wait until all
# 6 statements to finish.
#
# The collected information will be verified.
#
# ==== Related Bugs and Worklogs ====
#
# WL#9452: Log Position Lock
#
--source include/force_myisam_default.inc
--source include/have_myisam.inc
--source include/have_debug.inc
--source include/have_debug_sync.inc
# Test requires master-info-repository=TABLE, relay-log-info-repository=TABLE
--source include/have_slave_repository_type_table.inc
--let $rpl_extra_connections_per_server= 6
--source include/master-slave.inc
# Create a table to store the data to be validated
CREATE TABLE ils_copy (
uuid VARCHAR(36) PRIMARY KEY,
master JSON NOT NULL,
channels JSON NOT NULL,
storage_engines JSON NOT NULL);
CREATE TABLE t1_innodb (c1 INT);
CREATE TABLE t2_myisam (c1 INT) ENGINE=MyISAM;
--source include/sync_slave_sql_with_master.inc
# Make server to pause when fully blocked
--let $debug_point= pause_collecting_instance_logs_info
--source include/add_debug_point.inc
# Create a new channel, so we can test a non-empty channel name on results
CHANGE MASTER TO MASTER_HOST = '127.0.0.1' FOR CHANNEL 'ch1';
# Suppression of error messages
CALL mtr.add_suppression('Unsafe statement written to the binary log');
# Save current master binary log coordinates and gtid_executed
--let $_saved_gtids=
if (`SELECT @@GLOBAL.gtid_mode = "ON"`)
{
--let $use_gtids= 1
}
--source include/save_master_pos.inc
# Save current slave relay log coordinates
--let $relay_log_file= query_get_value(SHOW SLAVE STATUS, Relay_Log_File, 1)
--let $relay_log_pos= query_get_value(SHOW SLAVE STATUS, Relay_Log_Pos, 1)
--let $ch1_relay_log_file= query_get_value(SHOW SLAVE STATUS, Relay_Log_File, 2)
# As we do not start ch1, we cannot verify its positions accurately for this
# test case purposes. That is fine as the objective is to test a non-empty
# channel name.
--source include/rpl_connection_slave1.inc
FLUSH TABLES test.t2_myisam, performance_schema.threads WITH READ LOCK;
--source include/rpl_connection_slave.inc
# Save current InnoDB LSN and LSN_checkpoint before the collection
--replace_regex /\n/<EOL>/ /.*<EOL>Last checkpoint at[[:space:]]*([0-9]+)<EOL>.*/\1/
--let $innodb_seis=`SHOW ENGINE INNODB STATUS`
# Remove the "InnoDB" from the collected LSN_checkpoint info
--let $innodb_lsn_checkpoint_before=`SELECT LTRIM(RIGHT('$innodb_seis', LENGTH('$innodb_seis') - 6))`
--replace_regex /\n/<EOL>/ /.*<EOL>Log sequence number[[:space:]]*([0-9]+)<EOL>.*/\1/
--let $innodb_seis=`SHOW ENGINE INNODB STATUS`
# Remove the "InnoDB" from the collected LSN info
--let $innodb_lsn_before=`SELECT LTRIM(RIGHT('$innodb_seis', LENGTH('$innodb_seis') - 6))`
# Collect the instance log status into ils_copy table
--let $ils_dump= $MYSQLTEST_VARDIR/tmp/ils_$server_2_uuid
--replace_result $ils_dump ILS_DUMP
--send_eval SELECT * FROM performance_schema.log_status INTO OUTFILE '$ils_dump'
--source include/rpl_connection_slave1.inc
SET DEBUG_SYNC='now WAIT_FOR reached_collecting_instance_logs_info';
# No actions below show progress until
# signaling "continue_collecting_instance_logs_info" in DEBUG_SYNC
# No changes into binary log
--let $rpl_connection_name= server_2_1
--source include/rpl_connection.inc
--let $tid1=`SELECT CONNECTION_ID()`
--send FLUSH LOCAL BINARY LOGS;
# No changes into Gtid_state (GTID_EXECUTED)
--let $rpl_connection_name= server_2_2
--source include/rpl_connection.inc
--let $tid2=`SELECT CONNECTION_ID()`
--send SET @@GLOBAL.gtid_purged = '+00000000-0000-0000-0000-000000000000:1-999'
# No new channels can be created
--let $rpl_connection_name= server_2_3
--source include/rpl_connection.inc
--let $tid3=`SELECT CONNECTION_ID()`
--send CHANGE MASTER TO MASTER_HOST='127.0.0.1' FOR CHANNEL 'ch2'
# No existing channels can be removed
--let $rpl_connection_name= server_2_4
--source include/rpl_connection.inc
--let $tid4=`SELECT CONNECTION_ID()`
--send RESET SLAVE ALL FOR CHANNEL 'ch1'
# No changes into blocked storage engines (InnoDB)
--let $rpl_connection_name= server_2_5
--source include/rpl_connection.inc
--let $tid5=`SELECT CONNECTION_ID()`
SET @sql_log_bin = 0;
--send INSERT INTO t1_innodb VALUE (9)
# No changes into blocked tables (MyISAM)
--let $rpl_connection_name= server_2_6
--source include/rpl_connection.inc
--let $tid6=`SELECT CONNECTION_ID()`
SET @sql_log_bin = 0;
--send INSERT INTO t2_myisam VALUE (9)
# No changes into I/O thread relay log positions
--source include/rpl_connection_master.inc
FLUSH BINARY LOGS;
INSERT INTO t1_innodb VALUES (1);
INSERT INTO t2_myisam VALUES (1);
FLUSH BINARY LOGS;
INSERT INTO t1_innodb VALUES (2);
INSERT INTO t2_myisam VALUES (2);
# Give some time to all "--send" above
--sleep 1
--source include/rpl_connection_slave1.inc
--echo Wait until all threads expecting to be block be doing something
--source include/rpl_connection_slave1.inc
let $wait_condition=
SELECT COUNT(*) = 6 FROM performance_schema.threads
WHERE PROCESSLIST_ID IN ($tid1, $tid2, $tid3, $tid4, $tid5, $tid6)
AND PROCESSLIST_STATE IS NOT NULL;
--source include/wait_condition_or_abort.inc
SET DEBUG_SYNC='now SIGNAL continue_collecting_instance_logs_info';
UNLOCK TABLES;
--source include/rpl_connection_slave.inc
--reap
--replace_result $ils_dump ILS_DUMP
--eval LOAD DATA INFILE '$ils_dump' INTO TABLE ils_copy
--let $rpl_connection_name= server_2_1
--source include/rpl_connection.inc
--reap
--let $rpl_connection_name= server_2_2
--source include/rpl_connection.inc
--reap
--let $rpl_connection_name= server_2_3
--source include/rpl_connection.inc
--reap
--let $rpl_connection_name= server_2_4
--source include/rpl_connection.inc
--reap
--let $rpl_connection_name= server_2_5
--source include/rpl_connection.inc
--reap
--let $rpl_connection_name= server_2_6
--source include/rpl_connection.inc
--reap
--source include/rpl_connection_slave1.inc
--echo Wait until all blocked threads are released and finish
let $wait_condition=
SELECT COUNT(*) = 6 FROM performance_schema.threads
WHERE PROCESSLIST_ID IN ($tid1, $tid2, $tid3, $tid4, $tid5, $tid6)
AND PROCESSLIST_STATE IS NULL;
--source include/wait_condition_or_abort.inc
#
# Validate what was collected from performance_schema.log_status table
#
--source include/rpl_connection_slave.inc
if ($rpl_debug)
{
--query_vertical SELECT * FROM ils_copy
}
# Save current InnoDB LSN and LSN_checkpoint after the collection
--replace_regex /\n/<EOL>/ /.*<EOL>Last checkpoint at[[:space:]]*([0-9]+)<EOL>.*/\1/
--let $innodb_seis=`SHOW ENGINE INNODB STATUS`
# Remove the "InnoDB" from the collected LSN_checkpoint info
--let $innodb_lsn_checkpoint_after=`SELECT LTRIM(RIGHT('$innodb_seis', LENGTH('$innodb_seis') - 6))`
--replace_regex /\n/<EOL>/ /.*<EOL>Log sequence number[[:space:]]*([0-9]+)<EOL>.*/\1/
--let $innodb_seis=`SHOW ENGINE INNODB STATUS`
# Remove the "InnoDB" from the collected LSN info
--let $innodb_lsn_after=`SELECT LTRIM(RIGHT('$innodb_seis', LENGTH('$innodb_seis') - 6))`
--let $assert_text= Collected server UUID is correct
--let $ils_uuid= `SELECT uuid FROM ils_copy`
--let $assert_cond= "$ils_uuid" = "$server_2_uuid"
--source include/assert.inc
--let $assert_text= Collected master binary log file name is correct
--let $ils_master_file= `SELECT JSON_EXTRACT(master, "$.binary_log_file") FROM ils_copy`
--let $assert_cond= $ils_master_file = "$_saved_file"
--source include/assert.inc
--let $assert_text= Collected master binary log file position is correct
--let $ils_master_pos= `SELECT JSON_EXTRACT(master, "$.binary_log_position") FROM ils_copy`
--let $assert_cond= $ils_master_pos = $_saved_pos
--source include/assert.inc
--let $assert_text= Collected master gtid_executed is correct
--let $ils_gtid_executed= `SELECT JSON_EXTRACT(master, "$.gtid_executed") FROM ils_copy`
--let $assert_cond= $ils_gtid_executed = "$_saved_gtids"
--source include/assert.inc
--let $assert_text= Collected default replication channel name is correct
--let $ils_channel_name= `SELECT JSON_EXTRACT(channels, "$.channels[0].channel_name") FROM ils_copy`
--let $assert_cond= $ils_channel_name = ""
--source include/assert.inc
--let $assert_text= Collected default replication channel relay log file name is correct
--let $ils_relay_log_file= `SELECT JSON_EXTRACT(channels, "$.channels[0].relay_log_file") FROM ils_copy`
--let $assert_cond= $ils_relay_log_file = "$relay_log_file"
--source include/assert.inc
--let $assert_text= Collected default replication channel relay log file position is correct
--let $ils_relay_log_pos= `SELECT JSON_EXTRACT(channels, "$.channels[0].relay_log_position") FROM ils_copy`
--let $assert_cond= $ils_relay_log_pos = $relay_log_pos
--source include/assert.inc
--let $assert_text= Collected replication channel name for ch1 is correct
--let $ils_ch1_channel_name= `SELECT JSON_EXTRACT(channels, "$.channels[1].channel_name") FROM ils_copy`
--let $assert_cond= $ils_ch1_channel_name = "ch1"
--source include/assert.inc
--let $assert_text= Collected replication channel relay log file name for ch1 is correct
--let $ils_ch1_relay_log_file= `SELECT JSON_EXTRACT(channels, "$.channels[1].relay_log_file") FROM ils_copy`
--let $assert_cond= $ils_ch1_relay_log_file = "$ch1_relay_log_file"
--source include/assert.inc
--let $assert_text= There is no other channel information collected (no ch2)
--let $ils_ch2= `SELECT JSON_EXTRACT(channels, "$.channels[2].channel_name") IS NULL FROM ils_copy`
--let $assert_cond= $ils_ch2 = 1
--source include/assert.inc
--let $assert_text= Collected InnoDB LSN is in correct boundaries
--let $ils_innodb_lsn= `SELECT JSON_EXTRACT(storage_engines, "$.InnoDB.LSN") FROM ils_copy`
--let $assert_cond= $innodb_lsn_after >= $ils_innodb_lsn AND $ils_innodb_lsn >= $innodb_lsn_before
--source include/assert.inc
--let $assert_text= Collected InnoDB LSN_checkpoint is in correct boundaries
--let $ils_innodb_lsn_checkpoint = `SELECT JSON_EXTRACT(storage_engines, "$.InnoDB.LSN_checkpoint") FROM ils_copy`
--let $assert_cond= $innodb_lsn_checkpoint_after >= $ils_innodb_lsn_checkpoint AND $ils_innodb_lsn_checkpoint >= $innodb_lsn_checkpoint_before
--source include/assert.inc
# Cleanup
--source include/rpl_connection_slave.inc
--source include/remove_debug_point.inc
RESET SLAVE ALL FOR CHANNEL 'ch2';
--remove_file $ils_dump
--source include/rpl_connection_master.inc
DROP TABLE ils_copy, t1_innodb, t2_myisam;
--source include/rpl_end.inc