Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions mysql-test/mysql-test-run.pl
Original file line number Diff line number Diff line change
Expand Up @@ -3339,6 +3339,7 @@ sub environment_setup {
$ENV{'MYSQLTEST_VARDIR'} = $opt_vardir;
$ENV{'USE_RUNNING_SERVER'} = using_extern();
$ENV{'MTR_REPEAT'} = $opt_repeat;
$ENV{'MYSQL_TEST_MODE'} = "on";

if (IS_WINDOWS) {
$ENV{'SECURE_LOAD_PATH'} = $glob_mysql_test_dir . "\\std_data";
Expand Down Expand Up @@ -4410,6 +4411,8 @@ sub mysql_install_db {
mtr_add_arg($args, "--datadir=%s", "$install_datadir");
mtr_add_arg($args, "--secure-file-priv=%s", "$opt_vardir");

mtr_add_arg($args, "--mydb-dedicated-server=0");

# Overwrite the buffer size to 24M for certain tests to pass
mtr_add_arg($args, "--innodb_buffer_pool_size=24M");
mtr_add_arg($args, "--innodb-redo-log-capacity=10M");
Expand Down
5 changes: 5 additions & 0 deletions mysql-test/r/mysqld--help-notwin.result
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,10 @@ The following options may be given as the first argument:
--min-examined-row-limit=#
Don't write queries to slow log that examine fewer rows
than that
--mydb-dedicated-server
Automatically tune server parameters according to
available hardware resources and OS limits
(Defaults to on; use --skip-mydb-dedicated-server to disable.)
--myisam-block-size=#
Block size to be used for MyISAM index pages
--myisam-data-pointer-size=#
Expand Down Expand Up @@ -1942,6 +1946,7 @@ max-user-connections 0
max-write-lock-count 18446744073709551615
memlock FALSE
min-examined-row-limit 0
mydb-dedicated-server FALSE
myisam-block-size 1024
myisam-data-pointer-size 6
myisam-max-sort-file-size 9223372036853727232
Expand Down
2 changes: 2 additions & 0 deletions mysql-test/suite/sys_vars/r/all_vars.result
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ master_verify_checksum
master_verify_checksum
max_length_for_sort_data
max_length_for_sort_data
mydb_dedicated_server
mydb_dedicated_server
optimizer_max_subgraph_pairs
optimizer_max_subgraph_pairs
partial_revokes
Expand Down
57 changes: 55 additions & 2 deletions sql/mysqld.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1401,6 +1401,7 @@ ulong specialflag = 0;
ulong binlog_cache_use = 0, binlog_cache_disk_use = 0;
ulong binlog_stmt_cache_use = 0, binlog_stmt_cache_disk_use = 0;
ulong max_connections, max_connect_errors;
bool mydb_dedicated_server = true;
ulong rpl_stop_replica_timeout = LONG_TIMEOUT;
bool thread_cache_size_specified = false;
bool host_cache_size_specified = false;
Expand Down Expand Up @@ -9246,6 +9247,25 @@ class Plugin_and_data_dir_option_parser final {
bool valid_;
};

namespace {
bool is_sysvar_specified(const char *name) {
assert(get_static_system_variable_hash() != nullptr);

const std::string str{name};
sys_var *sysvar = find_or_nullptr(*get_static_system_variable_hash(), str);

return sysvar != nullptr && sysvar->get_source() != COMPILED;
}

auto get_sysvar_max_value(const char *name) {
assert(get_static_system_variable_hash() != nullptr);

const std::string str{name};

return find_or_nullptr(*get_static_system_variable_hash(), str)->get_max_value();
}
} // namespace

#ifdef _WIN32
int win_main(int argc, char **argv)
#else
Expand Down Expand Up @@ -9350,6 +9370,12 @@ int mysqld_main(int argc, char **argv)
if (init_error_log()) unireg_abort(MYSQLD_ABORT_EXIT);
heo_error = handle_early_options();

if (!is_sysvar_specified("mydb_dedicated_server") &&
getenv("MYSQL_TEST_MODE") != nullptr) {
// Make mydb_dedicated_server OFF by default under MTR
mydb_dedicated_server = false;
}

// this is to prevent mtr from accidentally printing this log when it runs
// mysqld with --verbose --help to extract version info and variable values
// and when mysqld is run with --validate-config option
Expand All @@ -9367,7 +9393,14 @@ int mysqld_main(int argc, char **argv)

init_sql_statement_names();
ulong requested_open_files = 0;
if (!opt_validate_config) adjust_related_options(&requested_open_files);
if (!opt_validate_config) {
adjust_related_options(&requested_open_files);

if (mydb_dedicated_server) {
if (!is_sysvar_specified("max_prepared_stmt_count"))
max_prepared_stmt_count = get_sysvar_max_value("max_prepared_stmt_count");
}
}
// moved signal initialization here so that PFS thread inherited signal mask
my_init_signals();

Expand Down Expand Up @@ -10857,12 +10890,17 @@ static void adjust_open_files_limit(ulong *requested_open_files) {
/* Try to allocate no less than 5000 by default. */
limit_3 = open_files_limit ? open_files_limit : 5000;

if (mydb_dedicated_server && !is_sysvar_specified("open_files_limit")) {
// Set the open files limit as high as the OS limits allow.
limit_3 = OS_FILE_LIMIT;
}

request_open_files = max<ulong>(max<ulong>(limit_1, limit_2), limit_3);

/* Notice: my_set_max_open_files() may return more than requested. */
effective_open_files = my_set_max_open_files(request_open_files);

if (effective_open_files < request_open_files) {
if (!mydb_dedicated_server && effective_open_files < request_open_files) {
if (open_files_limit == 0) {
LogErr(WARNING_LEVEL, ER_CHANGED_MAX_OPEN_FILES, effective_open_files,
request_open_files);
Expand All @@ -10883,6 +10921,14 @@ static constexpr const ulong TABLE_OPEN_CACHE_MIN{400};
static void adjust_max_connections(ulong requested_open_files) {
ulong limit;

if (mydb_dedicated_server && !is_sysvar_specified("max_connections")) {
// Limiting connections based on empriric formulas makes no sense in
// practice
max_connections = std::min(10000UL, requested_open_files);

return;
}

limit = requested_open_files - 10 - TABLE_OPEN_CACHE_MIN * 2;

if (limit < max_connections) {
Expand All @@ -10899,6 +10945,13 @@ static void adjust_table_cache_size(ulong requested_open_files) {
limit = max<ulong>((requested_open_files - 10 - max_connections) / 2,
TABLE_OPEN_CACHE_MIN);

if (mydb_dedicated_server && !is_sysvar_specified("table_open_cache")) {
// MySQL 8.0+ does not have .FRM files, so autosizing the table cache based
// on files and connections limits does not make sense.
table_cache_size = limit = get_sysvar_max_value("table_open_cache");
table_cache_instances = get_sysvar_max_value("table_open_cache_instances");
}

if (limit < table_cache_size) {
LogErr(WARNING_LEVEL, ER_CHANGED_TABLE_OPEN_CACHE, limit, table_cache_size);

Expand Down
1 change: 1 addition & 0 deletions sql/mysqld.h
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ extern ulong stored_program_def_size;
extern ulong table_def_size;
extern ulong tablespace_def_size;
extern MYSQL_PLUGIN_IMPORT ulong max_connections;
extern bool mydb_dedicated_server;
extern ulong max_digest_length;
extern ulong max_connect_errors, connect_timeout;
extern bool opt_replica_allow_batching;
Expand Down
11 changes: 11 additions & 0 deletions sql/sys_vars.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3126,6 +3126,17 @@ static Sys_var_ulong Sys_min_examined_row_limit(
VALID_RANGE(0, ULONG_MAX), DEFAULT(0), BLOCK_SIZE(1), NO_MUTEX_GUARD,
NOT_IN_BINLOG, ON_CHECK(check_session_admin_no_super));

static Sys_var_bool Sys_mydb_dedicated_server(
"mydb_dedicated_server",
"Automatically tune server parameters according to available hardware "
"resources and OS limits",
READ_ONLY GLOBAL_VAR(mydb_dedicated_server),
CMD_LINE(OPT_ARG),
DEFAULT(true), NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(nullptr),
ON_UPDATE(nullptr), nullptr,
// Changes defaults of other PARSE_EARLY variables */
sys_var::PARSE_EARLY);

#ifdef _WIN32
static Sys_var_bool Sys_named_pipe("named_pipe", "Enable the named pipe (NT)",
READ_ONLY NON_PERSIST
Expand Down
13 changes: 13 additions & 0 deletions storage/innobase/handler/ha_innodb.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5340,6 +5340,19 @@ static int innodb_init_params() {
srv_buf_pool_size = srv_buf_pool_def_size;
}

/* Enable innodb_dedicated_server, if mydb_dedicated_server is enabled */
if (mydb_dedicated_server && sysvar_source_svc != nullptr) {
static const char *variable_name = "innodb_dedicated_server";
enum enum_variable_source source;
if (!sysvar_source_svc->get(
variable_name, static_cast<unsigned int>(strlen(variable_name)),
&source)) {
if (source == COMPILED) {
srv_dedicated_server = true;
}
}
}

innodb_buffer_pool_size_init();

innodb_undo_tablespaces_deprecate();
Expand Down
Loading