Debian Codegraph @

mysql-test/suite/perfschema/t/system_events_component.test

raw
1 --echo ## Test the Performance Schema System service
2 --echo ##
3 --echo ## Verify that the SOURCE column in all wait, stage, statement,
4 --echo ## transaction and metadata lock tables is set to NULL after a plugin
5 --echo ## or component is unloaded.
6 --echo ##
7 --echo ## 0. Setup
8 --echo ## 1. Install an example component to generate wait events
9 --echo ## 2. Generate stage, statement and transaction events
10 --echo ## 3. Unload the component / component
11 --echo ## 4. Verify that the SOURCE column is null in relevant tables
12 --echo ## 5. Re-install the test plugin
13 --echo ## 6. Verify that the SOURCE column is re-enabled
14 --echo ## 7. Cleanup
15
16 # Note: MTR allows only one plugin or component loaded per test, so there
17 # are two versions of this test--one for plugins and one for components.
18
19 --source include/no_protocol.inc
20
21 --echo
22 --echo #
23 --echo # 0) Setup
24 --echo #
25
26 # Create con0 for the test session, use default as the control.
27 connect(con0, localhost, root,,);
28
29 --echo Connection default
30 --connection default
31 USE performance_schema;
32
33 --echo
34 --echo # Disable all events from the control thread.
35 --echo UPDATE performance_schema.threads SET instrumented = 'NO' WHERE processlist_id = CONNECTION_ID();
36 --disable_query_log
37 UPDATE performance_schema.threads SET instrumented = 'NO' WHERE processlist_id = CONNECTION_ID();
38 --enable_query_log
39
40 --echo
41 --echo # Disable all events.
42 UPDATE performance_schema.setup_instruments SET enabled = 'NO', timed = 'NO';
43
44 --echo
45 --echo # Clear the tables that have a SOURCE column.
46 TRUNCATE events_waits_current;
47 TRUNCATE events_waits_history;
48 TRUNCATE events_waits_history_long;
49 TRUNCATE events_stages_current;
50 TRUNCATE events_stages_history;
51 TRUNCATE events_stages_history_long;
52 TRUNCATE events_statements_current;
53 TRUNCATE events_statements_history;
54 TRUNCATE events_statements_history_long;
55 TRUNCATE events_transactions_current;
56 TRUNCATE events_transactions_history;
57 TRUNCATE events_transactions_history_long;
58 --echo # metadata_locks is not truncatable
59
60 --echo
61 --echo #
62 --echo # 1) Install a component that generates its own wait events.
63 --echo #
64
65 --echo Connection con0
66 --connection con0
67 USE test;
68
69 INSTALL COMPONENT 'file://component_pfs_example';
70
71 --echo
72 --echo Connection default
73 --connection default
74
75 --echo
76 --echo # Enable events that record the source file and line.
77 UPDATE performance_schema.setup_instruments SET enabled = 'yes', timed = 'yes'
78 WHERE name LIKE 'stage/%' OR name LIKE 'statement/%' OR name = 'transaction' OR
79 name LIKE '%metadata/sql%' OR name LIKE 'wait/synch/mutex/sql/THD::%';
80
81 --echo
82 --echo Connection con0
83 --connection con0
84
85 --echo
86 --echo #
87 --echo # 2) Generate wait, stage, statement, transaction and metadata lock events. Keep the transaction open for now.
88 --echo #
89 CREATE TABLE t1 (s1 INT);
90 START TRANSACTION;
91 INSERT INTO t1 VALUES (1), (2), (3);
92
93 --echo
94 --echo Connection default
95 --connection default
96
97 #--echo DEBUG
98 # SELECT * FROM performance_schema.events_waits_current;
99 # SELECT * FROM performance_schema.events_waits_history;
100 # SELECT * FROM performance_schema.events_waits_history_long;
101 #--echo /DEBUG
102
103 --echo
104 --echo # Verify that the component registered and generated the wait events.
105 --echo ## TODO Resolve timing issues with events_waits_history. ##
106 --echo # SELECT (COUNT(*) > 0) AS "Expect 1" FROM performance_schema.events_waits_history WHERE event_name LIKE "%pfs_example%";
107 --echo # SELECT (COUNT(*) > 0) AS "Expect 1" FROM performance_schema.events_waits_history_long WHERE event_name LIKE "%pfs_example%";
108
109 --echo
110 --echo # Verify that each table is non-empty and that the SOURCE columns are populated.
111 --echo
112 SELECT (COUNT(*) > 0) AS "Expect 1" FROM events_waits_current AS t1 WHERE source <> "";
113 SELECT (COUNT(*) > 0) AS "Expect 1" FROM events_waits_history WHERE source <> "";
114 SELECT (COUNT(*) > 0) AS "Expect 1" FROM events_waits_history_long WHERE source <> "";
115 --echo # May or may not contain rows, but shares same code path as _history and _history_long
116 --echo # SELECT (COUNT(*) > 0) AS "Expect 1" FROM events_stages_current WHERE source <> "";
117 --echo
118 SELECT (COUNT(*) > 0) AS "Expect 1" FROM events_stages_history WHERE source <> "";
119 SELECT (COUNT(*) > 0) AS "Expect 1" FROM events_stages_history_long WHERE source <> "";
120 SELECT (COUNT(*) > 0) AS "Expect 1" FROM events_statements_current WHERE source <> "";
121 SELECT (COUNT(*) > 0) AS "Expect 1" FROM events_statements_history WHERE source <> "";
122 SELECT (COUNT(*) > 0) AS "Expect 1" FROM events_statements_history_long WHERE source <> "";
123 SELECT (COUNT(*) > 0) AS "Expect 1" FROM events_transactions_current WHERE source <> "";
124 SELECT (COUNT(*) > 0) AS "Expect 1" FROM events_transactions_history WHERE source <> "";
125 SELECT (COUNT(*) > 0) AS "Expect 1" FROM events_transactions_history_long WHERE source <> "";
126 SELECT (COUNT(*) > 0) AS "Expect 1" FROM metadata_locks WHERE object_schema = "test" AND source <> "";
127
128 --echo
129 --echo #
130 --echo # 3) Uninstall the test component to force a reset of the SOURCE columns.
131 --echo #
132 UNINSTALL COMPONENT 'file://component_pfs_example';
133
134 --echo
135 --echo #
136 --echo # 4) Verify that the SOURCE column was reset for all events.
137 --echo #
138 SELECT (COUNT(*) = 0) AS "Expect 1" FROM events_waits_current WHERE source <> "";
139 SELECT (COUNT(*) = 0) AS "Expect 1" FROM events_waits_history WHERE source <> "";
140 SELECT (COUNT(*) = 0) AS "Expect 1" FROM events_waits_history_long WHERE source <> "";
141 --echo # May or may not contain rows, but shares same code path as _history and _history_long
142 --echo # SELECT (COUNT(*) > 0) AS "Expect 1" FROM events_stages_current WHERE source = "";
143 --echo
144 --echo # Some stage events occur after the component is unloaded, so confirm that at least some of the SOURCE columns were reset.
145 SELECT (COUNT(*) > 0) AS "Expect 1" FROM events_stages_history WHERE source = "";
146 SELECT (COUNT(*) > 0) AS "Expect 1" FROM events_stages_history_long WHERE source = "";
147 --echo
148 SELECT (COUNT(*) = 0) AS "Expect 1" FROM events_statements_current WHERE source <> "";
149 SELECT (COUNT(*) = 0) AS "Expect 1" FROM events_statements_history WHERE source <> "";
150 SELECT (COUNT(*) = 0) AS "Expect 1" FROM events_statements_history_long WHERE source <> "";
151 SELECT (COUNT(*) = 0) AS "Expect 1" FROM events_transactions_current WHERE source <> "";
152 SELECT (COUNT(*) = 0) AS "Expect 1" FROM events_transactions_history WHERE source <> "";
153 SELECT (COUNT(*) = 0) AS "Expect 1" FROM events_transactions_history_long WHERE source <> "";
154 SELECT (COUNT(*) = 0) AS "Expect 1" FROM metadata_locks WHERE object_schema = "test" AND source <> "";
155
156 --echo
157 --echo Connection con0
158 --connection con0
159
160 --echo
161 --echo # Commit the open transaction from step 2.
162 COMMIT;
163
164 --echo
165 --echo Connection default
166 --connection default
167
168 --echo
169 --echo # Clear tables with SOURCE columns.
170 TRUNCATE events_waits_current;
171 TRUNCATE events_waits_history;
172 TRUNCATE events_waits_history_long;
173 TRUNCATE events_stages_current;
174 TRUNCATE events_stages_history;
175 TRUNCATE events_stages_history_long;
176 TRUNCATE events_statements_current;
177 TRUNCATE events_statements_history;
178 TRUNCATE events_statements_history_long;
179 TRUNCATE events_transactions_current;
180 TRUNCATE events_transactions_history;
181 TRUNCATE events_transactions_history_long;
182 --echo # metadata_locks is not truncatable
183
184 --echo
185 --echo Connection con0
186 --connection con0
187
188 --echo
189 --echo #
190 --echo # 5) Verify that the SOURCE columns are re-enabled after the reset.
191 --echo #
192 --echo
193
194 --echo # Re-install the component.
195 INSTALL COMPONENT 'file://component_pfs_example';
196
197 --echo
198 --echo # Generate new wait, stage, statement and transaction events. Leave the transaction open.
199 START TRANSACTION;
200 INSERT INTO t1 VALUES (4), (5), (6);
201
202 --echo
203 --echo Connection default
204 --connection default
205
206 --echo
207 --echo #
208 --echo # 6) Verify that each table is non-empty and that the SOURCE columns are populated.
209 --echo #
210 SELECT (COUNT(*) > 0) AS "Expect 1" FROM events_waits_current AS t1 WHERE source <> "";
211 SELECT (COUNT(*) > 0) AS "Expect 1" FROM events_waits_history WHERE source <> "";
212 SELECT (COUNT(*) > 0) AS "Expect 1" FROM events_waits_history_long WHERE source <> "";
213 --echo # May or may not contain rows, but shares same code path as _history and _history_long
214 --echo # SELECT (COUNT(*) > 0) AS "Expect 1" FROM events_stages_current WHERE source <> "";
215 --echo
216 SELECT (COUNT(*) > 0) AS "Expect 1" FROM events_stages_history WHERE source <> "";
217 SELECT (COUNT(*) > 0) AS "Expect 1" FROM events_stages_history_long WHERE source <> "";
218 SELECT (COUNT(*) > 0) AS "Expect 1" FROM events_statements_current WHERE source <> "";
219 SELECT (COUNT(*) > 0) AS "Expect 1" FROM events_statements_history WHERE source <> "";
220 SELECT (COUNT(*) > 0) AS "Expect 1" FROM events_statements_history_long WHERE source <> "";
221 SELECT (COUNT(*) > 0) AS "Expect 1" FROM events_transactions_current WHERE source <> "";
222 SELECT (COUNT(*) > 0) AS "Expect 1" FROM events_transactions_history WHERE source <> "";
223 SELECT (COUNT(*) > 0) AS "Expect 1" FROM events_transactions_history_long WHERE source <> "";
224 SELECT (COUNT(*) > 0) AS "Expect 1" FROM metadata_locks WHERE object_schema = "test" AND source <> "";
225
226 --echo
227 --echo Connection con0
228 --connection con0
229
230 --echo
231 --echo #
232 --echo # 7) Clean up
233 --echo #
234
235 --echo
236 --echo # Commit the open transaction from step 5.
237 COMMIT;
238
239 --connection con0
240 --disconnect con0
241 --source include/wait_until_disconnected.inc
242
243 --echo
244 --echo Connection default
245 --connection default
246 DROP TABLE test.t1;
247 UNINSTALL COMPONENT 'file://component_pfs_example';
248 UPDATE performance_schema.setup_instruments SET enabled = 'YES', timed = 'YES';
249 --disable_query_log
250 UPDATE performance_schema.threads SET instrumented = 'YES' WHERE processlist_id = CONNECTION_ID();
251 --enable_query_log