Debian Codegraph @

mysql-test/suite/binlog/t/binlog_mysqlbinlog_compression.test

raw
1 #
2 # WL#3549: Binlog Compression
3 #
4 # This file contains tests for mysqlbinlog with binlog compression turned on
5 #
6 # - Test 1: Generate a compressed binlog and apply it back to the server
7 #
8 # This test case generates a compressed binlog, resets the server,
9 # replays the binary log again and verifies that the result is
10 # the same.
11 #
12 # - Test 2: Asserts that mysqlbinlog outputs the comments as per
13 # WL#3549 spec
14 #
15
16 # no need to run the tests in this file more than one combination
17 --source include/have_binlog_format_row.inc
18
19 --let $show_rpl_debug_info = 0
20
21 --let $saved_binlog_transaction_compression_session_master = `SELECT @@SESSION.binlog_transaction_compression`
22 --let $saved_binlog_transaction_compression_global_master = `SELECT @@GLOBAL.binlog_transaction_compression`
23 --let $trx_size_bytes = 1000000
24 --let $compression_type = ZSTD
25 --let $pfs_table = performance_schema.binary_log_transaction_compression_stats
26 --let $tmp_binlog_file_prefix=`SELECT UUID()`
27 --let $MYSQLD_DATADIR= `SELECT @@datadir`
28 --let $tmp_binlog_file = $MYSQL_TMP_DIR/$tmp_binlog_file_prefix.000001
29 --let $tmp_binlog_dump_file = $MYSQL_TMP_DIR/$tmp_binlog_file_prefix.sql
30 --let $ntrans_expected = 4
31
32 RESET MASTER;
33 --let $binlog_file= query_get_value(SHOW MASTER STATUS, File, 1)
34 --let $binlog_file=$MYSQLD_DATADIR/$binlog_file
35 --eval TRUNCATE $pfs_table
36
37 # transactions executed in this session shall be compressed
38 SET SESSION binlog_transaction_compression = ON;
39
40 # transactions replayed through mysqlbinlog will also be compressed
41 SET GLOBAL binlog_transaction_compression = ON;
42
43 #
44 # Test 1: Generate a compressed binlog and apply it back to the server
45 #
46 --let $i = 4
47 while($i > 0)
48 {
49 if ($i == 4)
50 {
51 CREATE TABLE t1 (c1 INT UNSIGNED PRIMARY KEY, c2 LONGTEXT);
52 --let $ntrans_expected = 0
53 }
54
55 if ($i == 3)
56 {
57 CREATE TABLE t1 (c1 INT UNSIGNED PRIMARY KEY, c2 LONGTEXT);
58 RESET MASTER;
59 --eval TRUNCATE $pfs_table
60 --eval INSERT INTO t1 VALUES (2, REPEAT('b', $trx_size_bytes))
61 --let $ntrans_expected = 1
62 }
63
64 if ($i == 2)
65 {
66 CREATE TABLE t1 (c1 INT UNSIGNED PRIMARY KEY, c2 LONGTEXT);
67 --eval INSERT INTO t1 VALUES (2, REPEAT('b', $trx_size_bytes))
68 RESET MASTER;
69 --eval TRUNCATE $pfs_table
70 --eval UPDATE t1 SET c2=REPEAT('c', $trx_size_bytes)
71 --let $ntrans_expected = 1
72 }
73
74 if ($i == 1)
75 {
76 CREATE TABLE t1 (c1 INT UNSIGNED PRIMARY KEY, c2 LONGTEXT);
77 --eval INSERT INTO t1 VALUES (2, REPEAT('b', $trx_size_bytes))
78 --eval UPDATE t1 SET c2=REPEAT('c', $trx_size_bytes)
79 RESET MASTER;
80 --eval TRUNCATE $pfs_table
81 DELETE FROM t1;
82 --let $ntrans_expected = 1
83 }
84
85 # assert that we have the stats on the table
86 --let $nrows = `SELECT COUNT(*) FROM $pfs_table`
87 --let $assert_cond = $nrows = 1
88 --let $assert_text = Number of rows in $pfs_table = 1
89 --source include/assert.inc
90
91 if ($i != 4)
92 {
93 --let $ntrxs = `SELECT transaction_counter FROM $pfs_table WHERE log_type = 'BINARY' AND compression_type = '$compression_type'`
94 --let $assert_cond = $ntrxs = $ntrans_expected
95 }
96
97 if ($i == 4)
98 {
99 --let $nrows_compressed = `SELECT count(*) FROM $pfs_table WHERE log_type = 'BINARY' AND compression_type = '$compression_type'`
100 --let $assert_cond = $nrows_compressed = $ntrans_expected
101 }
102
103 --let $assert_text = The number of transactions reported is $ntrans_expected ($assert_cond)
104 --source include/assert.inc
105
106 --let $cbytes = `SELECT COMPRESSED_BYTES_COUNTER FROM $pfs_table WHERE log_type = 'BINARY' AND compression_type = '$compression_type'`
107 --let $ubytes = `SELECT UNCOMPRESSED_BYTES_COUNTER FROM $pfs_table WHERE log_type = 'BINARY' AND compression_type = '$compression_type'`
108 --let $last_trx_id = `SELECT LAST_TRANSACTION_ID FROM $pfs_table WHERE log_type = 'BINARY' AND compression_type = '$compression_type'`
109 --let $last_trx_cbytes = `SELECT LAST_TRANSACTION_COMPRESSED_BYTES FROM $pfs_table WHERE log_type = 'BINARY' AND compression_type = '$compression_type'`
110 --let $last_trx_ubytes = `SELECT LAST_TRANSACTION_UNCOMPRESSED_BYTES FROM $pfs_table WHERE log_type = 'BINARY' AND compression_type = '$compression_type'`
111
112 --let $checksum_before = query_get_value(CHECKSUM TABLE t1 EXTENDED, Checksum, 1)
113
114 FLUSH LOGS;
115
116 # save a backup of the file
117 --copy_file $binlog_file $tmp_binlog_file
118
119 # clean up to start from a clean slate
120 if ($i == 4)
121 {
122 DROP TABLE t1;
123 }
124
125 if ($i == 3)
126 {
127 DELETE FROM t1;
128 }
129
130 if ($i == 2)
131 {
132 DELETE FROM t1;
133 --eval INSERT INTO t1 VALUES (2, REPEAT('b', $trx_size_bytes))
134 }
135
136 if ($i == 1)
137 {
138 DELETE FROM t1;
139 --eval INSERT INTO t1 VALUES (2, REPEAT('b', $trx_size_bytes))
140 --eval UPDATE t1 SET c2=REPEAT('c', $trx_size_bytes)
141 }
142
143 --eval TRUNCATE $pfs_table
144 RESET MASTER;
145
146 # replay the binary log
147 --exec $MYSQL_BINLOG $tmp_binlog_file > $tmp_binlog_dump_file
148 --exec $MYSQL test < $tmp_binlog_dump_file
149
150 --let $count = 1
151 --let $table = $pfs_table
152 --source include/wait_until_rows_count.inc
153
154 --let $checksum_after = query_get_value(CHECKSUM TABLE t1 EXTENDED, Checksum, 1)
155
156 --let $assert_cond = $checksum_before = $checksum_after
157 --let $assert_text = Table contents is the same after replaying with mysqlbinlog
158 --source include/assert.inc
159
160 # assert that we have the stats on the table
161 --let $nrows = `SELECT COUNT(*) FROM $pfs_table`
162 --let $assert_cond = $nrows = 1
163 --let $assert_text = Number of rows in $pfs_table = 1
164 --source include/assert.inc
165
166 --let $ntrxs_after = `SELECT SUM(transaction_counter) FROM $pfs_table WHERE log_type = 'BINARY'`
167
168
169 # DDL are not compressed
170 if ($i != 4)
171 {
172 --let $assert_cond = $ntrxs_after = $ntrxs
173 --let $assert_text = The number of transactions reported is $ntrxs_after
174 --source include/assert.inc
175
176 --let $cbytes_after = `SELECT COMPRESSED_BYTES_COUNTER FROM $pfs_table WHERE log_type = 'BINARY' AND compression_type = '$compression_type'`
177 --let $ubytes_after = `SELECT UNCOMPRESSED_BYTES_COUNTER FROM $pfs_table WHERE log_type = 'BINARY' AND compression_type = '$compression_type'`
178 --let $last_trx_id_after = `SELECT LAST_TRANSACTION_ID FROM $pfs_table WHERE log_type = 'BINARY' AND compression_type = '$compression_type'`
179 --let $last_trx_cbytes_after = `SELECT LAST_TRANSACTION_COMPRESSED_BYTES FROM $pfs_table WHERE log_type = 'BINARY' AND compression_type = '$compression_type'`
180 --let $last_trx_ubytes_after = `SELECT LAST_TRANSACTION_UNCOMPRESSED_BYTES FROM $pfs_table WHERE log_type = 'BINARY' AND compression_type = '$compression_type'`
181
182 #
183 # We give +/- 10% since replaying using BINLOG events may compress
184 # a bit differently from when executing SQL statements
185 #
186
187 --let $assert_cond = ($cbytes_after < ($cbytes * 1.1)) or ($cbytes_after > ($cbytes * 0.9))
188 --let $assert_text = Compression bytes is the same after replaying with mysqlbinlog
189 --source include/assert.inc
190
191 --let $assert_cond = ($ubytes_after < ($ubytes * 1.1)) or ($ubytes_after > ($ubytes * 0.9))
192 --let $assert_text = Uncompressed bytes is roughly the same after replaying with mysqlbinlog
193 --source include/assert.inc
194
195 --let $assert_cond = ($last_trx_cbytes_after < ($last_trx_cbytes * 1.1)) or ($last_trx_cbytes_after > ($last_trx_cbytes * 0.9))
196 --let $assert_text = Last transaction commpressed bytes is roughly the same after replaying with mysqlbinlog
197 --source include/assert.inc
198
199 --let $assert_cond = ($last_trx_ubytes_after < ($last_trx_ubytes * 1.1)) or ($last_trx_ubytes_after > ($last_trx_ubytes * 0.9))
200 --let $assert_text = Last transaction uncommpressed bytes is roughly the same after replaying with mysqlbinlog
201 --source include/assert.inc
202
203 --let $assert_cond = "$last_trx_id_after" = "$last_trx_id"
204 --let $assert_text = Last transaction id is the same after replaying with mysqlbinlog
205 --source include/assert.inc
206 }
207
208 DROP TABLE t1;
209 RESET MASTER;
210 --remove_file $tmp_binlog_file
211 --remove_file $tmp_binlog_dump_file
212
213 --dec $i
214 }
215
216
217 #
218 # Test 2: Search for the compression comment from mysqlbinlog
219 #
220
221 RESET MASTER;
222 --eval TRUNCATE $pfs_table
223 --let $binlog_file= query_get_value(SHOW MASTER STATUS, File, 1)
224 --let $binlog_file=$MYSQLD_DATADIR/$binlog_file
225
226 # transactions executed in this session shall be compressed
227 SET SESSION binlog_transaction_compression = ON;
228
229 CREATE TABLE t1 (c1 INT);
230 INSERT INTO t1 VALUES (1);
231 DROP TABLE t1;
232 FLUSH LOGS;
233
234 --exec $MYSQL_BINLOG -vv $binlog_file > $tmp_binlog_dump_file
235
236 --let $assert_file = $tmp_binlog_dump_file
237 --let $assert_select= ^#.*payload_size=.*compression_type=.*uncompressed_size=.*
238 --let $assert_match=
239 --let $assert_count= 1
240 --let $assert_text= mysqlbinlog prints comments for compressed transactions as instructed by the specification
241 --source include/assert_grep.inc
242
243 --let $assert_file = $tmp_binlog_dump_file
244 --let $assert_select= ^#.*payload_size=.*compression_type=.*uncompressed_size=.*
245 --let $assert_match=
246 --let $assert_count= 1
247 --let $assert_text= mysqlbinlog prints comments for compressed transactions as instructed by the specification
248 --source include/assert_grep.inc
249
250
251 --remove_file $tmp_binlog_dump_file
252 RESET MASTER;
253 --eval TRUNCATE $pfs_table
254
255 #
256 # Test 3: Replaying compressed binlogs through a session without binlog compression on
257 # must originate uncompressed binlogs
258 #
259
260 RESET MASTER;
261 --eval TRUNCATE $pfs_table
262 --let $binlog_file= query_get_value(SHOW MASTER STATUS, File, 1)
263 --let $binlog_file=$MYSQLD_DATADIR/$binlog_file
264
265 # transactions executed in this session shall be compressed
266 SET SESSION binlog_transaction_compression = ON;
267
268 # transactions executed in new connections shall not be compressed
269 SET GLOBAL binlog_transaction_compression = OFF;
270
271 CREATE TABLE t1 (c1 INT);
272 INSERT INTO t1 VALUES (1);
273 FLUSH LOGS;
274 --copy_file $binlog_file $tmp_binlog_file
275
276 DROP TABLE t1;
277 RESET MASTER;
278 --eval TRUNCATE $pfs_table
279
280 --exec $MYSQL_BINLOG $tmp_binlog_file | $MYSQL test
281
282 # assert that we have the stats on the table
283 --let $nrows = `SELECT COUNT(*) FROM $pfs_table WHERE log_type = 'BINARY' AND compression_type = '$compression_type'`
284 --let $assert_cond = $nrows = 0
285 --let $assert_text = Number of rows in $pfs_table where log_type='BINARY' AND compression = '$compression_type' is 0
286 --source include/assert.inc
287
288 --let $nrows = `SELECT COUNT(*) FROM $pfs_table WHERE log_type = 'BINARY' AND compression_type = 'NONE'`
289 --let $assert_cond = $nrows = 1
290 --let $assert_text = Number of rows in $pfs_table where log_type='BINARY' AND compression = 'NONE' is 1
291 --source include/assert.inc
292
293 --remove_file $tmp_binlog_file
294 DROP TABLE t1;
295 RESET MASTER;
296 --eval TRUNCATE $pfs_table
297
298 #
299 # Test 4: If session disables binlog, then no entry in the performance schema
300 #
301
302 --let $i=2
303 while ($i>0)
304 {
305 RESET MASTER;
306 --eval TRUNCATE $pfs_table
307
308
309 if ($i == 2)
310 {
311 # transactions executed in this session shall be compressed
312 --let $onoff = ON
313 }
314
315 if ($i == 1)
316 {
317 # transactions executed in this session shall not be compressed
318 --let $onoff = OFF
319 }
320
321 --eval SET SESSION binlog_transaction_compression = $onoff;
322
323 SET SESSION SQL_LOG_BIN=0;
324 CREATE TABLE t1 (c1 INT);
325 INSERT INTO t1 VALUES (1);
326 DROP TABLE t1;
327 SET SESSION SQL_LOG_BIN=1;
328
329 # assert that we have the stats on the table
330 --let $nrows = `SELECT COUNT(*) FROM $pfs_table`
331 --let $assert_cond = $nrows = 0
332 --let $assert_text = No rows in the performance schema table.
333 --source include/assert.inc
334
335 --dec $i
336 }
337
338 RESET MASTER;
339 --eval TRUNCATE $pfs_table
340
341 #
342 # Clean up
343 #
344 --replace_result $saved_binlog_transaction_compression_session_master SAVED
345 --eval SET SESSION binlog_transaction_compression = $saved_binlog_transaction_compression_session_master
346
347 --replace_result $saved_binlog_transaction_compression_session_master SAVED
348 --eval SET GLOBAL binlog_transaction_compression = $saved_binlog_transaction_compression_global_master