Skip to content

Commit 7c1e998

Browse files
Bug #25551311 BACKPORT BUG #23517560 REMOVE SPACE_ID
RESTRICTION FOR UNDO TABLESPACES Description: ============ The restriction that required the first undo tablespace to use space_id 1 is removed. The first undo tablespace can now use a space_id other than 1. space_id values for undo tablespaces are still assigned in a consecutive sequence. Reviewed-by: Kevin Lewis <[email protected]> Reviewed-by: Debarun Bannerjee <[email protected]> RB: 14016
1 parent 17973cc commit 7c1e998

File tree

9 files changed

+113
-28
lines changed

9 files changed

+113
-28
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Start mysqld to create tablespaces according to my.cnf
2+
ib_logfile0
3+
ib_logfile1
4+
ib_logfile2
5+
ibdata1
6+
ibdata2
7+
my.cnf
8+
my_restart.err
9+
undo003
10+
undo004
11+
undo005
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
--source include/have_innodb.inc
2+
let bugdir= $MYSQLTEST_VARDIR/tmp/datadir1;
3+
--mkdir $bugdir
4+
5+
let SEARCH_FILE = $bugdir/my_restart.err;
6+
let $args=--defaults-file=$bugdir/my.cnf --datadir=$bugdir --secure-file-priv="" --loose-console > $SEARCH_FILE 2>&1 ;
7+
8+
--write_file $bugdir/my.cnf
9+
[mysqld]
10+
EOF
11+
12+
--exec echo "innodb_data_home_dir = $bugdir" >> $bugdir/my.cnf
13+
14+
--append_file $bugdir/my.cnf
15+
innodb_data_file_path = ibdata1:10M;ibdata2:10M:autoextend
16+
innodb_undo_tablespaces = 3
17+
innodb_log_files_in_group = 3
18+
EOF
19+
20+
# Innodb creates system tablespaces according to my.cnf and aborts
21+
# after creating undo tablespace.
22+
--echo # Start mysqld to create tablespaces according to my.cnf
23+
--error 2
24+
--exec $MYSQLD $args --skip-grant-tables --debug=d,innodb_undo_upgrade --innodb-unknown-parameter
25+
26+
--list_files $bugdir
27+
--remove_files_wildcard $bugdir
28+
--rmdir $bugdir

storage/innobase/fil/fil0fil.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,8 @@ initialized. */
316316
static fil_system_t* fil_system = NULL;
317317

318318
/** Determine if (i) is a user tablespace id or not. */
319-
# define fil_is_user_tablespace_id(i) ((i) > srv_undo_tablespaces_open)
319+
# define fil_is_user_tablespace_id(i) (i != 0 \
320+
&& !srv_is_undo_tablespace(i))
320321

321322
/** Determine if user has explicitly disabled fsync(). */
322323
#ifndef __WIN__

storage/innobase/include/srv0srv.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*****************************************************************************
22
3-
Copyright (c) 1995, 2016, Oracle and/or its affiliates. All rights reserved.
3+
Copyright (c) 1995, 2017, Oracle and/or its affiliates. All rights reserved.
44
Copyright (c) 2008, 2009, Google Inc.
55
Copyright (c) 2009, Percona Inc.
66
@@ -785,6 +785,13 @@ void
785785
srv_purge_wakeup(void);
786786
/*==================*/
787787

788+
/** Check whether given space id is undo tablespace id
789+
@param[in] space_id space id to check
790+
@return true if it is undo tablespace else false. */
791+
bool
792+
srv_is_undo_tablespace(
793+
ulint space_id);
794+
788795
/** Status variables to be passed to MySQL */
789796
struct export_var_t{
790797
ulint innodb_data_pending_reads; /*!< Pending reads */

storage/innobase/include/srv0start.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*****************************************************************************
22
3-
Copyright (c) 1995, 2016, Oracle and/or its affiliates. All Rights Reserved.
3+
Copyright (c) 1995, 2017, Oracle and/or its affiliates. All Rights Reserved.
44
55
This program is free software; you can redistribute it and/or modify it under
66
the terms of the GNU General Public License as published by the Free Software
@@ -139,6 +139,8 @@ extern ibool srv_startup_is_before_trx_rollback_phase;
139139
/** TRUE if a raw partition is in use */
140140
extern ibool srv_start_raw_disk_in_use;
141141

142+
/** Undo tablespaces starts with space_id. */
143+
extern ulint srv_undo_space_id_start;
142144

143145
/** Shutdown state */
144146
enum srv_shutdown_state {

storage/innobase/srv/srv0srv.cc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2898,3 +2898,18 @@ srv_purge_wakeup(void)
28982898
}
28992899
}
29002900

2901+
/** Check whether given space id is undo tablespace id
2902+
@param[in] space_id space id to check
2903+
@return true if it is undo tablespace else false. */
2904+
bool
2905+
srv_is_undo_tablespace(
2906+
ulint space_id)
2907+
{
2908+
if (srv_undo_space_id_start == 0) {
2909+
return (false);
2910+
}
2911+
2912+
return(space_id >= srv_undo_space_id_start
2913+
&& space_id < (srv_undo_space_id_start
2914+
+ srv_undo_tablespaces_open));
2915+
}

storage/innobase/srv/srv0start.cc

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ UNIV_INTERN ibool srv_have_fullfsync = FALSE;
109109
/** TRUE if a raw partition is in use */
110110
UNIV_INTERN ibool srv_start_raw_disk_in_use = FALSE;
111111

112+
/** UNDO tablespaces starts with space id. */
113+
ulint srv_undo_space_id_start;
114+
112115
/** TRUE if the server is being started, before rolling back any
113116
incomplete transactions */
114117
UNIV_INTERN ibool srv_startup_is_before_trx_rollback_phase = FALSE;
@@ -1332,13 +1335,23 @@ srv_undo_tablespaces_init(
13321335

13331336
for (i = 0; create_new_db && i < n_conf_tablespaces; ++i) {
13341337
char name[OS_FILE_MAX_PATH];
1338+
ulint space_id = i + 1;
1339+
1340+
DBUG_EXECUTE_IF("innodb_undo_upgrade",
1341+
space_id = i + 3;);
13351342

13361343
ut_snprintf(
13371344
name, sizeof(name),
13381345
"%s%cundo%03lu",
1339-
srv_undo_dir, SRV_PATH_SEPARATOR, i + 1);
1346+
srv_undo_dir, SRV_PATH_SEPARATOR, space_id);
1347+
1348+
if (i == 0) {
1349+
srv_undo_space_id_start = space_id;
1350+
prev_space_id = srv_undo_space_id_start - 1;
1351+
}
1352+
1353+
undo_tablespace_ids[i] = space_id;
13401354

1341-
/* Undo space ids start from 1. */
13421355
err = srv_undo_tablespace_create(
13431356
name, SRV_UNDO_TABLESPACE_SIZE_IN_PAGES);
13441357

@@ -1360,14 +1373,16 @@ srv_undo_tablespaces_init(
13601373
if (!create_new_db) {
13611374
n_undo_tablespaces = trx_rseg_get_n_undo_tablespaces(
13621375
undo_tablespace_ids);
1363-
} else {
1364-
n_undo_tablespaces = n_conf_tablespaces;
13651376

1366-
for (i = 1; i <= n_undo_tablespaces; ++i) {
1367-
undo_tablespace_ids[i - 1] = i;
1377+
if (n_undo_tablespaces != 0) {
1378+
srv_undo_space_id_start = undo_tablespace_ids[0];
1379+
prev_space_id = srv_undo_space_id_start - 1;
13681380
}
13691381

1370-
undo_tablespace_ids[i] = ULINT_UNDEFINED;
1382+
} else {
1383+
n_undo_tablespaces = n_conf_tablespaces;
1384+
1385+
undo_tablespace_ids[n_conf_tablespaces] = ULINT_UNDEFINED;
13711386
}
13721387

13731388
/* Open all the undo tablespaces that are currently in use. If we
@@ -1391,8 +1406,6 @@ srv_undo_tablespaces_init(
13911406
ut_a(undo_tablespace_ids[i] != 0);
13921407
ut_a(undo_tablespace_ids[i] != ULINT_UNDEFINED);
13931408

1394-
/* Undo space ids start from 1. */
1395-
13961409
err = srv_undo_tablespace_open(name, undo_tablespace_ids[i]);
13971410

13981411
if (err != DB_SUCCESS) {
@@ -1427,11 +1440,23 @@ srv_undo_tablespaces_init(
14271440
break;
14281441
}
14291442

1443+
/** Note the first undo tablespace id in case of
1444+
no active undo tablespace. */
1445+
if (n_undo_tablespaces == 0) {
1446+
srv_undo_space_id_start = i;
1447+
}
1448+
14301449
++n_undo_tablespaces;
14311450

14321451
++*n_opened;
14331452
}
14341453

1454+
/** Explictly specify the srv_undo_space_id_start
1455+
as zero when there are no undo tablespaces. */
1456+
if (n_undo_tablespaces == 0) {
1457+
srv_undo_space_id_start = 0;
1458+
}
1459+
14351460
/* If the user says that there are fewer than what we find we
14361461
tolerate that discrepancy but not the inverse. Because there could
14371462
be unused undo tablespaces for future use. */
@@ -1476,10 +1501,11 @@ srv_undo_tablespaces_init(
14761501
mtr_start(&mtr);
14771502

14781503
/* The undo log tablespace */
1479-
for (i = 1; i <= n_undo_tablespaces; ++i) {
1504+
for (i = 0; i < n_undo_tablespaces; ++i) {
14801505

14811506
fsp_header_init(
1482-
i, SRV_UNDO_TABLESPACE_SIZE_IN_PAGES, &mtr);
1507+
undo_tablespace_ids[i],
1508+
SRV_UNDO_TABLESPACE_SIZE_IN_PAGES, &mtr);
14831509
}
14841510

14851511
mtr_commit(&mtr);

storage/innobase/trx/trx0purge.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*****************************************************************************
22
3-
Copyright (c) 1996, 2016, Oracle and/or its affiliates. All Rights Reserved.
3+
Copyright (c) 1996, 2017, Oracle and/or its affiliates. All Rights Reserved.
44
55
This program is free software; you can redistribute it and/or modify it under
66
the terms of the GNU General Public License as published by the Free Software
@@ -692,7 +692,8 @@ trx_purge_get_rseg_with_min_trx_id(
692692

693693
/* We assume in purge of externally stored fields that space id is
694694
in the range of UNDO tablespace space ids */
695-
ut_a(purge_sys->rseg->space <= srv_undo_tablespaces_open);
695+
ut_a(purge_sys->rseg->space == 0
696+
|| srv_is_undo_tablespace(purge_sys->rseg->space));
696697

697698
zip_size = purge_sys->rseg->zip_size;
698699

storage/innobase/trx/trx0sys.cc

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*****************************************************************************
22
3-
Copyright (c) 1996, 2015, Oracle and/or its affiliates. All Rights Reserved.
3+
Copyright (c) 1996, 2017, Oracle and/or its affiliates. All Rights Reserved.
44
55
This program is free software; you can redistribute it and/or modify it under
66
the terms of the GNU General Public License as published by the Free Software
@@ -909,18 +909,12 @@ trx_sys_create_rsegs(
909909
ulint new_rsegs = n_rsegs - n_used;
910910

911911
for (i = 0; i < new_rsegs; ++i) {
912-
ulint space;
912+
ulint space_id;
913+
space_id = (n_spaces == 0) ? 0
914+
: (srv_undo_space_id_start + i % n_spaces);
913915

914-
/* Tablespace 0 is the system tablespace. All UNDO
915-
log tablespaces start from 1. */
916-
917-
if (n_spaces > 0) {
918-
space = (i % n_spaces) + 1;
919-
} else {
920-
space = 0; /* System tablespace */
921-
}
922-
923-
if (trx_rseg_create(space) != NULL) {
916+
/* Tablespace 0 is the system tablespace. */
917+
if (trx_rseg_create(space_id) != NULL) {
924918
++n_used;
925919
} else {
926920
break;

0 commit comments

Comments
 (0)