Debian Codegraph @

mysql-test/suite/rpl/t/rpl_perfschema_log_status.test

raw
1 # ==== Purpose ====
2 #
3 # This test case validates the contents of
4 # performance_schema.log_status table and the privileges
5 # required to query the table. It also validates that the table can be
6 # accessed even when MySQL instance is locked for backup and FLUSH TABLES
7 # <table list> WITH READ LOCK is in place.
8 #
9 # In a first step, it generates some workload on the master and then collects
10 # the instance log resources status on the slave by querying
11 # performance_schema.log_status inserting its contents
12 # into a new table.
13 #
14 # The test case then validates some of the contents inserted into
15 # the new table.
16 #
17 # In a second step, the test case creates an unprivileged user asserting
18 # that the server will throw an error when the user tries to query
19 # performance_schema.log_status table.
20 #
21 # A third step queries performance_schema.log_status while other
22 # client session locked MySQL instance for backup and did
23 # FLUSH TABLE <table list> WITH READ LOCK.
24 #
25 # ==== Related Bugs and Worklogs ====
26 #
27 # WL#9452: Log Position Lock
28 #
29 --source include/force_myisam_default.inc
30 --source include/have_myisam.inc
31
32 # Test requires master-info-repository=TABLE, relay-log-info-repository=TABLE
33 --source include/have_slave_repository_type_table.inc
34 --source include/master-slave.inc
35
36
37 --echo # First step
38
39 # Table to collect instance_log_info
40 CREATE TABLE ils_copy (
41 uuid VARCHAR(36) PRIMARY KEY,
42 master JSON NOT NULL,
43 channels JSON NOT NULL,
44 storage_engines JSON NOT NULL);
45
46 # Table to be listed at FLUSH TABLES <table list> WITH READ LOCK
47 CREATE TABLE t1 (c1 INT) ENGINE=MyISAM;
48
49 --source include/sync_slave_sql_with_master.inc
50 # Create a new channel, so we can test a non-empty channel name on results
51 CHANGE REPLICATION SOURCE TO SOURCE_HOST = '127.0.0.1' FOR CHANNEL 'ch1';
52
53 # Save current master binary log coordinates and gtid_executed
54 --let $_saved_gtids=
55 if (`SELECT @@GLOBAL.gtid_mode = "ON"`)
56 {
57 --let $use_gtids= 1
58 }
59 --source include/save_master_pos.inc
60
61 # Sleep before collecting positions
62 --sleep 5
63
64 # Save current slave relay log coordinates
65 --let $relay_log_file= query_get_value(SHOW SLAVE STATUS, Relay_Log_File, 1)
66 --let $relay_log_pos= query_get_value(SHOW SLAVE STATUS, Relay_Log_Pos, 1)
67 --let $ch1_relay_log_file= query_get_value(SHOW SLAVE STATUS, Relay_Log_File, 2)
68 # As we do not start ch1, we cannot verify its positions accurately for this
69 # test case purposes. That is fine as the objective is to test a non-empty
70 # channel name.
71
72 # Save current InnoDB LSN and LSN_checkpoint before the collection
73 --replace_regex /\n/<EOL>/ /.*<EOL>Last checkpoint at[[:space:]]*([0-9]+)<EOL>.*/\1/
74 --let $innodb_seis=`SHOW ENGINE INNODB STATUS`
75 # Remove the "InnoDB" from the collected LSN_checkpoint info
76 --let $innodb_lsn_checkpoint_before=`SELECT LTRIM(RIGHT('$innodb_seis', LENGTH('$innodb_seis') - 6))`
77 --replace_regex /\n/<EOL>/ /.*<EOL>Log sequence number[[:space:]]*([0-9]+)<EOL>.*/\1/
78 --let $innodb_seis=`SHOW ENGINE INNODB STATUS`
79 # Remove the "InnoDB" from the collected LSN info
80 --let $innodb_lsn_before=`SELECT LTRIM(RIGHT('$innodb_seis', LENGTH('$innodb_seis') - 6))`
81
82 # Collect the instance log status into ils_copy table
83 --let $ils_dump= $MYSQLTEST_VARDIR/tmp/ils_$server_2_uuid
84 --replace_result $ils_dump ILS_DUMP
85 --eval SELECT * FROM performance_schema.log_status INTO OUTFILE '$ils_dump'
86 if ($rpl_debug)
87 {
88 --query_vertical SELECT * FROM ils_copy
89 }
90
91 # Save current InnoDB LSN and LSN_checkpoint after the collection
92 --replace_regex /\n/<EOL>/ /.*<EOL>Last checkpoint at[[:space:]]*([0-9]+)<EOL>.*/\1/
93 --let $innodb_seis=`SHOW ENGINE INNODB STATUS`
94 # Remove the "InnoDB" from the collected LSN_checkpoint info
95 --let $innodb_lsn_checkpoint_after=`SELECT LTRIM(RIGHT('$innodb_seis', LENGTH('$innodb_seis') - 6))`
96 --replace_regex /\n/<EOL>/ /.*<EOL>Log sequence number[[:space:]]*([0-9]+)<EOL>.*/\1/
97 --let $innodb_seis=`SHOW ENGINE INNODB STATUS`
98 # Remove the "InnoDB" from the collected LSN info
99 --let $innodb_lsn_after=`SELECT LTRIM(RIGHT('$innodb_seis', LENGTH('$innodb_seis') - 6))`
100
101 #
102 # Validate what was collected from performance_schema.log_status table
103 #
104 --replace_result $ils_dump ILS_DUMP
105 --eval LOAD DATA INFILE '$ils_dump' INTO TABLE ils_copy
106
107 --let $assert_text= Collected server UUID is correct
108 --let $ils_uuid= `SELECT uuid FROM ils_copy`
109 --let $assert_cond= "$ils_uuid" = "$server_2_uuid"
110 --source include/assert.inc
111
112 --let $assert_text= Collected master binary log file name is correct
113 --let $ils_master_file= `SELECT JSON_EXTRACT(master, "$.binary_log_file") FROM ils_copy`
114 --let $assert_cond= $ils_master_file = "$_saved_file"
115 --source include/assert.inc
116
117 --let $assert_text= Collected master binary log file position is correct
118 --let $ils_master_pos= `SELECT JSON_EXTRACT(master, "$.binary_log_position") FROM ils_copy`
119 --let $assert_cond= $ils_master_pos = $_saved_pos
120 --source include/assert.inc
121
122 --let $assert_text= Collected master gtid_executed is correct
123 --let $ils_gtid_executed= `SELECT JSON_EXTRACT(master, "$.gtid_executed") FROM ils_copy`
124 --let $assert_cond= $ils_gtid_executed = "$_saved_gtids"
125 --source include/assert.inc
126
127 --let $assert_text= Collected default replication channel name is correct
128 --let $ils_channel_name= `SELECT JSON_EXTRACT(channels, "$.channels[0].channel_name") FROM ils_copy`
129 --let $assert_cond= $ils_channel_name = ""
130 --source include/assert.inc
131
132 --let $assert_text= Collected default replication channel relay log file name is correct
133 --let $ils_relay_log_file= `SELECT JSON_EXTRACT(channels, "$.channels[0].relay_log_file") FROM ils_copy`
134 --let $assert_cond= $ils_relay_log_file = "$relay_log_file"
135 --source include/assert.inc
136
137 --let $assert_text= Collected default replication channel relay log file position is correct
138 --let $ils_relay_log_pos= `SELECT JSON_EXTRACT(channels, "$.channels[0].relay_log_position") FROM ils_copy`
139 --let $assert_cond= $ils_relay_log_pos = $relay_log_pos
140 --source include/assert.inc
141
142 --let $assert_text= Collected replication channel name for ch1 is correct
143 --let $ils_ch1_channel_name= `SELECT JSON_EXTRACT(channels, "$.channels[1].channel_name") FROM ils_copy`
144 --let $assert_cond= $ils_ch1_channel_name = "ch1"
145 --source include/assert.inc
146
147 --let $assert_text= Collected replication channel relay log file name for ch1 is correct
148 --let $ils_ch1_relay_log_file= `SELECT JSON_EXTRACT(channels, "$.channels[1].relay_log_file") FROM ils_copy`
149 --let $assert_cond= $ils_ch1_relay_log_file = "$ch1_relay_log_file"
150 --source include/assert.inc
151
152 --let $assert_text= Collected InnoDB LSN is in correct boundaries
153 --let $ils_innodb_lsn= `SELECT JSON_EXTRACT(storage_engines, "$.InnoDB.LSN") FROM ils_copy`
154 --let $assert_cond= $innodb_lsn_after >= $ils_innodb_lsn AND $ils_innodb_lsn >= $innodb_lsn_before
155 --source include/assert.inc
156
157 --let $assert_text= Collected InnoDB LSN_checkpoint is in correct boundaries
158 --let $ils_innodb_lsn_checkpoint = `SELECT JSON_EXTRACT(storage_engines, "$.InnoDB.LSN_checkpoint") FROM ils_copy`
159 --let $assert_cond= $innodb_lsn_checkpoint_after >= $ils_innodb_lsn_checkpoint AND $ils_innodb_lsn_checkpoint >= $innodb_lsn_checkpoint_before
160 --source include/assert.inc
161
162
163 --echo # Second step
164
165 #
166 # Check that unprivileged access to
167 # performance_schema.log_status table fails
168 #
169
170 # Create a new user and allow it to query any table
171 CREATE USER user1@'%';
172 GRANT SELECT ON *.* TO user1@'%';
173
174 # Connect the slave as the new user
175 --connect (user1,127.0.0.1,user1,,test,$SLAVE_MYPORT,)
176 --connection user1
177 # Ensure user1 has access to performance_schema tables.
178 # Disabling result log as it is not deterministic.
179 --disable_result_log
180 SELECT COUNT(*) FROM performance_schema.global_variables;
181 --enable_result_log
182 # Querying performance_schema.log_status should fail
183 --error ER_SPECIFIC_ACCESS_DENIED_ERROR
184 --query_vertical SELECT * FROM performance_schema.log_status
185
186 --source include/rpl_connection_slave.inc
187 --disconnect user1
188 DROP USER user1@'%';
189 RESET SLAVE ALL FOR CHANNEL 'ch1';
190
191
192 --echo # Third step
193
194 #
195 # Check that performance_schema.log_status can be accessed
196 # even when MySQL instance is locked for backup and
197 # FLUSH TABLES <table list> WITH READ LOCK is in place.
198 #
199 --source include/rpl_connection_slave1.inc
200 LOCK INSTANCE FOR BACKUP;
201 FLUSH TABLES test.t1 WITH READ LOCK;
202 --source include/rpl_connection_slave.inc
203 # The content of the result is not important in this step
204 --disable_result_log
205 SELECT * FROM performance_schema.log_status;
206 --enable_result_log
207 --source include/rpl_connection_slave1.inc
208 UNLOCK TABLES;
209 UNLOCK INSTANCE;
210
211
212 # Cleanup
213 --source include/rpl_connection_slave.inc
214 --remove_file $ils_dump
215 --source include/rpl_connection_master.inc
216 DROP TABLE ils_copy, t1;
217
218 --source include/rpl_end.inc