summaryrefslogtreecommitdiff
path: root/sql/repl_failsafe.cc
diff options
context:
space:
mode:
Diffstat (limited to 'sql/repl_failsafe.cc')
-rw-r--r--sql/repl_failsafe.cc158
1 files changed, 58 insertions, 100 deletions
diff --git a/sql/repl_failsafe.cc b/sql/repl_failsafe.cc
index 68c7158e9e5..e7873b185c5 100644
--- a/sql/repl_failsafe.cc
+++ b/sql/repl_failsafe.cc
@@ -38,13 +38,21 @@
#include "log_event.h"
#include <mysql.h>
-#define SLAVE_LIST_CHUNK 128
-#define SLAVE_ERRMSG_SIZE (FN_REFLEN+64)
+
+struct Slave_info
+{
+ uint32 server_id;
+ uint32 master_id;
+ char host[HOSTNAME_LENGTH*SYSTEM_CHARSET_MBMAXLEN+1];
+ char user[USERNAME_LENGTH+1];
+ char password[MAX_PASSWORD_LENGTH*SYSTEM_CHARSET_MBMAXLEN+1];
+ uint16 port;
+};
+Atomic_counter<uint32_t> binlog_dump_thread_count;
ulong rpl_status=RPL_NULL;
mysql_mutex_t LOCK_rpl_status;
-HASH slave_list;
const char *rpl_role_type[] = {"MASTER","SLAVE",NullS};
TYPELIB rpl_role_typelib = {array_elements(rpl_role_type)-1,"",
@@ -81,33 +89,26 @@ void change_rpl_status(ulong from_status, ulong to_status)
errmsg= msg;\
goto err; \
}\
- strmake(obj,(char*) p,len); \
+ ::strmake(obj, (char*) p, len); \
p+= len; \
}\
-void unregister_slave(THD* thd, bool only_mine, bool need_mutex)
+void THD::unregister_slave()
{
- uint32 thd_server_id= thd->variables.server_id;
- if (thd_server_id)
+ if (auto old_si= slave_info)
{
- if (need_mutex)
- mysql_mutex_lock(&LOCK_slave_list);
-
- SLAVE_INFO* old_si;
- if ((old_si = (SLAVE_INFO*)my_hash_search(&slave_list,
- (uchar*)&thd_server_id, 4)) &&
- (!only_mine || old_si->thd == thd))
- my_hash_delete(&slave_list, (uchar*)old_si);
-
- if (need_mutex)
- mysql_mutex_unlock(&LOCK_slave_list);
+ mysql_mutex_lock(&LOCK_thd_data);
+ slave_info= 0;
+ mysql_mutex_unlock(&LOCK_thd_data);
+ delete old_si;
+ binlog_dump_thread_count--;
}
}
/**
- Register slave in 'slave_list' hash table.
+ Register slave
@return
0 ok
@@ -115,19 +116,18 @@ void unregister_slave(THD* thd, bool only_mine, bool need_mutex)
1 Error. Error message sent to client
*/
-int register_slave(THD* thd, uchar* packet, size_t packet_length)
+int THD::register_slave(uchar *packet, size_t packet_length)
{
- int res;
- SLAVE_INFO *si;
+ Slave_info *si;
uchar *p= packet, *p_end= packet + packet_length;
const char *errmsg= "Wrong parameters to function register_slave";
- if (check_access(thd, REPL_SLAVE_ACL, any_db, NULL, NULL, 0, 0))
+ if (check_access(this, REPL_SLAVE_ACL, any_db, NULL, NULL, 0, 0))
+ return 1;
+ if (!(si= new Slave_info))
return 1;
- if (!(si = (SLAVE_INFO*)my_malloc(sizeof(SLAVE_INFO), MYF(MY_WME))))
- goto err2;
- thd->variables.server_id= si->server_id= uint4korr(p);
+ variables.server_id= si->server_id= uint4korr(p);
p+= 4;
get_object(p,si->host, "Failed to register slave: too long 'report-host'");
get_object(p,si->user, "Failed to register slave: too long 'report-user'");
@@ -146,77 +146,54 @@ int register_slave(THD* thd, uchar* packet, size_t packet_length)
p += 4;
if (!(si->master_id= uint4korr(p)))
si->master_id= global_system_variables.server_id;
- si->thd= thd;
- mysql_mutex_lock(&LOCK_slave_list);
- unregister_slave(thd,0,0);
- res= my_hash_insert(&slave_list, (uchar*) si);
- mysql_mutex_unlock(&LOCK_slave_list);
- return res;
+ unregister_slave();
+ mysql_mutex_lock(&LOCK_thd_data);
+ slave_info= si;
+ mysql_mutex_unlock(&LOCK_thd_data);
+ binlog_dump_thread_count++;
+ return 0;
err:
- my_free(si);
+ delete si;
my_message(ER_UNKNOWN_ERROR, errmsg, MYF(0)); /* purecov: inspected */
-err2:
return 1;
}
-extern "C" uint32
-*slave_list_key(SLAVE_INFO* si, size_t *len,
- my_bool not_used __attribute__((unused)))
-{
- *len = 4;
- return &si->server_id;
-}
-extern "C" void slave_info_free(void *s)
+bool THD::is_binlog_dump_thread()
{
- my_free(s);
-}
-
-#ifdef HAVE_PSI_INTERFACE
-static PSI_mutex_key key_LOCK_slave_list;
+ mysql_mutex_lock(&LOCK_thd_data);
+ bool res= slave_info != NULL;
+ mysql_mutex_unlock(&LOCK_thd_data);
-static PSI_mutex_info all_slave_list_mutexes[]=
-{
- { &key_LOCK_slave_list, "LOCK_slave_list", PSI_FLAG_GLOBAL}
-};
-
-static void init_all_slave_list_mutexes(void)
-{
- const char* category= "sql";
- int count;
-
- if (PSI_server == NULL)
- return;
-
- count= array_elements(all_slave_list_mutexes);
- PSI_server->register_mutex(category, all_slave_list_mutexes, count);
+ return res;
}
-#endif /* HAVE_PSI_INTERFACE */
-void init_slave_list()
-{
-#ifdef HAVE_PSI_INTERFACE
- init_all_slave_list_mutexes();
-#endif
-
- my_hash_init(&slave_list, system_charset_info, SLAVE_LIST_CHUNK, 0, 0,
- (my_hash_get_key) slave_list_key,
- (my_hash_free_key) slave_info_free, 0);
- mysql_mutex_init(key_LOCK_slave_list, &LOCK_slave_list, MY_MUTEX_INIT_FAST);
-}
-void end_slave_list()
+static my_bool show_slave_hosts_callback(THD *thd, Protocol *protocol)
{
- /* No protection by a mutex needed as we are only called at shutdown */
- if (my_hash_inited(&slave_list))
+ my_bool res= FALSE;
+ mysql_mutex_lock(&thd->LOCK_thd_data);
+ if (auto si= thd->slave_info)
{
- my_hash_free(&slave_list);
- mysql_mutex_destroy(&LOCK_slave_list);
+ protocol->prepare_for_resend();
+ protocol->store(si->server_id);
+ protocol->store(si->host, &my_charset_bin);
+ if (opt_show_slave_auth_info)
+ {
+ protocol->store(si->user, &my_charset_bin);
+ protocol->store(si->password, &my_charset_bin);
+ }
+ protocol->store((uint32) si->port);
+ protocol->store(si->master_id);
+ res= protocol->write();
}
+ mysql_mutex_unlock(&thd->LOCK_thd_data);
+ return res;
}
+
/**
Execute a SHOW SLAVE HOSTS statement.
@@ -258,28 +235,9 @@ bool show_slave_hosts(THD* thd)
Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF))
DBUG_RETURN(TRUE);
- mysql_mutex_lock(&LOCK_slave_list);
+ if (server_threads.iterate(show_slave_hosts_callback, protocol))
+ DBUG_RETURN(true);
- for (uint i = 0; i < slave_list.records; ++i)
- {
- SLAVE_INFO* si = (SLAVE_INFO*) my_hash_element(&slave_list, i);
- protocol->prepare_for_resend();
- protocol->store((uint32) si->server_id);
- protocol->store(si->host, &my_charset_bin);
- if (opt_show_slave_auth_info)
- {
- protocol->store(si->user, &my_charset_bin);
- protocol->store(si->password, &my_charset_bin);
- }
- protocol->store((uint32) si->port);
- protocol->store((uint32) si->master_id);
- if (protocol->write())
- {
- mysql_mutex_unlock(&LOCK_slave_list);
- DBUG_RETURN(TRUE);
- }
- }
- mysql_mutex_unlock(&LOCK_slave_list);
my_eof(thd);
DBUG_RETURN(FALSE);
}