Skip to content

Commit 8375a2c

Browse files
committed
MDEV-11585 Hard-code the shared InnoDB temporary tablespace ID at -1
MySQL 5.7 supports only one shared temporary tablespace. MariaDB 10.2 does not support any other shared InnoDB tablespaces than the two predefined tablespaces: the persistent InnoDB system tablespace (default file name ibdata1) and the temporary tablespace (default file name ibtmp1). InnoDB is unnecessarily allocating a tablespace ID for the predefined temporary tablespace on every startup, and it is in several places testing whether a tablespace ID matches this dynamically generated ID. We should use a compile-time constant to reduce code size and to avoid unnecessary updates to the DICT_HDR page at every startup. Using a hard-coded tablespace ID will should make it easier to remove the TEMPORARY flag from FSP_SPACE_FLAGS in MDEV-11202.
1 parent c35b8c4 commit 8375a2c

File tree

17 files changed

+76
-98
lines changed

17 files changed

+76
-98
lines changed

mysql-test/suite/encryption/r/debug_key_management.result

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ innodb_encryption_threads 4
99
select space,name,current_key_version from information_schema.innodb_tablespaces_encryption order by space;
1010
space name current_key_version
1111
0 NULL 1
12-
2 mysql/innodb_table_stats 1
13-
3 mysql/innodb_index_stats 1
12+
1 mysql/innodb_table_stats 1
13+
2 mysql/innodb_index_stats 1
1414
set global debug_key_management_version=10;
1515
select space,name,current_key_version from information_schema.innodb_tablespaces_encryption order by space;
1616
space name current_key_version
1717
0 NULL 10
18-
2 mysql/innodb_table_stats 10
19-
3 mysql/innodb_index_stats 10
18+
1 mysql/innodb_table_stats 10
19+
2 mysql/innodb_index_stats 10
2020
set global innodb_encrypt_tables=OFF;
2121
set global debug_key_management_version=1;

mysql-test/suite/encryption/r/innodb-bad-key-change4.result

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Warning 131 Using innodb_file_format is deprecated and the parameter may be remo
1616
SET GLOBAL innodb_file_per_table = ON;
1717
CHECK TABLE t1;
1818
Table Op Msg_type Msg_text
19-
test.t1 check Warning Table test/t1 in tablespace 7 is encrypted but encryption service or used key_id is not available. Can't continue reading table.
19+
test.t1 check Warning Table test/t1 in tablespace # is encrypted but encryption service or used key_id is not available. Can't continue reading table.
2020
test.t1 check Warning Table test/t1 is encrypted but encryption service or used key_id is not available. Can't continue checking table.
2121
test.t1 check error Corrupt
2222
SHOW WARNINGS;

mysql-test/suite/encryption/t/innodb-bad-key-change4.test

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ EOF
5959
SET GLOBAL innodb_file_format = `Barracuda`;
6060
SET GLOBAL innodb_file_per_table = ON;
6161

62+
--replace_regex /tablespace [0-9]*/tablespace #/
6263
CHECK TABLE t1;
6364
SHOW WARNINGS;
6465

storage/innobase/btr/btr0btr.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1097,7 +1097,7 @@ btr_free_root_check(
10971097
index_id_t index_id,
10981098
mtr_t* mtr)
10991099
{
1100-
ut_ad(page_id.space() != srv_tmp_space.space_id());
1100+
ut_ad(page_id.space() != SRV_TMP_SPACE_ID);
11011101
ut_ad(index_id != BTR_FREED_INDEX_ID);
11021102

11031103
buf_block_t* block = buf_page_get(

storage/innobase/buf/buf0buf.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6092,7 +6092,7 @@ buf_page_io_complete(
60926092
#endif /* MYSQL_COMPRESSION */
60936093
&& !recv_no_ibuf_operations
60946094
&& !Tablespace::is_undo_tablespace(bpage->id.space())
6095-
&& bpage->id.space() != srv_tmp_space.space_id()
6095+
&& bpage->id.space() != SRV_TMP_SPACE_ID
60966096
&& !srv_is_tablespace_truncated(bpage->id.space())
60976097
&& fil_page_get_type(frame) == FIL_PAGE_INDEX
60986098
&& page_is_leaf(frame)) {

storage/innobase/dict/dict0crea.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -571,8 +571,7 @@ dict_build_tablespace_for_table(
571571
supports Redundant and Compact */
572572
ut_ad(dict_tf_get_rec_format(table->flags)
573573
!= REC_FORMAT_COMPRESSED);
574-
table->space = static_cast<uint32_t>(
575-
srv_tmp_space.space_id());
574+
table->space = SRV_TMP_SPACE_ID;
576575
} else {
577576
/* Create in the system tablespace. */
578577
ut_ad(table->space == srv_sys_space.space_id());

storage/innobase/fil/fil0fil.cc

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ fil_is_user_tablespace_id(
185185
ulint space_id)
186186
{
187187
return(space_id > srv_undo_tablespaces_open
188-
&& space_id != srv_tmp_space.space_id());
188+
&& space_id != SRV_TMP_SPACE_ID);
189189
}
190190

191191
#ifdef UNIV_DEBUG
@@ -1313,7 +1313,7 @@ fil_space_create(
13131313

13141314
/* This warning is not applicable while MEB scanning the redo logs */
13151315
#ifndef UNIV_HOTBACKUP
1316-
if (fil_type_is_data(purpose)
1316+
if ((purpose == FIL_TYPE_TABLESPACE || purpose == FIL_TYPE_IMPORT)
13171317
&& !recv_recovery_on
13181318
&& id > fil_system->max_assigned_id) {
13191319

@@ -5104,10 +5104,13 @@ fil_space_extend(
51045104
ulint pages_per_mb = (1024 * 1024) / page_size;
51055105
ulint size_in_pages = ((node->size / pages_per_mb) * pages_per_mb);
51065106

5107-
if (space->id == srv_sys_space.space_id()) {
5107+
switch (space->id) {
5108+
case TRX_SYS_SPACE:
51085109
srv_sys_space.set_last_file_size(size_in_pages);
5109-
} else if (space->id == srv_tmp_space.space_id()) {
5110+
break;
5111+
case SRV_TMP_SPACE_ID:
51105112
srv_tmp_space.set_last_file_size(size_in_pages);
5113+
break;
51115114
}
51125115
#else
51135116
ib::trace() << "extended space : " << space->name << " from "

storage/innobase/fsp/fsp0fsp.cc

Lines changed: 21 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -338,16 +338,6 @@ fsp_flags_is_valid(
338338
return (false);
339339
}
340340

341-
/** Check if tablespace is system temporary.
342-
@param[in] space_id tablespace ID
343-
@return true if tablespace is system temporary. */
344-
bool
345-
fsp_is_system_temporary(
346-
ulint space_id)
347-
{
348-
return(space_id == srv_tmp_space.space_id());
349-
}
350-
351341
/** Check if checksum is disabled for the given space.
352342
@param[in] space_id tablespace ID
353343
@return true if checksum is disabled for given space. */
@@ -803,8 +793,7 @@ fsp_space_modify_check(
803793
#ifdef UNIV_DEBUG
804794
{
805795
const fil_type_t type = fil_space_get_type(id);
806-
ut_a(id == srv_tmp_space.space_id()
807-
|| srv_is_tablespace_truncated(id)
796+
ut_a(srv_is_tablespace_truncated(id)
808797
|| fil_space_is_being_truncated(id)
809798
|| fil_space_get_flags(id) == ULINT_UNDEFINED
810799
|| type == FIL_TYPE_TEMPORARY
@@ -814,10 +803,7 @@ fsp_space_modify_check(
814803
#endif /* UNIV_DEBUG */
815804
return;
816805
case MTR_LOG_ALL:
817-
/* We must not write redo log for the shared temporary
818-
tablespace. */
819-
ut_ad(id != srv_tmp_space.space_id());
820-
/* If we write redo log, the tablespace must exist. */
806+
/* We may only write redo log for a persistent tablespace. */
821807
ut_ad(fil_space_get_type(id) == FIL_TYPE_TABLESPACE);
822808
ut_ad(mtr->is_named_space(id));
823809
return;
@@ -1549,15 +1535,14 @@ fsp_try_extend_data_file(
15491535
const page_size_t page_size(
15501536
mach_read_from_4(header + FSP_SPACE_FLAGS));
15511537

1552-
if (space->id == srv_sys_space.space_id()) {
1553-
1538+
switch (space->id) {
1539+
case TRX_SYS_SPACE:
15541540
size_increase = srv_sys_space.get_increment();
1555-
1556-
} else if (space->id == srv_tmp_space.space_id()) {
1557-
1541+
break;
1542+
case SRV_TMP_SPACE_ID:
15581543
size_increase = srv_tmp_space.get_increment();
1559-
1560-
} else {
1544+
break;
1545+
default:
15611546
ulint extent_pages
15621547
= fsp_get_extent_size_in_pages(page_size);
15631548
if (size < extent_pages) {
@@ -1679,11 +1664,17 @@ fsp_fill_free_list(
16791664
const page_size_t page_size(flags);
16801665

16811666
if (size < limit + FSP_EXTENT_SIZE * FSP_FREE_ADD) {
1682-
if ((!init_space && !is_system_tablespace(space->id))
1683-
|| (space->id == srv_sys_space.space_id()
1684-
&& srv_sys_space.can_auto_extend_last_file())
1685-
|| (space->id == srv_tmp_space.space_id()
1686-
&& srv_tmp_space.can_auto_extend_last_file())) {
1667+
bool skip_resize = init_space;
1668+
switch (space->id) {
1669+
case TRX_SYS_SPACE:
1670+
skip_resize = !srv_sys_space.can_auto_extend_last_file();
1671+
break;
1672+
case SRV_TMP_SPACE_ID:
1673+
skip_resize = srv_tmp_space.can_auto_extend_last_file();
1674+
break;
1675+
}
1676+
1677+
if (!skip_resize) {
16871678
ulint n_pages = 0;
16881679
fsp_try_extend_data_file(space, header, mtr, &n_pages);
16891680
size = space->size_in_header;
@@ -1733,17 +1724,15 @@ fsp_fill_free_list(
17331724
order, and we must be able to release its latch.
17341725
Note: Insert-Buffering is disabled for tables that
17351726
reside in the temp-tablespace. */
1736-
if (space->id != srv_tmp_space.space_id()) {
1727+
if (space->purpose != FIL_TYPE_TEMPORARY) {
17371728
mtr_t ibuf_mtr;
17381729

17391730
mtr_start(&ibuf_mtr);
17401731
ibuf_mtr.set_named_space(space);
17411732

17421733
/* Avoid logging while truncate table
17431734
fix-up is active. */
1744-
if (space->purpose == FIL_TYPE_TEMPORARY
1745-
|| srv_is_tablespace_truncated(
1746-
space->id)) {
1735+
if (srv_is_tablespace_truncated(space->id)) {
17471736
mtr_set_log_mode(
17481737
&ibuf_mtr, MTR_LOG_NO_REDO);
17491738
}

storage/innobase/fsp/fsp0space.cc

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -207,17 +207,6 @@ Tablespace::delete_files()
207207
}
208208
}
209209

210-
/** Check if undo tablespace.
211-
@return true if undo tablespace */
212-
bool
213-
Tablespace::is_undo_tablespace(
214-
ulint id)
215-
{
216-
return(id <= srv_undo_tablespaces_open
217-
&& id != srv_sys_space.space_id()
218-
&& id != srv_tmp_space.space_id());
219-
}
220-
221210
/** Use the ADD DATAFILE path to create a Datafile object and add it to the
222211
front of m_files.
223212
Parse the datafile path into a path and a filename with extension 'ibd'.

storage/innobase/ibuf/ibuf0ibuf.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3727,9 +3727,10 @@ ibuf_insert(
37273727
op, page_id.space(), page_id.page_no()));
37283728

37293729
ut_ad(dtuple_check_typed(entry));
3730-
ut_ad(page_id.space() != srv_tmp_space.space_id());
3730+
ut_ad(page_id.space() != SRV_TMP_SPACE_ID);
37313731

37323732
ut_a(!dict_index_is_clust(index));
3733+
ut_ad(!dict_table_is_temporary(index->table));
37333734

37343735
no_counter = use <= IBUF_USE_INSERT;
37353736

0 commit comments

Comments
 (0)