Debian Codegraph @

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

raw
1 # ==== Purpose ====
2 #
3 # Verify that performance_schema.threads shows the correct
4 # PROCESSLIST_INFO for all thread stages.
5 #
6 # This is to verify that BUG#21127308 has been fixed. In the bug, the
7 # status of a replication worker thread waiting for more work (and
8 # several others) was not included in the array all_server_stages[],
9 # which caused PROCESSLIST_INFO in performance_schema.threads to be
10 # NULL for such threads.
11 #
12 # ==== Implementation ====
13 #
14 # It's hard to simulate all possible thread stages, as each case needs
15 # to be simulated in its own ad-hoc way, likely using debug sync
16 # points.
17 #
18 # Instead, we verify the bug just for one of the stages that was
19 # missing in the bug. Then, we parse mysqld.cc to find if there are
20 # any stages declared which are not listed in the array.
21 #
22 # This works currently, but the parsing depends on the current
23 # formatting in mysqld. So this test will fail if e.g. the
24 # declarations are moved to another file, or the datatype
25 # PSI_stage_info is renamed, etc. If that happens, please update this
26 # script accordingly.
27 #
28 # ==== Related bugs ====
29 #
30 # BUG#21127308: REPLICATION THREAD STATUSES NOT SHOWN IN PERFORMANCE_SCHEMA
31 # - Test was added in this bug.
32
33 # Test is binlog_format-agnostic
34 --source include/have_binlog_format_row.inc
35 --let $rpl_skip_start_slave= 1
36 --source include/master-slave.inc
37
38 --echo ==== Initialize ====
39
40 --connection slave
41 --let $old_replica_parallel_workers= `SELECT @@GLOBAL.REPLICA_PARALLEL_WORKERS`
42 --let $old_replica_transaction_retries= `SELECT @@GLOBAL.REPLICA_TRANSACTION_RETRIES`
43 SET GLOBAL REPLICA_TRANSACTION_RETRIES= 0;
44 SET GLOBAL REPLICA_PARALLEL_WORKERS= 1;
45 --source include/start_slave.inc
46
47 --echo ==== Test ====
48
49 --let $show_statement= SHOW PROCESSLIST
50 --let $field= State
51 --let $condition= = 'Waiting for an event from Coordinator'
52 --source include/wait_show_condition.inc
53
54 if (!$group_replication_plugin_installed)
55 {
56 --let $assert_cond= COUNT(*) = 1 FROM performance_schema.threads WHERE PROCESSLIST_STATE = "Waiting for an event from Coordinator"
57 }
58 if ($group_replication_plugin_installed)
59 {
60 # We will have one worker from the above configured slave plus the
61 # initial configured number of workers on group_replicatin_applier
62 # channel. group_replication_applier is not restarted during the
63 # test, so its configuration remains.
64 --let $workers= 1 + $old_replica_parallel_workers
65 --let $assert_cond= COUNT(*) = $workers FROM performance_schema.threads WHERE PROCESSLIST_STATE = "Waiting for an event from Coordinator"
66 }
67 --let $assert_text= The worker status should be set in P_S.threads
68 --source include/assert.inc
69
70 --echo ==== Look for more mistakes in mysqld.cc ====
71
72 perl;
73 # Find the location of mysqld.cc, if available.
74 my $mysqld;
75 for my $location ('../sql', '../../sql', '../../../sql')
76 {
77 if (-f "$location/mysqld.cc") {
78 $mysqld= "$location/mysqld.cc";
79 last;
80 }
81 }
82
83 # Tests may be installed in a completely different directory, in
84 # which case the source is not reachable. In that case, just skip
85 # this part of the test.
86 if ($mysqld)
87 {
88 # List of all stages declared in mysqld.cc
89 my %declared_stages= ();
90 # Hash of all stages included in the all_server_stages array.
91 my @listed_stages= ();
92
93 # This flag is set to true while processing lines from the array
94 # initialization.
95 my $in_server_stage_list= 0;
96
97 # Process mysqld.cc
98 open MYSQLD_CC, $mysqld or die "Error $? opening $mysqld: $!";
99 while (<MYSQLD_CC>)
100 {
101 # Read declaration.
102 if (/PSI_stage_info\s+([A-Za-z_0-9]+)\s*=/)
103 {
104 $declared_stages{$1} = 1;
105 }
106 # Figure out when we enter the array initialization.
107 elsif (/PSI_stage_info\s*\*\s*all_server_stages\s*\[/)
108 {
109 $in_server_stage_list= 1;
110 }
111 elsif ($in_server_stage_list)
112 {
113 # Read element from list.
114 if (/\&\s*([A-Za-z_0-9]+)\s*,?/) {
115 push(@listed_stages, $1);
116 }
117
118 # Figure out when we leave the array initialization.
119 # note that the last element may end with &stage_...};
120 if (/\};/) {
121 $in_server_stage_list= 0;
122 }
123 }
124 }
125 close MYSQLD_CC or die "Error $? closing $mysqld: $!";
126
127 # Sanity check, so that change in the format or naming doesn't make
128 # this test useless.
129 if (scalar(keys(%declared_stages)) < 10)
130 {
131 die "No declared stages found. Probably the format of stage declarations has changed; please update the regular expressions in this test to match the new format.";
132 }
133
134 # Check that every declared stage was found in the array.
135 for my $stage (@listed_stages)
136 {
137 delete($declared_stages{$stage});
138 }
139 if (scalar(%declared_stages))
140 {
141 die "Error: the following stages were declared in mysqld.cc but not listed in all_server_stages: " . join(", ", sort(keys(%declared_stages))) . ". This will make the PROCESSLIST_STATE column of performance_schema.threads show NULL when a thread is in this stage.";
142 }
143 }
144 EOF
145
146 --echo ==== Clean up ====
147
148 --source include/stop_slave.inc
149 --disable_warnings
150 --replace_result $old_replica_parallel_workers OLD_VALUE
151 eval SET GLOBAL REPLICA_PARALLEL_WORKERS= $old_replica_parallel_workers;
152 --enable_warnings
153 --replace_result $old_replica_transaction_retries OLD_VALUE
154 eval SET GLOBAL REPLICA_TRANSACTION_RETRIES= $old_replica_transaction_retries;
155
156 --let $rpl_only_running_threads= 1
157 --source include/rpl_end.inc