Commit 2739b5f5 authored by Monty's avatar Monty

MDEV-34494 Add server_uid global variable and add it to error log at startup

The feedback plugin server_uid variable and the calculate_server_uid()
function is moved from feedback/utils.cc to sql/mysqld.cc

server_uid is added as a global variable (shown in 'show variables') and
is written to the error log on server startup together with server version
and server commit id.
parent d8c9c5ea
......@@ -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
......
......@@ -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
......
......@@ -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
......
......@@ -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),
......
......@@ -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();
......
......@@ -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');
......
......@@ -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
......@@ -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;
}
......@@ -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;
......
......@@ -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_var_mybool,
PRIV_SET_SYSTEM_GLOBAL_VAR_SLAVE_COMPRESSED_PROTOCOL>
Sys_slave_compressed_protocol(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment