summaryrefslogtreecommitdiff
path: root/sql/slave.cc
diff options
context:
space:
mode:
authorunknown <guilhem@mysql.com>2004-03-11 16:23:35 +0100
committerunknown <guilhem@mysql.com>2004-03-11 16:23:35 +0100
commitf808030209e7bd102b6100df04aa7094bc767af2 (patch)
tree90f46c5c76afb57731f6600678fb72189c05d38a /sql/slave.cc
parentc6d91e00bbd103e46d806b1b9aad1963f4cfe18c (diff)
downloadmariadb-git-f808030209e7bd102b6100df04aa7094bc767af2.tar.gz
Fix for BUG#2921 "Replication problem on mutex lock in mySQL-4.0.18":
re-using unused LOCK_active_mi to serialize all administrative commands related to replication: START SLAVE, STOP SLAVE, RESET SLAVE, CHANGE MASTER, init_slave() (replication autostart at server startup), end_slave() (replication autostop at server shutdown), LOAD DATA FROM MASTER. This protects us against a handful of deadlocks (like BUG#2921 when two START SLAVE, but when two STOP SLAVE too). Removing unused variables. sql/item_func.cc: We don't need LOCK_active_mi just to MASTER_POS_WAIT(). sql/repl_failsafe.cc: no need for macro sql/set_var.cc: no need for macro sql/slave.cc: Re-using unused LOCK_active_mi to serialize all administrative commands related to replication: START SLAVE, STOP SLAVE, RESET SLAVE, CHANGE MASTER, init_slave() (replication autostart at server startup), end_slave() (replication autostop at server shutdown), LOAD DATA FROM MASTER. This protects us against a handful of deadlocks. Removing unused variables. sql/slave.h: Re-using LOCK_active_mi to serialize administrative replication commands. Macros unneeded. Removing unneeded variables. sql/sql_parse.cc: found unused variable. Replacing macros. sql/sql_show.cc: replacing macros
Diffstat (limited to 'sql/slave.cc')
-rw-r--r--sql/slave.cc21
1 files changed, 17 insertions, 4 deletions
diff --git a/sql/slave.cc b/sql/slave.cc
index 84f4ff4f3e0..30052e874b3 100644
--- a/sql/slave.cc
+++ b/sql/slave.cc
@@ -34,7 +34,6 @@ typedef bool (*CHECK_KILLED_FUNC)(THD*,void*);
volatile bool slave_sql_running = 0, slave_io_running = 0;
char* slave_load_tmpdir = 0;
MASTER_INFO *active_mi;
-volatile int active_mi_in_use = 0;
HASH replicate_do_table, replicate_ignore_table;
DYNAMIC_ARRAY replicate_wild_do_table, replicate_wild_ignore_table;
bool do_table_inited = 0, ignore_table_inited = 0;
@@ -114,8 +113,12 @@ int init_slave()
{
DBUG_ENTER("init_slave");
- /* This is called when mysqld starts */
-
+ /*
+ This is called when mysqld starts. Before client connections are
+ accepted. However bootstrap may conflict with us if it does START SLAVE.
+ So it's safer to take the lock.
+ */
+ pthread_mutex_lock(&LOCK_active_mi);
/*
TODO: re-write this to interate through the list of files
for multi-master
@@ -160,9 +163,11 @@ int init_slave()
goto err;
}
}
+ pthread_mutex_unlock(&LOCK_active_mi);
DBUG_RETURN(0);
err:
+ pthread_mutex_unlock(&LOCK_active_mi);
DBUG_RETURN(1);
}
@@ -806,7 +811,14 @@ static int end_slave_on_walk(MASTER_INFO* mi, gptr /*unused*/)
void end_slave()
{
- /* This is called when the server terminates, in close_connections(). */
+ /*
+ This is called when the server terminates, in close_connections().
+ It terminates slave threads. However, some CHANGE MASTER etc may still be
+ running presently. If a START SLAVE was in progress, the mutex lock below
+ will make us wait until slave threads have started, and START SLAVE
+ returns, then we terminate them here.
+ */
+ pthread_mutex_lock(&LOCK_active_mi);
if (active_mi)
{
/*
@@ -827,6 +839,7 @@ void end_slave()
delete active_mi;
active_mi= 0;
}
+ pthread_mutex_unlock(&LOCK_active_mi);
}