Skip to content

Commit 89af0f1

Browse files
committed
MDEV-8770: Incorrect error message when importing page compressed tablespace
Added decompression and after page update recompression support for import.
1 parent e96f3c7 commit 89af0f1

File tree

12 files changed

+519
-58
lines changed

12 files changed

+519
-58
lines changed
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
call mtr.add_suppression("InnoDB: Table .* tablespace is set as discarded");
2+
SET GLOBAL innodb_file_format = `Barracuda`;
3+
SET GLOBAL innodb_file_per_table = ON;
4+
SET GLOBAL innodb_compression_algorithm = 1;
5+
create table t1(c1 bigint not null, b char(200)) engine=innodb encrypted=yes encryption_key_id=4;
6+
show warnings;
7+
Level Code Message
8+
create table t2(c1 bigint not null, b char(200)) engine=innodb page_compressed=1 encrypted=yes encryption_key_id=4;
9+
show warnings;
10+
Level Code Message
11+
create table t3(c1 bigint not null, b char(200)) engine=innodb row_format=compressed encrypted=yes encryption_key_id=4;
12+
show warnings;
13+
Level Code Message
14+
create table t4(c1 bigint not null, b char(200)) engine=innodb page_compressed=1;
15+
show warnings;
16+
Level Code Message
17+
create procedure innodb_insert_proc (repeat_count int)
18+
begin
19+
declare current_num int;
20+
set current_num = 0;
21+
while current_num < repeat_count do
22+
insert into t1 values(current_num, repeat('foobar',30));
23+
insert into t2 values(current_num, repeat('barfoo',30));
24+
insert into t3 values(current_num, repeat('tmpres',30));
25+
insert into t4 values(current_num, repeat('mysql',30));
26+
set current_num = current_num + 1;
27+
end while;
28+
end//
29+
commit;
30+
set autocommit=0;
31+
call innodb_insert_proc(2000);
32+
commit;
33+
set autocommit=1;
34+
select count(*) from t1;
35+
count(*)
36+
2000
37+
select count(*) from t2;
38+
count(*)
39+
2000
40+
select count(*) from t3;
41+
count(*)
42+
2000
43+
select count(*) from t4;
44+
count(*)
45+
2000
46+
FLUSH TABLE t1,t2,t3,t4 FOR EXPORT;
47+
# List before copying files
48+
t1.cfg
49+
t1.frm
50+
t1.ibd
51+
t2.cfg
52+
t2.frm
53+
t2.ibd
54+
t3.cfg
55+
t3.frm
56+
t3.ibd
57+
t4.cfg
58+
t4.frm
59+
t4.ibd
60+
UNLOCK TABLES;
61+
# tables should be either encrypted and/or compressed
62+
# t1 yes on expecting NOT FOUND
63+
NOT FOUND /foobar/ in t1.ibd
64+
# t2 yes on expecting NOT FOUND
65+
NOT FOUND /barfoo/ in t2.ibd
66+
# t3 yes on expecting NOT FOUND
67+
NOT FOUND /tmpres/ in t3.ibd
68+
# t4 yes on expecting NOT FOUND
69+
NOT FOUND /mysql/ in t4.ibd
70+
ALTER TABLE t1 DISCARD TABLESPACE;
71+
ALTER TABLE t2 DISCARD TABLESPACE;
72+
ALTER TABLE t3 DISCARD TABLESPACE;
73+
ALTER TABLE t4 DISCARD TABLESPACE;
74+
SET GLOBAL innodb_file_format = `Barracuda`;
75+
SET GLOBAL innodb_file_per_table = ON;
76+
SET GLOBAL innodb_compression_algorithm = 1;
77+
# List after t1 DISCARD
78+
t1.frm
79+
t2.frm
80+
t3.frm
81+
t4.frm
82+
ALTER TABLE t1 IMPORT TABLESPACE;
83+
Warnings:
84+
Warning 1814 Tablespace has been discarded for table 't1'
85+
SHOW CREATE TABLE t1;
86+
Table Create Table
87+
t1 CREATE TABLE `t1` (
88+
`c1` bigint(20) NOT NULL,
89+
`b` char(200) DEFAULT NULL
90+
) ENGINE=InnoDB DEFAULT CHARSET=latin1 `encrypted`=yes `encryption_key_id`=4
91+
SELECT COUNT(*) FROM t1;
92+
COUNT(*)
93+
2000
94+
ALTER TABLE t2 IMPORT TABLESPACE;
95+
Warnings:
96+
Warning 1814 Tablespace has been discarded for table 't2'
97+
SHOW CREATE TABLE t2;
98+
Table Create Table
99+
t2 CREATE TABLE `t2` (
100+
`c1` bigint(20) NOT NULL,
101+
`b` char(200) DEFAULT NULL
102+
) ENGINE=InnoDB DEFAULT CHARSET=latin1 `page_compressed`=1 `encrypted`=yes `encryption_key_id`=4
103+
SELECT COUNT(*) FROM t2;
104+
COUNT(*)
105+
2000
106+
ALTER TABLE t3 IMPORT TABLESPACE;
107+
Warnings:
108+
Warning 1814 Tablespace has been discarded for table 't3'
109+
SHOW CREATE TABLE t3;
110+
Table Create Table
111+
t3 CREATE TABLE `t3` (
112+
`c1` bigint(20) NOT NULL,
113+
`b` char(200) DEFAULT NULL
114+
) ENGINE=InnoDB DEFAULT CHARSET=latin1 ROW_FORMAT=COMPRESSED `encrypted`=yes `encryption_key_id`=4
115+
SELECT COUNT(*) FROM t3;
116+
COUNT(*)
117+
2000
118+
ALTER TABLE t4 IMPORT TABLESPACE;
119+
Warnings:
120+
Warning 1814 Tablespace has been discarded for table 't4'
121+
SHOW CREATE TABLE t4;
122+
Table Create Table
123+
t4 CREATE TABLE `t4` (
124+
`c1` bigint(20) NOT NULL,
125+
`b` char(200) DEFAULT NULL
126+
) ENGINE=InnoDB DEFAULT CHARSET=latin1 `page_compressed`=1
127+
SELECT COUNT(*) FROM t4;
128+
COUNT(*)
129+
2000
130+
flush data to disk
131+
SET GLOBAL innodb_file_format = `Barracuda`;
132+
SET GLOBAL innodb_file_per_table = ON;
133+
SET GLOBAL innodb_compression_algorithm = 1;
134+
# tables should be still either encrypted and/or compressed
135+
# t1 yes on expecting NOT FOUND
136+
NOT FOUND /foobar/ in t1.ibd
137+
# t2 yes on expecting NOT FOUND
138+
NOT FOUND /barfoo/ in t2.ibd
139+
# t3 yes on expecting NOT FOUND
140+
NOT FOUND /tmpres/ in t3.ibd
141+
# t4 yes on expecting NOT FOUND
142+
NOT FOUND /mysql/ in t4.ibd
143+
DROP PROCEDURE innodb_insert_proc;
144+
DROP TABLE t1,t2,t3,t4;
Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
-- source include/have_innodb.inc
2+
-- source include/have_file_key_management_plugin.inc
3+
# embedded does not support restart
4+
-- source include/not_embedded.inc
5+
-- source include/not_valgrind.inc
6+
# Avoid CrashReporter popup on Mac
7+
-- source include/not_crashrep.inc
8+
9+
#
10+
# MDEV-8770: Incorrect error message when importing page compressed tablespace
11+
#
12+
13+
call mtr.add_suppression("InnoDB: Table .* tablespace is set as discarded");
14+
15+
--disable_query_log
16+
let $innodb_file_format_orig = `SELECT @@innodb_file_format`;
17+
let $innodb_file_per_table_orig = `SELECT @@innodb_file_per_table`;
18+
let $innodb_compression_algo = `SELECT @@innodb_compression_algorithm`;
19+
--enable_query_log
20+
21+
SET GLOBAL innodb_file_format = `Barracuda`;
22+
SET GLOBAL innodb_file_per_table = ON;
23+
SET GLOBAL innodb_compression_algorithm = 1;
24+
25+
--let $MYSQLD_TMPDIR = `SELECT @@tmpdir`
26+
--let $MYSQLD_DATADIR = `SELECT @@datadir`
27+
--let SEARCH_RANGE = 10000000
28+
--let t1_IBD = $MYSQLD_DATADIR/test/t1.ibd
29+
--let t2_IBD = $MYSQLD_DATADIR/test/t2.ibd
30+
--let t3_IBD = $MYSQLD_DATADIR/test/t3.ibd
31+
--let t4_IBD = $MYSQLD_DATADIR/test/t4.ibd
32+
33+
create table t1(c1 bigint not null, b char(200)) engine=innodb encrypted=yes encryption_key_id=4;
34+
show warnings;
35+
create table t2(c1 bigint not null, b char(200)) engine=innodb page_compressed=1 encrypted=yes encryption_key_id=4;
36+
show warnings;
37+
create table t3(c1 bigint not null, b char(200)) engine=innodb row_format=compressed encrypted=yes encryption_key_id=4;
38+
show warnings;
39+
create table t4(c1 bigint not null, b char(200)) engine=innodb page_compressed=1;
40+
show warnings;
41+
42+
delimiter //;
43+
create procedure innodb_insert_proc (repeat_count int)
44+
begin
45+
declare current_num int;
46+
set current_num = 0;
47+
while current_num < repeat_count do
48+
insert into t1 values(current_num, repeat('foobar',30));
49+
insert into t2 values(current_num, repeat('barfoo',30));
50+
insert into t3 values(current_num, repeat('tmpres',30));
51+
insert into t4 values(current_num, repeat('mysql',30));
52+
set current_num = current_num + 1;
53+
end while;
54+
end//
55+
delimiter ;//
56+
commit;
57+
58+
set autocommit=0;
59+
call innodb_insert_proc(2000);
60+
commit;
61+
set autocommit=1;
62+
63+
select count(*) from t1;
64+
select count(*) from t2;
65+
select count(*) from t3;
66+
select count(*) from t4;
67+
68+
FLUSH TABLE t1,t2,t3,t4 FOR EXPORT;
69+
--echo # List before copying files
70+
--list_files $MYSQLD_DATADIR/test
71+
--copy_file $MYSQLD_DATADIR/test/t1.cfg $MYSQLD_TMPDIR/t1.cfg
72+
--copy_file $MYSQLD_DATADIR/test/t1.ibd $MYSQLD_TMPDIR/t1.ibd
73+
--copy_file $MYSQLD_DATADIR/test/t2.cfg $MYSQLD_TMPDIR/t2.cfg
74+
--copy_file $MYSQLD_DATADIR/test/t2.ibd $MYSQLD_TMPDIR/t2.ibd
75+
--copy_file $MYSQLD_DATADIR/test/t3.cfg $MYSQLD_TMPDIR/t3.cfg
76+
--copy_file $MYSQLD_DATADIR/test/t3.ibd $MYSQLD_TMPDIR/t3.ibd
77+
--copy_file $MYSQLD_DATADIR/test/t4.cfg $MYSQLD_TMPDIR/t4.cfg
78+
--copy_file $MYSQLD_DATADIR/test/t4.ibd $MYSQLD_TMPDIR/t4.ibd
79+
UNLOCK TABLES;
80+
81+
--echo # tables should be either encrypted and/or compressed
82+
--let SEARCH_PATTERN=foobar
83+
--echo # t1 yes on expecting NOT FOUND
84+
-- let SEARCH_FILE=$t1_IBD
85+
-- source include/search_pattern_in_file.inc
86+
--let SEARCH_PATTERN=barfoo
87+
--echo # t2 yes on expecting NOT FOUND
88+
-- let SEARCH_FILE=$t2_IBD
89+
-- source include/search_pattern_in_file.inc
90+
--let SEARCH_PATTERN=tmpres
91+
--echo # t3 yes on expecting NOT FOUND
92+
-- let SEARCH_FILE=$t3_IBD
93+
-- source include/search_pattern_in_file.inc
94+
--let SEARCH_PATTERN=mysql
95+
--echo # t4 yes on expecting NOT FOUND
96+
-- let SEARCH_FILE=$t4_IBD
97+
-- source include/search_pattern_in_file.inc
98+
99+
ALTER TABLE t1 DISCARD TABLESPACE;
100+
ALTER TABLE t2 DISCARD TABLESPACE;
101+
ALTER TABLE t3 DISCARD TABLESPACE;
102+
ALTER TABLE t4 DISCARD TABLESPACE;
103+
104+
--source include/restart_mysqld.inc
105+
106+
SET GLOBAL innodb_file_format = `Barracuda`;
107+
SET GLOBAL innodb_file_per_table = ON;
108+
SET GLOBAL innodb_compression_algorithm = 1;
109+
110+
--echo # List after t1 DISCARD
111+
--list_files $MYSQLD_DATADIR/test
112+
--copy_file $MYSQLD_TMPDIR/t1.cfg $MYSQLD_DATADIR/test/t1.cfg
113+
--copy_file $MYSQLD_TMPDIR/t1.ibd $MYSQLD_DATADIR/test/t1.ibd
114+
--copy_file $MYSQLD_TMPDIR/t2.cfg $MYSQLD_DATADIR/test/t2.cfg
115+
--copy_file $MYSQLD_TMPDIR/t2.ibd $MYSQLD_DATADIR/test/t2.ibd
116+
--copy_file $MYSQLD_TMPDIR/t3.cfg $MYSQLD_DATADIR/test/t3.cfg
117+
--copy_file $MYSQLD_TMPDIR/t3.ibd $MYSQLD_DATADIR/test/t3.ibd
118+
--copy_file $MYSQLD_TMPDIR/t4.cfg $MYSQLD_DATADIR/test/t4.cfg
119+
--copy_file $MYSQLD_TMPDIR/t4.ibd $MYSQLD_DATADIR/test/t4.ibd
120+
121+
ALTER TABLE t1 IMPORT TABLESPACE;
122+
SHOW CREATE TABLE t1;
123+
SELECT COUNT(*) FROM t1;
124+
ALTER TABLE t2 IMPORT TABLESPACE;
125+
SHOW CREATE TABLE t2;
126+
SELECT COUNT(*) FROM t2;
127+
ALTER TABLE t3 IMPORT TABLESPACE;
128+
SHOW CREATE TABLE t3;
129+
SELECT COUNT(*) FROM t3;
130+
ALTER TABLE t4 IMPORT TABLESPACE;
131+
SHOW CREATE TABLE t4;
132+
SELECT COUNT(*) FROM t4;
133+
134+
--echo flush data to disk
135+
--source include/restart_mysqld.inc
136+
137+
SET GLOBAL innodb_file_format = `Barracuda`;
138+
SET GLOBAL innodb_file_per_table = ON;
139+
SET GLOBAL innodb_compression_algorithm = 1;
140+
141+
--echo # tables should be still either encrypted and/or compressed
142+
--let SEARCH_PATTERN=foobar
143+
--echo # t1 yes on expecting NOT FOUND
144+
-- let SEARCH_FILE=$t1_IBD
145+
-- source include/search_pattern_in_file.inc
146+
--let SEARCH_PATTERN=barfoo
147+
--echo # t2 yes on expecting NOT FOUND
148+
-- let SEARCH_FILE=$t2_IBD
149+
-- source include/search_pattern_in_file.inc
150+
--let SEARCH_PATTERN=tmpres
151+
--echo # t3 yes on expecting NOT FOUND
152+
-- let SEARCH_FILE=$t3_IBD
153+
-- source include/search_pattern_in_file.inc
154+
--let SEARCH_PATTERN=mysql
155+
--echo # t4 yes on expecting NOT FOUND
156+
-- let SEARCH_FILE=$t4_IBD
157+
-- source include/search_pattern_in_file.inc
158+
159+
DROP PROCEDURE innodb_insert_proc;
160+
DROP TABLE t1,t2,t3,t4;
161+
162+
# reset system
163+
--disable_query_log
164+
EVAL SET GLOBAL innodb_file_per_table = $innodb_file_per_table_orig;
165+
EVAL SET GLOBAL innodb_file_format = $innodb_file_format_orig;
166+
EVAL SET GLOBAL innodb_compression_algorithm = $innodb_compression_algo;
167+
--enable_query_log

storage/innobase/buf/buf0buf.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5892,6 +5892,7 @@ buf_page_init_for_backup_restore(
58925892
Reserve unused slot from temporary memory array and allocate necessary
58935893
temporary memory if not yet allocated.
58945894
@return reserved slot */
5895+
UNIV_INTERN
58955896
buf_tmp_buffer_t*
58965897
buf_pool_reserve_tmp_slot(
58975898
/*======================*/

storage/innobase/fil/fil0crypt.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,9 @@ fil_encrypt_buf(
613613
memcpy(dst_frame + page_size - FIL_PAGE_DATA_END,
614614
src_frame + page_size - FIL_PAGE_DATA_END,
615615
FIL_PAGE_DATA_END);
616+
} else {
617+
/* Clean up rest of buffer */
618+
memset(dst_frame+header_len+srclen, 0, page_size - (header_len+srclen));
616619
}
617620

618621
/* handle post encryption checksum */

0 commit comments

Comments
 (0)