From 1c91569274219ac612fcfdea4764311e2377977c Mon Sep 17 00:00:00 2001 From: Monty Date: Mon, 29 Aug 2016 20:28:06 +0300 Subject: [PATCH] Set server_id to 1 by default and disallow to set it to 0 This makes it easier to setup master as on only have to set --log-bin. Before this patch if one did set up the master with just --log-bin, slaves could not connect until server_id was set on the master, which could be both confusing and hard to do. --- mysql-test/r/mysqld--help.result | 4 ++-- mysql-test/r/variables.result | 6 ++++-- .../suite/sys_vars/r/server_id_basic.result | 18 +++++++++++------- .../r/sysvars_server_notembedded.result | 8 ++++---- .../suite/sys_vars/t/server_id_basic.test | 2 +- sql/mysqld.cc | 14 -------------- sql/mysqld.h | 2 +- sql/sql_repl.cc | 12 ------------ sql/sql_repl.h | 1 - sql/sys_vars.cc | 3 +-- 10 files changed, 24 insertions(+), 46 deletions(-) diff --git a/mysql-test/r/mysqld--help.result b/mysql-test/r/mysqld--help.result index b0e89b7f02d..0d52a50eb56 100644 --- a/mysql-test/r/mysqld--help.result +++ b/mysql-test/r/mysqld--help.result @@ -1339,7 +1339,7 @@ performance-schema-max-rwlock-instances -1 performance-schema-max-socket-classes 10 performance-schema-max-socket-instances -1 performance-schema-max-stage-classes 150 -performance-schema-max-statement-classes 181 +performance-schema-max-statement-classes 184 performance-schema-max-table-handles -1 performance-schema-max-table-instances -1 performance-schema-max-thread-classes 50 @@ -1384,7 +1384,7 @@ rowid-merge-buff-size 8388608 safe-user-create FALSE secure-auth TRUE secure-file-priv (No default value) -server-id 0 +server-id 1 show-slave-auth-info FALSE silent-startup FALSE skip-grant-tables TRUE diff --git a/mysql-test/r/variables.result b/mysql-test/r/variables.result index d8f8c0c03f7..b78b3caa58d 100644 --- a/mysql-test/r/variables.result +++ b/mysql-test/r/variables.result @@ -1466,15 +1466,17 @@ SELECT @@GLOBAL.server_id; @@GLOBAL.server_id 4294967295 SET GLOBAL server_id = 0; +Warnings: +Warning 1292 Truncated incorrect server_id value: '0' SELECT @@GLOBAL.server_id; @@GLOBAL.server_id -0 +1 SET GLOBAL server_id = -1; Warnings: Warning 1292 Truncated incorrect server_id value: '-1' SELECT @@GLOBAL.server_id; @@GLOBAL.server_id -0 +1 SET GLOBAL server_id = @old_server_id; # # BUG#10206 - InnoDB: Transaction requiring Max_BinLog_Cache_size > 4GB always rollsback diff --git a/mysql-test/suite/sys_vars/r/server_id_basic.result b/mysql-test/suite/sys_vars/r/server_id_basic.result index 4d82d8f102a..a2b117c1332 100644 --- a/mysql-test/suite/sys_vars/r/server_id_basic.result +++ b/mysql-test/suite/sys_vars/r/server_id_basic.result @@ -8,17 +8,19 @@ SET @@global.server_id = 500000; SET @@global.server_id = DEFAULT; SELECT @@global.server_id; @@global.server_id -0 +1 '#--------------------FN_DYNVARS_144_02-------------------------#' SET @@global.server_id = DEFAULT; -SELECT @@global.server_id = 0; -@@global.server_id = 0 +SELECT @@global.server_id = 1; +@@global.server_id = 1 1 '#--------------------FN_DYNVARS_144_03-------------------------#' SET @@global.server_id = 0; +Warnings: +Warning 1292 Truncated incorrect server_id value: '0' SELECT @@global.server_id; @@global.server_id -0 +1 SET @@global.server_id = 1; SELECT @@global.server_id; @@global.server_id @@ -62,13 +64,13 @@ Warnings: Warning 1292 Truncated incorrect server_id value: '-1' SELECT @@global.server_id; @@global.server_id -0 +1 SET @@global.server_id = -2147483648; Warnings: Warning 1292 Truncated incorrect server_id value: '-2147483648' SELECT @@global.server_id; @@global.server_id -0 +1 SET @@global.server_id = 2147483649*2; Warnings: Warning 1292 Truncated incorrect server_id value: '4294967298' @@ -102,9 +104,11 @@ SELECT @@global.server_id; @@global.server_id 1 SET @@global.server_id = FALSE; +Warnings: +Warning 1292 Truncated incorrect server_id value: '0' SELECT @@global.server_id; @@global.server_id -0 +1 '#---------------------FN_DYNVARS_001_09----------------------#' SET @@global.server_id = 512; SELECT @@server_id = @@global.server_id; diff --git a/mysql-test/suite/sys_vars/r/sysvars_server_notembedded.result b/mysql-test/suite/sys_vars/r/sysvars_server_notembedded.result index 371fd9e3918..4e98bc9f102 100644 --- a/mysql-test/suite/sys_vars/r/sysvars_server_notembedded.result +++ b/mysql-test/suite/sys_vars/r/sysvars_server_notembedded.result @@ -3007,9 +3007,9 @@ READ_ONLY YES COMMAND_LINE_ARGUMENT REQUIRED VARIABLE_NAME PERFORMANCE_SCHEMA_MAX_STATEMENT_CLASSES SESSION_VALUE NULL -GLOBAL_VALUE 181 +GLOBAL_VALUE 184 GLOBAL_VALUE_ORIGIN COMPILE-TIME -DEFAULT_VALUE 181 +DEFAULT_VALUE 184 VARIABLE_SCOPE GLOBAL VARIABLE_TYPE BIGINT UNSIGNED VARIABLE_COMMENT Maximum number of statement instruments. @@ -3779,11 +3779,11 @@ VARIABLE_NAME SERVER_ID SESSION_VALUE 1 GLOBAL_VALUE 1 GLOBAL_VALUE_ORIGIN CONFIG -DEFAULT_VALUE 0 +DEFAULT_VALUE 1 VARIABLE_SCOPE SESSION VARIABLE_TYPE BIGINT UNSIGNED VARIABLE_COMMENT Uniquely identifies the server instance in the community of replication partners -NUMERIC_MIN_VALUE 0 +NUMERIC_MIN_VALUE 1 NUMERIC_MAX_VALUE 4294967295 NUMERIC_BLOCK_SIZE 1 ENUM_VALUE_LIST NULL diff --git a/mysql-test/suite/sys_vars/t/server_id_basic.test b/mysql-test/suite/sys_vars/t/server_id_basic.test index 6940270c12e..c2dfa4c5f9d 100644 --- a/mysql-test/suite/sys_vars/t/server_id_basic.test +++ b/mysql-test/suite/sys_vars/t/server_id_basic.test @@ -54,7 +54,7 @@ SELECT @@global.server_id; ################################################################### SET @@global.server_id = DEFAULT; -SELECT @@global.server_id = 0; +SELECT @@global.server_id = 1; --echo '#--------------------FN_DYNVARS_144_03-------------------------#' ################################################################################## diff --git a/sql/mysqld.cc b/sql/mysqld.cc index 9b5fcbddd6c..8fa8f01b894 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -400,7 +400,6 @@ bool opt_error_log= IF_WIN(1,0); bool opt_disable_networking=0, opt_skip_show_db=0; bool opt_skip_name_resolve=0; my_bool opt_character_set_client_handshake= 1; -bool server_id_supplied = 0; bool opt_endinfo, using_udf_functions; my_bool locked_in_memory; bool opt_using_transactions; @@ -5831,17 +5830,6 @@ int mysqld_main(int argc, char **argv) if (WSREP_ON && wsrep_check_opts()) global_system_variables.wsrep_on= 0; - if (opt_bin_log && !global_system_variables.server_id) - { - SYSVAR_AUTOSIZE(global_system_variables.server_id, ::server_id= 1); -#ifdef EXTRA_DEBUG - sql_print_warning("You have enabled the binary log, but you haven't set " - "server-id to a non-zero value: we force server id to 1; " - "updates will be logged to the binary log, but " - "connections from slaves will not be accepted."); -#endif - } - /* The subsequent calls may take a long time : e.g. innodb log read. Thus set the long running service control manager timeout @@ -8707,7 +8695,6 @@ static int mysql_init_variables(void) mqh_used= 0; kill_in_progress= 0; cleanup_done= 0; - server_id_supplied= 0; test_flags= select_errors= dropping_tables= ha_open_options=0; thread_count= thread_running= kill_cached_threads= wake_thread= 0; service_thread_count= 0; @@ -9176,7 +9163,6 @@ mysqld_get_one_option(int optid, const struct my_option *opt, char *argument) opt_noacl=opt_bootstrap=1; break; case OPT_SERVER_ID: - server_id_supplied = 1; ::server_id= global_system_variables.server_id; break; case OPT_LOWER_CASE_TABLE_NAMES: diff --git a/sql/mysqld.h b/sql/mysqld.h index 6783eeff810..846a01a9427 100644 --- a/sql/mysqld.h +++ b/sql/mysqld.h @@ -107,7 +107,7 @@ extern CHARSET_INFO *error_message_charset_info; extern CHARSET_INFO *character_set_filesystem; extern MY_BITMAP temp_pool; -extern bool opt_large_files, server_id_supplied; +extern bool opt_large_files; extern bool opt_update_log, opt_bin_log, opt_error_log; extern my_bool opt_log, opt_bootstrap; extern my_bool opt_backup_history_log; diff --git a/sql/sql_repl.cc b/sql/sql_repl.cc index 36f0cd84cbf..6ece9b793c9 100644 --- a/sql/sql_repl.cc +++ b/sql/sql_repl.cc @@ -2116,12 +2116,6 @@ static int init_binlog_sender(binlog_send_info *info, info->error= ER_MASTER_FATAL_ERROR_READING_BINLOG; return 1; } - if (!server_id_supplied) - { - info->errmsg= "Misconfigured master - server id was not set"; - info->error= ER_MASTER_FATAL_ERROR_READING_BINLOG; - return 1; - } char search_file_name[FN_REFLEN]; const char *name=search_file_name; @@ -3072,12 +3066,6 @@ int start_slave(THD* thd , Master_info* mi, bool net_report) if (init_master_info(mi,master_info_file_tmp,relay_log_info_file_tmp, 0, thread_mask)) slave_errno=ER_MASTER_INFO; - else if (!server_id_supplied) - { - slave_errno= ER_BAD_SLAVE; net_report= 0; - my_message(slave_errno, "Misconfigured slave: server_id was not set; Fix in config file", - MYF(0)); - } else if (!*mi->host) { slave_errno= ER_BAD_SLAVE; net_report= 0; diff --git a/sql/sql_repl.h b/sql/sql_repl.h index e2000bbca73..4105bdddf4e 100644 --- a/sql/sql_repl.h +++ b/sql/sql_repl.h @@ -36,7 +36,6 @@ struct slave_connection_state; extern my_bool opt_show_slave_auth_info; extern char *master_host, *master_info_file; -extern bool server_id_supplied; extern int max_binlog_dump_events; extern my_bool opt_sporadic_binlog_dump_fail; diff --git a/sql/sys_vars.cc b/sql/sys_vars.cc index db054a635af..4047b5d6781 100644 --- a/sql/sys_vars.cc +++ b/sql/sys_vars.cc @@ -2850,7 +2850,6 @@ static bool fix_server_id(sys_var *self, THD *thd, enum_var_type type) { if (type == OPT_GLOBAL) { - server_id_supplied = 1; thd->variables.server_id= global_system_variables.server_id; /* Historically, server_id was a global variable that is exported to @@ -2867,7 +2866,7 @@ static Sys_var_ulong Sys_server_id( "Uniquely identifies the server instance in the community of " "replication partners", SESSION_VAR(server_id), CMD_LINE(REQUIRED_ARG, OPT_SERVER_ID), - VALID_RANGE(0, UINT_MAX32), DEFAULT(0), BLOCK_SIZE(1), NO_MUTEX_GUARD, + VALID_RANGE(1, UINT_MAX32), DEFAULT(1), BLOCK_SIZE(1), NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(check_has_super), ON_UPDATE(fix_server_id)); static Sys_var_mybool Sys_slave_compressed_protocol(