Skip to content

Commit 715e4f4

Browse files
committed
MDEV-12218 Clean up InnoDB parameter validation
Bind more InnoDB parameters directly to MYSQL_SYSVAR and remove "shadow variables". innodb_change_buffering: Declare as ENUM, not STRING. innodb_flush_method: Declare as ENUM, not STRING. innodb_log_buffer_size: Bind directly to srv_log_buffer_size, without rounding it to a multiple of innodb_page_size. LOG_BUFFER_SIZE: Remove. SysTablespace::normalize_size(): Renamed from normalize(). innodb_init_params(): A new function to initialize and validate InnoDB startup parameters. innodb_init(): Renamed from innobase_init(). Invoke innodb_init_params() before actually trying to start up InnoDB. srv_start(bool): Renamed from innobase_start_or_create_for_mysql(). Added the input parameter create_new_db. SRV_ALL_O_DIRECT_FSYNC: Define only for _WIN32. xb_normalize_init_values(): Merge to innodb_init_param().
1 parent 9ed2b2b commit 715e4f4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+622
-922
lines changed

extra/mariabackup/backup_mysql.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ Place, Suite 330, Boston, MA 02111-1307 USA
4848
#include <limits>
4949
#include "common.h"
5050
#include "xtrabackup.h"
51+
#include "srv0srv.h"
5152
#include "mysql_version.h"
5253
#include "backup_copy.h"
5354
#include "backup_mysql.h"

extra/mariabackup/changed_page_bitmap.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
2626

2727
#include "common.h"
2828
#include "xtrabackup.h"
29+
#include "srv0srv.h"
2930

3031
/* TODO: copy-pasted shared definitions from the XtraDB bitmap write code.
3132
Remove these on the first opportunity, i.e. single-binary XtraBackup. */

extra/mariabackup/fil_cur.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
2828
#include <my_dir.h>
2929
#include "read_filt.h"
3030
#include "srv0start.h"
31+
#include "srv0srv.h"
3132

3233
struct xb_fil_cur_t {
3334
pfs_os_file_t file; /*!< source file handle */

extra/mariabackup/xtrabackup.cc

Lines changed: 26 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ MariaBackup: hot backup tool for InnoDB
44
Originally Created 3/3/2009 Yasufumi Kinoshita
55
Written by Alexey Kopytov, Aleksandr Kuzminsky, Stewart Smith, Vadim Tkachenko,
66
Yasufumi Kinoshita, Ignacio Nin and Baron Schwartz.
7-
(c) 2017, MariaDB Corporation.
7+
(c) 2017, 2018, MariaDB Corporation.
88
Portions written by Marko Mäkelä.
99
1010
This program is free software; you can redistribute it and/or modify
@@ -223,7 +223,6 @@ long innobase_buffer_pool_awe_mem_mb = 0;
223223
long innobase_file_io_threads = 4;
224224
long innobase_read_io_threads = 4;
225225
long innobase_write_io_threads = 4;
226-
long innobase_log_buffer_size = 1024*1024L;
227226

228227
longlong innobase_page_size = (1LL << 14); /* 16KB */
229228
char* innobase_buffer_pool_filename = NULL;
@@ -236,9 +235,6 @@ are determined in innobase_init below: */
236235
static char* innobase_ignored_opt;
237236
char* innobase_data_home_dir;
238237
char* innobase_data_file_path;
239-
/* The following has a misleading name: starting from 4.0.5, this also
240-
affects Windows: */
241-
char* innobase_unix_file_flush_method;
242238

243239
my_bool innobase_use_doublewrite;
244240
my_bool innobase_use_large_pages;
@@ -621,13 +617,9 @@ enum options_xtrabackup
621617
OPT_INNODB_ADAPTIVE_HASH_INDEX,
622618
OPT_INNODB_DOUBLEWRITE,
623619
OPT_INNODB_FILE_PER_TABLE,
624-
OPT_INNODB_FLUSH_LOG_AT_TRX_COMMIT,
625-
OPT_INNODB_FLUSH_METHOD,
626-
OPT_INNODB_LOCKS_UNSAFE_FOR_BINLOG,
627620
OPT_INNODB_LOG_GROUP_HOME_DIR,
628621
OPT_INNODB_MAX_DIRTY_PAGES_PCT,
629622
OPT_INNODB_MAX_PURGE_LAG,
630-
OPT_INNODB_ROLLBACK_ON_TIMEOUT,
631623
OPT_INNODB_STATUS_FILE,
632624
OPT_INNODB_AUTOEXTEND_INCREMENT,
633625
OPT_INNODB_BUFFER_POOL_SIZE,
@@ -1127,15 +1119,10 @@ struct my_option xb_server_options[] =
11271119
(G_PTR*) &innobase_file_per_table, 0, GET_BOOL, NO_ARG,
11281120
FALSE, 0, 0, 0, 0, 0},
11291121

1130-
{"innodb_flush_method", OPT_INNODB_FLUSH_METHOD,
1131-
"With which method to flush data.", (G_PTR*) &innobase_unix_file_flush_method,
1132-
(G_PTR*) &innobase_unix_file_flush_method, 0, GET_STR, REQUIRED_ARG, 0, 0, 0,
1133-
0, 0, 0},
1134-
11351122
{"innodb_log_buffer_size", OPT_INNODB_LOG_BUFFER_SIZE,
11361123
"The size of the buffer which InnoDB uses to write log to the log files on disk.",
1137-
(G_PTR*) &innobase_log_buffer_size, (G_PTR*) &innobase_log_buffer_size, 0,
1138-
GET_LONG, REQUIRED_ARG, 1024*1024L, 256*1024L, LONG_MAX, 0, 1024, 0},
1124+
(G_PTR*) &srv_log_buffer_size, (G_PTR*) &srv_log_buffer_size, 0,
1125+
GET_ULONG, REQUIRED_ARG, 1024*1024L, 256*1024L, LONG_MAX, 0, 1024, 0},
11391126
{"innodb_log_file_size", OPT_INNODB_LOG_FILE_SIZE,
11401127
"Ignored for mysqld option compatibility",
11411128
(G_PTR*) &srv_log_file_size, (G_PTR*) &srv_log_file_size, 0,
@@ -1479,11 +1466,6 @@ xb_get_one_option(int optid,
14791466
case OPT_INNODB_LOG_FILE_SIZE:
14801467
break;
14811468

1482-
case OPT_INNODB_FLUSH_METHOD:
1483-
1484-
ADD_PRINT_PARAM_OPT(innobase_unix_file_flush_method);
1485-
break;
1486-
14871469
case OPT_INNODB_PAGE_SIZE:
14881470

14891471
ADD_PRINT_PARAM_OPT(innobase_page_size);
@@ -1587,15 +1569,14 @@ xb_get_one_option(int optid,
15871569
return 0;
15881570
}
15891571

1590-
static my_bool
1591-
innodb_init_param(void)
1572+
static bool innodb_init_param()
15921573
{
15931574
srv_is_being_started = TRUE;
15941575
/* === some variables from mysqld === */
15951576
memset((G_PTR) &mysql_tmpdir_list, 0, sizeof(mysql_tmpdir_list));
15961577

15971578
if (init_tmpdir(&mysql_tmpdir_list, opt_mysql_tmpdir))
1598-
exit(EXIT_FAILURE);
1579+
return true;
15991580
xtrabackup_tmpdir = my_tmpdir(&mysql_tmpdir_list);
16001581
/* dummy for initialize all_charsets[] */
16011582
get_charset_name(0);
@@ -1617,7 +1598,7 @@ innodb_init_param(void)
16171598
} else {
16181599
msg("InnoDB: Error: invalid value of "
16191600
"innobase_page_size: %lld", innobase_page_size);
1620-
exit(EXIT_FAILURE);
1601+
goto error;
16211602
}
16221603
} else {
16231604
srv_page_size_shift = 14;
@@ -1684,6 +1665,9 @@ innodb_init_param(void)
16841665
goto error;
16851666
}
16861667

1668+
srv_sys_space.normalize_size();
1669+
srv_lock_table_size = 5 * (srv_buf_pool_size >> srv_page_size_shift);
1670+
16871671
/* -------------- Log files ---------------------------*/
16881672

16891673
/* The default dir for log files is the datadir of MySQL */
@@ -1707,16 +1691,13 @@ innodb_init_param(void)
17071691

17081692
srv_adaptive_flushing = FALSE;
17091693

1710-
srv_file_flush_method_str = innobase_unix_file_flush_method;
1711-
1712-
srv_log_buffer_size = (ulint) innobase_log_buffer_size;
1713-
17141694
/* We set srv_pool_size here in units of 1 kB. InnoDB internally
17151695
changes the value so that it becomes the number of database pages. */
17161696

17171697
srv_buf_pool_size = (ulint) xtrabackup_use_memory;
17181698
srv_buf_pool_chunk_unit = (ulong)srv_buf_pool_size;
17191699
srv_buf_pool_instances = 1;
1700+
srv_n_page_cleaners = 1;
17201701

17211702
srv_n_file_io_threads = (ulint) innobase_file_io_threads;
17221703
srv_n_read_io_threads = (ulint) innobase_read_io_threads;
@@ -1732,7 +1713,7 @@ innodb_init_param(void)
17321713

17331714
srv_locks_unsafe_for_binlog = (ibool) innobase_locks_unsafe_for_binlog;
17341715

1735-
srv_max_n_open_files = ULINT_UNDEFINED;
1716+
srv_max_n_open_files = ULINT_UNDEFINED - 5;
17361717
srv_innodb_status = (ibool) innobase_create_status_file;
17371718

17381719
srv_print_verbose_log = 1;
@@ -1743,20 +1724,7 @@ innodb_init_param(void)
17431724
/* We cannot treat characterset here for now!! */
17441725
data_mysql_default_charset_coll = (ulint)default_charset_info->number;
17451726

1746-
ut_a(DATA_MYSQL_BINARY_CHARSET_COLL == my_charset_bin.number);
1747-
1748-
//innobase_commit_concurrency_init_default();
1749-
1750-
/* Since we in this module access directly the fields of a trx
1751-
struct, and due to different headers and flags it might happen that
1752-
mutex_t has a different size in this module and in InnoDB
1753-
modules, we check at run time that the size is the same in
1754-
these compilation modules. */
1755-
1756-
/* On 5.5+ srv_use_native_aio is TRUE by default. It is later reset
1757-
if it is not supported by the platform in
1758-
innobase_start_or_create_for_mysql(). As we don't call it in xtrabackup,
1759-
we have to duplicate checks from that function here. */
1727+
ut_ad(DATA_MYSQL_BINARY_CHARSET_COLL == my_charset_bin.number);
17601728

17611729
#ifdef _WIN32
17621730
srv_use_native_aio = TRUE;
@@ -1789,16 +1757,27 @@ innodb_init_param(void)
17891757
? log_block_calc_checksum_crc32
17901758
: log_block_calc_checksum_none;
17911759

1792-
return(FALSE);
1760+
#ifdef _WIN32
1761+
srv_use_native_aio = TRUE;
1762+
#endif
1763+
srv_file_flush_method = IF_WIN(SRV_ALL_O_DIRECT_FSYNC, SRV_FSYNC);
1764+
return false;
17931765

17941766
error:
17951767
msg("mariabackup: innodb_init_param(): Error occured.\n");
1796-
return(TRUE);
1768+
return true;
17971769
}
17981770

17991771
static bool innodb_init()
18001772
{
1801-
dberr_t err = innobase_start_or_create_for_mysql();
1773+
bool create_new_db = false;
1774+
/* Check if the data files exist or not. */
1775+
dberr_t err = srv_sys_space.check_file_spec(&create_new_db, 5U << 20);
1776+
1777+
if (err == DB_SUCCESS) {
1778+
err = srv_start(create_new_db);
1779+
}
1780+
18021781
if (err != DB_SUCCESS) {
18031782
msg("mariabackup: innodb_init() returned %d (%s).\n",
18041783
err, ut_strerr(err));
@@ -3583,19 +3562,6 @@ open_or_create_log_file(
35833562
return(DB_SUCCESS);
35843563
}
35853564

3586-
/*********************************************************************//**
3587-
Normalizes init parameter values to use units we use inside InnoDB.
3588-
@return DB_SUCCESS or error code */
3589-
static
3590-
void
3591-
xb_normalize_init_values(void)
3592-
/*==========================*/
3593-
{
3594-
srv_sys_space.normalize();
3595-
srv_log_buffer_size >>= srv_page_size_shift;
3596-
srv_lock_table_size = 5 * (srv_buf_pool_size >> srv_page_size_shift);
3597-
}
3598-
35993565
/***********************************************************************
36003566
Set the open files limit. Based on set_max_open_files().
36013567
@@ -3805,42 +3771,6 @@ xtrabackup_backup_func()
38053771
return(false);
38063772
}
38073773

3808-
xb_normalize_init_values();
3809-
3810-
3811-
if (srv_file_flush_method_str == NULL) {
3812-
/* These are the default options */
3813-
srv_file_flush_method = SRV_FSYNC;
3814-
} else if (0 == ut_strcmp(srv_file_flush_method_str, "fsync")) {
3815-
srv_file_flush_method = SRV_FSYNC;
3816-
} else if (0 == ut_strcmp(srv_file_flush_method_str, "O_DSYNC")) {
3817-
srv_file_flush_method = SRV_O_DSYNC;
3818-
3819-
} else if (0 == ut_strcmp(srv_file_flush_method_str, "O_DIRECT")) {
3820-
srv_file_flush_method = SRV_O_DIRECT;
3821-
msg("mariabackup: using O_DIRECT\n");
3822-
} else if (0 == ut_strcmp(srv_file_flush_method_str, "littlesync")) {
3823-
srv_file_flush_method = SRV_LITTLESYNC;
3824-
} else if (0 == ut_strcmp(srv_file_flush_method_str, "nosync")) {
3825-
srv_file_flush_method = SRV_NOSYNC;
3826-
} else if (0 == ut_strcmp(srv_file_flush_method_str, "ALL_O_DIRECT")) {
3827-
srv_file_flush_method = SRV_ALL_O_DIRECT_FSYNC;
3828-
msg("mariabackup: using ALL_O_DIRECT\n");
3829-
} else if (0 == ut_strcmp(srv_file_flush_method_str,
3830-
"O_DIRECT_NO_FSYNC")) {
3831-
srv_file_flush_method = SRV_O_DIRECT_NO_FSYNC;
3832-
msg("mariabackup: using O_DIRECT_NO_FSYNC\n");
3833-
} else {
3834-
msg("mariabackup: Unrecognized value %s for "
3835-
"innodb_flush_method\n", srv_file_flush_method_str);
3836-
goto fail;
3837-
}
3838-
3839-
#ifdef _WIN32
3840-
srv_file_flush_method = SRV_ALL_O_DIRECT_FSYNC;
3841-
srv_use_native_aio = TRUE;
3842-
#endif
3843-
38443774
if (srv_buf_pool_size >= 1000 * 1024 * 1024) {
38453775
/* Here we still have srv_pool_size counted
38463776
in kilobytes (in 4.0 this was in bytes)
@@ -5002,7 +4932,6 @@ xtrabackup_prepare_func(char** argv)
50024932
goto error_cleanup;
50034933
}
50044934

5005-
xb_normalize_init_values();
50064935
sync_check_init();
50074936
ut_d(sync_check_enable());
50084937
ut_crc32_init();

mysql-test/suite/sys_vars/r/innodb_change_buffering_basic.result

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,11 @@ ERROR HY000: Variable 'innodb_change_buffering' is a GLOBAL variable and should
5050
set global innodb_change_buffering=1.1;
5151
ERROR 42000: Incorrect argument type to variable 'innodb_change_buffering'
5252
set global innodb_change_buffering=1;
53-
ERROR 42000: Incorrect argument type to variable 'innodb_change_buffering'
53+
SELECT @@global.innodb_change_buffering;
54+
@@global.innodb_change_buffering
55+
inserts
5456
set global innodb_change_buffering=-2;
55-
ERROR 42000: Incorrect argument type to variable 'innodb_change_buffering'
57+
ERROR 42000: Variable 'innodb_change_buffering' can't be set to the value of '-2'
5658
set global innodb_change_buffering=1e1;
5759
ERROR 42000: Incorrect argument type to variable 'innodb_change_buffering'
5860
set global innodb_change_buffering='some';
Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
'#---------------------BS_STVARS_029_01----------------------#'
22
SELECT COUNT(@@GLOBAL.innodb_flush_method);
33
COUNT(@@GLOBAL.innodb_flush_method)
4-
0
5-
0 Expected
4+
1
5+
1 Expected
66
'#---------------------BS_STVARS_029_02----------------------#'
77
SET @@GLOBAL.innodb_flush_method=1;
88
ERROR HY000: Variable 'innodb_flush_method' is a read only variable
99
Expected error 'Read only variable'
1010
SELECT COUNT(@@GLOBAL.innodb_flush_method);
1111
COUNT(@@GLOBAL.innodb_flush_method)
12-
0
13-
0 Expected
12+
1
13+
1 Expected
1414
'#---------------------BS_STVARS_029_03----------------------#'
1515
SELECT @@GLOBAL.innodb_flush_method = VARIABLE_VALUE
1616
FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES
1717
WHERE VARIABLE_NAME='innodb_flush_method';
1818
@@GLOBAL.innodb_flush_method = VARIABLE_VALUE
19-
NULL
19+
1
2020
1 Expected
2121
SELECT COUNT(@@GLOBAL.innodb_flush_method);
2222
COUNT(@@GLOBAL.innodb_flush_method)
23-
0
24-
0 Expected
23+
1
24+
1 Expected
2525
SELECT COUNT(VARIABLE_VALUE)
2626
FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES
2727
WHERE VARIABLE_NAME='innodb_flush_method';
@@ -31,13 +31,13 @@ COUNT(VARIABLE_VALUE)
3131
'#---------------------BS_STVARS_029_04----------------------#'
3232
SELECT @@innodb_flush_method = @@GLOBAL.innodb_flush_method;
3333
@@innodb_flush_method = @@GLOBAL.innodb_flush_method
34-
NULL
34+
1
3535
1 Expected
3636
'#---------------------BS_STVARS_029_05----------------------#'
3737
SELECT COUNT(@@innodb_flush_method);
3838
COUNT(@@innodb_flush_method)
39-
0
40-
0 Expected
39+
1
40+
1 Expected
4141
SELECT COUNT(@@local.innodb_flush_method);
4242
ERROR HY000: Variable 'innodb_flush_method' is a GLOBAL variable
4343
Expected error 'Variable is a GLOBAL variable'
@@ -46,8 +46,8 @@ ERROR HY000: Variable 'innodb_flush_method' is a GLOBAL variable
4646
Expected error 'Variable is a GLOBAL variable'
4747
SELECT COUNT(@@GLOBAL.innodb_flush_method);
4848
COUNT(@@GLOBAL.innodb_flush_method)
49-
0
50-
0 Expected
49+
1
50+
1 Expected
5151
SELECT innodb_flush_method = @@SESSION.innodb_flush_method;
5252
ERROR 42S22: Unknown column 'innodb_flush_method' in 'field list'
5353
Expected error 'Readonly variable'
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
call mtr.add_suppression("InnoDB: Failed to set .*DIRECT");
2+
select @@innodb_flush_method;
3+
@@innodb_flush_method
4+
fsync
5+
create table t(a serial) engine=innodb;
6+
FLUSH TABLES;
7+
select @@innodb_flush_method;
8+
@@innodb_flush_method
9+
O_DIRECT_NO_FSYNC
10+
insert into t values(0);
11+
FLUSH TABLES;
12+
select @@innodb_flush_method;
13+
@@innodb_flush_method
14+
fsync
15+
drop table t;

mysql-test/suite/sys_vars/r/sysvars_innodb,32bit.rdiff

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,8 +293,8 @@
293293
GLOBAL_VALUE_ORIGIN CONFIG
294294
DEFAULT_VALUE 16777216
295295
VARIABLE_SCOPE GLOBAL
296-
-VARIABLE_TYPE BIGINT
297-
+VARIABLE_TYPE INT
296+
-VARIABLE_TYPE BIGINT UNSIGNED
297+
+VARIABLE_TYPE INT UNSIGNED
298298
VARIABLE_COMMENT The size of the buffer which InnoDB uses to write log to the log files on disk.
299299
NUMERIC_MIN_VALUE 262144
300300
-NUMERIC_MAX_VALUE 9223372036854775807

0 commit comments

Comments
 (0)