Skip to content

Commit e2f570b

Browse files
Thirunarayanandr-m
authored andcommitted
MDEV-20320 Tablespace flags mismatch for full_crc32 format
Files for PAGE_COMPRESSED tables that were created with innodb_checksum_algorithm=full_crc32 store the value of innodb_compression_algorithm at the time of the file creation. The server-wide setting of innodb_compression_algorithm may be changed after file creation. We must ignore any mismatch when opening a data file, and for writes, we must use the choice of algorithm that is stored in the file. fil_space_t::is_flags_full_crc32_equal(): Ignore the innodb_compression_algorithm but do compare innodb_page_size. fil_space_t::is_flags_non_full_crc32_equal(): Ignore the innodb_compression_algorithm.
1 parent 13f7409 commit e2f570b

File tree

3 files changed

+117
-5
lines changed

3 files changed

+117
-5
lines changed

mysql-test/suite/innodb/r/full_crc32_import.result

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,51 @@ Table Op Msg_type Msg_text
127127
test.t1 check status OK
128128
InnoDB 0 transactions not purged
129129
DROP TABLE t1;
130+
SET @save_algo = @@GLOBAL.innodb_compression_algorithm;
131+
SET GLOBAL innodb_compression_algorithm=2;
132+
CREATE TABLE t1(a SERIAL) PAGE_COMPRESSED=1 ENGINE=InnoDB;
133+
INSERT INTO t1 VALUES(1);
134+
FLUSH TABLE t1 FOR EXPORT;
135+
# List before copying files
136+
db.opt
137+
t1.cfg
138+
t1.frm
139+
t1.ibd
140+
backup: t1
141+
UNLOCK TABLES;
142+
SET GLOBAL innodb_compression_algorithm=0;
143+
ALTER TABLE t1 FORCE;
144+
ALTER TABLE t1 DISCARD TABLESPACE;
145+
db.opt
146+
t1.frm
147+
restore: t1 .ibd and .cfg files
148+
ALTER TABLE t1 IMPORT TABLESPACE;
149+
INSERT INTO t1 VALUES(2);
150+
SELECT * FROM t1;
151+
a
152+
1
153+
2
154+
SET GLOBAL innodb_compression_algorithm=3;
155+
FLUSH TABLE t1 FOR EXPORT;
156+
# List before copying files
157+
db.opt
158+
t1.cfg
159+
t1.frm
160+
t1.ibd
161+
backup: t1
162+
UNLOCK TABLES;
163+
SET GLOBAL innodb_compression_algorithm=0;
164+
ALTER TABLE t1 FORCE;
165+
ALTER TABLE t1 DISCARD TABLESPACE;
166+
db.opt
167+
t1.frm
168+
restore: t1 .ibd and .cfg files
169+
ALTER TABLE t1 IMPORT TABLESPACE;
170+
INSERT INTO t1 VALUES(3);
171+
SELECT * FROM t1;
172+
a
173+
1
174+
2
175+
3
176+
DROP TABLE t1;
177+
SET GLOBAL innodb_compression_algorithm=@save_algo;

mysql-test/suite/innodb/t/full_crc32_import.test

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,3 +137,64 @@ DELETE FROM t1;
137137
CHECK TABLE t1;
138138
--source include/wait_all_purged.inc
139139
DROP TABLE t1;
140+
141+
SET @save_algo = @@GLOBAL.innodb_compression_algorithm;
142+
SET GLOBAL innodb_compression_algorithm=2;
143+
CREATE TABLE t1(a SERIAL) PAGE_COMPRESSED=1 ENGINE=InnoDB;
144+
INSERT INTO t1 VALUES(1);
145+
146+
FLUSH TABLE t1 FOR EXPORT;
147+
--echo # List before copying files
148+
let MYSQLD_DATADIR =`SELECT @@datadir`;
149+
150+
--list_files $MYSQLD_DATADIR/test
151+
perl;
152+
do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
153+
ib_backup_tablespaces("test", "t1");
154+
EOF
155+
156+
UNLOCK TABLES;
157+
SET GLOBAL innodb_compression_algorithm=0;
158+
ALTER TABLE t1 FORCE;
159+
ALTER TABLE t1 DISCARD TABLESPACE;
160+
161+
--list_files $MYSQLD_DATADIR/test
162+
perl;
163+
do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
164+
ib_discard_tablespaces("test", "t1");
165+
ib_restore_tablespaces("test", "t1");
166+
EOF
167+
168+
ALTER TABLE t1 IMPORT TABLESPACE;
169+
INSERT INTO t1 VALUES(2);
170+
SELECT * FROM t1;
171+
172+
SET GLOBAL innodb_compression_algorithm=3;
173+
FLUSH TABLE t1 FOR EXPORT;
174+
--echo # List before copying files
175+
let MYSQLD_DATADIR =`SELECT @@datadir`;
176+
177+
--list_files $MYSQLD_DATADIR/test
178+
perl;
179+
do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
180+
ib_backup_tablespaces("test", "t1");
181+
EOF
182+
183+
UNLOCK TABLES;
184+
SET GLOBAL innodb_compression_algorithm=0;
185+
ALTER TABLE t1 FORCE;
186+
ALTER TABLE t1 DISCARD TABLESPACE;
187+
188+
--list_files $MYSQLD_DATADIR/test
189+
perl;
190+
do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
191+
ib_discard_tablespaces("test", "t1");
192+
ib_restore_tablespaces("test", "t1");
193+
EOF
194+
195+
ALTER TABLE t1 IMPORT TABLESPACE;
196+
INSERT INTO t1 VALUES(3);
197+
SELECT * FROM t1;
198+
DROP TABLE t1;
199+
200+
SET GLOBAL innodb_compression_algorithm=@save_algo;

storage/innobase/include/fil0fil.h

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -395,13 +395,16 @@ struct fil_space_t {
395395
static bool is_flags_full_crc32_equal(ulint flags, ulint expected)
396396
{
397397
ut_ad(full_crc32(flags));
398+
ulint page_ssize = FSP_FLAGS_FCRC32_GET_PAGE_SSIZE(flags);
398399

399400
if (full_crc32(expected)) {
400-
return get_compression_algo(flags)
401-
== get_compression_algo(expected);
401+
/* The data file may have been created with a
402+
different innodb_compression_algorithm. But
403+
we only support one innodb_page_size for all files. */
404+
return page_ssize
405+
== FSP_FLAGS_FCRC32_GET_PAGE_SSIZE(expected);
402406
}
403407

404-
ulint page_ssize = FSP_FLAGS_FCRC32_GET_PAGE_SSIZE(flags);
405408
ulint space_page_ssize = FSP_FLAGS_GET_PAGE_SSIZE(expected);
406409

407410
if (page_ssize == 5) {
@@ -412,7 +415,7 @@ struct fil_space_t {
412415
return false;
413416
}
414417

415-
return is_compressed(expected) == is_compressed(flags);
418+
return true;
416419
}
417420
/** Whether old tablespace flags match full_crc32 flags.
418421
@param[in] flags flags present
@@ -438,7 +441,7 @@ struct fil_space_t {
438441
return false;
439442
}
440443

441-
return is_compressed(expected) == is_compressed(flags);
444+
return true;
442445
}
443446
/** Whether both fsp flags are equivalent */
444447
static bool is_flags_equal(ulint flags, ulint expected)

0 commit comments

Comments
 (0)