diff --git a/mysql-test/main/mysqld--help.test b/mysql-test/main/mysqld--help.test index f918670d319..971983fd66c 100644 --- a/mysql-test/main/mysqld--help.test +++ b/mysql-test/main/mysqld--help.test @@ -27,7 +27,7 @@ perl; large-files-support lower-case-file-system system-time-zone collation-server character-set-server log-tc-size table-cache table-open-cache table-open-cache-instances max-connections - tls-version version.*/; + server-uid tls-version version.*/; # Plugins which may or may not be there: @plugins=qw/innodb archive blackhole federated partition s3 diff --git a/mysql-test/suite/sys_vars/r/sysvars_server_embedded.result b/mysql-test/suite/sys_vars/r/sysvars_server_embedded.result index f7aea1f9f3c..67c9b40ea2d 100644 --- a/mysql-test/suite/sys_vars/r/sysvars_server_embedded.result +++ b/mysql-test/suite/sys_vars/r/sysvars_server_embedded.result @@ -3072,6 +3072,16 @@ NUMERIC_BLOCK_SIZE 1 ENUM_VALUE_LIST NULL READ_ONLY NO COMMAND_LINE_ARGUMENT REQUIRED +VARIABLE_NAME SERVER_UID +VARIABLE_SCOPE GLOBAL +VARIABLE_TYPE VARCHAR +VARIABLE_COMMENT Automatically calculated server unique id hash +NUMERIC_MIN_VALUE NULL +NUMERIC_MAX_VALUE NULL +NUMERIC_BLOCK_SIZE NULL +ENUM_VALUE_LIST NULL +READ_ONLY YES +COMMAND_LINE_ARGUMENT NULL VARIABLE_NAME SKIP_EXTERNAL_LOCKING VARIABLE_SCOPE GLOBAL VARIABLE_TYPE BOOLEAN 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 35734466470..ea1dd7af53b 100644 --- a/mysql-test/suite/sys_vars/r/sysvars_server_notembedded.result +++ b/mysql-test/suite/sys_vars/r/sysvars_server_notembedded.result @@ -3522,6 +3522,16 @@ NUMERIC_BLOCK_SIZE 1 ENUM_VALUE_LIST NULL READ_ONLY NO COMMAND_LINE_ARGUMENT REQUIRED +VARIABLE_NAME SERVER_UID +VARIABLE_SCOPE GLOBAL +VARIABLE_TYPE VARCHAR +VARIABLE_COMMENT Automatically calculated server unique id hash +NUMERIC_MIN_VALUE NULL +NUMERIC_MAX_VALUE NULL +NUMERIC_BLOCK_SIZE NULL +ENUM_VALUE_LIST NULL +READ_ONLY YES +COMMAND_LINE_ARGUMENT NULL VARIABLE_NAME SESSION_TRACK_SCHEMA VARIABLE_SCOPE SESSION VARIABLE_TYPE BOOLEAN diff --git a/plugin/feedback/feedback.cc b/plugin/feedback/feedback.cc index c1794f0987e..619b17499dc 100644 --- a/plugin/feedback/feedback.cc +++ b/plugin/feedback/feedback.cc @@ -26,10 +26,8 @@ namespace feedback { ulong debug_startup_interval, debug_first_interval, debug_interval; #endif -char server_uid_buf[SERVER_UID_SIZE+1]; ///< server uid will be written here - /* backing store for system variables */ -static char *server_uid= server_uid_buf, *url, *http_proxy; +static char *url, *http_proxy; char *user_info; ulong send_timeout, send_retry_wait; @@ -254,9 +252,6 @@ static int init(void *p) PSI_register(cond); PSI_register(thread); - if (calculate_server_uid(server_uid_buf)) - return 1; - prepare_linux_info(); #ifndef DBUG_OFF @@ -362,9 +357,6 @@ static int free(void *p) #define DEFAULT_PROTO "http://" #endif -static MYSQL_SYSVAR_STR(server_uid, server_uid, - PLUGIN_VAR_READONLY | PLUGIN_VAR_NOCMDOPT, - "Automatically calculated server unique id hash.", NULL, NULL, 0); static MYSQL_SYSVAR_STR(user_info, user_info, PLUGIN_VAR_READONLY | PLUGIN_VAR_RQCMDARG, "User specified string that will be included in the feedback report.", @@ -395,7 +387,6 @@ static MYSQL_SYSVAR_ULONG(debug_interval, debug_interval, #endif static struct st_mysql_sys_var* settings[] = { - MYSQL_SYSVAR(server_uid), MYSQL_SYSVAR(user_info), MYSQL_SYSVAR(url), MYSQL_SYSVAR(send_timeout), diff --git a/plugin/feedback/feedback.h b/plugin/feedback/feedback.h index 6021eb85860..30ad1203ae7 100644 --- a/plugin/feedback/feedback.h +++ b/plugin/feedback/feedback.h @@ -25,8 +25,7 @@ int fill_misc_data(THD *thd, TABLE_LIST *tables); int fill_linux_info(THD *thd, TABLE_LIST *tables); int fill_collation_statistics(THD *thd, TABLE_LIST *tables); -static const int SERVER_UID_SIZE= 29; -extern char server_uid_buf[SERVER_UID_SIZE+1], *user_info; +extern char *user_info; int calculate_server_uid(char *); int prepare_linux_info(); diff --git a/plugin/feedback/sender_thread.cc b/plugin/feedback/sender_thread.cc index 74dc5e6ac6e..68aaa4c5dc7 100644 --- a/plugin/feedback/sender_thread.cc +++ b/plugin/feedback/sender_thread.cc @@ -183,7 +183,7 @@ static void send_report(const char *when) str.length(0); str.append(STRING_WITH_LEN("FEEDBACK_SERVER_UID")); str.append('\t'); - str.append(server_uid_buf); + str.append(server_uid); str.append('\n'); str.append(STRING_WITH_LEN("FEEDBACK_WHEN")); str.append('\t'); diff --git a/plugin/feedback/utils.cc b/plugin/feedback/utils.cc index e362446204f..c5d83794c52 100644 --- a/plugin/feedback/utils.cc +++ b/plugin/feedback/utils.cc @@ -412,31 +412,4 @@ int fill_collation_statistics(THD *thd, TABLE_LIST *tables) } return 0; }; - -/** - calculates the server unique identifier - - UID is a base64 encoded SHA1 hash of the MAC address of one of - the interfaces, and the tcp port that the server is listening on -*/ -int calculate_server_uid(char *dest) -{ - uchar rawbuf[2 + 6]; - uchar shabuf[MY_SHA1_HASH_SIZE]; - - int2store(rawbuf, mysqld_port); - if (my_gethwaddr(rawbuf + 2)) - { - sql_print_error("feedback plugin: failed to retrieve the MAC address"); - return 1; - } - - my_sha1((uint8*) shabuf, (char*) rawbuf, sizeof(rawbuf)); - - assert(my_base64_needed_encoded_length(sizeof(shabuf)) <= SERVER_UID_SIZE); - my_base64_encode(shabuf, sizeof(shabuf), dest); - - return 0; -} - } // namespace feedback diff --git a/sql/mysqld.cc b/sql/mysqld.cc index 3eb9e7830c3..7aa90bf357b 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -352,6 +352,8 @@ LEX_STRING opt_init_connect, opt_init_slave; static DYNAMIC_ARRAY all_options; static longlong start_memory_used; +char server_uid[SERVER_UID_SIZE+1]; // server uid will be written here + /* Global variables */ bool opt_bin_log, opt_bin_log_used=0, opt_ignore_builtin_innodb= 0; @@ -1130,6 +1132,8 @@ PSI_file_key key_file_map; PSI_statement_info stmt_info_new_packet; #endif +static int calculate_server_uid(char *dest); + #ifndef EMBEDDED_LIBRARY void net_before_header_psi(struct st_net *net, void *thd, size_t /* unused: count */) { @@ -3872,6 +3876,9 @@ static int init_common_variables() if (IS_SYSVAR_AUTOSIZE(&server_version_ptr)) set_server_version(server_version, sizeof(server_version)); + if (calculate_server_uid(server_uid)) + strmov(server_uid, "unknown"); + mysql_real_data_home_len= uint(strlen(mysql_real_data_home)); sf_leaking_memory= 0; // no memory leaks from now on @@ -4735,8 +4742,10 @@ static int init_server_components() first in error log, for troubleshooting and debugging purposes */ if (!opt_help) - sql_print_information("Starting MariaDB %s source revision %s as process %lu", - server_version, SOURCE_REVISION, (ulong) getpid()); + sql_print_information("Starting MariaDB %s source revision %s " + "server_uid %s as process %lu", + server_version, SOURCE_REVISION, server_uid, + (ulong) getpid()); #ifdef WITH_PERFSCHEMA_STORAGE_ENGINE /* @@ -9849,3 +9858,31 @@ my_thread_id next_thread_id(void) mysql_mutex_unlock(&LOCK_thread_id); return retval; } + + +/** + calculates the server unique identifier + + UID is a base64 encoded SHA1 hash of the MAC address of one of + the interfaces, and the tcp port that the server is listening on +*/ + +static int calculate_server_uid(char *dest) +{ + uchar rawbuf[2 + 6]; + uchar shabuf[MY_SHA1_HASH_SIZE]; + + int2store(rawbuf, mysqld_port); + if (my_gethwaddr(rawbuf + 2)) + { + sql_print_error("feedback plugin: failed to retrieve the MAC address"); + return 1; + } + + my_sha1((uint8*) shabuf, (char*) rawbuf, sizeof(rawbuf)); + + assert(my_base64_needed_encoded_length(sizeof(shabuf)) <= SERVER_UID_SIZE); + my_base64_encode(shabuf, sizeof(shabuf), dest); + + return 0; +} diff --git a/sql/mysqld.h b/sql/mysqld.h index 0624c68e9bd..bb6d32fdee6 100644 --- a/sql/mysqld.h +++ b/sql/mysqld.h @@ -957,6 +957,8 @@ extern my_bool opt_mysql56_temporal_format, strict_password_validation; extern ulong binlog_checksum_options; extern bool max_user_connections_checking; extern ulong opt_binlog_dbug_fsync_sleep; +static const int SERVER_UID_SIZE= 29; +extern char server_uid[SERVER_UID_SIZE+1]; extern uint volatile global_disable_checkpoint; extern my_bool opt_help; diff --git a/sql/sys_vars.cc b/sql/sys_vars.cc index b7866d3d5fa..2a6d0a52cfd 100644 --- a/sql/sys_vars.cc +++ b/sql/sys_vars.cc @@ -3273,6 +3273,14 @@ Sys_server_id( VALID_RANGE(1, UINT_MAX32), DEFAULT(1), BLOCK_SIZE(1), NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(check_server_id), ON_UPDATE(fix_server_id)); +char *server_uid_ptr= &server_uid[0]; + +static Sys_var_charptr Sys_server_uid( + "server_uid", "Automatically calculated server unique id hash", + READ_ONLY GLOBAL_VAR(server_uid_ptr), + CMD_LINE_HELP_ONLY, + DEFAULT(server_uid)); + static Sys_var_on_access_global Sys_slave_compressed_protocol(